StdAir Logo  1.00.19
C++ Standard Airline IT Object Library
Loading...
Searching...
No Matches
FacBom.hpp
Go to the documentation of this file.
1#ifndef __STDAIR_FAC_FACBOM_HPP
2#define __STDAIR_FAC_FACBOM_HPP
3
4// //////////////////////////////////////////////////////////////////////
5// Import section
6// //////////////////////////////////////////////////////////////////////
7// STL
8#include <cassert>
9#include <string>
10#include <list>
11// StdAir
15
16namespace stdair {
17
21 template <typename BOM>
22 class FacBom : public FacAbstract {
23
25 typedef std::list<BOM*> BomPool_T;
26 typedef typename BOM::Key_T Key_T;
27
28
29 public:
30 // ///////////// Business methods ////////////
37 static FacBom& instance();
38
42 BOM& create ();
43 BOM& create (const Key_T&);
44 BOM& create (const BOM&);
45
46 protected:
50 FacBom() {}
51
52 public:
57 clean();
58 }
59
63 void clean();
64
65
66 private:
67 // ///////////////////// Attributes //////////////////
71 static FacBom* _instance;
72
76 BomPool_T _pool;
77 };
78
79
80 // ////////////////////////////////////////////////////////////////////
81 template <typename BOM> FacBom<BOM>* FacBom<BOM>::_instance = NULL;
82
83 // ////////////////////////////////////////////////////////////////////
84 template <typename BOM> FacBom<BOM>& FacBom<BOM>::instance () {
85 if (_instance == NULL) {
86 _instance = new FacBom ();
87 assert (_instance != NULL);
88
90 }
91 return *_instance;
92 }
93
94 // ////////////////////////////////////////////////////////////////////
95 template <typename BOM> void FacBom<BOM>::clean () {
96 // Destroy all the objects
97 for (typename BomPool_T::iterator itBom = _pool.begin();
98 itBom != _pool.end(); ++itBom) {
99 BOM* currentBom_ptr = *itBom;
100 assert (currentBom_ptr != NULL);
101 delete currentBom_ptr; currentBom_ptr = NULL;
102 }
103
104 // Empty the pool.
105 _pool.clear();
106
107 // Reset the static instance.
108 _instance = NULL;
109 }
110
111 // ////////////////////////////////////////////////////////////////////
112 template <typename BOM> BOM& FacBom<BOM>::create () {
113 Key_T lKey;
114 return instance().create (lKey);
115 }
116
117 // ////////////////////////////////////////////////////////////////////
118 template <typename BOM> BOM& FacBom<BOM>::create (const Key_T& iKey) {
119 BOM* oBom_ptr = new BOM (iKey);
120 assert (oBom_ptr != NULL);
121 _pool.push_back (oBom_ptr);
122 return *oBom_ptr;
123 }
124
125 // ////////////////////////////////////////////////////////////////////
126 template <typename BOM> BOM& FacBom<BOM>::create (const BOM& iBom) {
127 BOM* oBom_ptr = new BOM (iBom);
128 assert (oBom_ptr != NULL);
129 _pool.push_back (oBom_ptr);
130 return *oBom_ptr;
131 }
132
133}
134#endif // __STDAIR_FAC_FACBOM_HPP
Handle on the StdAir library context.
FacBom< BOM > * FacBom< BOM >::_instance
Definition FacBom.hpp:81
Base class for Factory layer.
Definition FacBom.hpp:22
void clean()
Definition FacBom.hpp:95
BOM & create()
Definition FacBom.hpp:112
static FacBom & instance()
Definition FacBom.hpp:84
void registerPersistentBomFactory(FacAbstract *)
static FacSupervisor & instance()