source: XIOS/dev/dev_ym/XIOS_COUPLING/src/node/coupler_out.cpp @ 1782

Last change on this file since 1782 was 1782, checked in by ymipsl, 5 years ago

coupling branch : implement new objet coupler_in and coupler_out to be properly parsed from XML file.

YM

  • Property svn:eol-style set to native
  • Property svn:executable set to *
File size: 4.1 KB
Line 
1#include "coupler_out.hpp"
2#include "attribute_template.hpp"
3#include "object_template.hpp"
4#include "group_template.hpp"
5#include "object_factory.hpp"
6#include "context.hpp"
7#include "xios_spl.hpp"
8
9namespace xios
10{
11
12  CCouplerOut::CCouplerOut(void) : CObjectTemplate<CCouplerOut>(), CCouplerOutAttributes(),
13                                 virtualFieldGroup(), enabledFields() 
14  {
15     setVirtualFieldGroup(CFieldGroup::create(getId() + "_virtual_field_group"));
16  }
17
18  CCouplerOut::CCouplerOut(const StdString & id) : CObjectTemplate<CCouplerOut>(id), CCouplerOutAttributes(),
19                                                    virtualFieldGroup(), enabledFields()
20  {
21    setVirtualFieldGroup(CFieldGroup::create(getId() + "_virtual_field_group"));
22  }
23
24  CCouplerOut::~CCouplerOut(void)
25  { /* Ne rien faire de plus */ }
26
27   ///---------------------------------------------------------------
28  //! Get name of file
29  StdString CCouplerOut::GetName(void)   { return (StdString("coupler_out")); }
30  StdString CCouplerOut::GetDefName(void){ return (CCouplerOut::GetName()); }
31  ENodeType CCouplerOut::GetType(void)   { return (eCouplerIn); }
32
33   /*!
34   \brief Parse xml file and write information into coupler_in object
35   \param [in] node xmld node corresponding in xml coupler_in
36   */
37   void CCouplerOut::parse(xml::CXMLNode & node)
38   TRY
39   {
40      SuperClass::parse(node);
41
42      if (node.goToChildElement())
43      {
44        do
45        {
46           if (node.getElementName()=="field" || node.getElementName()=="field_group") this->getVirtualFieldGroup()->parseChild(node);
47        } while (node.goToNextElement());
48        node.goToParentElement();
49      }
50   }
51   CATCH_DUMP_ATTR
52
53   std::vector<CField*> CCouplerOut::getEnabledFields(void)
54   TRY
55   {
56      if (enabledFields.empty())
57      {
58        this->enabledFields = this->getAllFields();
59        std::vector<CField*> newEnabledFields;
60        bool enabled ;
61        for ( auto it = this->enabledFields.begin(); it != this->enabledFields.end(); it++ )
62        {
63           if ((*it)->enabled.isEmpty()) enabled=true ; 
64           else enabled=(*it)->enabled ;
65           if (enabled) newEnabledFields.push_back(*it);
66        }
67        enabledFields = newEnabledFields;
68      }
69      return (this->enabledFields);
70   }
71   CATCH_DUMP_ATTR
72
73      /*!
74   \brief Get virtual field group
75      In each CCouplerIn, there always exists a field group which is the ancestor of all
76   fields in the CCouplerIn. This is considered be virtual because it is created automatically during
77   CCouplerIn initialization and it normally doesn't appear on xml file
78   \return Pointer to field group
79   */
80   CFieldGroup* CCouplerOut::getVirtualFieldGroup(void) const
81   TRY
82   {
83      return (this->virtualFieldGroup);
84   }
85   CATCH
86
87
88   /*!
89   \brief Get virtual variable group
90      In each CCouplerIn, there always exists a variable group which is the ancestor of all
91   variable in the CCouplerIn. This is considered be virtual because it is created automatically during
92   CCouplerIn initialization and it normally doesn't appear on xml file
93   \return Pointer to variable group
94   */
95
96   //! Get all fields of a file
97   std::vector<CField*> CCouplerOut::getAllFields(void) const
98   TRY
99   {
100      return (this->virtualFieldGroup->getAllChildren());
101   }
102   CATCH
103
104
105
106   //----------------------------------------------------------------
107   //! Change virtual field group to a new one
108   void CCouplerOut::setVirtualFieldGroup(CFieldGroup* newVirtualFieldGroup)
109   TRY
110   {
111      this->virtualFieldGroup = newVirtualFieldGroup;
112   }
113   CATCH_DUMP_ATTR
114
115   ///--------------------------------------------------------------
116   /*!
117   */
118   StdString CCouplerOut::dumpClassAttributes(void)
119   {
120     StdString str;
121     CContext* context = CContext::getCurrent();
122     str.append("context=\"");
123     str.append(context->getId());
124     str.append("\"");
125     str.append(" enabled fields=\"");
126     int size = this->enabledFields.size();
127     for (int i = 0; i < size; ++i)
128     {
129       str.append(this->enabledFields[i]->getId());
130       str.append(" ");
131     }
132     str.append("\"");
133     return str;
134   }
135}
Note: See TracBrowser for help on using the repository browser.