Changeset 10624 for code/trunk/src/libraries/util
- Timestamp:
- Oct 4, 2015, 9:12:21 PM (9 years ago)
- Location:
- code/trunk
- Files:
-
- 4 deleted
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk
-
code/trunk/src/libraries/util/CMakeLists.txt
r9765 r10624 26 26 CRC32.cc 27 27 ExprParser.cc 28 Scope.cc29 ScopedSingletonManager.cc30 28 SharedPtr.cc 31 29 Sleep.cc -
code/trunk/src/libraries/util/SharedPtr.h
r8351 r10624 138 138 OtherClass* other3 = new OtherClass(object); // " 139 139 140 } // The S martPtr "object" is destroyed at the end of the scope,140 } // The SharedPtr "object" is destroyed at the end of the scope, 141 141 // but the three instances of OtherClass keep the object alive 142 142 // until they are all destroyed. -
code/trunk/src/libraries/util/Singleton.h
r8858 r10624 52 52 public: 53 53 TestSingleton(); // public constructor because we may want to manage this singleton 54 // with an orxonox::ScopedSingleton Manager (see below)54 // with an orxonox::ScopedSingletonWrapper 55 55 virtual ~TestSingleton(); // public destructor 56 56 … … 68 68 TestSingleton* TestSingleton::singletonPtr_s = NULL; 69 69 @endcode 70 71 Usually a singleton gets created automatically when it is first used, but it will never72 be destroyed (unless the singleton explicitly deletes itself). To allow controlled73 construction and destruction, the singleton can be put within a virtual scope. This is74 done by registering the singleton class with orxonox::ScopedSingletonManager. To75 do so, the ManageScopedSingleton() macro has to be called:76 77 @code78 ManageScopedSingleton(TestSingleton, ScopeID::Graphics, false); // muste be called in a source (*.cc) file79 @endcode80 81 @b Important: If you call ManageScopedSingleton(), you don't have to initialize singletonPtr_s anymore,82 because that's already done by the macro.83 84 Now the singleton TestSingleton gets automatically created if the scope Graphics becomes85 active and also gets destroyed if the scope is deactivated.86 87 Note that not all singletons must register with a scope, but it's recommended.88 70 89 71 If a class inherits from orxonox::Singleton, it also inherits its functions. The most important … … 112 94 #include "UtilPrereqs.h" 113 95 114 #include <cassert>115 96 #include <cstring> 97 #include <typeinfo> 98 99 #include "OrxAssert.h" 116 100 117 101 namespace orxonox … … 134 118 static T& getInstance() 135 119 { 136 assert(T::singletonPtr_s != NULL);120 OrxVerify(T::singletonPtr_s != NULL, "T=" << typeid(T).name()); 137 121 return *T::singletonPtr_s; 138 122 } … … 144 128 } 145 129 146 //! Update method called by ClassSingletonManager (if used)147 void preUpdateSingleton(const Clock& time) { static_cast<T*>(T::singletonPtr_s)->preUpdate(time); }148 //! Empty update method for the static polymorphism149 void preUpdate(const Clock& time) { }150 //! Update method called by ClassSingletonManager (if used)151 void postUpdateSingleton(const Clock& time) { static_cast<T*>(T::singletonPtr_s)->postUpdate(time); }152 //! Empty update method for the static polymorphism153 void postUpdate(const Clock& time) { }154 155 130 protected: 156 131 //! Constructor sets the singleton instance pointer 157 132 Singleton() 158 133 { 159 assert(T::singletonPtr_s == NULL);134 OrxVerify(T::singletonPtr_s == NULL, "T=" << typeid(T).name()); 160 135 T::singletonPtr_s = static_cast<T*>(this); 161 136 } … … 164 139 virtual ~Singleton() 165 140 { 166 assert(T::singletonPtr_s != NULL);141 OrxVerify(T::singletonPtr_s != NULL, "T=" << typeid(T).name()); 167 142 T::singletonPtr_s = NULL; 168 143 } -
code/trunk/src/libraries/util/UtilPrereqs.h
r9550 r10624 62 62 63 63 //----------------------------------------------------------------------- 64 // Enums65 //-----------------------------------------------------------------------66 67 namespace orxonox68 {69 namespace ScopeID70 {71 //!A list of available scopes for the Scope template.72 enum Value73 {74 Root,75 Graphics76 };77 }78 }79 80 //-----------------------------------------------------------------------81 64 // Forward declarations 82 65 //----------------------------------------------------------------------- … … 96 79 class OutputManager; 97 80 class OutputStream; 98 template <ScopeID::Value>99 class Scope;100 template <class, ScopeID::Value>101 class ScopedSingleton;102 81 class ScopeListener; 103 82 template <class T> -
code/trunk/src/libraries/util/output/OutputDefinitions.h
r10317 r10624 170 170 { 171 171 REGISTER_OUTPUT_SUBCONTEXT(misc, executor); 172 REGISTER_OUTPUT_SUBCONTEXT(misc, factory);173 172 REGISTER_OUTPUT_SUBCONTEXT(misc, gui); 174 173 REGISTER_OUTPUT_SUBCONTEXT(misc, overlays);
Note: See TracChangeset
for help on using the changeset viewer.