Changeset 10460
- Timestamp:
- May 24, 2015, 11:19:15 PM (10 years ago)
- Location:
- code/branches/core7
- Files:
-
- 1 added
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/core7/src/libraries/core/singleton/CMakeLists.txt
r10458 r10460 1 1 ADD_SOURCE_FILES(CORE_SRC_FILES 2 2 Scope.cc 3 ScopedSingletonIncludes.cc 3 4 ) -
code/branches/core7/src/libraries/core/singleton/Scope.h
r10458 r10460 76 76 template <ScopeID::Value scope> 77 77 friend class Scope; 78 friend class S copeListener;78 friend class StaticallyInitializedScopedSingletonWrapper; 79 79 80 80 private: … … 95 95 96 96 protected: 97 //! Constructor: Registers the instance. 98 ScopeListener(ScopeID::Value scope) : scope_(scope), bActivated_(false) 99 { ScopeManager::getListeners()[this->scope_].insert(this); } 100 //! Destructor: Unregisters the instance. 101 virtual ~ScopeListener() 102 { ScopeManager::getListeners()[this->scope_].erase(this); } 97 ScopeListener(ScopeID::Value scope) : scope_(scope), bActivated_(false) { } 98 virtual ~ScopeListener() { } 103 99 104 100 //! Gets called if the scope is activated … … 106 102 //! Gets called if the scope is deactivated 107 103 virtual void deactivated() = 0; 104 105 public: 106 inline ScopeID::Value getScope() const 107 { return this->scope_; } 108 108 109 109 private: -
code/branches/core7/src/libraries/core/singleton/ScopedSingletonIncludes.h
r10459 r10460 83 83 StaticallyInitializedScopedSingletonWrapper(ScopedSingletonWrapper* wrapper) : wrapper_(wrapper) {} 84 84 85 virtual void load() {}86 virtual void unload() {}85 virtual void load(); 86 virtual void unload(); 87 87 88 88 inline ScopedSingletonWrapper& getWrapper() -
code/branches/core7/src/libraries/core/singleton/ScopedSingletonWrapper.h
r10459 r10460 57 57 @brief Base class of ClassScopedSingletonWrapper. 58 58 */ 59 class _CoreExport ScopedSingletonWrapper 59 class _CoreExport ScopedSingletonWrapper : public ScopeListener 60 60 { 61 61 public: 62 62 /// Constructor: Initializes all the values 63 63 ScopedSingletonWrapper(const std::string& className, ScopeID::Value scope) 64 : className_(className)65 , scope_(scope)64 : ScopeListener(scope) 65 , className_(className) 66 66 { } 67 67 virtual ~ScopedSingletonWrapper() { } … … 69 69 protected: 70 70 const std::string className_; ///< The name of the scoped singleton class that is managed by this object 71 const ScopeID::Value scope_; ///< The scope of the singleton that is managed by this object72 71 }; 73 72 … … 89 88 */ 90 89 template <class T, ScopeID::Value scope, bool allowedToFail> 91 class ClassScopedSingletonWrapper : public ScopedSingletonWrapper , public ScopeListener90 class ClassScopedSingletonWrapper : public ScopedSingletonWrapper 92 91 { 93 92 public: … … 95 94 ClassScopedSingletonWrapper(const std::string& className) 96 95 : ScopedSingletonWrapper(className, scope) 97 , ScopeListener(scope)98 96 , singletonPtr_(NULL) 99 97 { … … 145 143 */ 146 144 template <class T, ScopeID::Value scope> 147 class ClassScopedSingletonWrapper<T, scope, true> : public ScopedSingletonWrapper , public ScopeListener145 class ClassScopedSingletonWrapper<T, scope, true> : public ScopedSingletonWrapper 148 146 { 149 147 public: … … 151 149 ClassScopedSingletonWrapper(const std::string& className) 152 150 : ScopedSingletonWrapper(className, scope) 153 , ScopeListener(scope)154 151 , singletonPtr_(NULL) 155 152 { -
code/branches/core7/test/core/singleton/ScopeTest.cc
r10459 r10460 1 1 #include <gtest/gtest.h> 2 2 #include "core/singleton/ScopedSingletonIncludes.h" 3 #include "core/module/ModuleInstance.h" 3 4 4 5 namespace orxonox … … 19 20 ManageScopedSingleton(TestSingletonRoot, ScopeID::Root, false); 20 21 ManageScopedSingleton(TestSingletonGraphics, ScopeID::Graphics, false); 22 23 // Fixture 24 class ScopeTest : public ::testing::Test 25 { 26 public: 27 virtual void SetUp() 28 { 29 ModuleInstance::getCurrentModuleInstance()->loadAllStaticallyInitializedInstances(); 30 } 31 32 virtual void TearDown() 33 { 34 ModuleInstance::getCurrentModuleInstance()->unloadAllStaticallyInitializedInstances(); 35 } 36 }; 21 37 } 22 38 23 TEST (Scope, ScopesDoNotExist)39 TEST_F(ScopeTest, ScopesDoNotExist) 24 40 { 25 41 EXPECT_FALSE(Scope<ScopeID::Root>::isActive()); … … 27 43 } 28 44 29 TEST (Scope, SingletonsDoNotExist)45 TEST_F(ScopeTest, SingletonsDoNotExist) 30 46 { 31 47 EXPECT_FALSE(TestSingletonRoot::exists()); … … 33 49 } 34 50 35 TEST (Scope, RootScope)51 TEST_F(ScopeTest, RootScope) 36 52 { 37 53 EXPECT_FALSE(Scope<ScopeID::Root>::isActive()); … … 43 59 } 44 60 45 TEST (DISABLED_Scope,RootAndGraphicsScope)61 TEST_F(ScopeTest, DISABLED_RootAndGraphicsScope) 46 62 { 47 63 EXPECT_FALSE(Scope<ScopeID::Graphics>::isActive()); … … 58 74 } 59 75 60 TEST (Scope, RootSingleton)76 TEST_F(ScopeTest, RootSingleton) 61 77 { 62 78 EXPECT_FALSE(TestSingletonRoot::exists()); … … 68 84 } 69 85 70 TEST (DISABLED_Scope,RootAndGraphicsSingleton)86 TEST_F(ScopeTest, DISABLED_RootAndGraphicsSingleton) 71 87 { 72 88 EXPECT_FALSE(TestSingletonGraphics::exists());
Note: See TracChangeset
for help on using the changeset viewer.