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