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

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

Adding new transformation for scalar: Reducing an axis to a scalar

+) Add new xml node for new transformation
+) Add new algorithms for axis reduction
+) Make change in some place to make sure everything work fine

Test
+) On Curie
+) Tests pass and are correct

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