source: XIOS/dev/branch_yushan/src/node/scalar.cpp @ 1109

Last change on this file since 1109 was 1109, checked in by yushan, 7 years ago

test_omp OK

File size: 5.6 KB
Line 
1#include "scalar.hpp"
2
3#include "attribute_template.hpp"
4#include "object_template.hpp"
5#include "group_template.hpp"
6#include "object_factory.hpp"
7#include "xios_spl.hpp"
8#include "type.hpp"
9
10namespace xios {
11
12   /// ////////////////////// Définitions ////////////////////// ///
13
14   CScalar::CScalar(void)
15      : CObjectTemplate<CScalar>()
16      , CScalarAttributes()
17      , relFiles()
18   { /* Ne rien faire de plus */ }
19
20   CScalar::CScalar(const StdString & id)
21      : CObjectTemplate<CScalar>(id)
22      , CScalarAttributes()
23      , relFiles()
24   { /* Ne rien faire de plus */ }
25
26   CScalar::~CScalar(void)
27   { /* Ne rien faire de plus */ }
28
29   //std::map<StdString, ETranformationType> CScalar::transformationMapList_ = std::map<StdString, ETranformationType>();
30   //bool CScalar::dummyTransformationMapList_ = CScalar::initializeTransformationMap(CScalar::transformationMapList_);
31
32   std::map<StdString, ETranformationType> *CScalar::transformationMapList_ptr = 0;
33   
34   bool CScalar::initializeTransformationMap(std::map<StdString, ETranformationType>& m)
35   {
36     m["reduce_axis"]   = TRANS_REDUCE_AXIS_TO_SCALAR;
37     m["extract_axis"]  = TRANS_EXTRACT_AXIS_TO_SCALAR;
38     m["reduce_domain"] = TRANS_REDUCE_DOMAIN_TO_SCALAR;
39   }
40
41   bool CScalar::initializeTransformationMap()
42   {
43     CScalar::transformationMapList_ptr = new std::map<StdString, ETranformationType>();
44     (*CScalar::transformationMapList_ptr)["reduce_axis"]   = TRANS_REDUCE_AXIS_TO_SCALAR;
45     (*CScalar::transformationMapList_ptr)["extract_axis"]  = TRANS_EXTRACT_AXIS_TO_SCALAR;
46     (*CScalar::transformationMapList_ptr)["reduce_domain"] = TRANS_REDUCE_DOMAIN_TO_SCALAR;
47   }
48
49   StdString CScalar::GetName(void)   { return (StdString("scalar")); }
50   StdString CScalar::GetDefName(void){ return (CScalar::GetName()); }
51   ENodeType CScalar::GetType(void)   { return (eScalar); }
52
53   CScalar* CScalar::createScalar()
54   {
55     CScalar* scalar = CScalarGroup::get("scalar_definition")->createChild();
56     return scalar;
57   }
58
59   bool CScalar::IsWritten(const StdString & filename) const
60   {
61      return (this->relFiles.find(filename) != this->relFiles.end());
62   }
63
64   void CScalar::addRelFile(const StdString& filename)
65   {
66      this->relFiles.insert(filename);
67   }
68
69   void CScalar::checkAttributes(void)
70   {
71   }
72
73  void CScalar::checkAttributesOnClient()
74  {
75
76  }
77
78  CTransformation<CScalar>* CScalar::addTransformation(ETranformationType transType, const StdString& id)
79  {
80    transformationMap_.push_back(std::make_pair(transType, CTransformation<CScalar>::createTransformation(transType,id)));
81    return transformationMap_.back().second;
82  }
83
84  bool CScalar::hasTransformation()
85  {
86    return (!transformationMap_.empty());
87  }
88
89  void CScalar::setTransformations(const TransMapTypes& scalarTrans)
90  {
91    transformationMap_ = scalarTrans;
92  }
93
94  CScalar::TransMapTypes CScalar::getAllTransformations(void)
95  {
96    return transformationMap_;
97  }
98
99  /*!
100    Check the validity of all transformations applied on scalar
101  This functions is called AFTER all inherited attributes are solved
102  */
103  void CScalar::checkTransformations()
104  {
105    TransMapTypes::const_iterator itb = transformationMap_.begin(), it,
106                                  ite = transformationMap_.end();
107//    for (it = itb; it != ite; ++it)
108//    {
109//      (it->second)->checkValid(this);
110//    }
111  }
112
113  void CScalar::duplicateTransformation(CScalar* src)
114  {
115    if (src->hasTransformation())
116    {
117      this->setTransformations(src->getAllTransformations());
118    }
119  }
120
121  /*!
122   * Go through the hierarchy to find the scalar from which the transformations must be inherited
123   */
124  void CScalar::solveInheritanceTransformation()
125  {
126    if (hasTransformation() || !hasDirectScalarReference())
127      return;
128
129    CScalar* scalar = this;
130    std::vector<CScalar*> refScalar;
131    while (!scalar->hasTransformation() && scalar->hasDirectScalarReference())
132    {
133      refScalar.push_back(scalar);
134      scalar = scalar->getDirectScalarReference();
135    }
136
137    if (scalar->hasTransformation())
138      for (size_t i = 0; i < refScalar.size(); ++i)
139        refScalar[i]->setTransformations(scalar->getAllTransformations());
140  }
141
142  /*!
143    Parse children nodes of a scalar in xml file.
144    \param node child node to process
145  */
146  void CScalar::parse(xml::CXMLNode & node)
147  {
148    SuperClass::parse(node);
149
150    if (node.goToChildElement())
151    {
152      StdString nodeElementName;
153      do
154      {
155        StdString nodeId("");
156        if (node.getAttributes().end() != node.getAttributes().find("id"))
157        { nodeId = node.getAttributes()["id"]; }
158
159        nodeElementName = node.getElementName();
160        if(CScalar::transformationMapList_ptr == 0) initializeTransformationMap();
161        std::map<StdString, ETranformationType>::const_iterator ite = (*CScalar::transformationMapList_ptr).end(), it;
162        it = (*CScalar::transformationMapList_ptr).find(nodeElementName);
163        if (ite != it)
164        {
165          transformationMap_.push_back(std::make_pair(it->second, CTransformation<CScalar>::createTransformation(it->second,
166                                                                                                                 nodeId,
167                                                                                                                 &node)));
168        }
169        else
170        {
171          ERROR("void CScalar::parse(xml::CXMLNode & node)",
172                << "The transformation " << nodeElementName << " has not been supported yet.");
173        }
174      } while (node.goToNextElement()) ;
175      node.goToParentElement();
176    }
177  }
178
179  // Definition of some macros
180  DEFINE_REF_FUNC(Scalar,scalar)
181
182} // namespace xios
Note: See TracBrowser for help on using the repository browser.