source: XMLIO_V2/dev/common/src/xmlio/object_factory_impl.hpp @ 219

Last change on this file since 219 was 219, checked in by hozdoba, 13 years ago

Préparation nouvelle arborescence

File size: 3.8 KB
Line 
1#ifndef __XMLIO_CObjectFactory_impl__
2#define __XMLIO_CObjectFactory_impl__
3
4namespace xmlioserver
5{
6   /// ////////////////////// Définitions ////////////////////// ///
7   template <typename U>
8       int CObjectFactory::GetObjectNum(void)
9   {
10      if (CurrContext.size() == 0)
11         ERROR("CObjectFactory::GetObjectNum(void)",
12               << "please define current context id !");
13      return (U::AllVectObj[CObjectFactory::CurrContext].size());
14   }
15
16   template <typename U>
17      int CObjectFactory::GetObjectIdNum(void)
18   {
19      if (CurrContext.size() == 0)
20         ERROR("CObjectFactory::GetObjectIdNum(void)",
21               << "please define current context id !");
22      return (U::AllMapObj[CObjectFactory::CurrContext].size());
23   }
24
25   template <typename U>
26      bool CObjectFactory::HasObject(const StdString & id)
27   {
28      if (CurrContext.size() == 0)
29         ERROR("CObjectFactory::HasObject(const StdString & id)",
30               << "[ id = " << id << " ] please define current context id !");
31      return (U::AllMapObj[CObjectFactory::CurrContext].find(id) !=
32              U::AllMapObj[CObjectFactory::CurrContext].end());
33   }
34
35   template <typename U>
36      boost::shared_ptr<U> CObjectFactory::GetObject(const U * const object)
37   {
38      if (CurrContext.size() == 0)
39         ERROR("CObjectFactory::GetObject(const U * const object)",
40               << "please define current context id !");
41      std::vector<boost::shared_ptr<U> > & vect =
42                     U::AllVectObj[CObjectFactory::CurrContext];
43                     
44      typename std::vector<boost::shared_ptr<U> >::const_iterator
45         it = vect.begin(), end = vect.end();
46     
47      for (; it != end; it++)
48      {
49         boost::shared_ptr<U> ptr = *it;
50         if (ptr.get() == object)
51            return (ptr);
52      }
53     
54      ERROR("CObjectFactory::GetObject(const U * const object)",
55               << "[type = " << U::GetName() << "]"
56               << " object was not found !");
57      return (boost::shared_ptr<U>()); // jamais atteint
58   }
59
60   template <typename U>
61      boost::shared_ptr<U> CObjectFactory::GetObject(const StdString & id)
62   {
63      if (CurrContext.size() == 0)
64         ERROR("CObjectFactory::GetObject(const StdString & id)",
65               << "[ id = " << id << " ] please define current context id !");
66      if (!CObjectFactory::HasObject<U>(id))
67         ERROR("CObjectFactory::GetObject(const StdString & id)",
68               << "[ id = " << id << ", U = " << U::GetName() << " ] "
69               << " object is not referenced !");
70      return (U::AllMapObj[CObjectFactory::CurrContext][id]);
71   }
72
73   template <typename U>
74      boost::shared_ptr<U> CObjectFactory::CreateObject(const StdString & id)
75   {
76      if (CurrContext.size() == 0)
77         ERROR("CObjectFactory::CreateObject(const StdString & id)",
78               << "[ id = " << id << " ] please define current context id !");
79      if (id.size() == 0)
80      {
81         boost::shared_ptr<U> value(new U);
82         U::AllVectObj[CObjectFactory::CurrContext].insert
83            (U::AllVectObj[CObjectFactory::CurrContext].end(), value);
84         return (value);
85      }
86      else if (CObjectFactory::HasObject<U>(id))
87      {
88         return (CObjectFactory::GetObject<U>(id));
89      }
90      else
91      {
92         boost::shared_ptr<U> value(new U(id));
93         U::AllVectObj[CObjectFactory::CurrContext].insert
94            (U::AllVectObj[CObjectFactory::CurrContext].end(), value);
95         U::AllMapObj[CObjectFactory::CurrContext].insert(std::make_pair(id, value));
96         return (value);
97      }
98   }
99
100   template <typename U>
101      const std::vector<boost::shared_ptr<U> > &
102         CObjectFactory::GetObjectVector(const StdString & context)
103   {
104      return (U::AllVectObj[context]);
105   }
106
107} // namespace xmlioserver
108
109#endif // __XMLIO_CObjectFactory_impl__
Note: See TracBrowser for help on using the repository browser.