diff --git a/src/backend/global_preferences.cc b/src/backend/global_preferences.cc index a5f3b23..426f77f 100644 --- a/src/backend/global_preferences.cc +++ b/src/backend/global_preferences.cc @@ -23,6 +23,8 @@ using namespace sgpem; +GlobalPreferences* GlobalPreferences::_instance = NULL; + GlobalPreferences::GlobalPreferences() : _mod_dirs(1, PLUGDIR), _pol_dirs(1, POLDIR) {} @@ -69,3 +71,10 @@ GlobalPreferences::add_policies_dir(const Glib::ustring& poldir) _pol_dirs.insert(_pol_dirs.begin(), poldir); } +GlobalPreferences& +GlobalPreferences::get_instance() +{ + if(_instance == NULL) + _instance = new GlobalPreferences(); + return *_instance; +} diff --git a/src/backend/global_preferences.hh b/src/backend/global_preferences.hh index d48ba93..3c0ccb8 100644 --- a/src/backend/global_preferences.hh +++ b/src/backend/global_preferences.hh @@ -35,7 +35,7 @@ namespace sgpem { #include "config.h" namespace sgpem { - class SG_DLLEXPORT GlobalPreferences : public Singleton + class SG_DLLEXPORT GlobalPreferences /*: public Singleton*/ { friend class Singleton; @@ -51,14 +51,18 @@ namespace sgpem { void add_modules_dir(const Glib::ustring& moddir); void add_policies_dir(const Glib::ustring& poldir); + static GlobalPreferences& get_instance(); + private: GlobalPreferences(); GlobalPreferences(const GlobalPreferences&); GlobalPreferences& operator=(const GlobalPreferences&); - std::vector _mod_dirs; - std::vector _pol_dirs; - }; + std::vector _mod_dirs; + std::vector _pol_dirs; + + static GlobalPreferences* _instance; + }; } #endif diff --git a/src/backend/history.cc b/src/backend/history.cc index 29f2c8d..35ad00d 100644 --- a/src/backend/history.cc +++ b/src/backend/history.cc @@ -23,6 +23,8 @@ using namespace std; using namespace sgpem; using namespace memory; +History* History::_instance = NULL; + /** The constructor sets _total_time_elapsed to -1: this permits to insert the INITIAL STATUS of the simulation which must begin at instant -1 and live for 1 instant. @@ -133,6 +135,12 @@ History::truncate_at(int instant) notify(); } - +History& +History::get_instance() +{ + if(_instance == NULL) + _instance = new History(); + return *_instance; +} diff --git a/src/backend/history.hh b/src/backend/history.hh index 62e5637..943568a 100644 --- a/src/backend/history.hh +++ b/src/backend/history.hh @@ -49,7 +49,7 @@ namespace sgpem */ class History; - class SG_DLLEXPORT History : public Singleton, public ObservedSubject + class SG_DLLEXPORT History : /*public Singleton,*/ public ObservedSubject { friend class Singleton; @@ -85,6 +85,8 @@ namespace sgpem \param instant Desired cutting time. */ virtual void truncate_at(int instant); + + static History& get_instance(); protected: @@ -95,6 +97,7 @@ namespace sgpem private: int _total_time_elapsed; std::vector _slices; + static History* _instance; }; }//~ namespace sgpem diff --git a/src/backend/policies_gatekeeper.cc b/src/backend/policies_gatekeeper.cc index f6d8c02..faf9479 100644 --- a/src/backend/policies_gatekeeper.cc +++ b/src/backend/policies_gatekeeper.cc @@ -34,6 +34,8 @@ using namespace sgpem; typedef vector::iterator ManagerIterator; typedef map::iterator ActiveIterator; +PoliciesGatekeeper* PoliciesGatekeeper::_instance = NULL; + vector PoliciesGatekeeper::get_registered() const { @@ -128,4 +130,12 @@ PoliciesGatekeeper::deactivate_policies(PolicyManager* manager) } } } - + +PoliciesGatekeeper& +PoliciesGatekeeper::get_instance() +{ + if(_instance == NULL) + _instance = new PoliciesGatekeeper(); + return *_instance; +} + diff --git a/src/backend/policies_gatekeeper.hh b/src/backend/policies_gatekeeper.hh index 33fb45b..bde38d3 100644 --- a/src/backend/policies_gatekeeper.hh +++ b/src/backend/policies_gatekeeper.hh @@ -45,7 +45,7 @@ namespace sgpem */ - class SG_DLLEXPORT PoliciesGatekeeper : public Singleton + class SG_DLLEXPORT PoliciesGatekeeper /*: public Singleton*/ { friend class Singleton; @@ -59,6 +59,8 @@ namespace sgpem Policy* get_current_policy(History* history) throw(std::runtime_error); void activate_policy(History* history, Policy* policy); + + static PoliciesGatekeeper& get_instance(); private: PoliciesGatekeeper(); //private constructor. @@ -70,8 +72,9 @@ namespace sgpem std::vector _registered; std::map _active_policies; + static PoliciesGatekeeper* _instance; }; - + }//~ namespace sgpem #endif //POLICIES_GATEKEEPER_HH diff --git a/src/backend/scheduler.cc b/src/backend/scheduler.cc index 236ad78..eba44b8 100644 --- a/src/backend/scheduler.cc +++ b/src/backend/scheduler.cc @@ -29,6 +29,8 @@ using namespace std; using namespace sgpem; using namespace memory; +Scheduler* Scheduler::_instance = NULL; + //private constructor. The parameter is discarded Scheduler::Scheduler() : _policy_manager(PolicyManager::get_registered_manager()) @@ -205,3 +207,10 @@ Scheduler::step_forward() throw(UserInterruptException) } } +Scheduler& +Scheduler::get_instance() +{ + if(_instance == NULL) + _instance = new Scheduler(); + return *_instance; +} diff --git a/src/backend/scheduler.hh b/src/backend/scheduler.hh index 0497e0f..b97dae0 100644 --- a/src/backend/scheduler.hh +++ b/src/backend/scheduler.hh @@ -54,7 +54,7 @@ namespace sgpem */ - class SG_DLLEXPORT Scheduler : public Singleton + class SG_DLLEXPORT Scheduler /*: public Singleton*/ { friend class Singleton; public: @@ -86,13 +86,16 @@ namespace sgpem Returns the policy that will be used to generate the simulation at the next instant. \return the policy that will be used to generate the simulation at the next instant. */ - Policy& get_policy(); + Policy& get_policy(); + + static Scheduler& get_instance(); private: Scheduler(); //private constructor. SchedulableQueue _ready_queue; PolicyManager& _policy_manager; + static Scheduler* _instance; }; }//~ namespace sgpem