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

Last change on this file since 1984 was 1984, checked in by ymipsl, 4 years ago

intermediate commit for new tranformation engine?
YM

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