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 | #include "string_tools.hpp" |
---|
9 | #include "contexts_manager.hpp" |
---|
10 | #include "services_manager.hpp" |
---|
11 | |
---|
12 | |
---|
13 | namespace xios |
---|
14 | { |
---|
15 | |
---|
16 | CCouplerOut::CCouplerOut(void) : CObjectTemplate<CCouplerOut>(), CCouplerOutAttributes(), |
---|
17 | virtualFieldGroup(), enabledFields() |
---|
18 | { |
---|
19 | setVirtualFieldGroup(CFieldGroup::create(getId() + "_virtual_field_group")); |
---|
20 | } |
---|
21 | |
---|
22 | CCouplerOut::CCouplerOut(const StdString & id) : CObjectTemplate<CCouplerOut>(id), CCouplerOutAttributes(), |
---|
23 | virtualFieldGroup(), enabledFields() |
---|
24 | { |
---|
25 | setVirtualFieldGroup(CFieldGroup::create(getId() + "_virtual_field_group")); |
---|
26 | } |
---|
27 | |
---|
28 | CCouplerOut::~CCouplerOut(void) |
---|
29 | { /* Ne rien faire de plus */ } |
---|
30 | |
---|
31 | ///--------------------------------------------------------------- |
---|
32 | //! Get name of file |
---|
33 | StdString CCouplerOut::GetName(void) { return (StdString("coupler_out")); } |
---|
34 | StdString CCouplerOut::GetDefName(void){ return (CCouplerOut::GetName()); } |
---|
35 | ENodeType CCouplerOut::GetType(void) { return (eCouplerIn); } |
---|
36 | |
---|
37 | /*! |
---|
38 | \brief Parse xml file and write information into coupler_in object |
---|
39 | \param [in] node xmld node corresponding in xml coupler_in |
---|
40 | */ |
---|
41 | void CCouplerOut::parse(xml::CXMLNode & node) |
---|
42 | TRY |
---|
43 | { |
---|
44 | SuperClass::parse(node); |
---|
45 | |
---|
46 | if (node.goToChildElement()) |
---|
47 | { |
---|
48 | do |
---|
49 | { |
---|
50 | if (node.getElementName()=="field" || node.getElementName()=="field_group") this->getVirtualFieldGroup()->parseChild(node); |
---|
51 | } while (node.goToNextElement()); |
---|
52 | node.goToParentElement(); |
---|
53 | } |
---|
54 | } |
---|
55 | CATCH_DUMP_ATTR |
---|
56 | |
---|
57 | const string& CCouplerOut::getCouplingContextId(void) |
---|
58 | { |
---|
59 | if (couplingContextId_.empty()) |
---|
60 | { |
---|
61 | vector<string> vectStr=splitRegex(context,"::") ; |
---|
62 | string poolId=vectStr[0] ; |
---|
63 | string serviceId=poolId ; |
---|
64 | string contextId=vectStr[1] ; |
---|
65 | int contextLeader ; |
---|
66 | int type = CServicesManager::CLIENT ; |
---|
67 | couplingContextId_=CXios::getContextsManager()->getServerContextName(poolId, serviceId, 0, type, contextId) ; |
---|
68 | } |
---|
69 | return couplingContextId_ ; |
---|
70 | } |
---|
71 | |
---|
72 | std::vector<CField*> CCouplerOut::getEnabledFields(void) |
---|
73 | TRY |
---|
74 | { |
---|
75 | if (enabledFields.empty()) |
---|
76 | { |
---|
77 | this->enabledFields = this->getAllFields(); |
---|
78 | std::vector<CField*> newEnabledFields; |
---|
79 | bool enabled ; |
---|
80 | for ( auto it = this->enabledFields.begin(); it != this->enabledFields.end(); it++ ) |
---|
81 | { |
---|
82 | if ((*it)->enabled.isEmpty()) enabled=true ; |
---|
83 | else enabled=(*it)->enabled ; |
---|
84 | if (enabled) newEnabledFields.push_back(*it); |
---|
85 | } |
---|
86 | enabledFields = newEnabledFields; |
---|
87 | } |
---|
88 | return (this->enabledFields); |
---|
89 | } |
---|
90 | CATCH_DUMP_ATTR |
---|
91 | |
---|
92 | /*! |
---|
93 | * assign the context associated to the coupler to the enabled fields |
---|
94 | */ |
---|
95 | void CCouplerOut::assignContext(void) |
---|
96 | { |
---|
97 | client_ = CContext::getCurrent()->getCouplerOutClient(getCouplingContextId()); |
---|
98 | for (auto& field : getEnabledFields()) field->setContextClient(client_) ; |
---|
99 | } |
---|
100 | |
---|
101 | /*! |
---|
102 | \brief Get virtual field group |
---|
103 | In each CCouplerIn, there always exists a field group which is the ancestor of all |
---|
104 | fields in the CCouplerIn. This is considered be virtual because it is created automatically during |
---|
105 | CCouplerIn initialization and it normally doesn't appear on xml file |
---|
106 | \return Pointer to field group |
---|
107 | */ |
---|
108 | CFieldGroup* CCouplerOut::getVirtualFieldGroup(void) const |
---|
109 | TRY |
---|
110 | { |
---|
111 | return (this->virtualFieldGroup); |
---|
112 | } |
---|
113 | CATCH |
---|
114 | |
---|
115 | |
---|
116 | /*! |
---|
117 | \brief Get virtual variable group |
---|
118 | In each CCouplerIn, there always exists a variable group which is the ancestor of all |
---|
119 | variable in the CCouplerIn. This is considered be virtual because it is created automatically during |
---|
120 | CCouplerIn initialization and it normally doesn't appear on xml file |
---|
121 | \return Pointer to variable group |
---|
122 | */ |
---|
123 | |
---|
124 | //! Get all fields of a file |
---|
125 | std::vector<CField*> CCouplerOut::getAllFields(void) const |
---|
126 | TRY |
---|
127 | { |
---|
128 | return (this->virtualFieldGroup->getAllChildren()); |
---|
129 | } |
---|
130 | CATCH |
---|
131 | |
---|
132 | void CCouplerOut::solveDescInheritance(bool apply, const CAttributeMap * const parent) |
---|
133 | TRY |
---|
134 | { |
---|
135 | SuperClassAttribute::setAttributes(parent,apply); |
---|
136 | this->getVirtualFieldGroup()->solveDescInheritance(apply, NULL); |
---|
137 | } |
---|
138 | CATCH_DUMP_ATTR |
---|
139 | |
---|
140 | void CCouplerOut::solveFieldRefInheritance(bool apply) |
---|
141 | TRY |
---|
142 | { |
---|
143 | // Rsolution des hritages par rfrence de chacun des champs contenus dans le fichier. |
---|
144 | std::vector<CField*> allF = this->getAllFields(); |
---|
145 | for (unsigned int i = 0; i < allF.size(); i++) |
---|
146 | allF[i]->solveRefInheritance(apply); |
---|
147 | } |
---|
148 | CATCH_DUMP_ATTR |
---|
149 | |
---|
150 | void CCouplerOut::createInterCommunicator(void) |
---|
151 | TRY |
---|
152 | { |
---|
153 | if (context.isEmpty()) |
---|
154 | { |
---|
155 | ERROR("void CCouplerOut::createInterCommunicator(void)", |
---|
156 | "The attribute <context> must be defined to specify the target coupling context"); |
---|
157 | } |
---|
158 | CContext* contextPtr = CContext::getCurrent(); |
---|
159 | contextPtr->addCouplingChanel(getCouplingContextId(), true) ; |
---|
160 | } |
---|
161 | CATCH_DUMP_ATTR |
---|
162 | |
---|
163 | |
---|
164 | void CCouplerOut::checkGridOfEnabledFields(void) |
---|
165 | TRY |
---|
166 | { |
---|
167 | int size = this->enabledFields.size(); |
---|
168 | for (int i = 0; i < size; ++i) |
---|
169 | { |
---|
170 | this->enabledFields[i]->checkGridOfEnabledFields(); |
---|
171 | } |
---|
172 | } |
---|
173 | CATCH_DUMP_ATTR |
---|
174 | |
---|
175 | //---------------------------------------------------------------- |
---|
176 | //! Change virtual field group to a new one |
---|
177 | void CCouplerOut::setVirtualFieldGroup(CFieldGroup* newVirtualFieldGroup) |
---|
178 | TRY |
---|
179 | { |
---|
180 | this->virtualFieldGroup = newVirtualFieldGroup; |
---|
181 | } |
---|
182 | CATCH_DUMP_ATTR |
---|
183 | |
---|
184 | ///-------------------------------------------------------------- |
---|
185 | /*! |
---|
186 | */ |
---|
187 | StdString CCouplerOut::dumpClassAttributes(void) |
---|
188 | { |
---|
189 | StdString str; |
---|
190 | CContext* context = CContext::getCurrent(); |
---|
191 | str.append("context=\""); |
---|
192 | str.append(context->getId()); |
---|
193 | str.append("\""); |
---|
194 | str.append(" enabled fields=\""); |
---|
195 | int size = this->enabledFields.size(); |
---|
196 | for (int i = 0; i < size; ++i) |
---|
197 | { |
---|
198 | str.append(this->enabledFields[i]->getId()); |
---|
199 | str.append(" "); |
---|
200 | } |
---|
201 | str.append("\""); |
---|
202 | return str; |
---|
203 | } |
---|
204 | } |
---|