source: XIOS/branchs/xios-2.5/src/node/scalar.cpp @ 1850

Last change on this file since 1850 was 1850, checked in by ymipsl, 4 years ago

Compiler fix : solve the problem of crash occured with recent version of GCC, only in optimised mode > O1
It seems to be due to non return value from a non void function in case of early initialization (static initialization).
Thanks to A. Durocher who find the tip.

YM

File size: 5.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     m["extract_axis"]  = TRANS_EXTRACT_AXIS_TO_SCALAR;
35     m["reduce_domain"] = TRANS_REDUCE_DOMAIN_TO_SCALAR;
36     m["reduce_scalar"] = TRANS_REDUCE_SCALAR_TO_SCALAR;
37     return true ;
38   }
39
40   StdString CScalar::GetName(void)   { return (StdString("scalar")); }
41   StdString CScalar::GetDefName(void){ return (CScalar::GetName()); }
42   ENodeType CScalar::GetType(void)   { return (eScalar); }
43
44   CScalar* CScalar::createScalar()
45   {
46     CScalar* scalar = CScalarGroup::get("scalar_definition")->createChild();
47     return scalar;
48   }
49
50   bool CScalar::IsWritten(const StdString & filename) const
51   {
52      return (this->relFiles.find(filename) != this->relFiles.end());
53   }
54
55   void CScalar::addRelFile(const StdString& filename)
56   {
57      this->relFiles.insert(filename);
58   }
59
60   void CScalar::checkAttributes(void)
61   {
62   }
63
64  void CScalar::checkAttributesOnClient()
65  {
66
67  }
68
69  /*!
70    Compare two scalar objects.
71    They are equal if only if they have identical attributes as well as their values.
72    Moreover, they must have the same transformations.
73  \param [in] scalar Compared scalar
74  \return result of the comparison
75  */
76  bool CScalar::isEqual(CScalar* obj)
77  {
78    vector<StdString> excludedAttr;
79    excludedAttr.push_back("scalar_ref");
80    bool objEqual = SuperClass::isEqual(obj, excludedAttr);
81    if (!objEqual) return objEqual;
82
83    TransMapTypes thisTrans = this->getAllTransformations();
84    TransMapTypes objTrans  = obj->getAllTransformations();
85
86    TransMapTypes::const_iterator it, itb, ite;
87    std::vector<ETranformationType> thisTransType, objTransType;
88    for (it = thisTrans.begin(); it != thisTrans.end(); ++it)
89      thisTransType.push_back(it->first);
90    for (it = objTrans.begin(); it != objTrans.end(); ++it)
91      objTransType.push_back(it->first);
92
93    if (thisTransType.size() != objTransType.size()) return false;
94    for (int idx = 0; idx < thisTransType.size(); ++idx)
95      objEqual &= (thisTransType[idx] == objTransType[idx]);
96
97    return objEqual;
98  }
99
100  CTransformation<CScalar>* CScalar::addTransformation(ETranformationType transType, const StdString& id)
101  {
102    transformationMap_.push_back(std::make_pair(transType, CTransformation<CScalar>::createTransformation(transType,id)));
103    return transformationMap_.back().second;
104  }
105
106  bool CScalar::hasTransformation()
107  {
108    return (!transformationMap_.empty());
109  }
110
111  void CScalar::setTransformations(const TransMapTypes& scalarTrans)
112  {
113    transformationMap_ = scalarTrans;
114  }
115
116  CScalar::TransMapTypes CScalar::getAllTransformations(void)
117  {
118    return transformationMap_;
119  }
120
121  void CScalar::duplicateTransformation(CScalar* src)
122  {
123    if (src->hasTransformation())
124    {
125      this->setTransformations(src->getAllTransformations());
126    }
127  }
128
129  /*!
130   * Go through the hierarchy to find the scalar from which the transformations must be inherited
131   */
132  void CScalar::solveInheritanceTransformation()
133  {
134    if (hasTransformation() || !hasDirectScalarReference())
135      return;
136
137    CScalar* scalar = this;
138    std::vector<CScalar*> refScalar;
139    while (!scalar->hasTransformation() && scalar->hasDirectScalarReference())
140    {
141      refScalar.push_back(scalar);
142      scalar = scalar->getDirectScalarReference();
143    }
144
145    if (scalar->hasTransformation())
146      for (size_t i = 0; i < refScalar.size(); ++i)
147        refScalar[i]->setTransformations(scalar->getAllTransformations());
148  }
149
150  /*!
151    Parse children nodes of a scalar in xml file.
152    \param node child node to process
153  */
154  void CScalar::parse(xml::CXMLNode & node)
155  {
156    SuperClass::parse(node);
157
158    if (node.goToChildElement())
159    {
160      StdString nodeElementName;
161      do
162      {
163        StdString nodeId("");
164        if (node.getAttributes().end() != node.getAttributes().find("id"))
165        { nodeId = node.getAttributes()["id"]; }
166
167        nodeElementName = node.getElementName();
168        std::map<StdString, ETranformationType>::const_iterator ite = transformationMapList_.end(), it;
169        it = transformationMapList_.find(nodeElementName);
170        if (ite != it)
171        {
172          transformationMap_.push_back(std::make_pair(it->second, CTransformation<CScalar>::createTransformation(it->second,
173                                                                                                                 nodeId,
174                                                                                                                 &node)));
175        }
176        else
177        {
178          ERROR("void CScalar::parse(xml::CXMLNode & node)",
179                << "The transformation " << nodeElementName << " has not been supported yet.");
180        }
181      } while (node.goToNextElement()) ;
182      node.goToParentElement();
183    }
184  }
185
186  // Definition of some macros
187  DEFINE_REF_FUNC(Scalar,scalar)
188
189} // namespace xios
Note: See TracBrowser for help on using the repository browser.