source: XIOS/dev/dev_ym/XIOS_COUPLING/src/transformation/transformation_path.cpp @ 2291

Last change on this file since 2291 was 2005, checked in by ymipsl, 3 years ago

fix some problems in transformation_path
Not sure something else wil be broken
YM

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