source: XIOS/dev/branch_yushan/src/group_factory_impl.hpp @ 1101

Last change on this file since 1101 was 1101, checked in by yushan, 7 years ago

From ADA, test_omp (test_client + openmp) OK. Todo: add field_C

  • 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.6 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      printf("SetCurrentContextId OK %d , %d, %s\n", id.size(), CGroupFactory::HasChild(group, id), id);
73      if (id.size() == 0)
74      {
75         boost::shared_ptr<typename U::RelChild> value = CObjectFactory::CreateObject<typename U::RelChild>();
76         printf("boost::shared_ptr<typename U::RelChild> value OK\n");
77         group->childList.insert(group->childList.end(), value.get());
78         printf("group->childList.insert OK\n");
79         group->childMap.insert(std::make_pair(value->getId(), value.get()));
80         printf("group->childMap.insert OK\n");
81         return (value);
82      }
83      else if (CGroupFactory::HasChild(group, id))
84      {
85         printf("has child\n");
86         return (CGroupFactory::GetChild(group, id));
87      }
88      else
89      {
90         boost::shared_ptr<typename U::RelChild> value = CObjectFactory::CreateObject<typename U::RelChild>(id);
91         printf("shared_ptr OK\n");
92         group->childList.insert(group->childList.end(), value.get());
93         printf("childList.insert OK\n");
94         group->childMap.insert(std::make_pair(id, value.get()));
95         printf("childMap.insert OK\n");
96         return (value);
97      }
98   }
99
100   template <typename U>
101      bool CGroupFactory::HasGroup(boost::shared_ptr<U> group, const StdString & id)
102   {  return (group->groupMap.find(id) != group->groupMap.end()); }
103
104   template <typename U>
105      bool CGroupFactory::HasChild(boost::shared_ptr<U> group, const StdString & id)
106   {  return (group->childMap.find(id) != group->childMap.end()); }
107
108   template <typename U>
109      int CGroupFactory::GetGroupNum(boost::shared_ptr<U> group)
110   { return (group->groupList.size()); }
111
112   template <typename U>
113      int CGroupFactory::GetGroupIdNum(boost::shared_ptr<U> group)
114   { return (group->groupMap.size()); }
115
116   template <typename U>
117      int CGroupFactory::GetChildNum(boost::shared_ptr<U> group)
118   { return (group->childList.size()); }
119
120   template <typename U>
121      int CGroupFactory::GetChildIdNum(boost::shared_ptr<U> group)
122   { return (group->childMap.size()); }
123
124   template <typename U>
125      boost::shared_ptr<U>
126         CGroupFactory::GetGroup(boost::shared_ptr<U> group, const StdString & id)
127   {
128      if (!CGroupFactory::HasGroup<U>(group, id))
129         ERROR("CGroupFactory::GetGroup(boost::shared_ptr<U> group, const StdString & id)",
130               << "[ id = " << id << ", U = " << U::GetName() << " ] "
131               << " group is not referenced !");
132      return (group->groupMap[id]->getShared());
133   }
134
135   template <typename U>
136      boost::shared_ptr<typename U::RelChild>
137         CGroupFactory::GetChild(boost::shared_ptr<U> group, const StdString & id)
138   {
139      if (!CGroupFactory::HasChild<U>(group, id))
140         ERROR("CGroupFactory::GetChild(boost::shared_ptr<U> group, const StdString & id)",
141               << "[ id = " << id << ", U = " << U::GetName() << " ] "
142               << " child is not referenced !");
143      return (group->childMap[id]->getShared());
144   }
145
146} // namespace xios
147
148#endif // __XIOS_CGroupFactory_impl__
Note: See TracBrowser for help on using the repository browser.