source: XIOS3/trunk/src/attribute_map.cpp

Last change on this file was 2633, checked in by ymipsl, 2 months 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
RevLine 
[219]1#include "attribute_map.hpp"
[313]2#include "indent.hpp"
[219]3
[335]4namespace xios
[219]5{
6      /// ////////////////////// Définitions ////////////////////// ///
[581]7      CAttributeMap* CAttributeMap::Current = NULL;
[219]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 */ }
[509]15
[219]16      ///--------------------------------------------------------------
17
[1158]18      /*!
19         Clear all attributes of an object and reset them to empty state
20      */
[219]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         {
[581]27            const StdStrAttPair& att = *it;
[369]28            att.second->reset();
[219]29         }
30      }
31
[1622]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
[2146]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
[219]82      //---------------------------------------------------------------
83
[1158]84      /*
[2146]85        Cleassr an attribute and reset its value
[1158]86        \param[in] key id of attribute
87      */
[509]88      void CAttributeMap::clearAttribute(const StdString& key)
89      {
90        if (hasAttribute(key)) this->find(key)->second->reset();
91      }
92
[219]93      //---------------------------------------------------------------
[509]94
[1158]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      */
[581]100      void CAttributeMap::setAttribute(const StdString& key, CAttribute* const attr)
[219]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 !");
[581]108         this->find(key)->second->set(*attr);
109//       this->find(key)->second->setAnyValue(attr->getAnyValue());
[219]110      }
[509]111
[219]112      //---------------------------------------------------------------
[509]113
[1158]114      /*!
115        Subscript operator. Return attribute with a specific id
116      */
[581]117      CAttribute* CAttributeMap::operator[](const StdString& key)
[219]118      {
119         if (!this->hasAttribute(key))
[581]120            ERROR("CAttributeMap::operator[](const StdString& key)",
[219]121                  << "[ key = " << key << "] key not found !");
[581]122         return SuperClassMap::operator[](key);
[219]123      }
[509]124
[219]125      //---------------------------------------------------------------
[509]126
[219]127      StdString CAttributeMap::toString(void) const
128      {
129         typedef std::pair<StdString, CAttribute*> StdStrAttPair;
130         StdOStringStream oss;
[509]131
[219]132         SuperClassMap::const_iterator it = SuperClassMap::begin(), end = SuperClassMap::end();
133         for (; it != end; it++)
134         {
[581]135            const StdStrAttPair& att = *it;
[219]136            if (!att.second->isEmpty())
137               oss << *att.second << " ";
138         }
[581]139         return oss.str();
[219]140      }
[509]141
[219]142      //---------------------------------------------------------------
[509]143
[581]144      void CAttributeMap::fromString(const StdString& str)
[509]145      {
[581]146         ERROR("CAttributeMap::fromString(const StdString& str)",
[509]147               << "[ str = " << str << "] Not implemented yet !");
[219]148      }
[509]149
[219]150      //---------------------------------------------------------------
151
[581]152      //StdOStream& operator << (StdOStream& os, const CAttributeMap& attributmap)
[219]153      //{ os << attributmap.toString(); return (os); }
[509]154
[219]155      //---------------------------------------------------------------
[509]156
[581]157      void CAttributeMap::setAttributes(const xml::THashAttributes& attributes)
[219]158      {
159         for (xml::THashAttributes::const_iterator it  = attributes.begin();
160                                                   it != attributes.end();
[581]161                                                   it++)
[278]162         {
[581]163            if ((*it).first.compare(StdString("id")) != 0 && (*it).first.compare(StdString("src")) != 0)
[219]164            {
165               //if (CAttributeMap::operator[]((*it).first)->isEmpty())
166               CAttributeMap::operator[]((*it).first)->fromString((*it).second);
167            }
[278]168         }
[219]169      }
[509]170
[1158]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
[219]213      //---------------------------------------------------------------
[509]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      */
[581]224      void CAttributeMap::setAttributes(const CAttributeMap* const _parent, bool apply)
[219]225      {
226         typedef std::pair<StdString, CAttribute*> StdStrAttPair;
[509]227
[219]228         SuperClassMap::const_iterator it = _parent->begin(), end = _parent->end();
229         for (; it != end; it++)
230         {
[581]231            const StdStrAttPair& el = *it;
[219]232            if (this->hasAttribute(el.first))
233            {
[581]234               CAttribute* currentAtt = CAttributeMap::operator[](el.first);
235               CAttribute* parentAtt = el.second;
[445]236               if (apply)
[219]237               {
[1158]238                 if (currentAtt->isEmpty() && currentAtt->canInherite() && !el.second->isEmpty())
[445]239                 {
240                    this->setAttribute(el.first, el.second);
241                 }
[2633]242                 else if (currentAtt->isEmpty() && currentAtt->canInherite() && el.second->isEmpty() && !el.second->canInherite())
243                 {
244                    currentAtt->setCannotInherit() ; // propagate non-inheritance
245                 }
[219]246               }
[581]247               else currentAtt->setInheritedValue(*parentAtt);
[219]248            }
249         }
250      }
[509]251
[1158]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      */
[623]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
[2386]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      */
[2388]279      size_t CAttributeMap::computeGlobalAttributesHash(const vector<StdString>& excludedAttrs)
[2386]280      {
[2388]281         size_t attrs_hash( 0 );
[2386]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 
[219]302      //---------------------------------------------------------------
[509]303/*
[581]304      void CAttributeMap::toBinary(StdOStream& os) const
[219]305      {
306         typedef std::pair<StdString, CAttribute*> StdStrAttPair;
307         SuperClassMap::const_iterator it = this->begin(), end = this->end();
[509]308
[219]309         const StdSize nbatt = SuperClassMap::size();
310         os.write (reinterpret_cast<const char*>(&nbatt) , sizeof(StdSize));
[509]311
[219]312         for (; it != end; it++)
313         {
[581]314            const StdString& key   = it->first;
[509]315            const CAttribute* value = it->second;
[219]316            const StdSize size = key.size();
[509]317
[219]318            os.write (reinterpret_cast<const char*>(&size) , sizeof(StdSize));
[581]319            os.write (key.data(), size* sizeof(char));
[509]320
[219]321            if (!value->isEmpty())
322            {
323               bool b = true;
324               os.write (reinterpret_cast<const char*>(&b) , sizeof(bool));
325               value->toBinary(os);
326            }
[509]327            else
[219]328            {
329               bool b = false;
330               os.write (reinterpret_cast<const char*>(&b) , sizeof(bool));
331            }
332         }
333      }
[509]334
[219]335      //---------------------------------------------------------------
[509]336
[581]337      void CAttributeMap::fromBinary(StdIStream& is)
[219]338      {
339         StdSize nbatt = 0;
340         is.read (reinterpret_cast<char*>(&nbatt), sizeof(StdSize));
[509]341
[219]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, ' ');
[581]348            is.read (const_cast<char *>(key.data()), size* sizeof(char));
[509]349
[219]350            if (!this->hasAttribute(key))
[581]351               ERROR("CAttributeMap::fromBinary(StdIStream& is)",
[219]352                     << "[ key = " << key << "] key not found !");
[509]353
[219]354            is.read (reinterpret_cast<char*>(&hasValue), sizeof(bool));
[509]355
356            if (hasValue)
[219]357               this->operator[](key)->fromBinary(is);
358         }
359      }
[509]360 */
[1158]361     
[313]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         {
[778]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           }
[313]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         {
[778]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           }
[313]389         }
[509]390      }
391
[219]392      ///--------------------------------------------------------------
393
[313]394      void CAttributeMap::generateFortranInterface_hdl_(ostream& oss, const string& className)
395      {
[581]396         oss << "SUBROUTINE xios(set_" << className << "_attr_hdl_)   &" << iendl++;
397         SuperClassMap::const_iterator it;
[313]398         SuperClassMap::const_iterator begin = SuperClassMap::begin(), end = SuperClassMap::end();
[509]399
[649]400         long startPos = oss.tellp();
[509]401
[649]402         oss << "( " << className << "_hdl";
[581]403         for (it = begin; it != end; it++)
[313]404         {
[778]405           if (it->second->isPublic())
[313]406           {
[778]407             oss << ", " << it->second->getName() << "_";
[2471]408             if ((long)oss.tellp() - startPos > 90)
[778]409             {
410               oss << "  &" << iendl;
411               startPos = oss.tellp();
412             }
[313]413           }
414         }
[649]415         oss << " )";
416         oss << std::endl;
[581]417         oss << iendl;
[509]418
[581]419         oss << "IMPLICIT NONE" << iendl++;
420         oss << "TYPE(txios(" << className << ")) , INTENT(IN) :: " << className << "_hdl";
[509]421
[581]422         for (it = begin; it != end; it++)
[313]423         {
[778]424           if (it->second->isPublic())
425           {
426             oss << iendl;
427             it->second->generateFortranInterfaceDeclaration_(oss, className);
428           }
[313]429         }
[509]430
[581]431         for (it = begin; it != end; it++)
[313]432         {
[778]433           if (it->second->isPublic())
434           {
435             oss << std::endl << iendl;
436             it->second->generateFortranInterfaceBody_(oss, className);
437           }
[313]438         }
[509]439
[581]440         oss << std::endl << (iendl -= 2);
441         oss << "END SUBROUTINE xios(set_" << className << "_attr_hdl_)" << std::endl;
[509]442      }
443
[313]444      void CAttributeMap::generateFortranInterfaceGet_hdl_(ostream& oss, const string& className)
445      {
[581]446         oss << "SUBROUTINE xios(get_" << className << "_attr_hdl_)   &" << iendl++;
447         SuperClassMap::const_iterator it;
[313]448         SuperClassMap::const_iterator begin = SuperClassMap::begin(), end = SuperClassMap::end();
[509]449
[649]450         long startPos = oss.tellp();
[509]451
[649]452         oss << "( " << className << "_hdl";
[581]453         for (it = begin; it != end; it++)
[313]454         {
[778]455           if (it->second->isPublic())
[313]456           {
[778]457             oss << ", " << it->second->getName() << "_";
[2471]458             if ((long)oss.tellp() - startPos > 90)
[778]459             {
460               oss << "  &" << iendl;
461               startPos = oss.tellp();
462             }
[313]463           }
464         }
[649]465         oss << " )";
466         oss << std::endl;
[581]467         oss << iendl;
[509]468
[581]469         oss << "IMPLICIT NONE" << iendl++;
470         oss << "TYPE(txios(" << className << ")) , INTENT(IN) :: " << className << "_hdl";
[509]471
[581]472         for (it = begin; it != end; it++)
[313]473         {
[778]474           if (it->second->isPublic())
475           {
476             oss << iendl;
477             it->second->generateFortranInterfaceGetDeclaration_(oss, className);
478           }
[313]479         }
[509]480
[581]481         for (it = begin; it != end; it++)
[313]482         {
[778]483           if (it->second->isPublic())
484           {
485             oss << std::endl << iendl;
486             it->second->generateFortranInterfaceGetBody_(oss, className);
487           }
[313]488         }
[509]489
[581]490         oss << std::endl << (iendl -= 2);
491         oss << "END SUBROUTINE xios(get_" << className << "_attr_hdl_)" << std::endl;
[509]492      }
493
[432]494      void CAttributeMap::generateFortranInterfaceIsDefined_hdl_(ostream& oss, const string& className)
495      {
[581]496         oss << "SUBROUTINE xios(is_defined_" << className << "_attr_hdl_)   &" << iendl++;
497         SuperClassMap::const_iterator it;
[432]498         SuperClassMap::const_iterator begin = SuperClassMap::begin(), end = SuperClassMap::end();
[509]499
[649]500         long startPos = oss.tellp();
[509]501
[649]502         oss << "( " << className << "_hdl";
[581]503         for (it = begin; it != end; it++)
[432]504         {
[778]505           if (it->second->isPublic())
[432]506           {
[778]507             oss << ", " << it->second->getName() << "_";
[2471]508             if ((long)oss.tellp() - startPos > 90)
[778]509             {
510               oss << "  &" << iendl;
511               startPos = oss.tellp();
512             }
[432]513           }
514         }
[649]515         oss << " )";
516         oss << std::endl;
[581]517         oss << iendl;
[509]518
[581]519         oss << "IMPLICIT NONE" << iendl++;
520         oss << "TYPE(txios(" << className << ")) , INTENT(IN) :: " << className << "_hdl";
[509]521
[581]522         for (it = begin; it != end; it++)
[432]523         {
[778]524           if (it->second->isPublic())
525           {
526             oss << iendl;
527             it->second->generateFortranInterfaceIsDefinedDeclaration_(oss, className);
528           }
[432]529         }
[509]530
[581]531         for (it = begin; it != end; it++)
[432]532         {
[778]533           if (it->second->isPublic())
534           {
535             oss << std::endl << iendl;
536             it->second->generateFortranInterfaceIsDefinedBody_(oss, className);
537           }
[432]538         }
[509]539
[581]540         oss << std::endl << (iendl -= 2);
541         oss << "END SUBROUTINE xios(is_defined_" << className << "_attr_hdl_)" << std::endl;
[509]542      }
543
[313]544      void CAttributeMap::generateFortranInterface_hdl(ostream& oss, const string& className)
545      {
[581]546         oss << "SUBROUTINE xios(set_" << className << "_attr_hdl)  &" << iendl++;
547         SuperClassMap::const_iterator it;
[313]548         SuperClassMap::const_iterator begin = SuperClassMap::begin(), end = SuperClassMap::end();
[509]549
[649]550         long startPos = oss.tellp();
551
552         oss << "( " << className << "_hdl";
[581]553         for (it = begin; it != end; it++)
[313]554         {
[778]555           if (it->second->isPublic())
[313]556           {
[778]557             oss << ", " << it->second->getName();
[2471]558             if ((long)oss.tellp() - startPos > 90)
[778]559             {
560               oss << "  &" << iendl;
561               startPos = oss.tellp();
562             }
[313]563           }
564         }
[649]565         oss << " )";
566         oss << std::endl;
[581]567         oss << iendl;
[509]568
[581]569         oss << "IMPLICIT NONE" << iendl++;
570         oss << "TYPE(txios(" << className << ")) , INTENT(IN) :: " << className << "_hdl";
[509]571
[581]572         for (it = begin; it != end; it++)
[313]573         {
[778]574           if (it->second->isPublic())
575           {
576             oss << iendl;
577             it->second->generateFortranInterfaceDeclaration(oss, className);
578           }
[313]579         }
[509]580
[581]581         oss << std::endl << iendl;
[509]582
[581]583         oss << "CALL xios(set_" << className << "_attr_hdl_)  &" << iendl;
[509]584
[649]585         startPos = oss.tellp();
586
587         oss << "( " << className << "_hdl";
[581]588         for (it = begin; it != end; it++)
[313]589         {
[778]590           if (it->second->isPublic())
[313]591           {
[778]592             oss << ", " << it->second->getName();
[2471]593             if ((long)oss.tellp() - startPos > 90)
[778]594             {
595               oss << "  &" << iendl;
596               startPos = oss.tellp();
597             }
[313]598           }
599         }
[649]600         oss << " )";
[509]601
[581]602         oss << std::endl << (iendl -= 2);
603         oss << "END SUBROUTINE xios(set_" << className << "_attr_hdl)" << std::endl;
[509]604      }
605
[313]606      void CAttributeMap::generateFortranInterfaceGet_hdl(ostream& oss, const string& className)
607      {
[581]608         oss << "SUBROUTINE xios(get_" << className << "_attr_hdl)  &" << iendl++;
609         SuperClassMap::const_iterator it;
[313]610         SuperClassMap::const_iterator begin = SuperClassMap::begin(), end = SuperClassMap::end();
[509]611
[649]612         long startPos = oss.tellp();
613
614         oss << "( " << className << "_hdl";
[581]615         for (it = begin; it != end; it++)
[313]616         {
[778]617           if (it->second->isPublic())
[313]618           {
[778]619             oss << ", " << it->second->getName();
[2471]620             if ((long)oss.tellp() - startPos > 90)
[778]621             {
622               oss << "  &" << iendl;
623               startPos = oss.tellp();
624             }
[313]625           }
626         }
[649]627         oss << " )";
628         oss << std::endl;
[581]629         oss << iendl;
[509]630
[581]631         oss << "IMPLICIT NONE" << iendl++;
632         oss << "TYPE(txios(" << className << ")) , INTENT(IN) :: " << className << "_hdl";
[509]633
[581]634         for (it = begin; it != end; it++)
[313]635         {
[778]636           if (it->second->isPublic())
637           {
638             oss << iendl;
639             it->second->generateFortranInterfaceGetDeclaration(oss, className);
640           }
[313]641         }
[509]642
[581]643         oss << std::endl << iendl;
[509]644
[581]645         oss << "CALL xios(get_" << className << "_attr_hdl_)  &" << iendl;
[509]646
[649]647         startPos = oss.tellp();
648
649         oss << "( " << className << "_hdl";
[581]650         for (it = begin; it != end; it++)
[313]651         {
[778]652           if (it->second->isPublic())
[313]653           {
[778]654             oss << ", " << it->second->getName();
[2471]655             if ((long)oss.tellp() - startPos > 90)
[778]656             {
657               oss << "  &" << iendl;
658               startPos = oss.tellp();
659             }
[313]660           }
661         }
[649]662         oss << " )";
[509]663
[581]664         oss << std::endl << (iendl -= 2);
665         oss << "END SUBROUTINE xios(get_" << className << "_attr_hdl)" << std::endl;
[509]666      }
[432]667
668      void CAttributeMap::generateFortranInterfaceIsDefined_hdl(ostream& oss, const string& className)
669      {
[581]670         oss << "SUBROUTINE xios(is_defined_" << className << "_attr_hdl)  &" << iendl++;
671         SuperClassMap::const_iterator it;
[432]672         SuperClassMap::const_iterator begin = SuperClassMap::begin(), end = SuperClassMap::end();
[509]673
[649]674         long startPos = oss.tellp();
675
676         oss << "( " << className << "_hdl";
[581]677         for (it = begin; it != end; it++)
[432]678         {
[778]679           if (it->second->isPublic())
[432]680           {
[778]681             oss << ", " << it->second->getName();
[2471]682             if ((long)oss.tellp() - startPos > 90)
[778]683             {
684               oss << "  &" << iendl;
685               startPos = oss.tellp();
686             }
[432]687           }
688         }
[649]689         oss << " )";
690         oss << std::endl;
[581]691         oss << iendl;
[509]692
[581]693         oss << "IMPLICIT NONE" << iendl++;
694         oss << "TYPE(txios(" << className << ")) , INTENT(IN) :: " << className << "_hdl";
[509]695
[581]696         for (it = begin; it != end; it++)
[432]697         {
[778]698           if (it->second->isPublic())
699           {
700             oss << iendl;
701             it->second->generateFortranInterfaceIsDefinedDeclaration(oss, className);
702           }
[432]703         }
[509]704
[581]705         oss << std::endl << iendl;
[509]706
[581]707         oss << "CALL xios(is_defined_" << className << "_attr_hdl_)  &" << iendl;
[509]708
[649]709         startPos = oss.tellp();
710
711         oss << "( " << className << "_hdl";
[581]712         for (it = begin; it != end; it++)
[432]713         {
[778]714           if (it->second->isPublic())
[432]715           {
[778]716             oss << ", " << it->second->getName();
[2471]717             if ((long)oss.tellp() - startPos > 90)
[778]718             {
719               oss << "  &" << iendl;
720               startPos = oss.tellp();
721             }
[432]722           }
723         }
[649]724         oss << " )";
[509]725
[581]726         oss << std::endl << (iendl -= 2);
727         oss << "END SUBROUTINE xios(is_defined_" << className << "_attr_hdl)" << std::endl;
[509]728      }
[432]729
[313]730      void CAttributeMap::generateFortranInterface_id(ostream& oss, const string& className)
731      {
[581]732         oss << "SUBROUTINE xios(set_" << className << "_attr)  &" << iendl++;
733         SuperClassMap::const_iterator it;
[313]734         SuperClassMap::const_iterator begin = SuperClassMap::begin(), end = SuperClassMap::end();
[509]735
[649]736         long startPos = oss.tellp();
737
738         oss << "( " << className << "_id";
[581]739         for (it = begin; it != end; it++)
[313]740         {
[778]741           if (it->second->isPublic())
[313]742           {
[778]743             oss << ", " << it->second->getName();
[2471]744             if ((long)oss.tellp() - startPos > 90)
[778]745             {
746               oss << "  &" << iendl;
747               startPos = oss.tellp();
748             }
[313]749           }
750         }
[649]751         oss << " )";
752         oss << std::endl;
[581]753         oss << iendl;
[509]754
[581]755         oss << "IMPLICIT NONE" << iendl++;
[313]756
[581]757         oss << "TYPE(txios(" << className << "))  :: " << className << "_hdl" << iendl;
758         oss << "CHARACTER(LEN=*), INTENT(IN) ::" << className << "_id";
[509]759
[581]760         for (it = begin; it != end; it++)
[313]761         {
[778]762           if (it->second->isPublic())
763           {
764             oss << iendl;
765             it->second->generateFortranInterfaceDeclaration(oss, className);
766           }
[313]767         }
[509]768
[581]769         oss << std::endl << iendl;
[966]770         oss << "CALL xios(get_" << className << "_handle) &" << iendl;
771         oss << "(" << className << "_id," << className << "_hdl)" << iendl;
[581]772         oss << "CALL xios(set_" << className << "_attr_hdl_)   &" << iendl;
[649]773
774         startPos = oss.tellp();
775
776         oss << "( " << className << "_hdl";
[581]777         for (it = begin; it != end; it++)
[313]778         {
[778]779           if (it->second->isPublic())
[313]780           {
[778]781             oss << ", " << it->second->getName();
[2471]782             if ((long)oss.tellp() - startPos > 90)
[778]783             {
784               oss << "  &" << iendl;
785               startPos = oss.tellp();
786             }
[313]787           }
788         }
[649]789         oss << " )";
[509]790
[581]791         oss << std::endl << (iendl -= 2);
792         oss << "END SUBROUTINE xios(set_" << className << "_attr)" << std::endl;
[509]793      }
794
[313]795      void CAttributeMap::generateFortranInterfaceGet_id(ostream& oss, const string& className)
796      {
[581]797         oss << "SUBROUTINE xios(get_" << className << "_attr)  &" << iendl++;
798         SuperClassMap::const_iterator it;
[313]799         SuperClassMap::const_iterator begin = SuperClassMap::begin(), end = SuperClassMap::end();
[509]800
[649]801         long startPos = oss.tellp();
802
803         oss << "( " << className << "_id";
[581]804         for (it = begin; it != end; it++)
[313]805         {
[778]806           if (it->second->isPublic())
[313]807           {
[778]808             oss << ", " << it->second->getName();
[2471]809             if ((long)oss.tellp() - startPos > 90)
[778]810             {
811               oss << "  &" << iendl;
812               startPos = oss.tellp();
813             }
[313]814           }
815         }
[649]816         oss << " )";
817         oss << std::endl;
[581]818         oss << iendl;
[509]819
[581]820         oss << "IMPLICIT NONE" << iendl++;
[313]821
[581]822         oss << "TYPE(txios(" << className << "))  :: " << className << "_hdl" << iendl;
823         oss << "CHARACTER(LEN=*), INTENT(IN) ::" << className << "_id";
[509]824
[581]825         for (it = begin; it != end; it++)
[313]826         {
[778]827           if (it->second->isPublic())
828           {
829             oss << iendl;
830             it->second->generateFortranInterfaceGetDeclaration(oss, className);
831           }
[313]832         }
[509]833
[581]834         oss << std::endl << iendl;
[966]835         oss << "CALL xios(get_" << className << "_handle) &" << iendl;
836         oss << "(" << className << "_id," << className << "_hdl)" << iendl;
[581]837         oss << "CALL xios(get_" << className << "_attr_hdl_)   &" << iendl;
[649]838
839         startPos = oss.tellp();
840
841         oss << "( " << className << "_hdl";
[581]842         for (it = begin; it != end; it++)
[313]843         {
[778]844           if (it->second->isPublic())
[313]845           {
[778]846             oss << ", " << it->second->getName();
[2471]847             if ((long)oss.tellp() - startPos > 90)
[778]848             {
849               oss << "  &" << iendl;
850               startPos = oss.tellp();
851             }
[313]852           }
853         }
[649]854         oss << " )";
[509]855
[581]856         oss << std::endl << (iendl -= 2);
857         oss << "END SUBROUTINE xios(get_" << className << "_attr)" << std::endl;
[509]858      }
859
[432]860      void CAttributeMap::generateFortranInterfaceIsDefined_id(ostream& oss, const string& className)
861      {
[581]862         oss << "SUBROUTINE xios(is_defined_" << className << "_attr)  &" << iendl++;
863         SuperClassMap::const_iterator it;
[432]864         SuperClassMap::const_iterator begin = SuperClassMap::begin(), end = SuperClassMap::end();
[509]865
[649]866         long startPos = oss.tellp();
867
868         oss << "( " << className << "_id";
[581]869         for (it = begin; it != end; it++)
[432]870         {
[778]871           if (it->second->isPublic())
[432]872           {
[778]873             oss << ", " << it->second->getName();
[2471]874             if ((long)oss.tellp() - startPos > 90)
[778]875             {
876               oss << "  &" << iendl;
877               startPos = oss.tellp();
878             }
[432]879           }
880         }
[649]881         oss << " )";
882         oss << std::endl;
[581]883         oss << iendl;
[509]884
[581]885         oss << "IMPLICIT NONE" << iendl++;
[432]886
[581]887         oss << "TYPE(txios(" << className << "))  :: " << className << "_hdl" << iendl;
888         oss << "CHARACTER(LEN=*), INTENT(IN) ::" << className << "_id";
[509]889
[581]890         for (it = begin; it != end; it++)
[432]891         {
[778]892           if (it->second->isPublic())
893           {
894             oss << iendl;
895             it->second->generateFortranInterfaceIsDefinedDeclaration(oss, className);
896           }
[432]897         }
[509]898
[581]899         oss << std::endl << iendl;
[966]900         oss << "CALL xios(get_" << className << "_handle) &" << iendl;
901         oss << "(" << className << "_id," << className << "_hdl)" << iendl;
[581]902         oss << "CALL xios(is_defined_" << className << "_attr_hdl_)   &" << iendl;
[649]903
904         startPos = oss.tellp();
905
906         oss << "( " << className << "_hdl";
[581]907         for (it = begin; it != end; it++)
[432]908         {
[778]909           if (it->second->isPublic())
[432]910           {
[778]911             oss << ", " << it->second->getName();
[2471]912             if ((long)oss.tellp() - startPos > 90)
[778]913             {
914               oss << "  &" << iendl;
915               startPos = oss.tellp();
916             }
[432]917           }
918         }
[649]919         oss << " )";
[509]920
[581]921         oss << std::endl << (iendl -= 2);
922         oss << "END SUBROUTINE xios(is_defined_" << className << "_attr)" << std::endl;
[509]923      }
[591]924} // namespace xios
Note: See TracBrowser for help on using the repository browser.