source: XMLIO_V2/dev/dev_rv/src/object_factory_impl.hpp @ 141

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

Mise à jour depuis un autre dépôt

File size: 3.6 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      BOOST_FOREACH(boost::shared_ptr<U> ptr, vect)
44         if (ptr.get() == object)
45            return (ptr);
46      ERROR("CObjectFactory::GetObject(const U * const object)",
47               << "[type = " << U::GetName() << "]"
48               << " object was not found !");
49      return (boost::shared_ptr<U>()); // jamais atteint
50   }
51
52   template <typename U>
53      boost::shared_ptr<U> CObjectFactory::GetObject(const StdString & id)
54   {
55      if (CurrContext.size() == 0)
56         ERROR("CObjectFactory::GetObject(const StdString & id)",
57               << "[ id = " << id << " ] please define current context id !");
58      if (!CObjectFactory::HasObject<U>(id))
59         ERROR("CObjectFactory::GetObject(const StdString & id)",
60               << "[ id = " << id << ", U = " << U::GetName() << " ] "
61               << " object is not referenced !");
62      return (U::AllMapObj[CObjectFactory::CurrContext][id]);
63   }
64
65   template <typename U>
66      boost::shared_ptr<U> CObjectFactory::CreateObject(const StdString & id)
67   {
68      if (CurrContext.size() == 0)
69         ERROR("CObjectFactory::CreateObject(const StdString & id)",
70               << "[ id = " << id << " ] please define current context id !");
71      if (id.size() == 0)
72      {
73         boost::shared_ptr<U> value(new U);
74         U::AllVectObj[CObjectFactory::CurrContext].insert
75            (U::AllVectObj[CObjectFactory::CurrContext].end(), value);
76         return (value);
77      }
78      else if (CObjectFactory::HasObject<U>(id))
79         return (CObjectFactory::GetObject<U>(id));
80      else
81      {
82         boost::shared_ptr<U> value(new U(id));
83         U::AllVectObj[CObjectFactory::CurrContext].insert
84            (U::AllVectObj[CObjectFactory::CurrContext].end(), value);
85         U::AllMapObj[CObjectFactory::CurrContext].insert(std::make_pair(id, value));
86         return (value);
87      }
88   }
89
90   template <typename U>
91      const std::vector<boost::shared_ptr<U> > &
92         CObjectFactory::GetObjectVector(const StdString & context)
93   {
94      return (U::AllVectObj[context]);
95   }
96
97} // namespace xmlioserver
98
99#endif // __XMLIO_CObjectFactory_impl__
Note: See TracBrowser for help on using the repository browser.