source: XIOS/dev/branch_openmp/src/node/scalar.cpp @ 1328

Last change on this file since 1328 was 1328, checked in by yushan, 6 years ago

dev_omp

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