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

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

Corrections après tests sur titane

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               << "adress = " << object << "]"
57               << " object was not found !");
58      return (boost::shared_ptr<U>()); // jamais atteint
59   }
60
61   template <typename U>
62      boost::shared_ptr<U> CObjectFactory::GetObject(const StdString & id)
63   {
64      if (CurrContext.size() == 0)
65         ERROR("CObjectFactory::GetObject(const StdString & id)",
66               << "[ id = " << id << " ] please define current context id !");
67      if (!CObjectFactory::HasObject<U>(id))
68         ERROR("CObjectFactory::GetObject(const StdString & id)",
69               << "[ id = " << id << ", U = " << U::GetName() << " ] "
70               << " object is not referenced !");
71      return (U::AllMapObj[CObjectFactory::CurrContext][id]);
72   }
73
74   template <typename U>
75      boost::shared_ptr<U> CObjectFactory::CreateObject(const StdString & id)
76   {
77      if (CurrContext.size() == 0)
78         ERROR("CObjectFactory::CreateObject(const StdString & id)",
79               << "[ id = " << id << " ] please define current context id !");
80      if (id.size() == 0)
81      {
82         boost::shared_ptr<U> value(new U);
83         U::AllVectObj[CObjectFactory::CurrContext].insert
84            (U::AllVectObj[CObjectFactory::CurrContext].end(), value);
85         return (value);
86      }
87      else if (CObjectFactory::HasObject<U>(id))
88      {
89         return (CObjectFactory::GetObject<U>(id));
90      }
91      else
92      {
93         boost::shared_ptr<U> value(new U(id));
94         U::AllVectObj[CObjectFactory::CurrContext].insert
95            (U::AllVectObj[CObjectFactory::CurrContext].end(), value);
96         U::AllMapObj[CObjectFactory::CurrContext].insert(std::make_pair(id, value));
97         return (value);
98      }
99   }
100
101   template <typename U>
102      const std::vector<boost::shared_ptr<U> > &
103         CObjectFactory::GetObjectVector(const StdString & context)
104   {
105      return (U::AllVectObj[context]);
106   }
107
108} // namespace xmlioserver
109
110#endif // __XMLIO_CObjectFactory_impl__
Note: See TracBrowser for help on using the repository browser.