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