StdAir Logo  1.00.19
C++ Standard Airline IT Object Library
Loading...
Searching...
No Matches
FacCloneBom.hpp
Go to the documentation of this file.
1#ifndef __STDAIR_FAC_FACCLONEBOM_HPP
2#define __STDAIR_FAC_FACCLONEBOM_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 FacCloneBom : 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 FacCloneBom& instance();
38
42 BOM& clone (const BOM&);
43
44 protected:
49
50 public:
55 clean();
56 }
57
61 void clean();
62
63
64 private:
65 // ///////////////////// Attributes //////////////////
69 static FacCloneBom* _instance;
70
74 BomPool_T _pool;
75 };
76
77
78 // ////////////////////////////////////////////////////////////////////
79 template <typename BOM> FacCloneBom<BOM>* FacCloneBom<BOM>::_instance = NULL;
80
81 // ////////////////////////////////////////////////////////////////////
82 template <typename BOM> FacCloneBom<BOM>& FacCloneBom<BOM>::instance () {
83 if (_instance == NULL) {
84 _instance = new FacCloneBom ();
85 assert (_instance != NULL);
86
88 }
89 return *_instance;
90 }
91
92 // ////////////////////////////////////////////////////////////////////
93 template <typename BOM> void FacCloneBom<BOM>::clean () {
94 // Destroy all the objects
95 for (typename BomPool_T::iterator itBom = _pool.begin();
96 itBom != _pool.end(); ++itBom) {
97 BOM* currentBom_ptr = *itBom;
98 assert (currentBom_ptr != NULL);
99 delete currentBom_ptr; currentBom_ptr = NULL;
100 }
101
102 // Empty the pool.
103 _pool.clear();
104
105 // Reset the static instance.
106 _instance = NULL;
107 }
108
109 // ////////////////////////////////////////////////////////////////////
110 template <typename BOM> BOM& FacCloneBom<BOM>::clone (const BOM& iBom) {
111 BOM* oBom_ptr = new BOM (iBom);
112 assert (oBom_ptr != NULL);
113 _pool.push_back (oBom_ptr);
114 return *oBom_ptr;
115 }
116
117}
118#endif // __STDAIR_FAC_FACCLONEBOM_HPP
Handle on the StdAir library context.
FacBom< BOM > * FacBom< BOM >::_instance
Definition FacBom.hpp:81
Base class for Factory layer.
static FacCloneBom & instance()
BOM & clone(const BOM &)
void registerCloneBomFactory(FacAbstract *)
static FacSupervisor & instance()