source: XIOS3/trunk/src/attribute_map.cpp

Last change on this file was 2633, checked in by ymipsl, 3 weeks ago

Fix misfunction of "_reset_" for attributes when using field_ref.
YM

  • Property copyright set to
    Software name : XIOS (Xml I/O Server)
    http://forge.ipsl.jussieu.fr/ioserver
    Creation date : January 2009
    Licence : CeCCIL version2
    see license file in root directory : Licence_CeCILL_V2-en.txt
    or http://www.cecill.info/licences/Licence_CeCILL_V2-en.html
    Holder : CEA/LSCE (Laboratoire des Sciences du CLimat et de l'Environnement)
    CNRS/IPSL (Institut Pierre Simon Laplace)
    Project Manager : Yann Meurdesoif
    yann.meurdesoif@cea.fr
File size: 29.9 KB
Line 
1#include "attribute_map.hpp"
2#include "indent.hpp"
3
4namespace 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                 else if (currentAtt->isEmpty() && currentAtt->canInherite() && el.second->isEmpty() && !el.second->canInherite())
243                 {
244                    currentAtt->setCannotInherit() ; // propagate non-inheritance
245                 }
246               }
247               else currentAtt->setInheritedValue(*parentAtt);
248            }
249         }
250      }
251
252      /*!
253        Duplicate attribute map with a specific attribute map.
254        Copy all non-empty attribute of the current attribute map
255        \param [in] srcAttr attribute map which is copied from.
256      */
257      void CAttributeMap::duplicateAttributes(const CAttributeMap* const srcAttr)
258      {
259         typedef std::pair<StdString, CAttribute*> StdStrAttPair;
260
261         SuperClassMap::const_iterator it = srcAttr->begin(), end = srcAttr->end();
262         for (; it != end; it++)
263         {
264            const StdStrAttPair& el = *it;
265            if (this->hasAttribute(el.first))
266            {
267               if (!el.second->isEmpty())
268               {
269                 this->setAttribute(el.first, el.second);
270               }
271            }
272         }
273      }
274
275      /*!
276        Compute the hash value of current attribute map excluding some attributs.
277        \param [in] excludedAttrs attribute to be excluded from hash computation
278      */
279      size_t CAttributeMap::computeGlobalAttributesHash(const vector<StdString>& excludedAttrs)
280      {
281         size_t attrs_hash( 0 );
282         typedef std::pair<StdString, CAttribute*> StdStrAttPair;
283
284         SuperClassMap::const_iterator it = this->begin(), end = this->end();
285         for (; it != end; it++)
286         {
287            const StdStrAttPair& el = *it;
288            if ( std::find( excludedAttrs.begin(), excludedAttrs.end(), el.first ) == excludedAttrs.end() )
289            {
290              if (this->hasAttribute(el.first))
291              {
292                if (!el.second->isEmpty())
293                {
294                  attrs_hash += el.second->computeHash();
295                }
296              }
297            }
298         }
299         return attrs_hash;
300      }
301 
302      //---------------------------------------------------------------
303/*
304      void CAttributeMap::toBinary(StdOStream& os) const
305      {
306         typedef std::pair<StdString, CAttribute*> StdStrAttPair;
307         SuperClassMap::const_iterator it = this->begin(), end = this->end();
308
309         const StdSize nbatt = SuperClassMap::size();
310         os.write (reinterpret_cast<const char*>(&nbatt) , sizeof(StdSize));
311
312         for (; it != end; it++)
313         {
314            const StdString& key   = it->first;
315            const CAttribute* value = it->second;
316            const StdSize size = key.size();
317
318            os.write (reinterpret_cast<const char*>(&size) , sizeof(StdSize));
319            os.write (key.data(), size* sizeof(char));
320
321            if (!value->isEmpty())
322            {
323               bool b = true;
324               os.write (reinterpret_cast<const char*>(&b) , sizeof(bool));
325               value->toBinary(os);
326            }
327            else
328            {
329               bool b = false;
330               os.write (reinterpret_cast<const char*>(&b) , sizeof(bool));
331            }
332         }
333      }
334
335      //---------------------------------------------------------------
336
337      void CAttributeMap::fromBinary(StdIStream& is)
338      {
339         StdSize nbatt = 0;
340         is.read (reinterpret_cast<char*>(&nbatt), sizeof(StdSize));
341
342         for (StdSize i = 0; i < nbatt; i++)
343         {
344            bool hasValue = false;
345            StdSize size  = 0;
346            is.read (reinterpret_cast<char*>(&size), sizeof(StdSize));
347            StdString key(size, ' ');
348            is.read (const_cast<char *>(key.data()), size* sizeof(char));
349
350            if (!this->hasAttribute(key))
351               ERROR("CAttributeMap::fromBinary(StdIStream& is)",
352                     << "[ key = " << key << "] key not found !");
353
354            is.read (reinterpret_cast<char*>(&hasValue), sizeof(bool));
355
356            if (hasValue)
357               this->operator[](key)->fromBinary(is);
358         }
359      }
360 */
361     
362      void CAttributeMap::generateCInterface(ostream& oss, const string& className)
363      {
364         SuperClassMap::const_iterator it = SuperClassMap::begin(), end = SuperClassMap::end();
365         for (; it != end; it++)
366         {
367           if (it->second->isPublic())
368           {
369             oss << std::endl << iendl;
370             it->second->generateCInterface(oss, className);
371             oss << iendl;
372             it->second->generateCInterfaceIsDefined(oss, className);
373           }
374         }
375      }
376
377      void CAttributeMap::generateFortran2003Interface(ostream& oss, const string& className)
378      {
379         SuperClassMap::const_iterator it = SuperClassMap::begin(), end = SuperClassMap::end();
380         for (; it != end; it++)
381         {
382           if (it->second->isPublic())
383           {
384             oss << std::endl << iendl;
385             it->second->generateFortran2003Interface(oss, className);
386             oss << iendl;
387             it->second->generateFortran2003InterfaceIsDefined(oss, className);
388           }
389         }
390      }
391
392      ///--------------------------------------------------------------
393
394      void CAttributeMap::generateFortranInterface_hdl_(ostream& oss, const string& className)
395      {
396         oss << "SUBROUTINE xios(set_" << className << "_attr_hdl_)   &" << iendl++;
397         SuperClassMap::const_iterator it;
398         SuperClassMap::const_iterator begin = SuperClassMap::begin(), end = SuperClassMap::end();
399
400         long startPos = oss.tellp();
401
402         oss << "( " << className << "_hdl";
403         for (it = begin; it != end; it++)
404         {
405           if (it->second->isPublic())
406           {
407             oss << ", " << it->second->getName() << "_";
408             if ((long)oss.tellp() - startPos > 90)
409             {
410               oss << "  &" << iendl;
411               startPos = oss.tellp();
412             }
413           }
414         }
415         oss << " )";
416         oss << std::endl;
417         oss << iendl;
418
419         oss << "IMPLICIT NONE" << iendl++;
420         oss << "TYPE(txios(" << className << ")) , INTENT(IN) :: " << className << "_hdl";
421
422         for (it = begin; it != end; it++)
423         {
424           if (it->second->isPublic())
425           {
426             oss << iendl;
427             it->second->generateFortranInterfaceDeclaration_(oss, className);
428           }
429         }
430
431         for (it = begin; it != end; it++)
432         {
433           if (it->second->isPublic())
434           {
435             oss << std::endl << iendl;
436             it->second->generateFortranInterfaceBody_(oss, className);
437           }
438         }
439
440         oss << std::endl << (iendl -= 2);
441         oss << "END SUBROUTINE xios(set_" << className << "_attr_hdl_)" << std::endl;
442      }
443
444      void CAttributeMap::generateFortranInterfaceGet_hdl_(ostream& oss, const string& className)
445      {
446         oss << "SUBROUTINE xios(get_" << className << "_attr_hdl_)   &" << iendl++;
447         SuperClassMap::const_iterator it;
448         SuperClassMap::const_iterator begin = SuperClassMap::begin(), end = SuperClassMap::end();
449
450         long startPos = oss.tellp();
451
452         oss << "( " << className << "_hdl";
453         for (it = begin; it != end; it++)
454         {
455           if (it->second->isPublic())
456           {
457             oss << ", " << it->second->getName() << "_";
458             if ((long)oss.tellp() - startPos > 90)
459             {
460               oss << "  &" << iendl;
461               startPos = oss.tellp();
462             }
463           }
464         }
465         oss << " )";
466         oss << std::endl;
467         oss << iendl;
468
469         oss << "IMPLICIT NONE" << iendl++;
470         oss << "TYPE(txios(" << className << ")) , INTENT(IN) :: " << className << "_hdl";
471
472         for (it = begin; it != end; it++)
473         {
474           if (it->second->isPublic())
475           {
476             oss << iendl;
477             it->second->generateFortranInterfaceGetDeclaration_(oss, className);
478           }
479         }
480
481         for (it = begin; it != end; it++)
482         {
483           if (it->second->isPublic())
484           {
485             oss << std::endl << iendl;
486             it->second->generateFortranInterfaceGetBody_(oss, className);
487           }
488         }
489
490         oss << std::endl << (iendl -= 2);
491         oss << "END SUBROUTINE xios(get_" << className << "_attr_hdl_)" << std::endl;
492      }
493
494      void CAttributeMap::generateFortranInterfaceIsDefined_hdl_(ostream& oss, const string& className)
495      {
496         oss << "SUBROUTINE xios(is_defined_" << className << "_attr_hdl_)   &" << iendl++;
497         SuperClassMap::const_iterator it;
498         SuperClassMap::const_iterator begin = SuperClassMap::begin(), end = SuperClassMap::end();
499
500         long startPos = oss.tellp();
501
502         oss << "( " << className << "_hdl";
503         for (it = begin; it != end; it++)
504         {
505           if (it->second->isPublic())
506           {
507             oss << ", " << it->second->getName() << "_";
508             if ((long)oss.tellp() - startPos > 90)
509             {
510               oss << "  &" << iendl;
511               startPos = oss.tellp();
512             }
513           }
514         }
515         oss << " )";
516         oss << std::endl;
517         oss << iendl;
518
519         oss << "IMPLICIT NONE" << iendl++;
520         oss << "TYPE(txios(" << className << ")) , INTENT(IN) :: " << className << "_hdl";
521
522         for (it = begin; it != end; it++)
523         {
524           if (it->second->isPublic())
525           {
526             oss << iendl;
527             it->second->generateFortranInterfaceIsDefinedDeclaration_(oss, className);
528           }
529         }
530
531         for (it = begin; it != end; it++)
532         {
533           if (it->second->isPublic())
534           {
535             oss << std::endl << iendl;
536             it->second->generateFortranInterfaceIsDefinedBody_(oss, className);
537           }
538         }
539
540         oss << std::endl << (iendl -= 2);
541         oss << "END SUBROUTINE xios(is_defined_" << className << "_attr_hdl_)" << std::endl;
542      }
543
544      void CAttributeMap::generateFortranInterface_hdl(ostream& oss, const string& className)
545      {
546         oss << "SUBROUTINE xios(set_" << className << "_attr_hdl)  &" << iendl++;
547         SuperClassMap::const_iterator it;
548         SuperClassMap::const_iterator begin = SuperClassMap::begin(), end = SuperClassMap::end();
549
550         long startPos = oss.tellp();
551
552         oss << "( " << className << "_hdl";
553         for (it = begin; it != end; it++)
554         {
555           if (it->second->isPublic())
556           {
557             oss << ", " << it->second->getName();
558             if ((long)oss.tellp() - startPos > 90)
559             {
560               oss << "  &" << iendl;
561               startPos = oss.tellp();
562             }
563           }
564         }
565         oss << " )";
566         oss << std::endl;
567         oss << iendl;
568
569         oss << "IMPLICIT NONE" << iendl++;
570         oss << "TYPE(txios(" << className << ")) , INTENT(IN) :: " << className << "_hdl";
571
572         for (it = begin; it != end; it++)
573         {
574           if (it->second->isPublic())
575           {
576             oss << iendl;
577             it->second->generateFortranInterfaceDeclaration(oss, className);
578           }
579         }
580
581         oss << std::endl << iendl;
582
583         oss << "CALL xios(set_" << className << "_attr_hdl_)  &" << iendl;
584
585         startPos = oss.tellp();
586
587         oss << "( " << className << "_hdl";
588         for (it = begin; it != end; it++)
589         {
590           if (it->second->isPublic())
591           {
592             oss << ", " << it->second->getName();
593             if ((long)oss.tellp() - startPos > 90)
594             {
595               oss << "  &" << iendl;
596               startPos = oss.tellp();
597             }
598           }
599         }
600         oss << " )";
601
602         oss << std::endl << (iendl -= 2);
603         oss << "END SUBROUTINE xios(set_" << className << "_attr_hdl)" << std::endl;
604      }
605
606      void CAttributeMap::generateFortranInterfaceGet_hdl(ostream& oss, const string& className)
607      {
608         oss << "SUBROUTINE xios(get_" << className << "_attr_hdl)  &" << iendl++;
609         SuperClassMap::const_iterator it;
610         SuperClassMap::const_iterator begin = SuperClassMap::begin(), end = SuperClassMap::end();
611
612         long startPos = oss.tellp();
613
614         oss << "( " << className << "_hdl";
615         for (it = begin; it != end; it++)
616         {
617           if (it->second->isPublic())
618           {
619             oss << ", " << it->second->getName();
620             if ((long)oss.tellp() - startPos > 90)
621             {
622               oss << "  &" << iendl;
623               startPos = oss.tellp();
624             }
625           }
626         }
627         oss << " )";
628         oss << std::endl;
629         oss << iendl;
630
631         oss << "IMPLICIT NONE" << iendl++;
632         oss << "TYPE(txios(" << className << ")) , INTENT(IN) :: " << className << "_hdl";
633
634         for (it = begin; it != end; it++)
635         {
636           if (it->second->isPublic())
637           {
638             oss << iendl;
639             it->second->generateFortranInterfaceGetDeclaration(oss, className);
640           }
641         }
642
643         oss << std::endl << iendl;
644
645         oss << "CALL xios(get_" << className << "_attr_hdl_)  &" << iendl;
646
647         startPos = oss.tellp();
648
649         oss << "( " << className << "_hdl";
650         for (it = begin; it != end; it++)
651         {
652           if (it->second->isPublic())
653           {
654             oss << ", " << it->second->getName();
655             if ((long)oss.tellp() - startPos > 90)
656             {
657               oss << "  &" << iendl;
658               startPos = oss.tellp();
659             }
660           }
661         }
662         oss << " )";
663
664         oss << std::endl << (iendl -= 2);
665         oss << "END SUBROUTINE xios(get_" << className << "_attr_hdl)" << std::endl;
666      }
667
668      void CAttributeMap::generateFortranInterfaceIsDefined_hdl(ostream& oss, const string& className)
669      {
670         oss << "SUBROUTINE xios(is_defined_" << className << "_attr_hdl)  &" << iendl++;
671         SuperClassMap::const_iterator it;
672         SuperClassMap::const_iterator begin = SuperClassMap::begin(), end = SuperClassMap::end();
673
674         long startPos = oss.tellp();
675
676         oss << "( " << className << "_hdl";
677         for (it = begin; it != end; it++)
678         {
679           if (it->second->isPublic())
680           {
681             oss << ", " << it->second->getName();
682             if ((long)oss.tellp() - startPos > 90)
683             {
684               oss << "  &" << iendl;
685               startPos = oss.tellp();
686             }
687           }
688         }
689         oss << " )";
690         oss << std::endl;
691         oss << iendl;
692
693         oss << "IMPLICIT NONE" << iendl++;
694         oss << "TYPE(txios(" << className << ")) , INTENT(IN) :: " << className << "_hdl";
695
696         for (it = begin; it != end; it++)
697         {
698           if (it->second->isPublic())
699           {
700             oss << iendl;
701             it->second->generateFortranInterfaceIsDefinedDeclaration(oss, className);
702           }
703         }
704
705         oss << std::endl << iendl;
706
707         oss << "CALL xios(is_defined_" << className << "_attr_hdl_)  &" << iendl;
708
709         startPos = oss.tellp();
710
711         oss << "( " << className << "_hdl";
712         for (it = begin; it != end; it++)
713         {
714           if (it->second->isPublic())
715           {
716             oss << ", " << it->second->getName();
717             if ((long)oss.tellp() - startPos > 90)
718             {
719               oss << "  &" << iendl;
720               startPos = oss.tellp();
721             }
722           }
723         }
724         oss << " )";
725
726         oss << std::endl << (iendl -= 2);
727         oss << "END SUBROUTINE xios(is_defined_" << className << "_attr_hdl)" << std::endl;
728      }
729
730      void CAttributeMap::generateFortranInterface_id(ostream& oss, const string& className)
731      {
732         oss << "SUBROUTINE xios(set_" << className << "_attr)  &" << iendl++;
733         SuperClassMap::const_iterator it;
734         SuperClassMap::const_iterator begin = SuperClassMap::begin(), end = SuperClassMap::end();
735
736         long startPos = oss.tellp();
737
738         oss << "( " << className << "_id";
739         for (it = begin; it != end; it++)
740         {
741           if (it->second->isPublic())
742           {
743             oss << ", " << it->second->getName();
744             if ((long)oss.tellp() - startPos > 90)
745             {
746               oss << "  &" << iendl;
747               startPos = oss.tellp();
748             }
749           }
750         }
751         oss << " )";
752         oss << std::endl;
753         oss << iendl;
754
755         oss << "IMPLICIT NONE" << iendl++;
756
757         oss << "TYPE(txios(" << className << "))  :: " << className << "_hdl" << iendl;
758         oss << "CHARACTER(LEN=*), INTENT(IN) ::" << className << "_id";
759
760         for (it = begin; it != end; it++)
761         {
762           if (it->second->isPublic())
763           {
764             oss << iendl;
765             it->second->generateFortranInterfaceDeclaration(oss, className);
766           }
767         }
768
769         oss << std::endl << iendl;
770         oss << "CALL xios(get_" << className << "_handle) &" << iendl;
771         oss << "(" << className << "_id," << className << "_hdl)" << iendl;
772         oss << "CALL xios(set_" << className << "_attr_hdl_)   &" << iendl;
773
774         startPos = oss.tellp();
775
776         oss << "( " << className << "_hdl";
777         for (it = begin; it != end; it++)
778         {
779           if (it->second->isPublic())
780           {
781             oss << ", " << it->second->getName();
782             if ((long)oss.tellp() - startPos > 90)
783             {
784               oss << "  &" << iendl;
785               startPos = oss.tellp();
786             }
787           }
788         }
789         oss << " )";
790
791         oss << std::endl << (iendl -= 2);
792         oss << "END SUBROUTINE xios(set_" << className << "_attr)" << std::endl;
793      }
794
795      void CAttributeMap::generateFortranInterfaceGet_id(ostream& oss, const string& className)
796      {
797         oss << "SUBROUTINE xios(get_" << className << "_attr)  &" << iendl++;
798         SuperClassMap::const_iterator it;
799         SuperClassMap::const_iterator begin = SuperClassMap::begin(), end = SuperClassMap::end();
800
801         long startPos = oss.tellp();
802
803         oss << "( " << className << "_id";
804         for (it = begin; it != end; it++)
805         {
806           if (it->second->isPublic())
807           {
808             oss << ", " << it->second->getName();
809             if ((long)oss.tellp() - startPos > 90)
810             {
811               oss << "  &" << iendl;
812               startPos = oss.tellp();
813             }
814           }
815         }
816         oss << " )";
817         oss << std::endl;
818         oss << iendl;
819
820         oss << "IMPLICIT NONE" << iendl++;
821
822         oss << "TYPE(txios(" << className << "))  :: " << className << "_hdl" << iendl;
823         oss << "CHARACTER(LEN=*), INTENT(IN) ::" << className << "_id";
824
825         for (it = begin; it != end; it++)
826         {
827           if (it->second->isPublic())
828           {
829             oss << iendl;
830             it->second->generateFortranInterfaceGetDeclaration(oss, className);
831           }
832         }
833
834         oss << std::endl << iendl;
835         oss << "CALL xios(get_" << className << "_handle) &" << iendl;
836         oss << "(" << className << "_id," << className << "_hdl)" << iendl;
837         oss << "CALL xios(get_" << className << "_attr_hdl_)   &" << iendl;
838
839         startPos = oss.tellp();
840
841         oss << "( " << className << "_hdl";
842         for (it = begin; it != end; it++)
843         {
844           if (it->second->isPublic())
845           {
846             oss << ", " << it->second->getName();
847             if ((long)oss.tellp() - startPos > 90)
848             {
849               oss << "  &" << iendl;
850               startPos = oss.tellp();
851             }
852           }
853         }
854         oss << " )";
855
856         oss << std::endl << (iendl -= 2);
857         oss << "END SUBROUTINE xios(get_" << className << "_attr)" << std::endl;
858      }
859
860      void CAttributeMap::generateFortranInterfaceIsDefined_id(ostream& oss, const string& className)
861      {
862         oss << "SUBROUTINE xios(is_defined_" << className << "_attr)  &" << iendl++;
863         SuperClassMap::const_iterator it;
864         SuperClassMap::const_iterator begin = SuperClassMap::begin(), end = SuperClassMap::end();
865
866         long startPos = oss.tellp();
867
868         oss << "( " << className << "_id";
869         for (it = begin; it != end; it++)
870         {
871           if (it->second->isPublic())
872           {
873             oss << ", " << it->second->getName();
874             if ((long)oss.tellp() - startPos > 90)
875             {
876               oss << "  &" << iendl;
877               startPos = oss.tellp();
878             }
879           }
880         }
881         oss << " )";
882         oss << std::endl;
883         oss << iendl;
884
885         oss << "IMPLICIT NONE" << iendl++;
886
887         oss << "TYPE(txios(" << className << "))  :: " << className << "_hdl" << iendl;
888         oss << "CHARACTER(LEN=*), INTENT(IN) ::" << className << "_id";
889
890         for (it = begin; it != end; it++)
891         {
892           if (it->second->isPublic())
893           {
894             oss << iendl;
895             it->second->generateFortranInterfaceIsDefinedDeclaration(oss, className);
896           }
897         }
898
899         oss << std::endl << iendl;
900         oss << "CALL xios(get_" << className << "_handle) &" << iendl;
901         oss << "(" << className << "_id," << className << "_hdl)" << iendl;
902         oss << "CALL xios(is_defined_" << className << "_attr_hdl_)   &" << iendl;
903
904         startPos = oss.tellp();
905
906         oss << "( " << className << "_hdl";
907         for (it = begin; it != end; it++)
908         {
909           if (it->second->isPublic())
910           {
911             oss << ", " << it->second->getName();
912             if ((long)oss.tellp() - startPos > 90)
913             {
914               oss << "  &" << iendl;
915               startPos = oss.tellp();
916             }
917           }
918         }
919         oss << " )";
920
921         oss << std::endl << (iendl -= 2);
922         oss << "END SUBROUTINE xios(is_defined_" << className << "_attr)" << std::endl;
923      }
924} // namespace xios
Note: See TracBrowser for help on using the repository browser.