source: XIOS/dev/dev_trunk_graph/src/attribute_map.cpp @ 2030

Last change on this file since 2030 was 2019, checked in by yushan, 3 years ago

Graph intermedia commit to a tmp branch

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