[Orxonox-commit 1056] r5776 - in code/branches/core5/src: libraries/core orxonox/gametypes orxonox/infos
landauf at orxonox.net
landauf at orxonox.net
Wed Sep 23 23:47:13 CEST 2009
Author: landauf
Date: 2009-09-23 23:47:13 +0200 (Wed, 23 Sep 2009)
New Revision: 5776
Added:
code/branches/core5/src/libraries/core/SubclassIdentifier.h
Modified:
code/branches/core5/src/libraries/core/CoreIncludes.h
code/branches/core5/src/libraries/core/Identifier.h
code/branches/core5/src/orxonox/gametypes/Gametype.h
code/branches/core5/src/orxonox/infos/PlayerInfo.h
Log:
moved SubclassIdentifier to a separate file
Modified: code/branches/core5/src/libraries/core/CoreIncludes.h
===================================================================
--- code/branches/core5/src/libraries/core/CoreIncludes.h 2009-09-23 21:35:54 UTC (rev 5775)
+++ code/branches/core5/src/libraries/core/CoreIncludes.h 2009-09-23 21:47:13 UTC (rev 5776)
@@ -44,6 +44,7 @@
#include "util/Debug.h"
#include "Identifier.h"
+#include "SubclassIdentifier.h"
#include "Factory.h"
#include "ClassFactory.h"
#include "ObjectList.h"
Modified: code/branches/core5/src/libraries/core/Identifier.h
===================================================================
--- code/branches/core5/src/libraries/core/Identifier.h 2009-09-23 21:35:54 UTC (rev 5775)
+++ code/branches/core5/src/libraries/core/Identifier.h 2009-09-23 21:47:13 UTC (rev 5776)
@@ -28,7 +28,7 @@
/**
@file
- @brief Definition of the Identifier, ClassIdentifier and SubclassIdentifier classes, implementation of the ClassIdentifier and SubclassIdentifier classes.
+ @brief Definition of the Identifier class, definition and implementation of the ClassIdentifier class.
The Identifier contains all needed information about the class it belongs to:
- the name
@@ -44,9 +44,6 @@
To create the class-hierarchy, the Identifier has some intern functions and variables.
Every Identifier is in fact a ClassIdentifier, but they are derived from Identifier.
-
- SubclassIdentifier is a separated class, acting like an Identifier, but has a given class.
- You can only assign Identifiers of exactly the given class or of a derivative to a SubclassIdentifier.
*/
#ifndef _Identifier_H__
@@ -507,149 +504,6 @@
return dynamic_cast<T>(source);
#endif
}
-
-
- // ###############################
- // ### SubclassIdentifier ###
- // ###############################
- //! The SubclassIdentifier acts almost like an Identifier, but has some prerequisites.
- /**
- You can only assign an Identifier that belongs to a class T (or derived) to a SubclassIdentifier<T>.
- If you assign something else, the program aborts.
- Because we know the minimum type, a dynamic_cast is done, which makes it easier to create a new object.
- */
- template <class T>
- class SubclassIdentifier
- {
- public:
- /**
- @brief Constructor: Automaticaly assigns the Identifier of the given class.
- */
- SubclassIdentifier()
- {
- this->identifier_ = ClassIdentifier<T>::getIdentifier();
- }
-
- /**
- @brief Constructor: Assigns the given Identifier.
- @param identifier The Identifier
- */
- SubclassIdentifier(Identifier* identifier)
- {
- this->operator=(identifier);
- }
-
- /**
- @brief Copyconstructor: Assigns the identifier of the other SubclassIdentifier.
- @param identifier The other SublcassIdentifier
- */
- template <class O>
- SubclassIdentifier(const SubclassIdentifier<O>& identifier)
- {
- this->operator=(identifier.getIdentifier());
- }
-
- /**
- @brief Overloading of the = operator: assigns the identifier and checks its type.
- @param identifier The Identifier to assign
- @return The SubclassIdentifier itself
- */
- const SubclassIdentifier<T>& operator=(Identifier* identifier)
- {
- if (!identifier || !identifier->isA(ClassIdentifier<T>::getIdentifier()))
- {
- COUT(1) << "An error occurred in SubclassIdentifier (Identifier.h):" << std::endl;
- if (identifier)
- {
- COUT(1) << "Error: Class " << identifier->getName() << " is not a " << ClassIdentifier<T>::getIdentifier()->getName() << "!" << std::endl;
- COUT(1) << "Error: SubclassIdentifier<" << ClassIdentifier<T>::getIdentifier()->getName() << "> = Class(" << identifier->getName() << ") is forbidden." << std::endl;
- }
- else
- {
- COUT(1) << "Error: Can't assign NULL identifier" << std::endl;
- }
- }
- else
- {
- this->identifier_ = identifier;
- }
- return *this;
- }
-
- /**
- @brief Overloading of the = operator: assigns the identifier of the other SubclassIdentifier.
- @param identifier The other SublcassIdentifier
- */
- template <class O>
- const SubclassIdentifier<T>& operator=(const SubclassIdentifier<O>& identifier)
- {
- return this->operator=(identifier.getIdentifier());
- }
-
- /**
- @brief Overloading of the * operator: returns the assigned identifier.
- */
- inline Identifier* operator*() const
- {
- return this->identifier_;
- }
-
- /**
- @brief Overloading of the -> operator: returns the assigned identifier.
- */
- inline Identifier* operator->() const
- {
- return this->identifier_;
- }
-
- /**
- @brief Returns the assigned identifier. This allows you to assign a SubclassIdentifier to a normal Identifier*.
- */
- inline operator Identifier*() const
- {
- return this->identifier_;
- }
-
- /**
- @brief Creates a new object of the type of the assigned Identifier and dynamic_casts it to the minimal type given by T.
- @return The new object
- */
- T* fabricate(BaseObject* creator) const
- {
- BaseObject* newObject = this->identifier_->fabricate(creator);
-
- // Check if the creation was successful
- if (newObject)
- {
- return orxonox_cast<T*>(newObject);
- }
- else
- {
- // Something went terribly wrong
- if (this->identifier_)
- {
- COUT(1) << "An error occurred in SubclassIdentifier (Identifier.h):" << std::endl;
- COUT(1) << "Error: Class " << this->identifier_->getName() << " is not a " << ClassIdentifier<T>::getIdentifier()->getName() << "!" << std::endl;
- COUT(1) << "Error: Couldn't fabricate a new Object." << std::endl;
- }
- else
- {
- COUT(1) << "An error occurred in SubclassIdentifier (Identifier.h):" << std::endl;
- COUT(1) << "Error: Couldn't fabricate a new Object - Identifier is undefined." << std::endl;
- }
-
- assert(false);
- return 0;
- }
- }
-
- /** @brief Returns the assigned identifier. @return The identifier */
- inline Identifier* getIdentifier() const
- { return this->identifier_; }
-
- private:
- Identifier* identifier_; //!< The assigned identifier
- };
}
#endif /* _Identifier_H__ */
Added: code/branches/core5/src/libraries/core/SubclassIdentifier.h
===================================================================
--- code/branches/core5/src/libraries/core/SubclassIdentifier.h (rev 0)
+++ code/branches/core5/src/libraries/core/SubclassIdentifier.h 2009-09-23 21:47:13 UTC (rev 5776)
@@ -0,0 +1,190 @@
+/*
+ * ORXONOX - the hottest 3D action shooter ever to exist
+ * > www.orxonox.net <
+ *
+ *
+ * License notice:
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Author:
+ * Fabian 'x3n' Landau
+ * Co-authors:
+ * ...
+ *
+ */
+
+/**
+ @file
+ @brief Definition of SubclassIdentifier.
+
+ SubclassIdentifier is a separated class, acting like an Identifier, but has a given class.
+ You can only assign Identifiers of exactly the given class or of a derivative to a SubclassIdentifier.
+*/
+
+#ifndef _SubclassIdentifier_H__
+#define _SubclassIdentifier_H__
+
+#include "CorePrereqs.h"
+
+#include "util/Debug.h"
+#include "Identifier.h"
+
+namespace orxonox
+{
+ // ###############################
+ // ### SubclassIdentifier ###
+ // ###############################
+ //! The SubclassIdentifier acts almost like an Identifier, but has some prerequisites.
+ /**
+ You can only assign an Identifier that belongs to a class T (or derived) to a SubclassIdentifier<T>.
+ If you assign something else, the program aborts.
+ Because we know the minimum type, a dynamic_cast is done, which makes it easier to create a new object.
+ */
+ template <class T>
+ class SubclassIdentifier
+ {
+ public:
+ /**
+ @brief Constructor: Automaticaly assigns the Identifier of the given class.
+ */
+ SubclassIdentifier()
+ {
+ this->identifier_ = ClassIdentifier<T>::getIdentifier();
+ }
+
+ /**
+ @brief Constructor: Assigns the given Identifier.
+ @param identifier The Identifier
+ */
+ SubclassIdentifier(Identifier* identifier)
+ {
+ this->operator=(identifier);
+ }
+
+ /**
+ @brief Copyconstructor: Assigns the identifier of the other SubclassIdentifier.
+ @param identifier The other SublcassIdentifier
+ */
+ template <class O>
+ SubclassIdentifier(const SubclassIdentifier<O>& identifier)
+ {
+ this->operator=(identifier.getIdentifier());
+ }
+
+ /**
+ @brief Overloading of the = operator: assigns the identifier and checks its type.
+ @param identifier The Identifier to assign
+ @return The SubclassIdentifier itself
+ */
+ const SubclassIdentifier<T>& operator=(Identifier* identifier)
+ {
+ if (!identifier || !identifier->isA(ClassIdentifier<T>::getIdentifier()))
+ {
+ COUT(1) << "An error occurred in SubclassIdentifier (Identifier.h):" << std::endl;
+ if (identifier)
+ {
+ COUT(1) << "Error: Class " << identifier->getName() << " is not a " << ClassIdentifier<T>::getIdentifier()->getName() << "!" << std::endl;
+ COUT(1) << "Error: SubclassIdentifier<" << ClassIdentifier<T>::getIdentifier()->getName() << "> = Class(" << identifier->getName() << ") is forbidden." << std::endl;
+ }
+ else
+ {
+ COUT(1) << "Error: Can't assign NULL identifier" << std::endl;
+ }
+ }
+ else
+ {
+ this->identifier_ = identifier;
+ }
+ return *this;
+ }
+
+ /**
+ @brief Overloading of the = operator: assigns the identifier of the other SubclassIdentifier.
+ @param identifier The other SublcassIdentifier
+ */
+ template <class O>
+ const SubclassIdentifier<T>& operator=(const SubclassIdentifier<O>& identifier)
+ {
+ return this->operator=(identifier.getIdentifier());
+ }
+
+ /**
+ @brief Overloading of the * operator: returns the assigned identifier.
+ */
+ inline Identifier* operator*() const
+ {
+ return this->identifier_;
+ }
+
+ /**
+ @brief Overloading of the -> operator: returns the assigned identifier.
+ */
+ inline Identifier* operator->() const
+ {
+ return this->identifier_;
+ }
+
+ /**
+ @brief Returns the assigned identifier. This allows you to assign a SubclassIdentifier to a normal Identifier*.
+ */
+ inline operator Identifier*() const
+ {
+ return this->identifier_;
+ }
+
+ /**
+ @brief Creates a new object of the type of the assigned Identifier and dynamic_casts it to the minimal type given by T.
+ @return The new object
+ */
+ T* fabricate(BaseObject* creator) const
+ {
+ BaseObject* newObject = this->identifier_->fabricate(creator);
+
+ // Check if the creation was successful
+ if (newObject)
+ {
+ return orxonox_cast<T*>(newObject);
+ }
+ else
+ {
+ // Something went terribly wrong
+ if (this->identifier_)
+ {
+ COUT(1) << "An error occurred in SubclassIdentifier (Identifier.h):" << std::endl;
+ COUT(1) << "Error: Class " << this->identifier_->getName() << " is not a " << ClassIdentifier<T>::getIdentifier()->getName() << "!" << std::endl;
+ COUT(1) << "Error: Couldn't fabricate a new Object." << std::endl;
+ }
+ else
+ {
+ COUT(1) << "An error occurred in SubclassIdentifier (Identifier.h):" << std::endl;
+ COUT(1) << "Error: Couldn't fabricate a new Object - Identifier is undefined." << std::endl;
+ }
+
+ assert(false);
+ return 0;
+ }
+ }
+
+ /** @brief Returns the assigned identifier. @return The identifier */
+ inline Identifier* getIdentifier() const
+ { return this->identifier_; }
+
+ private:
+ Identifier* identifier_; //!< The assigned identifier
+ };
+}
+
+#endif /* _SubclassIdentifier_H__ */
Property changes on: code/branches/core5/src/libraries/core/SubclassIdentifier.h
___________________________________________________________________
Added: svn:eol-style
+ native
Modified: code/branches/core5/src/orxonox/gametypes/Gametype.h
===================================================================
--- code/branches/core5/src/orxonox/gametypes/Gametype.h 2009-09-23 21:35:54 UTC (rev 5775)
+++ code/branches/core5/src/orxonox/gametypes/Gametype.h 2009-09-23 21:47:13 UTC (rev 5776)
@@ -36,7 +36,7 @@
#include <string>
#include "core/BaseObject.h"
-#include "core/Identifier.h"
+#include "core/SubclassIdentifier.h"
#include "tools/interfaces/Tickable.h"
#include "infos/GametypeInfo.h"
Modified: code/branches/core5/src/orxonox/infos/PlayerInfo.h
===================================================================
--- code/branches/core5/src/orxonox/infos/PlayerInfo.h 2009-09-23 21:35:54 UTC (rev 5775)
+++ code/branches/core5/src/orxonox/infos/PlayerInfo.h 2009-09-23 21:47:13 UTC (rev 5776)
@@ -32,7 +32,7 @@
#include "OrxonoxPrereqs.h"
#include "Info.h"
-#include "core/Identifier.h"
+#include "core/SubclassIdentifier.h"
#include "controllers/Controller.h"
namespace orxonox
More information about the Orxonox-commit
mailing list