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

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

Ticket 110: Implementing domain reduction to scalar

+) Add xml node for this new transformation
+) Add algorithm for this new transformation

Test
+) On Curie
+) Work

File size: 5.0 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  /*!
89    Check the validity of all transformations applied on scalar
90  This functions is called AFTER all inherited attributes are solved
91  */
92  void CScalar::checkTransformations()
93  {
94    TransMapTypes::const_iterator itb = transformationMap_.begin(), it,
95                                  ite = transformationMap_.end();
96//    for (it = itb; it != ite; ++it)
97//    {
98//      (it->second)->checkValid(this);
99//    }
100  }
101
102  void CScalar::duplicateTransformation(CScalar* src)
103  {
104    if (src->hasTransformation())
105    {
106      this->setTransformations(src->getAllTransformations());
107    }
108  }
109
110  /*!
111   * Go through the hierarchy to find the scalar from which the transformations must be inherited
112   */
113  void CScalar::solveInheritanceTransformation()
114  {
115    if (hasTransformation() || !hasDirectScalarReference())
116      return;
117
118    CScalar* scalar = this;
119    std::vector<CScalar*> refScalar;
120    while (!scalar->hasTransformation() && scalar->hasDirectScalarReference())
121    {
122      refScalar.push_back(scalar);
123      scalar = scalar->getDirectScalarReference();
124    }
125
126    if (scalar->hasTransformation())
127      for (size_t i = 0; i < refScalar.size(); ++i)
128        refScalar[i]->setTransformations(scalar->getAllTransformations());
129  }
130
131  /*!
132    Parse children nodes of a scalar in xml file.
133    \param node child node to process
134  */
135  void CScalar::parse(xml::CXMLNode & node)
136  {
137    SuperClass::parse(node);
138
139    if (node.goToChildElement())
140    {
141      StdString nodeElementName;
142      do
143      {
144        StdString nodeId("");
145        if (node.getAttributes().end() != node.getAttributes().find("id"))
146        { nodeId = node.getAttributes()["id"]; }
147
148        nodeElementName = node.getElementName();
149        std::map<StdString, ETranformationType>::const_iterator ite = transformationMapList_.end(), it;
150        it = transformationMapList_.find(nodeElementName);
151        if (ite != it)
152        {
153          transformationMap_.push_back(std::make_pair(it->second, CTransformation<CScalar>::createTransformation(it->second,
154                                                                                                                 nodeId,
155                                                                                                                 &node)));
156        }
157        else
158        {
159          ERROR("void CScalar::parse(xml::CXMLNode & node)",
160                << "The transformation " << nodeElementName << " has not been supported yet.");
161        }
162      } while (node.goToNextElement()) ;
163      node.goToParentElement();
164    }
165  }
166
167  // Definition of some macros
168  DEFINE_REF_FUNC(Scalar,scalar)
169
170} // namespace xios
Note: See TracBrowser for help on using the repository browser.