Changeset 5776 for code/branches/core5
- Timestamp:
- Sep 23, 2009, 11:47:13 PM (15 years ago)
- Location:
- code/branches/core5/src
- Files:
-
- 1 added
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/core5/src/libraries/core/CoreIncludes.h
r5738 r5776 45 45 #include "util/Debug.h" 46 46 #include "Identifier.h" 47 #include "SubclassIdentifier.h" 47 48 #include "Factory.h" 48 49 #include "ClassFactory.h" -
code/branches/core5/src/libraries/core/Identifier.h
r5775 r5776 29 29 /** 30 30 @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. 32 32 33 33 The Identifier contains all needed information about the class it belongs to: … … 45 45 46 46 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.50 47 */ 51 48 … … 508 505 #endif 509 506 } 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 SubclassIdentifier523 {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 Identifier536 */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 SublcassIdentifier545 */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 assign555 @return The SubclassIdentifier itself556 */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 else568 {569 COUT(1) << "Error: Can't assign NULL identifier" << std::endl;570 }571 }572 else573 {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 SublcassIdentifier582 */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*() const593 {594 return this->identifier_;595 }596 597 /**598 @brief Overloading of the -> operator: returns the assigned identifier.599 */600 inline Identifier* operator->() const601 {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*() const609 {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 object616 */617 T* fabricate(BaseObject* creator) const618 {619 BaseObject* newObject = this->identifier_->fabricate(creator);620 621 // Check if the creation was successful622 if (newObject)623 {624 return orxonox_cast<T*>(newObject);625 }626 else627 {628 // Something went terribly wrong629 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 else636 {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() const648 { return this->identifier_; }649 650 private:651 Identifier* identifier_; //!< The assigned identifier652 };653 507 } 654 508 -
code/branches/core5/src/orxonox/gametypes/Gametype.h
r5738 r5776 37 37 38 38 #include "core/BaseObject.h" 39 #include "core/ Identifier.h"39 #include "core/SubclassIdentifier.h" 40 40 #include "tools/interfaces/Tickable.h" 41 41 #include "infos/GametypeInfo.h" -
code/branches/core5/src/orxonox/infos/PlayerInfo.h
r5738 r5776 33 33 34 34 #include "Info.h" 35 #include "core/ Identifier.h"35 #include "core/SubclassIdentifier.h" 36 36 #include "controllers/Controller.h" 37 37
Note: See TracChangeset
for help on using the changeset viewer.