Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/modules/pickup/PickupCollectionIdentifier.cc @ 6987

Last change on this file since 6987 was 6538, checked in by dafrick, 15 years ago

Done some (almost final) documenting in pickup module.

File size: 3.9 KB
Line 
1/*
2 *   ORXONOX - the hottest 3D action shooter ever to exist
3 *                    > www.orxonox.net <
4 *
5 *
6 *   License notice:
7 *
8 *   This program is free software; you can redistribute it and/or
9 *   modify it under the terms of the GNU General Public License
10 *   as published by the Free Software Foundation; either version 2
11 *   of the License, or (at your option) any later version.
12 *
13 *   This program is distributed in the hope that it will be useful,
14 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
15 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 *   GNU General Public License for more details.
17 *
18 *   You should have received a copy of the GNU General Public License
19 *   along with this program; if not, write to the Free Software
20 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
21 *
22 *   Author:
23 *      Damian 'Mozork' Frick
24 *   Co-authors:
25 *      ...
26 *
27*/
28
29/**
30    @file PickupCollectionIdentifier.cc
31    @brief Implementation of PickupCollectionIdentifier.
32*/
33
34#include "core/CoreIncludes.h"
35
36#include "PickupCollectionIdentifier.h"
37
38namespace orxonox
39{
40   
41    /**
42    @brief
43        Constructor. Registers the object.
44    */
45    PickupCollectionIdentifier::PickupCollectionIdentifier(Pickupable* pickup) : PickupIdentifier(pickup)
46    {
47        RegisterObject(PickupCollectionIdentifier);
48    }
49   
50    /**
51    @brief
52        Destructor.
53    */
54    PickupCollectionIdentifier::~PickupCollectionIdentifier()
55    {
56       
57    }
58
59    /**
60    @brief
61        Compares a PickupCollectionIdentifier with a PickupIdentifier and returns 0 if a == b, <0 if a < b and >0 if a > b for a.compare(b), where a is a PickupCollectionIdentifier and b is just some PickupIdentifier.
62    @param identifier
63        Pointer to the second PickupIdentifier, b.
64    @return
65        Returns an integer. 0 if the two compared PickupIdentifiers are the same, <0 if a < b and >0 if a > b.
66    */
67    int PickupCollectionIdentifier::compare(const PickupIdentifier* identifier) const
68    {
69        //! Slight un-niceity to cast the PickupIdentifier to a PickupCollectionIdentifier.
70        PickupIdentifier* temp = const_cast<PickupIdentifier*>(identifier);
71        const PickupCollectionIdentifier* collectionIdentifier = dynamic_cast<PickupCollectionIdentifier*>(temp);
72       
73        //! If the input PickupIdentifier 'identifier' is no PickupCollectionIdentifier then just the two PickupIdentifiers are compared.
74        if(collectionIdentifier == NULL)
75        {
76            return this->PickupIdentifier::compare(identifier);
77        }
78       
79        //! If the number of Pickupables each of the two PickupCollectionIdentifiers contain differ, the one with less is considered smaller.
80        if(this->identifiers_.size() != collectionIdentifier->identifiers_.size())
81            return this->identifiers_.size()-collectionIdentifier->identifiers_.size();
82       
83        //! Compare the Pickupables of the two PickupCollectionIdentifiers one after the other. the one with the first 'smaller' one is considered smaller.
84        std::set<const PickupIdentifier*, PickupIdentifierCompare>::const_iterator it2 = collectionIdentifier->identifiers_.begin();
85        for(std::set<const PickupIdentifier*, PickupIdentifierCompare>::const_iterator it = this->identifiers_.begin(); it != this->identifiers_.end(); it++)
86        {
87           
88            if((*it)->compare(*it2) < 0)
89                return -1;
90            if((*it2)->compare(*it) < 0)
91                return 1;
92        }
93       
94        //! Means they are equal.
95        return 0;
96    }
97   
98    /**
99    @brief
100        Add a Pickupable to the PickupCollectionIdentifier.
101    @param
102        A pointer to the PickupIdentifier of the Pickupable to be added.
103    */
104    void PickupCollectionIdentifier::addPickup(const PickupIdentifier* identifier)
105    {
106        this->identifiers_.insert(identifier);
107    }
108   
109}
110
Note: See TracBrowser for help on using the repository browser.