Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 10460 for code/branches


Ignore:
Timestamp:
May 24, 2015, 11:19:15 PM (10 years ago)
Author:
landauf
Message:

StaticallyInitializedScopedSingletonWrapper registers ScopedSingletonWrapper in ScopeManager

Location:
code/branches/core7
Files:
1 added
5 edited

Legend:

Unmodified
Added
Removed
  • code/branches/core7/src/libraries/core/singleton/CMakeLists.txt

    r10458 r10460  
    11ADD_SOURCE_FILES(CORE_SRC_FILES
    22  Scope.cc
     3  ScopedSingletonIncludes.cc
    34)
  • code/branches/core7/src/libraries/core/singleton/Scope.h

    r10458 r10460  
    7676        template <ScopeID::Value scope>
    7777        friend class Scope;
    78         friend class ScopeListener;
     78        friend class StaticallyInitializedScopedSingletonWrapper;
    7979
    8080        private:
     
    9595
    9696        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() { }
    10399
    104100            //! Gets called if the scope is activated
     
    106102            //! Gets called if the scope is deactivated
    107103            virtual void deactivated() = 0;
     104
     105        public:
     106            inline ScopeID::Value getScope() const
     107                { return this->scope_; }
    108108
    109109        private:
  • code/branches/core7/src/libraries/core/singleton/ScopedSingletonIncludes.h

    r10459 r10460  
    8383            StaticallyInitializedScopedSingletonWrapper(ScopedSingletonWrapper* wrapper) : wrapper_(wrapper) {}
    8484
    85             virtual void load() {}
    86             virtual void unload() {}
     85            virtual void load();
     86            virtual void unload();
    8787
    8888            inline ScopedSingletonWrapper& getWrapper()
  • code/branches/core7/src/libraries/core/singleton/ScopedSingletonWrapper.h

    r10459 r10460  
    5757        @brief Base class of ClassScopedSingletonWrapper.
    5858    */
    59     class _CoreExport ScopedSingletonWrapper
     59    class _CoreExport ScopedSingletonWrapper : public ScopeListener
    6060    {
    6161        public:
    6262            /// Constructor: Initializes all the values
    6363            ScopedSingletonWrapper(const std::string& className, ScopeID::Value scope)
    64                 : className_(className)
    65                 , scope_(scope)
     64                : ScopeListener(scope)
     65                , className_(className)
    6666            { }
    6767            virtual ~ScopedSingletonWrapper() { }
     
    6969        protected:
    7070            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 object
    7271    };
    7372
     
    8988    */
    9089    template <class T, ScopeID::Value scope, bool allowedToFail>
    91     class ClassScopedSingletonWrapper : public ScopedSingletonWrapper, public ScopeListener
     90    class ClassScopedSingletonWrapper : public ScopedSingletonWrapper
    9291    {
    9392    public:
     
    9594        ClassScopedSingletonWrapper(const std::string& className)
    9695            : ScopedSingletonWrapper(className, scope)
    97             , ScopeListener(scope)
    9896            , singletonPtr_(NULL)
    9997        {
     
    145143    */
    146144    template <class T, ScopeID::Value scope>
    147     class ClassScopedSingletonWrapper<T, scope, true> : public ScopedSingletonWrapper, public ScopeListener
     145    class ClassScopedSingletonWrapper<T, scope, true> : public ScopedSingletonWrapper
    148146    {
    149147    public:
     
    151149        ClassScopedSingletonWrapper(const std::string& className)
    152150            : ScopedSingletonWrapper(className, scope)
    153             , ScopeListener(scope)
    154151            , singletonPtr_(NULL)
    155152        {
  • code/branches/core7/test/core/singleton/ScopeTest.cc

    r10459 r10460  
    11#include <gtest/gtest.h>
    22#include "core/singleton/ScopedSingletonIncludes.h"
     3#include "core/module/ModuleInstance.h"
    34
    45namespace orxonox
     
    1920        ManageScopedSingleton(TestSingletonRoot, ScopeID::Root, false);
    2021        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        };
    2137    }
    2238
    23     TEST(Scope, ScopesDoNotExist)
     39    TEST_F(ScopeTest, ScopesDoNotExist)
    2440    {
    2541        EXPECT_FALSE(Scope<ScopeID::Root>::isActive());
     
    2743    }
    2844
    29     TEST(Scope, SingletonsDoNotExist)
     45    TEST_F(ScopeTest, SingletonsDoNotExist)
    3046    {
    3147        EXPECT_FALSE(TestSingletonRoot::exists());
     
    3349    }
    3450
    35     TEST(Scope, RootScope)
     51    TEST_F(ScopeTest, RootScope)
    3652    {
    3753        EXPECT_FALSE(Scope<ScopeID::Root>::isActive());
     
    4359    }
    4460
    45     TEST(DISABLED_Scope, RootAndGraphicsScope)
     61    TEST_F(ScopeTest, DISABLED_RootAndGraphicsScope)
    4662    {
    4763        EXPECT_FALSE(Scope<ScopeID::Graphics>::isActive());
     
    5874    }
    5975
    60     TEST(Scope, RootSingleton)
     76    TEST_F(ScopeTest, RootSingleton)
    6177    {
    6278        EXPECT_FALSE(TestSingletonRoot::exists());
     
    6884    }
    6985
    70     TEST(DISABLED_Scope, RootAndGraphicsSingleton)
     86    TEST_F(ScopeTest, DISABLED_RootAndGraphicsSingleton)
    7187    {
    7288        EXPECT_FALSE(TestSingletonGraphics::exists());
Note: See TracChangeset for help on using the changeset viewer.