Changeset 244 for code/branches/objecthierarchie/src/Identifier.h
- Timestamp:
- Nov 25, 2007, 5:21:53 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/objecthierarchie/src/Identifier.h
r243 r244 8 8 #include "Factory.h" 9 9 10 #define HIERARCHY_VERBOSE false10 #define HIERARCHY_VERBOSE true 11 11 12 12 … … 26 26 friend class SubclassIdentifier; 27 27 28 template <class T> 29 friend class ClassFactory; 30 28 31 public: 29 32 virtual void removeObject(OrxonoxClass* object) const = 0; 30 33 virtual void removeObjectIntern(OrxonoxClass* object, bool bIterateForwards) const = 0; 31 34 32 virtual BaseObject* fabricate() const = 0; 35 inline void addFactory(BaseFactory* factory) { this->factory_ = factory; } 36 BaseObject* fabricate(); 33 37 34 38 bool isA(const Identifier* identifier) const; … … 37 41 bool isParentOf(const Identifier* identifier) const; 38 42 39 const std::string& getName() const { return this->name_; }40 const IdentifierList& getParents() const { return this->parents_; }41 IdentifierList& getChildren() const { return *this->children_; }42 43 static bool isCreatingHierarchy() { return (hierarchyCreatingCounter_s > 0); }43 inline const std::string& getName() const { return this->name_; } 44 inline const IdentifierList& getParents() const { return this->parents_; } 45 inline IdentifierList& getChildren() const { return *this->children_; } 46 47 inline static bool isCreatingHierarchy() { return (hierarchyCreatingCounter_s > 0); } 44 48 45 49 private: … … 49 53 void initialize(const IdentifierList* parents); 50 54 51 static void startCreatingHierarchy()55 inline static void startCreatingHierarchy() 52 56 { 53 57 hierarchyCreatingCounter_s++; … … 57 61 } 58 62 59 static void stopCreatingHierarchy()63 inline static void stopCreatingHierarchy() 60 64 { 61 65 hierarchyCreatingCounter_s--; … … 70 74 std::string name_; 71 75 72 bool bIsAbstractClass_;76 BaseFactory* factory_; 73 77 bool bCreatedOneObject_; 74 75 78 static int hierarchyCreatingCounter_s; 76 79 }; … … 87 90 88 91 public: 89 static ClassIdentifier<T>* registerClass(const IdentifierList* parents, const std::string& name, bool bRootClass , bool bIsAbstractClass);92 static ClassIdentifier<T>* registerClass(const IdentifierList* parents, const std::string& name, bool bRootClass); 90 93 static ClassIdentifier<T>* getIdentifier(); 91 BaseObject* fabricate() const;92 T* fabricateClass() const;93 94 static void addObject(T* object); 94 95 void removeObject(OrxonoxClass* object) const; … … 121 122 122 123 template <class T> 123 BaseObject* ClassIdentifier<T>::fabricate() const 124 { 125 return dynamic_cast<BaseObject*>(this->fabricateClass()); 126 } 127 128 template <class T> 129 T* ClassIdentifier<T>::fabricateClass() const 130 { 131 if (!this->bIsAbstractClass_) 132 { 133 return new T; 134 } 135 else 136 { 137 std::cout << "Error: Couldn't create a new Object - Class " << this->name_ << " is abstract!\n"; 138 std::cout << "Aborting...\n"; 139 abort(); 140 } 141 } 142 143 template <class T> 144 ClassIdentifier<T>* ClassIdentifier<T>::registerClass(const IdentifierList* parents, const std::string& name, bool bRootClass, bool bIsAbstractClass) 124 ClassIdentifier<T>* ClassIdentifier<T>::registerClass(const IdentifierList* parents, const std::string& name, bool bRootClass) 145 125 { 146 126 #if HIERARCHY_VERBOSE … … 152 132 std::cout << "*** Register Class in " << name << "-Singleton -> Create Singleton.\n"; 153 133 #endif 154 if (parents || bRootClass)155 {156 pointer_s = new ClassIdentifier(); 157 pointer_s->name_ = name;158 pointer_s->bIsAbstractClass_ = bIsAbstractClass;159 160 ClassFactory::add(name, pointer_s);161 162 if (!bRootClass)163 pointer_s->initialize(parents);164 else 165 pointer_s->initialize(NULL);166 }134 pointer_s = new ClassIdentifier(); 135 } 136 137 if (!pointer_s->bCreatedOneObject_) 138 { 139 #if HIERARCHY_VERBOSE 140 std::cout << "*** Register Class in " << name << "-Singleton -> Initialize Singleton.\n"; 141 #endif 142 pointer_s->name_ = name; 143 Factory::add(name, pointer_s); 144 145 if (bRootClass) 146 pointer_s->initialize(NULL); 167 147 else 168 { 169 pointer_s = getIdentifier(); 170 } 148 pointer_s->initialize(parents); 171 149 } 172 150 … … 177 155 ClassIdentifier<T>* ClassIdentifier<T>::getIdentifier() 178 156 { 179 #if HIERARCHY_VERBOSE180 // std::cout << "*** Get Identifier.\n";181 #endif182 157 if (!pointer_s) 183 158 { 184 159 #if HIERARCHY_VERBOSE 185 std::cout << "*** Get Identifier -> Create Class\n"; 186 #endif 187 Identifier::startCreatingHierarchy(); 188 T* temp = new T(); 189 delete temp; 190 Identifier::stopCreatingHierarchy(); 160 std::cout << "*** Create Singleton.\n"; 161 #endif 162 pointer_s = new ClassIdentifier(); 191 163 } 192 164
Note: See TracChangeset
for help on using the changeset viewer.