source: XIOS3/trunk/src/attribute_map.cpp @ 2362

Last change on this file since 2362 was 2146, checked in by yushan, 3 years ago

Big commit on graph functionality. Other graph related dev

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