source: XIOS/trunk/src/group_factory_impl.hpp @ 2146

Last change on this file since 2146 was 1542, checked in by oabramkina, 6 years ago

Replacing Boost's unordered_map and shared_pointer by its STL counterparts.

Two notes for Curie:

  • one can see the content of unordered_map with ddt only if XIOS has been compiled with gnu
  • XIOS will not compile any more with pgi (all available versions use old STL which are not up to the c++11 norms)
  • 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.1 KB
RevLine 
[591]1#ifndef __XIOS_CGroupFactory_impl__
2#define __XIOS_CGroupFactory_impl__
[219]3
[352]4#include "group_factory.hpp"
5
[335]6namespace xios
[219]7{
8   /// ////////////////////// Définitions ////////////////////// ///
9
10   template <typename U>
[1542]11      void CGroupFactory::AddGroup(std::shared_ptr<U> pgroup,
12                                   std::shared_ptr<U> cgroup)
[219]13   {
14      if (cgroup.get() == NULL || pgroup.get() == NULL )
[1542]15         ERROR("CGroupFactory::AddGroup(std::shared_ptr<U> pgroup, std::shared_ptr<U> cgroup)",
[219]16               << " pgroup or cgroup NULL !");
17      if (!cgroup->hasId())
[352]18         pgroup->groupList.insert(pgroup->groupList.end(), cgroup.get());
[219]19      else
20      {
[352]21         pgroup->groupList.insert(pgroup->groupList.end(), cgroup.get());
22         pgroup->groupMap.insert(std::make_pair(cgroup->getId(), cgroup.get()));
[219]23      }
24   }
25
26   template <typename U>
[1542]27      void CGroupFactory::AddChild(std::shared_ptr<U> group,
28                                   std::shared_ptr<typename U::RelChild> child)
[219]29   {
30      if (group.get() == NULL || child.get() == NULL )
[1542]31         ERROR("CGroupFactory::AddGroup(std::shared_ptr<U> pgroup, std::shared_ptr<U> cgroup)",
[219]32               << " pgroup or cgroup NULL !");
33      if (!child->hasId())
[347]34         group->childList.insert(group->childList.end(), child.get());
[219]35      else
36      {
[347]37         group->childList.insert(group->childList.end(), child.get());
38         group->childMap.insert(std::make_pair(child->getId(), child.get()));
[219]39      }
40   }
41
42   template <typename U>
[1542]43      std::shared_ptr<U>
44         CGroupFactory::CreateGroup(std::shared_ptr<U> group, const StdString & id)
[219]45   {
46      CObjectFactory::SetCurrentContextId
47      (CGroupFactory::GetCurrentContextId());
48      if (id.size() == 0)
49      {
[1542]50         std::shared_ptr<U> value = CObjectFactory::CreateObject<U>(CObjectFactory::GenUId<U>());
[347]51         group->groupList.insert(group->groupList.end(), value.get());
52         group->groupMap.insert(std::make_pair(value->getId(), value.get()));
[219]53         return (value);
54      }
55      else if (CGroupFactory::HasGroup(group, id))
56         return (CGroupFactory::GetGroup(group, id));
57      else
58      {
[1542]59         std::shared_ptr<U> value = CObjectFactory::CreateObject<U>(id);
[347]60         group->groupList.insert(group->groupList.end(), value.get());
61         group->groupMap.insert(std::make_pair(id, value.get()));
[219]62         return (value);
63      }
64   }
65
66   template <typename U>
[1542]67      std::shared_ptr<typename U::RelChild>
68         CGroupFactory::CreateChild(std::shared_ptr<U> group, const StdString & id)
[219]69   {
70      CObjectFactory::SetCurrentContextId
71      (CGroupFactory::GetCurrentContextId());
72      if (id.size() == 0)
73      {
[1542]74         std::shared_ptr<typename U::RelChild> value =
[219]75               CObjectFactory::CreateObject<typename U::RelChild>();
[347]76         group->childList.insert(group->childList.end(), value.get());
77         group->childMap.insert(std::make_pair(value->getId(), value.get()));
[219]78         return (value);
79      }
80      else if (CGroupFactory::HasChild(group, id))
81         return (CGroupFactory::GetChild(group, id));
82      else
83      {
[1542]84         std::shared_ptr<typename U::RelChild> value =
[219]85               CObjectFactory::CreateObject<typename U::RelChild>(id);
[347]86         group->childList.insert(group->childList.end(), value.get());
87         group->childMap.insert(std::make_pair(id, value.get()));
[219]88         return (value);
89      }
90   }
91
92   template <typename U>
[1542]93      bool CGroupFactory::HasGroup(std::shared_ptr<U> group, const StdString & id)
[219]94   {  return (group->groupMap.find(id) != group->groupMap.end()); }
95
96   template <typename U>
[1542]97      bool CGroupFactory::HasChild(std::shared_ptr<U> group, const StdString & id)
[219]98   {  return (group->childMap.find(id) != group->childMap.end()); }
99
100   template <typename U>
[1542]101      int CGroupFactory::GetGroupNum(std::shared_ptr<U> group)
[219]102   { return (group->groupList.size()); }
103
104   template <typename U>
[1542]105      int CGroupFactory::GetGroupIdNum(std::shared_ptr<U> group)
[219]106   { return (group->groupMap.size()); }
107
108   template <typename U>
[1542]109      int CGroupFactory::GetChildNum(std::shared_ptr<U> group)
[219]110   { return (group->childList.size()); }
111
112   template <typename U>
[1542]113      int CGroupFactory::GetChildIdNum(std::shared_ptr<U> group)
[219]114   { return (group->childMap.size()); }
115
116   template <typename U>
[1542]117      std::shared_ptr<U>
118         CGroupFactory::GetGroup(std::shared_ptr<U> group, const StdString & id)
[219]119   {
120      if (!CGroupFactory::HasGroup<U>(group, id))
[1542]121         ERROR("CGroupFactory::GetGroup(std::shared_ptr<U> group, const StdString & id)",
[219]122               << "[ id = " << id << ", U = " << U::GetName() << " ] "
123               << " group is not referenced !");
[347]124      return (group->groupMap[id]->getShared());
[219]125   }
126
127   template <typename U>
[1542]128      std::shared_ptr<typename U::RelChild>
129         CGroupFactory::GetChild(std::shared_ptr<U> group, const StdString & id)
[219]130   {
131      if (!CGroupFactory::HasChild<U>(group, id))
[1542]132         ERROR("CGroupFactory::GetChild(std::shared_ptr<U> group, const StdString & id)",
[219]133               << "[ id = " << id << ", U = " << U::GetName() << " ] "
134               << " child is not referenced !");
[347]135      return (group->childMap[id]->getShared());
[219]136   }
137
[335]138} // namespace xios
[219]139
[591]140#endif // __XIOS_CGroupFactory_impl__
Note: See TracBrowser for help on using the repository browser.