Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 5776 for code/branches/core5


Ignore:
Timestamp:
Sep 23, 2009, 11:47:13 PM (15 years ago)
Author:
landauf
Message:

moved SubclassIdentifier to a separate file

Location:
code/branches/core5/src
Files:
1 added
4 edited

Legend:

Unmodified
Added
Removed
  • code/branches/core5/src/libraries/core/CoreIncludes.h

    r5738 r5776  
    4545#include "util/Debug.h"
    4646#include "Identifier.h"
     47#include "SubclassIdentifier.h"
    4748#include "Factory.h"
    4849#include "ClassFactory.h"
  • code/branches/core5/src/libraries/core/Identifier.h

    r5775 r5776  
    2929/**
    3030    @file
    31     @brief Definition of the Identifier, ClassIdentifier and SubclassIdentifier classes, implementation of the ClassIdentifier and SubclassIdentifier classes.
     31    @brief Definition of the Identifier class, definition and implementation of the ClassIdentifier class.
    3232
    3333    The Identifier contains all needed information about the class it belongs to:
     
    4545
    4646    Every Identifier is in fact a ClassIdentifier, but they are derived from Identifier.
    47 
    48     SubclassIdentifier is a separated class, acting like an Identifier, but has a given class.
    49     You can only assign Identifiers of exactly the given class or of a derivative to a SubclassIdentifier.
    5047*/
    5148
     
    508505#endif
    509506    }
    510 
    511 
    512     // ###############################
    513     // ###   SubclassIdentifier    ###
    514     // ###############################
    515     //! The SubclassIdentifier acts almost like an Identifier, but has some prerequisites.
    516     /**
    517         You can only assign an Identifier that belongs to a class T (or derived) to a SubclassIdentifier<T>.
    518         If you assign something else, the program aborts.
    519         Because we know the minimum type, a dynamic_cast is done, which makes it easier to create a new object.
    520     */
    521     template <class T>
    522     class SubclassIdentifier
    523     {
    524         public:
    525             /**
    526                 @brief Constructor: Automaticaly assigns the Identifier of the given class.
    527             */
    528             SubclassIdentifier()
    529             {
    530                 this->identifier_ = ClassIdentifier<T>::getIdentifier();
    531             }
    532 
    533             /**
    534                 @brief Constructor: Assigns the given Identifier.
    535                 @param identifier The Identifier
    536             */
    537             SubclassIdentifier(Identifier* identifier)
    538             {
    539                 this->operator=(identifier);
    540             }
    541 
    542             /**
    543                 @brief Copyconstructor: Assigns the identifier of the other SubclassIdentifier.
    544                 @param identifier The other SublcassIdentifier
    545             */
    546             template <class O>
    547             SubclassIdentifier(const SubclassIdentifier<O>& identifier)
    548             {
    549                 this->operator=(identifier.getIdentifier());
    550             }
    551 
    552             /**
    553                 @brief Overloading of the = operator: assigns the identifier and checks its type.
    554                 @param identifier The Identifier to assign
    555                 @return The SubclassIdentifier itself
    556             */
    557             const SubclassIdentifier<T>& operator=(Identifier* identifier)
    558             {
    559                 if (!identifier || !identifier->isA(ClassIdentifier<T>::getIdentifier()))
    560                 {
    561                     COUT(1) << "An error occurred in SubclassIdentifier (Identifier.h):" << std::endl;
    562                     if (identifier)
    563                     {
    564                         COUT(1) << "Error: Class " << identifier->getName() << " is not a " << ClassIdentifier<T>::getIdentifier()->getName() << "!" << std::endl;
    565                         COUT(1) << "Error: SubclassIdentifier<" << ClassIdentifier<T>::getIdentifier()->getName() << "> = Class(" << identifier->getName() << ") is forbidden." << std::endl;
    566                     }
    567                     else
    568                     {
    569                         COUT(1) << "Error: Can't assign NULL identifier" << std::endl;
    570                     }
    571                 }
    572                 else
    573                 {
    574                     this->identifier_ = identifier;
    575                 }
    576                 return *this;
    577             }
    578 
    579             /**
    580                 @brief Overloading of the = operator: assigns the identifier of the other SubclassIdentifier.
    581                 @param identifier The other SublcassIdentifier
    582             */
    583             template <class O>
    584             const SubclassIdentifier<T>& operator=(const SubclassIdentifier<O>& identifier)
    585             {
    586                 return this->operator=(identifier.getIdentifier());
    587             }
    588 
    589             /**
    590                 @brief Overloading of the * operator: returns the assigned identifier.
    591             */
    592             inline Identifier* operator*() const
    593             {
    594                 return this->identifier_;
    595             }
    596 
    597             /**
    598                 @brief Overloading of the -> operator: returns the assigned identifier.
    599             */
    600             inline Identifier* operator->() const
    601             {
    602                 return this->identifier_;
    603             }
    604 
    605             /**
    606                 @brief Returns the assigned identifier. This allows you to assign a SubclassIdentifier to a normal Identifier*.
    607             */
    608             inline operator Identifier*() const
    609             {
    610                 return this->identifier_;
    611             }
    612 
    613             /**
    614                 @brief Creates a new object of the type of the assigned Identifier and dynamic_casts it to the minimal type given by T.
    615                 @return The new object
    616             */
    617             T* fabricate(BaseObject* creator) const
    618             {
    619                 BaseObject* newObject = this->identifier_->fabricate(creator);
    620 
    621                 // Check if the creation was successful
    622                 if (newObject)
    623                 {
    624                     return orxonox_cast<T*>(newObject);
    625                 }
    626                 else
    627                 {
    628                     // Something went terribly wrong
    629                     if (this->identifier_)
    630                     {
    631                         COUT(1) << "An error occurred in SubclassIdentifier (Identifier.h):" << std::endl;
    632                         COUT(1) << "Error: Class " << this->identifier_->getName() << " is not a " << ClassIdentifier<T>::getIdentifier()->getName() << "!" << std::endl;
    633                         COUT(1) << "Error: Couldn't fabricate a new Object." << std::endl;
    634                     }
    635                     else
    636                     {
    637                         COUT(1) << "An error occurred in SubclassIdentifier (Identifier.h):" << std::endl;
    638                         COUT(1) << "Error: Couldn't fabricate a new Object - Identifier is undefined." << std::endl;
    639                     }
    640 
    641                     assert(false);
    642                     return 0;
    643                 }
    644             }
    645 
    646             /** @brief Returns the assigned identifier. @return The identifier */
    647             inline Identifier* getIdentifier() const
    648                 { return this->identifier_; }
    649 
    650         private:
    651             Identifier* identifier_;            //!< The assigned identifier
    652     };
    653507}
    654508
  • code/branches/core5/src/orxonox/gametypes/Gametype.h

    r5738 r5776  
    3737
    3838#include "core/BaseObject.h"
    39 #include "core/Identifier.h"
     39#include "core/SubclassIdentifier.h"
    4040#include "tools/interfaces/Tickable.h"
    4141#include "infos/GametypeInfo.h"
  • code/branches/core5/src/orxonox/infos/PlayerInfo.h

    r5738 r5776  
    3333
    3434#include "Info.h"
    35 #include "core/Identifier.h"
     35#include "core/SubclassIdentifier.h"
    3636#include "controllers/Controller.h"
    3737
Note: See TracChangeset for help on using the changeset viewer.