[Orxonox-commit 4903] r9572 - in code/branches/core6/src/libraries/core: . class object
landauf at orxonox.net
landauf at orxonox.net
Sun Mar 24 22:30:39 CET 2013
Author: landauf
Date: 2013-03-24 22:30:39 +0100 (Sun, 24 Mar 2013)
New Revision: 9572
Added:
code/branches/core6/src/libraries/core/object/Listable.cc
code/branches/core6/src/libraries/core/object/Listable.h
Modified:
code/branches/core6/src/libraries/core/CorePrereqs.h
code/branches/core6/src/libraries/core/class/Identifiable.cc
code/branches/core6/src/libraries/core/class/Identifiable.h
code/branches/core6/src/libraries/core/class/Identifier.h
code/branches/core6/src/libraries/core/class/OrxonoxClass.h
code/branches/core6/src/libraries/core/object/CMakeLists.txt
Log:
moved meta-object-list from Identifiable to Listable, a new base class for objects with objectlists (yep)
Modified: code/branches/core6/src/libraries/core/CorePrereqs.h
===================================================================
--- code/branches/core6/src/libraries/core/CorePrereqs.h 2013-03-24 20:03:22 UTC (rev 9571)
+++ code/branches/core6/src/libraries/core/CorePrereqs.h 2013-03-24 21:30:39 UTC (rev 9572)
@@ -160,6 +160,7 @@
template <class T>
class Iterator;
class Language;
+ class Listable;
class LuaFunctor;
class LuaState;
class MemoryArchive;
Modified: code/branches/core6/src/libraries/core/class/Identifiable.cc
===================================================================
--- code/branches/core6/src/libraries/core/class/Identifiable.cc 2013-03-24 20:03:22 UTC (rev 9571)
+++ code/branches/core6/src/libraries/core/class/Identifiable.cc 2013-03-24 21:30:39 UTC (rev 9572)
@@ -47,7 +47,6 @@
{
this->identifier_ = 0;
this->parents_ = 0;
- this->metaList_ = new MetaObjectList();
// Optimisation
this->objectPointers_.reserve(6);
}
@@ -57,26 +56,11 @@
*/
Identifiable::~Identifiable()
{
-// if (!this->requestedDestruction_)
-// orxout(internal_warning) << "Destroyed object without destroy() (" << this->getIdentifier()->getName() << ')' << endl;
-
- this->unregisterObject();
-
// parents_ exists only if isCreatingHierarchy() of the associated Identifier returned true while creating the class
if (this->parents_)
delete this->parents_;
}
- /**
- @brief Removes this object from the object-lists.
- */
- void Identifiable::unregisterObject()
- {
- if (this->metaList_)
- delete this->metaList_;
- this->metaList_ = 0;
- }
-
/// Returns true if the object's class is of the given type or a derivative.
bool Identifiable::isA(const Identifier* identifier)
{ return this->getIdentifier()->isA(identifier); }
Modified: code/branches/core6/src/libraries/core/class/Identifiable.h
===================================================================
--- code/branches/core6/src/libraries/core/class/Identifiable.h 2013-03-24 20:03:22 UTC (rev 9571)
+++ code/branches/core6/src/libraries/core/class/Identifiable.h 2013-03-24 21:30:39 UTC (rev 9572)
@@ -56,8 +56,6 @@
Identifiable();
virtual ~Identifiable();
- void unregisterObject();
-
/// Returns the Identifier of the object.
inline Identifier* getIdentifier() const { return this->identifier_; }
@@ -119,9 +117,8 @@
{ return const_cast<Identifiable*>(this)->getDerivedPointer<T>(classID); }
private:
- Identifier* identifier_; //!< The Identifier of the object
- std::set<const Identifier*>* parents_; //!< List of all parents of the object
- MetaObjectList* metaList_; //!< MetaObjectList, containing all ObjectLists and ObjectListElements the object is registered in
+ Identifier* identifier_; //!< The Identifier of the object
+ std::set<const Identifier*>* parents_; //!< List of all parents of the object
/// 'Fast map' that holds this-pointers of all derived types
std::vector<std::pair<unsigned int, void*> > objectPointers_;
Modified: code/branches/core6/src/libraries/core/class/Identifier.h
===================================================================
--- code/branches/core6/src/libraries/core/class/Identifier.h 2013-03-24 20:03:22 UTC (rev 9571)
+++ code/branches/core6/src/libraries/core/class/Identifier.h 2013-03-24 21:30:39 UTC (rev 9572)
@@ -288,6 +288,9 @@
bool initialiseObject(T* object, const std::string& className, bool bRootClass);
+ void addObjectToList(T* object, Listable*);
+ void addObjectToList(T* object, Identifiable*);
+
void updateConfigValues(bool updateChildren = true) const;
private:
@@ -391,8 +394,7 @@
}
else
{
- orxout(verbose, context::object_list) << "Added object to " << this->getName() << "-list." << endl;
- object->metaList_->add(this->objects_, this->objects_->add(new ObjectListElement<T>(object)));
+ this->addObjectToList(object, object);
// Add pointer of type T to the map in the Identifiable instance that enables "dynamic_casts"
object->objectPointers_.push_back(std::make_pair(this->getClassID(), static_cast<void*>(object)));
@@ -401,6 +403,22 @@
}
/**
+ * @brief Only adds the object to the object list if is a @ref Listable
+ */
+ template <class T>
+ void ClassIdentifier<T>::addObjectToList(T* object, Listable*)
+ {
+ orxout(verbose, context::object_list) << "Added object to " << this->getName() << "-list." << endl;
+ object->metaList_->add(this->objects_, this->objects_->add(new ObjectListElement<T>(object)));
+ }
+
+ template <class T>
+ void ClassIdentifier<T>::addObjectToList(T*, Identifiable*)
+ {
+ // no action
+ }
+
+ /**
@brief Updates the config-values of all existing objects of this class by calling their setConfigValues() function.
*/
template <class T>
Modified: code/branches/core6/src/libraries/core/class/OrxonoxClass.h
===================================================================
--- code/branches/core6/src/libraries/core/class/OrxonoxClass.h 2013-03-24 20:03:22 UTC (rev 9571)
+++ code/branches/core6/src/libraries/core/class/OrxonoxClass.h 2013-03-24 21:30:39 UTC (rev 9572)
@@ -42,7 +42,7 @@
#include "core/CorePrereqs.h"
-#include "Identifiable.h"
+#include "core/object/Listable.h"
#include "core/object/Destroyable.h"
namespace orxonox
@@ -52,7 +52,7 @@
The BaseObject and Interfaces are derived with @c virtual @c public @c OrxonoxClass from OrxonoxClass.
*/
- class _CoreExport OrxonoxClass : public Identifiable, public Destroyable
+ class _CoreExport OrxonoxClass : virtual public Listable, virtual public Destroyable
{
public:
OrxonoxClass();
Modified: code/branches/core6/src/libraries/core/object/CMakeLists.txt
===================================================================
--- code/branches/core6/src/libraries/core/object/CMakeLists.txt 2013-03-24 20:03:22 UTC (rev 9571)
+++ code/branches/core6/src/libraries/core/object/CMakeLists.txt 2013-03-24 21:30:39 UTC (rev 9572)
@@ -2,6 +2,7 @@
Context.cc
ContextObject.cc
Destroyable.cc
+ Listable.cc
MetaObjectList.cc
ObjectListBase.cc
)
Added: code/branches/core6/src/libraries/core/object/Listable.cc
===================================================================
--- code/branches/core6/src/libraries/core/object/Listable.cc (rev 0)
+++ code/branches/core6/src/libraries/core/object/Listable.cc 2013-03-24 21:30:39 UTC (rev 9572)
@@ -0,0 +1,65 @@
+/*
+ * 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 Implementation of Listable.
+*/
+
+#include "Listable.h"
+
+#include "core/object/MetaObjectList.h"
+
+namespace orxonox
+{
+ /**
+ @brief Constructor: creates the meta-object-list.
+ */
+ Listable::Listable()
+ {
+ this->metaList_ = new MetaObjectList();
+ }
+
+ /**
+ @brief Destructor: Removes the object from the object-lists
+ */
+ Listable::~Listable()
+ {
+ this->unregisterObject();
+ }
+
+ /**
+ @brief Removes this object from the object-lists.
+ */
+ void Listable::unregisterObject()
+ {
+ if (this->metaList_)
+ delete this->metaList_;
+ this->metaList_ = 0;
+ }
+}
Property changes on: code/branches/core6/src/libraries/core/object/Listable.cc
___________________________________________________________________
Added: svn:eol-style
+ native
Added: code/branches/core6/src/libraries/core/object/Listable.h
===================================================================
--- code/branches/core6/src/libraries/core/object/Listable.h (rev 0)
+++ code/branches/core6/src/libraries/core/object/Listable.h 2013-03-24 21:30:39 UTC (rev 9572)
@@ -0,0 +1,62 @@
+/*
+ * 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
+ @ingroup Object ObjectList
+ @brief Declaration of Listable, the base of all classes whose instances can be stored in object lists.
+*/
+
+#ifndef _Listable_H__
+#define _Listable_H__
+
+#include "core/CorePrereqs.h"
+#include "core/class/Identifiable.h"
+
+namespace orxonox
+{
+ /**
+ @brief Listable stores the MetaObjectList which is used when storing instances in object lists.
+ */
+ class _CoreExport Listable : virtual public Identifiable
+ {
+ template <class T>
+ friend class ClassIdentifier;
+
+ public:
+ Listable();
+ virtual ~Listable();
+
+ void unregisterObject();
+
+ private:
+ MetaObjectList* metaList_; //!< MetaObjectList, containing all ObjectLists and ObjectListElements the object is registered in
+ };
+}
+
+#endif /* _Listable_H__ */
Property changes on: code/branches/core6/src/libraries/core/object/Listable.h
___________________________________________________________________
Added: svn:eol-style
+ native
More information about the Orxonox-commit
mailing list