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

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

Adding a new type of element into grid: Scalar

+) Add a new node Scalar for xml
+) Make some change on writing scalar value
+) Reorganize some codes
+) Remove some redundant codes

Test
+) On Curie
+) All tests pass

File size: 3.3 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   StdString CScalar::GetName(void)   { return (StdString("scalar")); }
30   StdString CScalar::GetDefName(void){ return (CScalar::GetName()); }
31   ENodeType CScalar::GetType(void)   { return (eScalar); }
32
33   CScalar* CScalar::createScalar()
34   {
35     CScalar* scalar = CScalarGroup::get("scalar_definition")->createChild();
36     return scalar;
37   }
38
39   bool CScalar::IsWritten(const StdString & filename) const
40   {
41      return (this->relFiles.find(filename) != this->relFiles.end());
42   }
43
44   void CScalar::addRelFile(const StdString& filename)
45   {
46      this->relFiles.insert(filename);
47   }
48
49   void CScalar::checkAttributes(void)
50   {
51//      if (this->value.isEmpty())
52//      {
53//        this->value.setValue(0);
54//      }
55   }
56
57  void CScalar::checkAttributesOnClient()
58  {
59
60  }
61
62  CTransformation<CScalar>* CScalar::addTransformation(ETranformationType transType, const StdString& id)
63  {
64    transformationMap_.push_back(std::make_pair(transType, CTransformation<CScalar>::createTransformation(transType,id)));
65    return transformationMap_.back().second;
66  }
67
68  bool CScalar::hasTransformation()
69  {
70    return (!transformationMap_.empty());
71  }
72
73  void CScalar::setTransformations(const TransMapTypes& scalarTrans)
74  {
75    transformationMap_ = scalarTrans;
76  }
77
78  CScalar::TransMapTypes CScalar::getAllTransformations(void)
79  {
80    return transformationMap_;
81  }
82
83  /*!
84    Check the validity of all transformations applied on scalar
85  This functions is called AFTER all inherited attributes are solved
86  */
87  void CScalar::checkTransformations()
88  {
89    TransMapTypes::const_iterator itb = transformationMap_.begin(), it,
90                                  ite = transformationMap_.end();
91    for (it = itb; it != ite; ++it)
92    {
93      (it->second)->checkValid(this);
94    }
95  }
96
97  void CScalar::duplicateTransformation(CScalar* src)
98  {
99    if (src->hasTransformation())
100    {
101      this->setTransformations(src->getAllTransformations());
102    }
103  }
104
105  /*!
106   * Go through the hierarchy to find the scalar from which the transformations must be inherited
107   */
108  void CScalar::solveInheritanceTransformation()
109  {
110    if (hasTransformation() || !hasDirectScalarReference())
111      return;
112
113    CScalar* scalar = this;
114    std::vector<CScalar*> refScalar;
115    while (!scalar->hasTransformation() && scalar->hasDirectScalarReference())
116    {
117      refScalar.push_back(scalar);
118      scalar = scalar->getDirectScalarReference();
119    }
120
121    if (scalar->hasTransformation())
122      for (size_t i = 0; i < refScalar.size(); ++i)
123        refScalar[i]->setTransformations(scalar->getAllTransformations());
124  }
125
126
127  // Definition of some macros
128  DEFINE_REF_FUNC(Scalar,scalar)
129
130} // namespace xios
Note: See TracBrowser for help on using the repository browser.