Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Mar 16, 2010, 6:15:45 PM (14 years ago)
Author:
dafrick
Message:

Done some (almost final) documenting in pickup module.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/trunk/src/modules/pickup/PickupCollection.cc

    r6533 r6538  
    2828
    2929/**
    30     @file
     30    @file PickupCollection.cc
    3131    @brief Implementation of PickupCollection.
    3232*/
    3333
    34 #include "PickupCollection.h"
    35 
    3634#include "core/CoreIncludes.h"
    37 #include "core/Template.h"
    3835#include "core/XMLPort.h"
    3936#include "interfaces/PickupCarrier.h"
    4037#include "DroppedPickup.h"
    41 
    4238#include "PickupCollectionIdentifier.h"
     39
     40#include "PickupCollection.h"
    4341
    4442namespace orxonox
     
    6058    /**
    6159    @brief
    62         Destructor.
     60        Destructor. Iterates through all Pickupables this PickupCollection consists of and destroys them if they haven't been already.
    6361    */
    6462    PickupCollection::~PickupCollection()
     
    8583    }
    8684   
     85    /**
     86    @brief
     87        Initializes the PickupIdentifier for this pickup.
     88    */
    8789    void PickupCollection::initializeIdentifier(void)
    8890    {
     
    9395    }
    9496   
     97    /**
     98    @brief
     99        Is called when the pickup has transited from used to unused or the other way around.
     100        Any Class overwriting this method must call its SUPER function by adding SUPER(Classname, changedUsed); to their changdeUsed method.
     101    */
     102    void PickupCollection::changedUsed(void)
     103    {
     104        SUPER(PickupCollection, changedUsed);
     105       
     106        //! Change used for all Pickupables this PickupCollection consists of.
     107        for(std::vector<WeakPtr<Pickupable> >::iterator it = this->pickups_.begin(); it != this->pickups_.end(); it++)
     108        {
     109            (*it).get()->setUsed(this->isUsed());
     110        }
     111    }
     112   
     113    /**
     114    @brief
     115        Is called when the pickup has changed its PickupCarrier.
     116        Any Class overwriting this method must call its SUPER function by adding SUPER(Classname, changedCarrier); to their changedCarrier method.
     117    */
     118    void PickupCollection::changedCarrier(void)
     119    {
     120        SUPER(PickupCollection, changedCarrier);
     121       
     122        //! Change the PickupCarrier for all Pickupables this PickupCollection consists of.
     123        for(std::vector<WeakPtr<Pickupable> >::iterator it = this->pickups_.begin(); it != this->pickups_.end(); it++)
     124        {
     125            (*it).get()->setCarrier(this->getCarrier());
     126        }
     127    }
     128   
     129    /**
     130    @brief
     131        Is called when the pickup has transited from picked up to dropped or the other way around.
     132        Any Class overwriting this method must call its SUPER function by adding SUPER(Classname, changedPickedUp); to their changedPickedUp method.
     133    */
     134    void PickupCollection::changedPickedUp()
     135    {
     136        SUPER(PickupCollection, changedPickedUp);
     137       
     138        //! Change the pickedUp status for all Pickupables this PickupCollection consists of.
     139        for(std::vector<WeakPtr<Pickupable> >::iterator it = this->pickups_.begin(); it != this->pickups_.end(); it++)
     140        {
     141            (*it).get()->setPickedUp(this->isPickedUp());
     142        }
     143    }
     144   
     145    /**
     146    @brief
     147        Creates a duplicate of the input OrxonoxClass.
     148        This method needs to be implemented by any Class inheriting from Pickupable.
     149    @param item
     150        A reference to a pointer to the OrxonoxClass that is to be duplicated.
     151    */
     152    void PickupCollection::clone(OrxonoxClass*& item)
     153    {
     154        if(item == NULL)
     155            item = new PickupCollection(this);
     156       
     157        SUPER(PickupCollection, clone, item);
     158       
     159        PickupCollection* pickup = dynamic_cast<PickupCollection*>(item);
     160        //! Clone allPickupables this PickupCollection consist of.
     161        for(std::vector<WeakPtr<Pickupable> >::iterator it = this->pickups_.begin(); it != this->pickups_.end(); it++)
     162        {
     163            Pickupable* newPickup = (*it).get()->clone();
     164            pickup->addPickupable(newPickup);
     165        }
     166
     167        pickup->initializeIdentifier();
     168    }
     169   
     170    /**
     171    @brief
     172        Get whether a given class, represented by the input Identifier, is a target of this PickupCollection.
     173    @param identifier
     174        A pointer to the PickupIdentifier of the PickupCarrier we want to know of, whether it is a target of this PickupCollection.
     175    @return
     176        Returns true if the PickupCarrier identified by the input PickupIdentififer it is a target of this PickupCollection, false if not.
     177    */
     178    bool PickupCollection::isTarget(Identifier* identifier) const
     179    {
     180        for(std::vector<WeakPtr<Pickupable> >::const_iterator it = this->pickups_.begin(); it != this->pickups_.end(); it++)
     181        {
     182            if(!(*it).get()->isTarget(identifier))
     183                return false;
     184        }
     185       
     186        return true;
     187    }
     188   
     189    /**
     190    @brief
     191        Get the PickupIdentifier of this PickupCollection.
     192        This is in fact the PickupCollectionIdentifier.
     193    @return
     194        Returns a pointer to the PickupIdentifier of this PickupCollection.
     195    */
     196    const PickupIdentifier* PickupCollection::getPickupIdentifier(void)
     197    {
     198        return this->pickupCollectionIdentifier_;
     199    }
     200   
     201    /**
     202    @brief
     203        Add the input Pickupable to list of Pickupables combined by this PickupCollection.
     204    @param pickup
     205        The Pickupable to be added.
     206    @return
     207        Returns true if successful,
     208    */
     209    bool PickupCollection::addPickupable(Pickupable* pickup)
     210    {
     211        if(pickup == NULL)
     212            return false;
     213       
     214        WeakPtr<Pickupable> ptr = pickup; //!< Create a weak pointer to be able to test in the constructor if the Pointer is still valid.
     215        this->pickups_.push_back(ptr);
     216        return true;
     217    }
     218   
     219    /**
     220    @brief
     221        Get the Pickupable at the given index.
     222    @param index
     223        The index the Pickupable is fetched from.
     224    @return
     225        Returns a pointer to the Pickupable at the index given by index.
     226    */
     227    const Pickupable* PickupCollection::getPickupable(unsigned int index)
     228    {
     229        return this->pickups_[index].get();
     230    }
     231       
    95232    /**
    96233    @brief
     
    109246    }
    110247   
    111     /**
    112     @brief
    113         Add the input Pickupable to list of Pickupables combined by this PickupCollection.
    114     @param pickup
    115         The Pickupable to be added.
    116     @return
    117         Returns true if successful,
    118     */
    119     bool PickupCollection::addPickupable(Pickupable* pickup)
    120     {
    121         if(pickup == NULL)
    122             return false;
    123        
    124         WeakPtr<Pickupable> ptr = pickup;
    125         this->pickups_.push_back(ptr);
    126         return true;
    127     }
    128    
    129     /**
    130     @brief
    131         Get the Pickupable at the given index.
    132     @param index
    133         The index the Pickupable is fetched from.
    134     @return
    135         Returns a pointer to the Pickupable at the index given by index.
    136     */
    137     const Pickupable* PickupCollection::getPickupable(unsigned int index)
    138     {
    139         return this->pickups_[index].get(); //TODO. Does this work?
    140     }
    141    
    142     void PickupCollection::changedUsed(void)
    143     {
    144         SUPER(PickupCollection, changedUsed);
    145        
    146         //! Change used for all Pickupables this PickupCollection consists of.
    147         for(std::vector<WeakPtr<Pickupable> >::iterator it = this->pickups_.begin(); it != this->pickups_.end(); it++)
    148         {
    149             (*it).get()->setUsed(this->isUsed());
    150         }
    151     }
    152    
    153     void PickupCollection::changedCarrier(void)
    154     {
    155         SUPER(PickupCollection, changedCarrier);
    156        
    157         //! Change used for all Pickupables this PickupCollection consists of.
    158         for(std::vector<WeakPtr<Pickupable> >::iterator it = this->pickups_.begin(); it != this->pickups_.end(); it++)
    159         {
    160             (*it).get()->setCarrier(this->getCarrier());
    161         }
    162     }
    163    
    164     void PickupCollection::changedPickedUp()
    165     {
    166         SUPER(PickupCollection, changedPickedUp);
    167        
    168         //! Change the carrier for all Pickupables this PickupCollection consists of.
    169         for(std::vector<WeakPtr<Pickupable> >::iterator it = this->pickups_.begin(); it != this->pickups_.end(); it++)
    170         {
    171             (*it).get()->setPickedUp(this->isPickedUp());
    172         }
    173     }
    174    
    175     void PickupCollection::clone(OrxonoxClass*& item)
    176     {
    177         if(item == NULL)
    178             item = new PickupCollection(this);
    179        
    180         SUPER(PickupCollection, clone, item);
    181        
    182         PickupCollection* pickup = dynamic_cast<PickupCollection*>(item);
    183         for(std::vector<WeakPtr<Pickupable> >::iterator it = this->pickups_.begin(); it != this->pickups_.end(); it++)
    184         {
    185             Pickupable* newPickup = (*it).get()->clone();
    186             pickup->addPickupable(newPickup);
    187         }
    188 
    189         pickup->initializeIdentifier();
    190     }
    191    
    192     bool PickupCollection::isTarget(Identifier* identifier) const
    193     {
    194         for(std::vector<WeakPtr<Pickupable> >::const_iterator it = this->pickups_.begin(); it != this->pickups_.end(); it++)
    195         {
    196             if(!(*it).get()->isTarget(identifier))
    197                 return false;
    198         }
    199        
    200         return true;
    201     }
    202    
    203     const PickupIdentifier* PickupCollection::getPickupIdentifier(void)
    204     {
    205         return this->pickupCollectionIdentifier_;
    206     }
    207    
    208248}
Note: See TracChangeset for help on using the changeset viewer.