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