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