Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Oct 4, 2009, 12:02:28 AM (15 years ago)
Author:
rgrieder
Message:

Modified Scoped Singleton concept: Derive from Singleton normally, but place an important pre-main() instruction in the source file: ManageScopedSingleton(className, scope) (it's a macro).
This causes the Singleton to be created and destroyed with the Scope. Thus if a Singleton c'tor throws, it is much easier to react accordingly.

Location:
code/branches/core5/src/libraries/util
Files:
1 deleted
2 edited

Legend:

Unmodified
Added
Removed
  • code/branches/core5/src/libraries/util/Scope.h

    r5858 r5867  
    7373            //! Gets called if the scope is deactivated
    7474            virtual void deactivated() = 0;
    75             //! Gets called if the scope is updated
    76             virtual void updated(const Clock& time) = 0;
    7775
    7876        private:
     
    124122                return (ScopeManager::instanceCounts_s[scope] > 0);
    125123            }
    126 
    127             //! Update method for the ScopeListeners (to implement singleton updates)
    128             static void update(const Clock& time)
    129             {
    130                 if (isActive())
    131                 {
    132                     for (typename std::set<ScopeListener*>::iterator it = ScopeManager::listeners_s[scope].begin(); it != ScopeManager::listeners_s[scope].end(); )
    133                         (*(it++))->updated(time);
    134                 }
    135             }
    136124    };
    137125}
  • code/branches/core5/src/libraries/util/Singleton.h

    r5738 r5867  
    5555        }
    5656
     57        //! Update method called by ClassSingletonManager (if used)
     58        void updateSingleton(const Clock& time) { static_cast<T*>(T::singletonPtr_s)->update(time); }
     59        //! Empty update method for the static polymorphism
     60        void update(const Clock& time) { }
     61
    5762    protected:
    5863        //! Constructor sets the singleton instance pointer
Note: See TracChangeset for help on using the changeset viewer.