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