1 | #include "attribute_map.hpp" |
---|
2 | #include "indent.hpp" |
---|
3 | |
---|
4 | namespace xios |
---|
5 | { |
---|
6 | /// ////////////////////// Définitions ////////////////////// /// |
---|
7 | CAttributeMap* CAttributeMap::Current = NULL; |
---|
8 | |
---|
9 | CAttributeMap::CAttributeMap(void) |
---|
10 | : xios_map<StdString, CAttribute*>() |
---|
11 | { CAttributeMap::Current = this; } |
---|
12 | |
---|
13 | CAttributeMap::~CAttributeMap(void) |
---|
14 | { /* Ne rien faire de plus */ } |
---|
15 | |
---|
16 | ///-------------------------------------------------------------- |
---|
17 | |
---|
18 | /*! |
---|
19 | Clear all attributes of an object and reset them to empty state |
---|
20 | */ |
---|
21 | void CAttributeMap::clearAllAttributes(void) |
---|
22 | { |
---|
23 | typedef std::pair<StdString, CAttribute*> StdStrAttPair; |
---|
24 | SuperClassMap::const_iterator it = SuperClassMap::begin(), end = SuperClassMap::end(); |
---|
25 | for (; it != end; it++) |
---|
26 | { |
---|
27 | const StdStrAttPair& att = *it; |
---|
28 | att.second->reset(); |
---|
29 | } |
---|
30 | } |
---|
31 | |
---|
32 | ///-------------------------------------------------------------- |
---|
33 | /*! |
---|
34 | Dump of all non-empty attributes of an object |
---|
35 | */ |
---|
36 | StdString CAttributeMap::dumpXiosAttributes(void) const |
---|
37 | { |
---|
38 | int maxNbChar = 250; |
---|
39 | StdString str; |
---|
40 | typedef std::pair<StdString, CAttribute*> StdStrAttPair; |
---|
41 | auto it = SuperClassMap::begin(), end = SuperClassMap::end(); |
---|
42 | for (; it != end; it++) |
---|
43 | { |
---|
44 | const StdStrAttPair& att = *it; |
---|
45 | if (!att.second->isEmpty()) |
---|
46 | { |
---|
47 | if (str.length() < maxNbChar) |
---|
48 | { |
---|
49 | str.append(att.second->dump()); |
---|
50 | str.append(" "); |
---|
51 | } |
---|
52 | else if (str.length() == maxNbChar) |
---|
53 | { |
---|
54 | str.append("..."); |
---|
55 | } |
---|
56 | } |
---|
57 | } |
---|
58 | return str; |
---|
59 | } |
---|
60 | |
---|
61 | ///-------------------------------------------------------------- |
---|
62 | /*! |
---|
63 | Record all non-empty attributes of an object (used only for field) for graph |
---|
64 | */ |
---|
65 | StdString CAttributeMap::recordXiosAttributes(void) const |
---|
66 | { |
---|
67 | StdString str; |
---|
68 | typedef std::pair<StdString, CAttribute*> StdStrAttPair; |
---|
69 | auto it = SuperClassMap::begin(), end = SuperClassMap::end(); |
---|
70 | for (; it != end; it++) |
---|
71 | { |
---|
72 | const StdStrAttPair& att = *it; |
---|
73 | if (!att.second->isEmpty()) |
---|
74 | { |
---|
75 | str.append(att.second->dumpGraph()); |
---|
76 | str.append(" "); |
---|
77 | } |
---|
78 | } |
---|
79 | return str; |
---|
80 | } |
---|
81 | |
---|
82 | //--------------------------------------------------------------- |
---|
83 | |
---|
84 | /* |
---|
85 | Cleassr an attribute and reset its value |
---|
86 | \param[in] key id of attribute |
---|
87 | */ |
---|
88 | void CAttributeMap::clearAttribute(const StdString& key) |
---|
89 | { |
---|
90 | if (hasAttribute(key)) this->find(key)->second->reset(); |
---|
91 | } |
---|
92 | |
---|
93 | //--------------------------------------------------------------- |
---|
94 | |
---|
95 | /*! |
---|
96 | Set an attribute of certain id with a value |
---|
97 | \param[in] key id of the attribute |
---|
98 | \param[in] attr value of attribute |
---|
99 | */ |
---|
100 | void CAttributeMap::setAttribute(const StdString& key, CAttribute* const attr) |
---|
101 | { |
---|
102 | if (!this->hasAttribute(key)) |
---|
103 | ERROR("CAttributeMap::setAttribute(key, attr)", |
---|
104 | << "[ key = " << key << "] key not found !"); |
---|
105 | if (attr == NULL) |
---|
106 | ERROR("CAttributeMap::setAttribute(key, attr)", |
---|
107 | << "[ key = " << key << "] attr is null !"); |
---|
108 | this->find(key)->second->set(*attr); |
---|
109 | // this->find(key)->second->setAnyValue(attr->getAnyValue()); |
---|
110 | } |
---|
111 | |
---|
112 | //--------------------------------------------------------------- |
---|
113 | |
---|
114 | /*! |
---|
115 | Subscript operator. Return attribute with a specific id |
---|
116 | */ |
---|
117 | CAttribute* CAttributeMap::operator[](const StdString& key) |
---|
118 | { |
---|
119 | if (!this->hasAttribute(key)) |
---|
120 | ERROR("CAttributeMap::operator[](const StdString& key)", |
---|
121 | << "[ key = " << key << "] key not found !"); |
---|
122 | return SuperClassMap::operator[](key); |
---|
123 | } |
---|
124 | |
---|
125 | //--------------------------------------------------------------- |
---|
126 | |
---|
127 | StdString CAttributeMap::toString(void) const |
---|
128 | { |
---|
129 | typedef std::pair<StdString, CAttribute*> StdStrAttPair; |
---|
130 | StdOStringStream oss; |
---|
131 | |
---|
132 | SuperClassMap::const_iterator it = SuperClassMap::begin(), end = SuperClassMap::end(); |
---|
133 | for (; it != end; it++) |
---|
134 | { |
---|
135 | const StdStrAttPair& att = *it; |
---|
136 | if (!att.second->isEmpty()) |
---|
137 | oss << *att.second << " "; |
---|
138 | } |
---|
139 | return oss.str(); |
---|
140 | } |
---|
141 | |
---|
142 | //--------------------------------------------------------------- |
---|
143 | |
---|
144 | void CAttributeMap::fromString(const StdString& str) |
---|
145 | { |
---|
146 | ERROR("CAttributeMap::fromString(const StdString& str)", |
---|
147 | << "[ str = " << str << "] Not implemented yet !"); |
---|
148 | } |
---|
149 | |
---|
150 | //--------------------------------------------------------------- |
---|
151 | |
---|
152 | //StdOStream& operator << (StdOStream& os, const CAttributeMap& attributmap) |
---|
153 | //{ os << attributmap.toString(); return (os); } |
---|
154 | |
---|
155 | //--------------------------------------------------------------- |
---|
156 | |
---|
157 | void CAttributeMap::setAttributes(const xml::THashAttributes& attributes) |
---|
158 | { |
---|
159 | for (xml::THashAttributes::const_iterator it = attributes.begin(); |
---|
160 | it != attributes.end(); |
---|
161 | it++) |
---|
162 | { |
---|
163 | if ((*it).first.compare(StdString("id")) != 0 && (*it).first.compare(StdString("src")) != 0) |
---|
164 | { |
---|
165 | //if (CAttributeMap::operator[]((*it).first)->isEmpty()) |
---|
166 | CAttributeMap::operator[]((*it).first)->fromString((*it).second); |
---|
167 | } |
---|
168 | } |
---|
169 | } |
---|
170 | |
---|
171 | /*! |
---|
172 | Compare two attribute maps |
---|
173 | \param [in] another attribute map to compare |
---|
174 | \param [in] excludedAttrs attribute to be excluded from comparasion |
---|
175 | \return true if these two maps have same attributes whose value are identical |
---|
176 | */ |
---|
177 | bool CAttributeMap::isEqual(const CAttributeMap& another, const vector<StdString>& excludedAttrs) |
---|
178 | { |
---|
179 | SuperClassMap::const_iterator itb = another.begin(), ite = another.end(), it; |
---|
180 | for (it = itb; it !=ite; ++it) |
---|
181 | { |
---|
182 | bool excluded = false; |
---|
183 | for (int idx = 0; idx < excludedAttrs.size(); ++idx) |
---|
184 | { |
---|
185 | if (0 == (*it).first.compare(excludedAttrs[idx])) |
---|
186 | { |
---|
187 | excluded = true; |
---|
188 | break; |
---|
189 | } |
---|
190 | } |
---|
191 | |
---|
192 | if (!excluded) |
---|
193 | { |
---|
194 | if ((*it).first.compare(StdString("id")) != 0 && (*it).first.compare(StdString("src")) != 0) |
---|
195 | { |
---|
196 | if (this->hasAttribute(it->first)) |
---|
197 | { |
---|
198 | if (!((*it).second->isEqual(*(*this)[it->first]))) |
---|
199 | { |
---|
200 | return false; |
---|
201 | } |
---|
202 | } |
---|
203 | else |
---|
204 | return false; |
---|
205 | } |
---|
206 | } |
---|
207 | } |
---|
208 | |
---|
209 | return true; |
---|
210 | } |
---|
211 | |
---|
212 | |
---|
213 | //--------------------------------------------------------------- |
---|
214 | |
---|
215 | /*! |
---|
216 | \brief Set attributes from a specific attributemap, considered parent. |
---|
217 | The child attribute map will insert the attributes of its parent into its current attribute map. |
---|
218 | The existing attributes can be filled with the values of the parent map if they are empty or |
---|
219 | simply replaced by these values depending on choice of user. |
---|
220 | \param [in] _parent Attribute map from which the current map gets attributes. |
---|
221 | \param [in] apply Specify if current attribute map is replaced by the attributes of parent (false) |
---|
222 | or filled in in case of emptyp (true) |
---|
223 | */ |
---|
224 | void CAttributeMap::setAttributes(const CAttributeMap* const _parent, bool apply) |
---|
225 | { |
---|
226 | typedef std::pair<StdString, CAttribute*> StdStrAttPair; |
---|
227 | |
---|
228 | SuperClassMap::const_iterator it = _parent->begin(), end = _parent->end(); |
---|
229 | for (; it != end; it++) |
---|
230 | { |
---|
231 | const StdStrAttPair& el = *it; |
---|
232 | if (this->hasAttribute(el.first)) |
---|
233 | { |
---|
234 | CAttribute* currentAtt = CAttributeMap::operator[](el.first); |
---|
235 | CAttribute* parentAtt = el.second; |
---|
236 | if (apply) |
---|
237 | { |
---|
238 | if (currentAtt->isEmpty() && currentAtt->canInherite() && !el.second->isEmpty()) |
---|
239 | { |
---|
240 | this->setAttribute(el.first, el.second); |
---|
241 | } |
---|
242 | } |
---|
243 | else currentAtt->setInheritedValue(*parentAtt); |
---|
244 | } |
---|
245 | } |
---|
246 | } |
---|
247 | |
---|
248 | /*! |
---|
249 | Duplicate attribute map with a specific attribute map. |
---|
250 | Copy all non-empty attribute of the current attribute map |
---|
251 | \param [in] srcAttr attribute map which is copied from. |
---|
252 | */ |
---|
253 | void CAttributeMap::duplicateAttributes(const CAttributeMap* const srcAttr) |
---|
254 | { |
---|
255 | typedef std::pair<StdString, CAttribute*> StdStrAttPair; |
---|
256 | |
---|
257 | SuperClassMap::const_iterator it = srcAttr->begin(), end = srcAttr->end(); |
---|
258 | for (; it != end; it++) |
---|
259 | { |
---|
260 | const StdStrAttPair& el = *it; |
---|
261 | if (this->hasAttribute(el.first)) |
---|
262 | { |
---|
263 | if (!el.second->isEmpty()) |
---|
264 | { |
---|
265 | this->setAttribute(el.first, el.second); |
---|
266 | } |
---|
267 | } |
---|
268 | } |
---|
269 | } |
---|
270 | |
---|
271 | /*! |
---|
272 | Compute the hash value of current attribute map excluding some attributs. |
---|
273 | \param [in] excludedAttrs attribute to be excluded from hash computation |
---|
274 | */ |
---|
275 | size_t CAttributeMap::computeGlobalAttributesHash(const vector<StdString>& excludedAttrs) |
---|
276 | { |
---|
277 | size_t attrs_hash( 0 ); |
---|
278 | typedef std::pair<StdString, CAttribute*> StdStrAttPair; |
---|
279 | |
---|
280 | SuperClassMap::const_iterator it = this->begin(), end = this->end(); |
---|
281 | for (; it != end; it++) |
---|
282 | { |
---|
283 | const StdStrAttPair& el = *it; |
---|
284 | if ( std::find( excludedAttrs.begin(), excludedAttrs.end(), el.first ) == excludedAttrs.end() ) |
---|
285 | { |
---|
286 | if (this->hasAttribute(el.first)) |
---|
287 | { |
---|
288 | if (!el.second->isEmpty()) |
---|
289 | { |
---|
290 | attrs_hash += el.second->computeHash(); |
---|
291 | } |
---|
292 | } |
---|
293 | } |
---|
294 | } |
---|
295 | return attrs_hash; |
---|
296 | } |
---|
297 | |
---|
298 | //--------------------------------------------------------------- |
---|
299 | /* |
---|
300 | void CAttributeMap::toBinary(StdOStream& os) const |
---|
301 | { |
---|
302 | typedef std::pair<StdString, CAttribute*> StdStrAttPair; |
---|
303 | SuperClassMap::const_iterator it = this->begin(), end = this->end(); |
---|
304 | |
---|
305 | const StdSize nbatt = SuperClassMap::size(); |
---|
306 | os.write (reinterpret_cast<const char*>(&nbatt) , sizeof(StdSize)); |
---|
307 | |
---|
308 | for (; it != end; it++) |
---|
309 | { |
---|
310 | const StdString& key = it->first; |
---|
311 | const CAttribute* value = it->second; |
---|
312 | const StdSize size = key.size(); |
---|
313 | |
---|
314 | os.write (reinterpret_cast<const char*>(&size) , sizeof(StdSize)); |
---|
315 | os.write (key.data(), size* sizeof(char)); |
---|
316 | |
---|
317 | if (!value->isEmpty()) |
---|
318 | { |
---|
319 | bool b = true; |
---|
320 | os.write (reinterpret_cast<const char*>(&b) , sizeof(bool)); |
---|
321 | value->toBinary(os); |
---|
322 | } |
---|
323 | else |
---|
324 | { |
---|
325 | bool b = false; |
---|
326 | os.write (reinterpret_cast<const char*>(&b) , sizeof(bool)); |
---|
327 | } |
---|
328 | } |
---|
329 | } |
---|
330 | |
---|
331 | //--------------------------------------------------------------- |
---|
332 | |
---|
333 | void CAttributeMap::fromBinary(StdIStream& is) |
---|
334 | { |
---|
335 | StdSize nbatt = 0; |
---|
336 | is.read (reinterpret_cast<char*>(&nbatt), sizeof(StdSize)); |
---|
337 | |
---|
338 | for (StdSize i = 0; i < nbatt; i++) |
---|
339 | { |
---|
340 | bool hasValue = false; |
---|
341 | StdSize size = 0; |
---|
342 | is.read (reinterpret_cast<char*>(&size), sizeof(StdSize)); |
---|
343 | StdString key(size, ' '); |
---|
344 | is.read (const_cast<char *>(key.data()), size* sizeof(char)); |
---|
345 | |
---|
346 | if (!this->hasAttribute(key)) |
---|
347 | ERROR("CAttributeMap::fromBinary(StdIStream& is)", |
---|
348 | << "[ key = " << key << "] key not found !"); |
---|
349 | |
---|
350 | is.read (reinterpret_cast<char*>(&hasValue), sizeof(bool)); |
---|
351 | |
---|
352 | if (hasValue) |
---|
353 | this->operator[](key)->fromBinary(is); |
---|
354 | } |
---|
355 | } |
---|
356 | */ |
---|
357 | |
---|
358 | void CAttributeMap::generateCInterface(ostream& oss, const string& className) |
---|
359 | { |
---|
360 | SuperClassMap::const_iterator it = SuperClassMap::begin(), end = SuperClassMap::end(); |
---|
361 | for (; it != end; it++) |
---|
362 | { |
---|
363 | if (it->second->isPublic()) |
---|
364 | { |
---|
365 | oss << std::endl << iendl; |
---|
366 | it->second->generateCInterface(oss, className); |
---|
367 | oss << iendl; |
---|
368 | it->second->generateCInterfaceIsDefined(oss, className); |
---|
369 | } |
---|
370 | } |
---|
371 | } |
---|
372 | |
---|
373 | void CAttributeMap::generateFortran2003Interface(ostream& oss, const string& className) |
---|
374 | { |
---|
375 | SuperClassMap::const_iterator it = SuperClassMap::begin(), end = SuperClassMap::end(); |
---|
376 | for (; it != end; it++) |
---|
377 | { |
---|
378 | if (it->second->isPublic()) |
---|
379 | { |
---|
380 | oss << std::endl << iendl; |
---|
381 | it->second->generateFortran2003Interface(oss, className); |
---|
382 | oss << iendl; |
---|
383 | it->second->generateFortran2003InterfaceIsDefined(oss, className); |
---|
384 | } |
---|
385 | } |
---|
386 | } |
---|
387 | |
---|
388 | ///-------------------------------------------------------------- |
---|
389 | |
---|
390 | void CAttributeMap::generateFortranInterface_hdl_(ostream& oss, const string& className) |
---|
391 | { |
---|
392 | oss << "SUBROUTINE xios(set_" << className << "_attr_hdl_) &" << iendl++; |
---|
393 | SuperClassMap::const_iterator it; |
---|
394 | SuperClassMap::const_iterator begin = SuperClassMap::begin(), end = SuperClassMap::end(); |
---|
395 | |
---|
396 | long startPos = oss.tellp(); |
---|
397 | |
---|
398 | oss << "( " << className << "_hdl"; |
---|
399 | for (it = begin; it != end; it++) |
---|
400 | { |
---|
401 | if (it->second->isPublic()) |
---|
402 | { |
---|
403 | oss << ", " << it->second->getName() << "_"; |
---|
404 | if (oss.tellp() - startPos > 90) |
---|
405 | { |
---|
406 | oss << " &" << iendl; |
---|
407 | startPos = oss.tellp(); |
---|
408 | } |
---|
409 | } |
---|
410 | } |
---|
411 | oss << " )"; |
---|
412 | oss << std::endl; |
---|
413 | oss << iendl; |
---|
414 | |
---|
415 | oss << "IMPLICIT NONE" << iendl++; |
---|
416 | oss << "TYPE(txios(" << className << ")) , INTENT(IN) :: " << className << "_hdl"; |
---|
417 | |
---|
418 | for (it = begin; it != end; it++) |
---|
419 | { |
---|
420 | if (it->second->isPublic()) |
---|
421 | { |
---|
422 | oss << iendl; |
---|
423 | it->second->generateFortranInterfaceDeclaration_(oss, className); |
---|
424 | } |
---|
425 | } |
---|
426 | |
---|
427 | for (it = begin; it != end; it++) |
---|
428 | { |
---|
429 | if (it->second->isPublic()) |
---|
430 | { |
---|
431 | oss << std::endl << iendl; |
---|
432 | it->second->generateFortranInterfaceBody_(oss, className); |
---|
433 | } |
---|
434 | } |
---|
435 | |
---|
436 | oss << std::endl << (iendl -= 2); |
---|
437 | oss << "END SUBROUTINE xios(set_" << className << "_attr_hdl_)" << std::endl; |
---|
438 | } |
---|
439 | |
---|
440 | void CAttributeMap::generateFortranInterfaceGet_hdl_(ostream& oss, const string& className) |
---|
441 | { |
---|
442 | oss << "SUBROUTINE xios(get_" << className << "_attr_hdl_) &" << iendl++; |
---|
443 | SuperClassMap::const_iterator it; |
---|
444 | SuperClassMap::const_iterator begin = SuperClassMap::begin(), end = SuperClassMap::end(); |
---|
445 | |
---|
446 | long startPos = oss.tellp(); |
---|
447 | |
---|
448 | oss << "( " << className << "_hdl"; |
---|
449 | for (it = begin; it != end; it++) |
---|
450 | { |
---|
451 | if (it->second->isPublic()) |
---|
452 | { |
---|
453 | oss << ", " << it->second->getName() << "_"; |
---|
454 | if (oss.tellp() - startPos > 90) |
---|
455 | { |
---|
456 | oss << " &" << iendl; |
---|
457 | startPos = oss.tellp(); |
---|
458 | } |
---|
459 | } |
---|
460 | } |
---|
461 | oss << " )"; |
---|
462 | oss << std::endl; |
---|
463 | oss << iendl; |
---|
464 | |
---|
465 | oss << "IMPLICIT NONE" << iendl++; |
---|
466 | oss << "TYPE(txios(" << className << ")) , INTENT(IN) :: " << className << "_hdl"; |
---|
467 | |
---|
468 | for (it = begin; it != end; it++) |
---|
469 | { |
---|
470 | if (it->second->isPublic()) |
---|
471 | { |
---|
472 | oss << iendl; |
---|
473 | it->second->generateFortranInterfaceGetDeclaration_(oss, className); |
---|
474 | } |
---|
475 | } |
---|
476 | |
---|
477 | for (it = begin; it != end; it++) |
---|
478 | { |
---|
479 | if (it->second->isPublic()) |
---|
480 | { |
---|
481 | oss << std::endl << iendl; |
---|
482 | it->second->generateFortranInterfaceGetBody_(oss, className); |
---|
483 | } |
---|
484 | } |
---|
485 | |
---|
486 | oss << std::endl << (iendl -= 2); |
---|
487 | oss << "END SUBROUTINE xios(get_" << className << "_attr_hdl_)" << std::endl; |
---|
488 | } |
---|
489 | |
---|
490 | void CAttributeMap::generateFortranInterfaceIsDefined_hdl_(ostream& oss, const string& className) |
---|
491 | { |
---|
492 | oss << "SUBROUTINE xios(is_defined_" << className << "_attr_hdl_) &" << iendl++; |
---|
493 | SuperClassMap::const_iterator it; |
---|
494 | SuperClassMap::const_iterator begin = SuperClassMap::begin(), end = SuperClassMap::end(); |
---|
495 | |
---|
496 | long startPos = oss.tellp(); |
---|
497 | |
---|
498 | oss << "( " << className << "_hdl"; |
---|
499 | for (it = begin; it != end; it++) |
---|
500 | { |
---|
501 | if (it->second->isPublic()) |
---|
502 | { |
---|
503 | oss << ", " << it->second->getName() << "_"; |
---|
504 | if (oss.tellp() - startPos > 90) |
---|
505 | { |
---|
506 | oss << " &" << iendl; |
---|
507 | startPos = oss.tellp(); |
---|
508 | } |
---|
509 | } |
---|
510 | } |
---|
511 | oss << " )"; |
---|
512 | oss << std::endl; |
---|
513 | oss << iendl; |
---|
514 | |
---|
515 | oss << "IMPLICIT NONE" << iendl++; |
---|
516 | oss << "TYPE(txios(" << className << ")) , INTENT(IN) :: " << className << "_hdl"; |
---|
517 | |
---|
518 | for (it = begin; it != end; it++) |
---|
519 | { |
---|
520 | if (it->second->isPublic()) |
---|
521 | { |
---|
522 | oss << iendl; |
---|
523 | it->second->generateFortranInterfaceIsDefinedDeclaration_(oss, className); |
---|
524 | } |
---|
525 | } |
---|
526 | |
---|
527 | for (it = begin; it != end; it++) |
---|
528 | { |
---|
529 | if (it->second->isPublic()) |
---|
530 | { |
---|
531 | oss << std::endl << iendl; |
---|
532 | it->second->generateFortranInterfaceIsDefinedBody_(oss, className); |
---|
533 | } |
---|
534 | } |
---|
535 | |
---|
536 | oss << std::endl << (iendl -= 2); |
---|
537 | oss << "END SUBROUTINE xios(is_defined_" << className << "_attr_hdl_)" << std::endl; |
---|
538 | } |
---|
539 | |
---|
540 | void CAttributeMap::generateFortranInterface_hdl(ostream& oss, const string& className) |
---|
541 | { |
---|
542 | oss << "SUBROUTINE xios(set_" << className << "_attr_hdl) &" << iendl++; |
---|
543 | SuperClassMap::const_iterator it; |
---|
544 | SuperClassMap::const_iterator begin = SuperClassMap::begin(), end = SuperClassMap::end(); |
---|
545 | |
---|
546 | long startPos = oss.tellp(); |
---|
547 | |
---|
548 | oss << "( " << className << "_hdl"; |
---|
549 | for (it = begin; it != end; it++) |
---|
550 | { |
---|
551 | if (it->second->isPublic()) |
---|
552 | { |
---|
553 | oss << ", " << it->second->getName(); |
---|
554 | if (oss.tellp() - startPos > 90) |
---|
555 | { |
---|
556 | oss << " &" << iendl; |
---|
557 | startPos = oss.tellp(); |
---|
558 | } |
---|
559 | } |
---|
560 | } |
---|
561 | oss << " )"; |
---|
562 | oss << std::endl; |
---|
563 | oss << iendl; |
---|
564 | |
---|
565 | oss << "IMPLICIT NONE" << iendl++; |
---|
566 | oss << "TYPE(txios(" << className << ")) , INTENT(IN) :: " << className << "_hdl"; |
---|
567 | |
---|
568 | for (it = begin; it != end; it++) |
---|
569 | { |
---|
570 | if (it->second->isPublic()) |
---|
571 | { |
---|
572 | oss << iendl; |
---|
573 | it->second->generateFortranInterfaceDeclaration(oss, className); |
---|
574 | } |
---|
575 | } |
---|
576 | |
---|
577 | oss << std::endl << iendl; |
---|
578 | |
---|
579 | oss << "CALL xios(set_" << className << "_attr_hdl_) &" << iendl; |
---|
580 | |
---|
581 | startPos = oss.tellp(); |
---|
582 | |
---|
583 | oss << "( " << className << "_hdl"; |
---|
584 | for (it = begin; it != end; it++) |
---|
585 | { |
---|
586 | if (it->second->isPublic()) |
---|
587 | { |
---|
588 | oss << ", " << it->second->getName(); |
---|
589 | if (oss.tellp() - startPos > 90) |
---|
590 | { |
---|
591 | oss << " &" << iendl; |
---|
592 | startPos = oss.tellp(); |
---|
593 | } |
---|
594 | } |
---|
595 | } |
---|
596 | oss << " )"; |
---|
597 | |
---|
598 | oss << std::endl << (iendl -= 2); |
---|
599 | oss << "END SUBROUTINE xios(set_" << className << "_attr_hdl)" << std::endl; |
---|
600 | } |
---|
601 | |
---|
602 | void CAttributeMap::generateFortranInterfaceGet_hdl(ostream& oss, const string& className) |
---|
603 | { |
---|
604 | oss << "SUBROUTINE xios(get_" << className << "_attr_hdl) &" << iendl++; |
---|
605 | SuperClassMap::const_iterator it; |
---|
606 | SuperClassMap::const_iterator begin = SuperClassMap::begin(), end = SuperClassMap::end(); |
---|
607 | |
---|
608 | long startPos = oss.tellp(); |
---|
609 | |
---|
610 | oss << "( " << className << "_hdl"; |
---|
611 | for (it = begin; it != end; it++) |
---|
612 | { |
---|
613 | if (it->second->isPublic()) |
---|
614 | { |
---|
615 | oss << ", " << it->second->getName(); |
---|
616 | if (oss.tellp() - startPos > 90) |
---|
617 | { |
---|
618 | oss << " &" << iendl; |
---|
619 | startPos = oss.tellp(); |
---|
620 | } |
---|
621 | } |
---|
622 | } |
---|
623 | oss << " )"; |
---|
624 | oss << std::endl; |
---|
625 | oss << iendl; |
---|
626 | |
---|
627 | oss << "IMPLICIT NONE" << iendl++; |
---|
628 | oss << "TYPE(txios(" << className << ")) , INTENT(IN) :: " << className << "_hdl"; |
---|
629 | |
---|
630 | for (it = begin; it != end; it++) |
---|
631 | { |
---|
632 | if (it->second->isPublic()) |
---|
633 | { |
---|
634 | oss << iendl; |
---|
635 | it->second->generateFortranInterfaceGetDeclaration(oss, className); |
---|
636 | } |
---|
637 | } |
---|
638 | |
---|
639 | oss << std::endl << iendl; |
---|
640 | |
---|
641 | oss << "CALL xios(get_" << className << "_attr_hdl_) &" << iendl; |
---|
642 | |
---|
643 | startPos = oss.tellp(); |
---|
644 | |
---|
645 | oss << "( " << className << "_hdl"; |
---|
646 | for (it = begin; it != end; it++) |
---|
647 | { |
---|
648 | if (it->second->isPublic()) |
---|
649 | { |
---|
650 | oss << ", " << it->second->getName(); |
---|
651 | if (oss.tellp() - startPos > 90) |
---|
652 | { |
---|
653 | oss << " &" << iendl; |
---|
654 | startPos = oss.tellp(); |
---|
655 | } |
---|
656 | } |
---|
657 | } |
---|
658 | oss << " )"; |
---|
659 | |
---|
660 | oss << std::endl << (iendl -= 2); |
---|
661 | oss << "END SUBROUTINE xios(get_" << className << "_attr_hdl)" << std::endl; |
---|
662 | } |
---|
663 | |
---|
664 | void CAttributeMap::generateFortranInterfaceIsDefined_hdl(ostream& oss, const string& className) |
---|
665 | { |
---|
666 | oss << "SUBROUTINE xios(is_defined_" << className << "_attr_hdl) &" << iendl++; |
---|
667 | SuperClassMap::const_iterator it; |
---|
668 | SuperClassMap::const_iterator begin = SuperClassMap::begin(), end = SuperClassMap::end(); |
---|
669 | |
---|
670 | long startPos = oss.tellp(); |
---|
671 | |
---|
672 | oss << "( " << className << "_hdl"; |
---|
673 | for (it = begin; it != end; it++) |
---|
674 | { |
---|
675 | if (it->second->isPublic()) |
---|
676 | { |
---|
677 | oss << ", " << it->second->getName(); |
---|
678 | if (oss.tellp() - startPos > 90) |
---|
679 | { |
---|
680 | oss << " &" << iendl; |
---|
681 | startPos = oss.tellp(); |
---|
682 | } |
---|
683 | } |
---|
684 | } |
---|
685 | oss << " )"; |
---|
686 | oss << std::endl; |
---|
687 | oss << iendl; |
---|
688 | |
---|
689 | oss << "IMPLICIT NONE" << iendl++; |
---|
690 | oss << "TYPE(txios(" << className << ")) , INTENT(IN) :: " << className << "_hdl"; |
---|
691 | |
---|
692 | for (it = begin; it != end; it++) |
---|
693 | { |
---|
694 | if (it->second->isPublic()) |
---|
695 | { |
---|
696 | oss << iendl; |
---|
697 | it->second->generateFortranInterfaceIsDefinedDeclaration(oss, className); |
---|
698 | } |
---|
699 | } |
---|
700 | |
---|
701 | oss << std::endl << iendl; |
---|
702 | |
---|
703 | oss << "CALL xios(is_defined_" << className << "_attr_hdl_) &" << iendl; |
---|
704 | |
---|
705 | startPos = oss.tellp(); |
---|
706 | |
---|
707 | oss << "( " << className << "_hdl"; |
---|
708 | for (it = begin; it != end; it++) |
---|
709 | { |
---|
710 | if (it->second->isPublic()) |
---|
711 | { |
---|
712 | oss << ", " << it->second->getName(); |
---|
713 | if (oss.tellp() - startPos > 90) |
---|
714 | { |
---|
715 | oss << " &" << iendl; |
---|
716 | startPos = oss.tellp(); |
---|
717 | } |
---|
718 | } |
---|
719 | } |
---|
720 | oss << " )"; |
---|
721 | |
---|
722 | oss << std::endl << (iendl -= 2); |
---|
723 | oss << "END SUBROUTINE xios(is_defined_" << className << "_attr_hdl)" << std::endl; |
---|
724 | } |
---|
725 | |
---|
726 | void CAttributeMap::generateFortranInterface_id(ostream& oss, const string& className) |
---|
727 | { |
---|
728 | oss << "SUBROUTINE xios(set_" << className << "_attr) &" << iendl++; |
---|
729 | SuperClassMap::const_iterator it; |
---|
730 | SuperClassMap::const_iterator begin = SuperClassMap::begin(), end = SuperClassMap::end(); |
---|
731 | |
---|
732 | long startPos = oss.tellp(); |
---|
733 | |
---|
734 | oss << "( " << className << "_id"; |
---|
735 | for (it = begin; it != end; it++) |
---|
736 | { |
---|
737 | if (it->second->isPublic()) |
---|
738 | { |
---|
739 | oss << ", " << it->second->getName(); |
---|
740 | if (oss.tellp() - startPos > 90) |
---|
741 | { |
---|
742 | oss << " &" << iendl; |
---|
743 | startPos = oss.tellp(); |
---|
744 | } |
---|
745 | } |
---|
746 | } |
---|
747 | oss << " )"; |
---|
748 | oss << std::endl; |
---|
749 | oss << iendl; |
---|
750 | |
---|
751 | oss << "IMPLICIT NONE" << iendl++; |
---|
752 | |
---|
753 | oss << "TYPE(txios(" << className << ")) :: " << className << "_hdl" << iendl; |
---|
754 | oss << "CHARACTER(LEN=*), INTENT(IN) ::" << className << "_id"; |
---|
755 | |
---|
756 | for (it = begin; it != end; it++) |
---|
757 | { |
---|
758 | if (it->second->isPublic()) |
---|
759 | { |
---|
760 | oss << iendl; |
---|
761 | it->second->generateFortranInterfaceDeclaration(oss, className); |
---|
762 | } |
---|
763 | } |
---|
764 | |
---|
765 | oss << std::endl << iendl; |
---|
766 | oss << "CALL xios(get_" << className << "_handle) &" << iendl; |
---|
767 | oss << "(" << className << "_id," << className << "_hdl)" << iendl; |
---|
768 | oss << "CALL xios(set_" << className << "_attr_hdl_) &" << iendl; |
---|
769 | |
---|
770 | startPos = oss.tellp(); |
---|
771 | |
---|
772 | oss << "( " << className << "_hdl"; |
---|
773 | for (it = begin; it != end; it++) |
---|
774 | { |
---|
775 | if (it->second->isPublic()) |
---|
776 | { |
---|
777 | oss << ", " << it->second->getName(); |
---|
778 | if (oss.tellp() - startPos > 90) |
---|
779 | { |
---|
780 | oss << " &" << iendl; |
---|
781 | startPos = oss.tellp(); |
---|
782 | } |
---|
783 | } |
---|
784 | } |
---|
785 | oss << " )"; |
---|
786 | |
---|
787 | oss << std::endl << (iendl -= 2); |
---|
788 | oss << "END SUBROUTINE xios(set_" << className << "_attr)" << std::endl; |
---|
789 | } |
---|
790 | |
---|
791 | void CAttributeMap::generateFortranInterfaceGet_id(ostream& oss, const string& className) |
---|
792 | { |
---|
793 | oss << "SUBROUTINE xios(get_" << className << "_attr) &" << iendl++; |
---|
794 | SuperClassMap::const_iterator it; |
---|
795 | SuperClassMap::const_iterator begin = SuperClassMap::begin(), end = SuperClassMap::end(); |
---|
796 | |
---|
797 | long startPos = oss.tellp(); |
---|
798 | |
---|
799 | oss << "( " << className << "_id"; |
---|
800 | for (it = begin; it != end; it++) |
---|
801 | { |
---|
802 | if (it->second->isPublic()) |
---|
803 | { |
---|
804 | oss << ", " << it->second->getName(); |
---|
805 | if (oss.tellp() - startPos > 90) |
---|
806 | { |
---|
807 | oss << " &" << iendl; |
---|
808 | startPos = oss.tellp(); |
---|
809 | } |
---|
810 | } |
---|
811 | } |
---|
812 | oss << " )"; |
---|
813 | oss << std::endl; |
---|
814 | oss << iendl; |
---|
815 | |
---|
816 | oss << "IMPLICIT NONE" << iendl++; |
---|
817 | |
---|
818 | oss << "TYPE(txios(" << className << ")) :: " << className << "_hdl" << iendl; |
---|
819 | oss << "CHARACTER(LEN=*), INTENT(IN) ::" << className << "_id"; |
---|
820 | |
---|
821 | for (it = begin; it != end; it++) |
---|
822 | { |
---|
823 | if (it->second->isPublic()) |
---|
824 | { |
---|
825 | oss << iendl; |
---|
826 | it->second->generateFortranInterfaceGetDeclaration(oss, className); |
---|
827 | } |
---|
828 | } |
---|
829 | |
---|
830 | oss << std::endl << iendl; |
---|
831 | oss << "CALL xios(get_" << className << "_handle) &" << iendl; |
---|
832 | oss << "(" << className << "_id," << className << "_hdl)" << iendl; |
---|
833 | oss << "CALL xios(get_" << className << "_attr_hdl_) &" << iendl; |
---|
834 | |
---|
835 | startPos = oss.tellp(); |
---|
836 | |
---|
837 | oss << "( " << className << "_hdl"; |
---|
838 | for (it = begin; it != end; it++) |
---|
839 | { |
---|
840 | if (it->second->isPublic()) |
---|
841 | { |
---|
842 | oss << ", " << it->second->getName(); |
---|
843 | if (oss.tellp() - startPos > 90) |
---|
844 | { |
---|
845 | oss << " &" << iendl; |
---|
846 | startPos = oss.tellp(); |
---|
847 | } |
---|
848 | } |
---|
849 | } |
---|
850 | oss << " )"; |
---|
851 | |
---|
852 | oss << std::endl << (iendl -= 2); |
---|
853 | oss << "END SUBROUTINE xios(get_" << className << "_attr)" << std::endl; |
---|
854 | } |
---|
855 | |
---|
856 | void CAttributeMap::generateFortranInterfaceIsDefined_id(ostream& oss, const string& className) |
---|
857 | { |
---|
858 | oss << "SUBROUTINE xios(is_defined_" << className << "_attr) &" << iendl++; |
---|
859 | SuperClassMap::const_iterator it; |
---|
860 | SuperClassMap::const_iterator begin = SuperClassMap::begin(), end = SuperClassMap::end(); |
---|
861 | |
---|
862 | long startPos = oss.tellp(); |
---|
863 | |
---|
864 | oss << "( " << className << "_id"; |
---|
865 | for (it = begin; it != end; it++) |
---|
866 | { |
---|
867 | if (it->second->isPublic()) |
---|
868 | { |
---|
869 | oss << ", " << it->second->getName(); |
---|
870 | if (oss.tellp() - startPos > 90) |
---|
871 | { |
---|
872 | oss << " &" << iendl; |
---|
873 | startPos = oss.tellp(); |
---|
874 | } |
---|
875 | } |
---|
876 | } |
---|
877 | oss << " )"; |
---|
878 | oss << std::endl; |
---|
879 | oss << iendl; |
---|
880 | |
---|
881 | oss << "IMPLICIT NONE" << iendl++; |
---|
882 | |
---|
883 | oss << "TYPE(txios(" << className << ")) :: " << className << "_hdl" << iendl; |
---|
884 | oss << "CHARACTER(LEN=*), INTENT(IN) ::" << className << "_id"; |
---|
885 | |
---|
886 | for (it = begin; it != end; it++) |
---|
887 | { |
---|
888 | if (it->second->isPublic()) |
---|
889 | { |
---|
890 | oss << iendl; |
---|
891 | it->second->generateFortranInterfaceIsDefinedDeclaration(oss, className); |
---|
892 | } |
---|
893 | } |
---|
894 | |
---|
895 | oss << std::endl << iendl; |
---|
896 | oss << "CALL xios(get_" << className << "_handle) &" << iendl; |
---|
897 | oss << "(" << className << "_id," << className << "_hdl)" << iendl; |
---|
898 | oss << "CALL xios(is_defined_" << className << "_attr_hdl_) &" << iendl; |
---|
899 | |
---|
900 | startPos = oss.tellp(); |
---|
901 | |
---|
902 | oss << "( " << className << "_hdl"; |
---|
903 | for (it = begin; it != end; it++) |
---|
904 | { |
---|
905 | if (it->second->isPublic()) |
---|
906 | { |
---|
907 | oss << ", " << it->second->getName(); |
---|
908 | if (oss.tellp() - startPos > 90) |
---|
909 | { |
---|
910 | oss << " &" << iendl; |
---|
911 | startPos = oss.tellp(); |
---|
912 | } |
---|
913 | } |
---|
914 | } |
---|
915 | oss << " )"; |
---|
916 | |
---|
917 | oss << std::endl << (iendl -= 2); |
---|
918 | oss << "END SUBROUTINE xios(is_defined_" << className << "_attr)" << std::endl; |
---|
919 | } |
---|
920 | } // namespace xios |
---|