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 | const string& CCouplerIn::getCouplingContextId(void) |
---|
54 | { |
---|
55 | if (couplingContextId_.empty()) |
---|
56 | { |
---|
57 | vector<string> vectStr=splitRegex(context,"::") ; |
---|
58 | string poolId=vectStr[0] ; |
---|
59 | string serviceId=poolId ; |
---|
60 | string contextId=vectStr[1] ; |
---|
61 | int contextLeader ; |
---|
62 | int type = CServicesManager::CLIENT ; |
---|
63 | couplingContextId_=CXios::getContextsManager()->getServerContextName(poolId, serviceId, 0, type, contextId) ; |
---|
64 | } |
---|
65 | return couplingContextId_ ; |
---|
66 | } |
---|
67 | |
---|
68 | void CCouplerIn::createInterCommunicator(void) |
---|
69 | TRY |
---|
70 | { |
---|
71 | if (context.isEmpty()) |
---|
72 | { |
---|
73 | ERROR("void CCouplerOut::createInterCommunicator(void)", |
---|
74 | "The attribute <context> must be defined to specify the target coupling context"); |
---|
75 | } |
---|
76 | CContext* contextPtr = CContext::getCurrent(); |
---|
77 | contextPtr->addCouplingChanel(getCouplingContextId(), false) ; |
---|
78 | } |
---|
79 | CATCH_DUMP_ATTR |
---|
80 | |
---|
81 | |
---|
82 | /*! |
---|
83 | \brief Parse xml file and write information into coupler_in object |
---|
84 | \param [in] node xmld node corresponding in xml coupler_in |
---|
85 | */ |
---|
86 | void CCouplerIn::parse(xml::CXMLNode & node) |
---|
87 | TRY |
---|
88 | { |
---|
89 | SuperClass::parse(node); |
---|
90 | |
---|
91 | if (node.goToChildElement()) |
---|
92 | { |
---|
93 | do |
---|
94 | { |
---|
95 | if (node.getElementName()=="field" || node.getElementName()=="field_group") this->getVirtualFieldGroup()->parseChild(node); |
---|
96 | } while (node.goToNextElement()); |
---|
97 | node.goToParentElement(); |
---|
98 | } |
---|
99 | } |
---|
100 | CATCH_DUMP_ATTR |
---|
101 | |
---|
102 | /*! |
---|
103 | \brief Get virtual field group |
---|
104 | In each CCouplerIn, there always exists a field group which is the ancestor of all |
---|
105 | fields in the CCouplerIn. This is considered be virtual because it is created automatically during |
---|
106 | CCouplerIn initialization and it normally doesn't appear on xml file |
---|
107 | \return Pointer to field group |
---|
108 | */ |
---|
109 | CFieldGroup* CCouplerIn::getVirtualFieldGroup(void) const |
---|
110 | TRY |
---|
111 | { |
---|
112 | return (this->virtualFieldGroup); |
---|
113 | } |
---|
114 | CATCH |
---|
115 | |
---|
116 | void CCouplerIn::solveDescInheritance(bool apply, const CAttributeMap * const parent) |
---|
117 | TRY |
---|
118 | { |
---|
119 | SuperClassAttribute::setAttributes(parent,apply); |
---|
120 | this->getVirtualFieldGroup()->solveDescInheritance(apply, NULL); |
---|
121 | } |
---|
122 | CATCH_DUMP_ATTR |
---|
123 | |
---|
124 | void CCouplerIn::solveFieldRefInheritance(bool apply) |
---|
125 | TRY |
---|
126 | { |
---|
127 | // Rsolution des hritages par rfrence de chacun des champs contenus dans le fichier. |
---|
128 | std::vector<CField*> allF = this->getAllFields(); |
---|
129 | for (unsigned int i = 0; i < allF.size(); i++) |
---|
130 | allF[i]->solveRefInheritance(apply); |
---|
131 | } |
---|
132 | CATCH_DUMP_ATTR |
---|
133 | /*! |
---|
134 | \brief Get virtual variable group |
---|
135 | In each CCouplerIn, there always exists a variable group which is the ancestor of all |
---|
136 | variable in the CCouplerIn. This is considered be virtual because it is created automatically during |
---|
137 | CCouplerIn initialization and it normally doesn't appear on xml file |
---|
138 | \return Pointer to variable group |
---|
139 | */ |
---|
140 | |
---|
141 | //! Get all fields of a file |
---|
142 | std::vector<CField*> CCouplerIn::getAllFields(void) const |
---|
143 | TRY |
---|
144 | { |
---|
145 | return (this->virtualFieldGroup->getAllChildren()); |
---|
146 | } |
---|
147 | CATCH |
---|
148 | |
---|
149 | /*! |
---|
150 | * assign the context associated to the coupler to the enabled fields |
---|
151 | */ |
---|
152 | void CCouplerIn::assignContext(void) |
---|
153 | { |
---|
154 | client_ = CContext::getCurrent()->getCouplerInClient(getCouplingContextId()); |
---|
155 | for (auto& field : getEnabledFields()) field->setContextClient(client_) ; |
---|
156 | } |
---|
157 | |
---|
158 | //---------------------------------------------------------------- |
---|
159 | //! Change virtual field group to a new one |
---|
160 | void CCouplerIn::setVirtualFieldGroup(CFieldGroup* newVirtualFieldGroup) |
---|
161 | TRY |
---|
162 | { |
---|
163 | this->virtualFieldGroup = newVirtualFieldGroup; |
---|
164 | } |
---|
165 | CATCH_DUMP_ATTR |
---|
166 | |
---|
167 | ///-------------------------------------------------------------- |
---|
168 | /*! |
---|
169 | */ |
---|
170 | StdString CCouplerIn::dumpClassAttributes(void) |
---|
171 | { |
---|
172 | StdString str; |
---|
173 | CContext* context = CContext::getCurrent(); |
---|
174 | str.append("context=\""); |
---|
175 | str.append(context->getId()); |
---|
176 | str.append("\""); |
---|
177 | str.append(" enabled fields=\""); |
---|
178 | int size = this->enabledFields.size(); |
---|
179 | for (int i = 0; i < size; ++i) |
---|
180 | { |
---|
181 | str.append(this->enabledFields[i]->getId()); |
---|
182 | str.append(" "); |
---|
183 | } |
---|
184 | str.append("\""); |
---|
185 | return str; |
---|
186 | } |
---|
187 | } |
---|