source: XIOS/dev/dev_cmip6_omp/src/group_factory_impl.hpp @ 1606

Last change on this file since 1606 was 591, checked in by rlacroix, 9 years ago

Remove leftovers from the XMLIO age.

  • Property copyright set to
    Software name : XIOS (Xml I/O Server)
    http://forge.ipsl.jussieu.fr/ioserver
    Creation date : January 2009
    Licence : CeCCIL version2
    see license file in root directory : Licence_CeCILL_V2-en.txt
    or http://www.cecill.info/licences/Licence_CeCILL_V2-en.html
    Holder : CEA/LSCE (Laboratoire des Sciences du CLimat et de l'Environnement)
    CNRS/IPSL (Institut Pierre Simon Laplace)
    Project Manager : Yann Meurdesoif
    yann.meurdesoif@cea.fr
File size: 5.2 KB
Line 
1#ifndef __XIOS_CGroupFactory_impl__
2#define __XIOS_CGroupFactory_impl__
3
4#include "group_factory.hpp"
5
6namespace xios
7{
8   /// ////////////////////// Définitions ////////////////////// ///
9
10   template <typename U>
11      void CGroupFactory::AddGroup(boost::shared_ptr<U> pgroup,
12                                   boost::shared_ptr<U> cgroup)
13   {
14      if (cgroup.get() == NULL || pgroup.get() == NULL )
15         ERROR("CGroupFactory::AddGroup(boost::shared_ptr<U> pgroup, boost::shared_ptr<U> cgroup)",
16               << " pgroup or cgroup NULL !");
17      if (!cgroup->hasId())
18         pgroup->groupList.insert(pgroup->groupList.end(), cgroup.get());
19      else
20      {
21         pgroup->groupList.insert(pgroup->groupList.end(), cgroup.get());
22         pgroup->groupMap.insert(std::make_pair(cgroup->getId(), cgroup.get()));
23      }
24   }
25
26   template <typename U>
27      void CGroupFactory::AddChild(boost::shared_ptr<U> group,
28                                   boost::shared_ptr<typename U::RelChild> child)
29   {
30      if (group.get() == NULL || child.get() == NULL )
31         ERROR("CGroupFactory::AddGroup(boost::shared_ptr<U> pgroup, boost::shared_ptr<U> cgroup)",
32               << " pgroup or cgroup NULL !");
33      if (!child->hasId())
34         group->childList.insert(group->childList.end(), child.get());
35      else
36      {
37         group->childList.insert(group->childList.end(), child.get());
38         group->childMap.insert(std::make_pair(child->getId(), child.get()));
39      }
40   }
41
42   template <typename U>
43      boost::shared_ptr<U>
44         CGroupFactory::CreateGroup(boost::shared_ptr<U> group, const StdString & id)
45   {
46      CObjectFactory::SetCurrentContextId
47      (CGroupFactory::GetCurrentContextId());
48      if (id.size() == 0)
49      {
50         boost::shared_ptr<U> value = CObjectFactory::CreateObject<U>(CObjectFactory::GenUId<U>());
51         group->groupList.insert(group->groupList.end(), value.get());
52         group->groupMap.insert(std::make_pair(value->getId(), value.get()));
53         return (value);
54      }
55      else if (CGroupFactory::HasGroup(group, id))
56         return (CGroupFactory::GetGroup(group, id));
57      else
58      {
59         boost::shared_ptr<U> value = CObjectFactory::CreateObject<U>(id);
60         group->groupList.insert(group->groupList.end(), value.get());
61         group->groupMap.insert(std::make_pair(id, value.get()));
62         return (value);
63      }
64   }
65
66   template <typename U>
67      boost::shared_ptr<typename U::RelChild>
68         CGroupFactory::CreateChild(boost::shared_ptr<U> group, const StdString & id)
69   {
70      CObjectFactory::SetCurrentContextId
71      (CGroupFactory::GetCurrentContextId());
72      if (id.size() == 0)
73      {
74         boost::shared_ptr<typename U::RelChild> value =
75               CObjectFactory::CreateObject<typename U::RelChild>();
76         group->childList.insert(group->childList.end(), value.get());
77         group->childMap.insert(std::make_pair(value->getId(), value.get()));
78         return (value);
79      }
80      else if (CGroupFactory::HasChild(group, id))
81         return (CGroupFactory::GetChild(group, id));
82      else
83      {
84         boost::shared_ptr<typename U::RelChild> value =
85               CObjectFactory::CreateObject<typename U::RelChild>(id);
86         group->childList.insert(group->childList.end(), value.get());
87         group->childMap.insert(std::make_pair(id, value.get()));
88         return (value);
89      }
90   }
91
92   template <typename U>
93      bool CGroupFactory::HasGroup(boost::shared_ptr<U> group, const StdString & id)
94   {  return (group->groupMap.find(id) != group->groupMap.end()); }
95
96   template <typename U>
97      bool CGroupFactory::HasChild(boost::shared_ptr<U> group, const StdString & id)
98   {  return (group->childMap.find(id) != group->childMap.end()); }
99
100   template <typename U>
101      int CGroupFactory::GetGroupNum(boost::shared_ptr<U> group)
102   { return (group->groupList.size()); }
103
104   template <typename U>
105      int CGroupFactory::GetGroupIdNum(boost::shared_ptr<U> group)
106   { return (group->groupMap.size()); }
107
108   template <typename U>
109      int CGroupFactory::GetChildNum(boost::shared_ptr<U> group)
110   { return (group->childList.size()); }
111
112   template <typename U>
113      int CGroupFactory::GetChildIdNum(boost::shared_ptr<U> group)
114   { return (group->childMap.size()); }
115
116   template <typename U>
117      boost::shared_ptr<U>
118         CGroupFactory::GetGroup(boost::shared_ptr<U> group, const StdString & id)
119   {
120      if (!CGroupFactory::HasGroup<U>(group, id))
121         ERROR("CGroupFactory::GetGroup(boost::shared_ptr<U> group, const StdString & id)",
122               << "[ id = " << id << ", U = " << U::GetName() << " ] "
123               << " group is not referenced !");
124      return (group->groupMap[id]->getShared());
125   }
126
127   template <typename U>
128      boost::shared_ptr<typename U::RelChild>
129         CGroupFactory::GetChild(boost::shared_ptr<U> group, const StdString & id)
130   {
131      if (!CGroupFactory::HasChild<U>(group, id))
132         ERROR("CGroupFactory::GetChild(boost::shared_ptr<U> group, const StdString & id)",
133               << "[ id = " << id << ", U = " << U::GetName() << " ] "
134               << " child is not referenced !");
135      return (group->childMap[id]->getShared());
136   }
137
138} // namespace xios
139
140#endif // __XIOS_CGroupFactory_impl__
Note: See TracBrowser for help on using the repository browser.