Go to the documentation of this file.00001 #ifndef __STDAIR_FAC_FACBOM_HPP
00002 #define __STDAIR_FAC_FACBOM_HPP
00003
00004
00005
00006
00007
00008 #include <cassert>
00009 #include <string>
00010 #include <list>
00011
00012 #include <stdair/factory/FacAbstract.hpp>
00013 #include <stdair/service/FacSupervisor.hpp>
00014 #include <stdair/service/Logger.hpp>
00015
00016 namespace stdair {
00017
00021 template <typename BOM>
00022 class FacBom : public FacAbstract {
00023
00025 typedef std::list<BOM*> BomPool_T;
00026 typedef typename BOM::Key_T Key_T;
00027
00028
00029 public:
00030
00037 static FacBom& instance();
00038
00042 BOM& create ();
00043 BOM& create (const Key_T&);
00044
00045 protected:
00049 FacBom() {}
00050
00051 public:
00055 ~FacBom() {
00056 clean();
00057 }
00058
00062 void clean();
00063
00064
00065 private:
00066
00070 static FacBom* _instance;
00071
00075 BomPool_T _pool;
00076 };
00077
00078
00079
00080 template <typename BOM> FacBom<BOM>* FacBom<BOM>::_instance = NULL;
00081
00082
00083 template <typename BOM> FacBom<BOM>& FacBom<BOM>::instance () {
00084 if (_instance == NULL) {
00085 _instance = new FacBom ();
00086 assert (_instance != NULL);
00087
00088 FacSupervisor::instance().registerBomFactory (_instance);
00089 }
00090 return *_instance;
00091 }
00092
00093
00094 template <typename BOM> void FacBom<BOM>::clean () {
00095
00096 for (typename BomPool_T::iterator itBom = _pool.begin();
00097 itBom != _pool.end(); ++itBom) {
00098 BOM* currentBom_ptr = *itBom;
00099 assert (currentBom_ptr != NULL);
00100 delete currentBom_ptr; currentBom_ptr = NULL;
00101 }
00102
00103
00104 _pool.clear();
00105
00106
00107 _instance = NULL;
00108 }
00109
00110
00111 template <typename BOM> BOM& FacBom<BOM>::create () {
00112 Key_T lKey;
00113 return instance().create (lKey);
00114 }
00115
00116
00117 template <typename BOM> BOM& FacBom<BOM>::create (const Key_T& iKey) {
00118 BOM* oBom_ptr = new BOM (iKey);
00119 assert (oBom_ptr != NULL);
00120 _pool.push_back (oBom_ptr);
00121 return *oBom_ptr;
00122 }
00123
00124 }
00125 #endif // __STDAIR_FAC_FACBOM_HPP