source: XIOS/dev/dev_olga/src/node/scalar.cpp @ 1144

Last change on this file since 1144 was 1144, checked in by mhnguyen, 7 years ago

Cleaning up some redundant codes

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