source: XIOS/trunk/src/node/scalar.cpp @ 968

Last change on this file since 968 was 968, checked in by mhnguyen, 8 years ago

Improvements: Tighten checking transformation type in xml

+) A not-supported transformation will cause error message

Test
+) On Curie
+) OK

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