[1984] | 1 | #include "transformation_path.hpp" |
---|
| 2 | |
---|
| 3 | namespace xios |
---|
| 4 | { |
---|
| 5 | void CTransformationPaths::mergePaths(const CTransformationPaths& transformationPaths) |
---|
| 6 | { |
---|
| 7 | donePath_ = transformationPaths.donePath_ ; |
---|
| 8 | //? if (donePath_.empty()) donePath_.push_back(transformationPaths.path_) ; // entry point |
---|
[1993] | 9 | if (get<1>(remainPath_)!="") return ; |
---|
| 10 | |
---|
[1984] | 11 | if (!donePath_.empty()) |
---|
| 12 | { |
---|
| 13 | TPath& remotePath = donePath_.back() ; |
---|
| 14 | |
---|
| 15 | // same element type and element id |
---|
| 16 | if (std::get<0>(remotePath)==std::get<0>(path_) && std::get<1>(remotePath)==std::get<1>(path_)) |
---|
| 17 | { |
---|
| 18 | auto it = get<2>(path_).begin() ; |
---|
| 19 | auto remoteIt = get<2>(remotePath).begin() ; |
---|
| 20 | for( ; remoteIt !=get<2>(remotePath).end() ; remoteIt++ ) |
---|
| 21 | { |
---|
| 22 | if (it==get<2>(path_).end() || *it != *remoteIt) break ; |
---|
| 23 | else it++ ; |
---|
| 24 | } |
---|
| 25 | |
---|
[1993] | 26 | if (remoteIt==get<2>(remotePath).end()) |
---|
| 27 | { |
---|
| 28 | get<0>(remainPath_) = std::get<0>(path_) ; |
---|
| 29 | get<1>(remainPath_) = std::get<1>(path_) ; |
---|
| 30 | get<2>(remainPath_).insert( get<2>(remainPath_).begin(), it , std::get<2>(path_).end() ) ; |
---|
| 31 | } |
---|
[1984] | 32 | else remainPath_ = path_ ; |
---|
| 33 | |
---|
| 34 | } |
---|
| 35 | else remainPath_=path_ ; |
---|
| 36 | } |
---|
| 37 | else |
---|
| 38 | { |
---|
| 39 | remainPath_=path_ ; |
---|
| 40 | } |
---|
[1993] | 41 | get<1>(path_).clear() ; |
---|
| 42 | get<2>(path_).clear() ; |
---|
[1984] | 43 | } |
---|
| 44 | |
---|
| 45 | void CTransformationPaths::mergePaths(void) |
---|
| 46 | { |
---|
| 47 | CTransformationPaths transformationPath ; |
---|
[1993] | 48 | /* TPath newPath = path_ ; |
---|
| 49 | get<2>(newPath).clear() ; |
---|
| 50 | transformationPath.donePath_.push_back(newPath) ; */ |
---|
[1984] | 51 | mergePaths(transformationPath) ; |
---|
| 52 | } |
---|
| 53 | |
---|
| 54 | CTransformationPaths CTransformationPaths::getDonePath(void) |
---|
| 55 | { |
---|
| 56 | CTransformationPaths returnDonePath ; |
---|
| 57 | returnDonePath.donePath_ = donePath_ ; |
---|
| 58 | return returnDonePath ; |
---|
| 59 | } |
---|
| 60 | |
---|
| 61 | EElement CTransformationPaths::getNextElementType(void) |
---|
| 62 | { |
---|
| 63 | if (get<1>(remainPath_)=="") return get<0>(donePath_.back()); |
---|
| 64 | else return get<0>(remainPath_) ; |
---|
| 65 | } |
---|
| 66 | |
---|
| 67 | string CTransformationPaths::getNextElementId(void) |
---|
| 68 | { |
---|
[1993] | 69 | CTransformationPaths transformationPath = *this ; |
---|
| 70 | transformationPath.removeNextTransform() ; |
---|
| 71 | return transformationPath.getPathsId(transformationPath.donePath_) ; |
---|
| 72 | /* |
---|
[1984] | 73 | string sep="/" ; |
---|
| 74 | string doneId=getPathsId(donePath_) ; |
---|
| 75 | if (doneId=="") sep="" ; |
---|
| 76 | TPath next = remainPath_ ; |
---|
| 77 | get<2>(next).erase(++(get<2>(next).begin()),get<2>(next).end()) ; |
---|
| 78 | string remainId=getPathId(next) ; |
---|
| 79 | if (remainId=="") sep="" ; |
---|
| 80 | return doneId+sep+remainId ; |
---|
[1993] | 81 | */ |
---|
[1984] | 82 | } |
---|
| 83 | |
---|
| 84 | string CTransformationPaths::getNextElementSrcId(void) |
---|
| 85 | { |
---|
| 86 | return getPathsId(donePath_) ; |
---|
| 87 | } |
---|
| 88 | |
---|
| 89 | ETranformationType CTransformationPaths::getNextTransformationType(void) |
---|
| 90 | { |
---|
| 91 | return get<2>(remainPath_).front().first ; |
---|
| 92 | } |
---|
| 93 | |
---|
| 94 | string CTransformationPaths::getNextTransformationId(void) |
---|
| 95 | { |
---|
| 96 | return get<2>(remainPath_).front().second ; |
---|
| 97 | } |
---|
| 98 | |
---|
| 99 | void CTransformationPaths::removeNextTransform(void) |
---|
| 100 | { |
---|
| 101 | if (get<1>(remainPath_)!="") |
---|
| 102 | { |
---|
| 103 | TPath newPath; |
---|
| 104 | get<0>(newPath)=get<0>(remainPath_) ; |
---|
| 105 | get<1>(newPath)=get<1>(remainPath_) ; |
---|
| 106 | if (!get<2>(remainPath_).empty()) get<2>(newPath).push_back(get<2>(remainPath_).front()) ; |
---|
[1993] | 107 | if (donePath_.empty()) donePath_.push_back(newPath); |
---|
| 108 | else |
---|
| 109 | { |
---|
| 110 | if (get<0>(donePath_.back())==get<0>(newPath) && get<1>(donePath_.back())==get<1>(newPath)) |
---|
| 111 | get<2>(donePath_.back()).push_back(get<2>(newPath).front()) ; |
---|
| 112 | else donePath_.push_back(newPath); |
---|
| 113 | } |
---|
[1984] | 114 | if (!get<2>(newPath).empty()) get<2>(remainPath_).pop_front() ; |
---|
[1993] | 115 | if (get<2>(remainPath_).empty()) get<1>(remainPath_)="" ; |
---|
[1984] | 116 | } |
---|
| 117 | else |
---|
| 118 | { |
---|
| 119 | if (!get<2>(remainPath_).empty()) |
---|
| 120 | { |
---|
| 121 | get<2>(donePath_.back()).push_back(get<2>(remainPath_).front()) ; |
---|
| 122 | get<2>(remainPath_).pop_front() ; |
---|
| 123 | } |
---|
| 124 | } |
---|
| 125 | } |
---|
| 126 | |
---|
| 127 | |
---|
| 128 | string CTransformationPaths::getPathId(const TPath& path) |
---|
| 129 | { |
---|
| 130 | string id,id1 ; |
---|
| 131 | if (get<1>(path)!="") |
---|
| 132 | { |
---|
| 133 | if (get<0>(path)==EElement::DOMAIN) id="CDomain" ; |
---|
| 134 | if (get<0>(path)==EElement::AXIS) id="CAxis" ; |
---|
| 135 | if (get<0>(path)==EElement::SCALAR) id="CScalar" ; |
---|
| 136 | id=id+":"+get<1>(path) ; |
---|
| 137 | id1="/" ; |
---|
| 138 | } |
---|
| 139 | |
---|
| 140 | for(auto transform : get<2>(path)) |
---|
| 141 | { |
---|
| 142 | |
---|
| 143 | id=id+id1 ; |
---|
| 144 | id=id+to_string(transform.first) ; // not very nice but enough for now. Should be replace by string tranformation name |
---|
| 145 | id=id+":"+transform.second ; |
---|
| 146 | id1="/" ; |
---|
| 147 | } |
---|
| 148 | return id ; |
---|
| 149 | } |
---|
| 150 | |
---|
| 151 | string CTransformationPaths::getPathsId(const list<TPath>& paths) |
---|
| 152 | { |
---|
| 153 | string id ; |
---|
| 154 | string sep("") ; |
---|
| 155 | for(auto path:paths) |
---|
| 156 | { |
---|
| 157 | id=id+sep+getPathId(path) ; |
---|
| 158 | sep="//" ; |
---|
| 159 | } |
---|
| 160 | return id ; |
---|
| 161 | } |
---|
| 162 | } |
---|