1 | #ifndef __XIOS_CTransformation__ |
---|
2 | #define __XIOS_CTransformation__ |
---|
3 | |
---|
4 | #include "xios_spl.hpp" |
---|
5 | #include "xml_node.hpp" |
---|
6 | #include "transformation_enum.hpp" |
---|
7 | #include "exception.hpp" |
---|
8 | |
---|
9 | namespace xios { |
---|
10 | |
---|
11 | ///-------------------------------------------------------------- |
---|
12 | /*! |
---|
13 | \class CTransformation |
---|
14 | This class describes inverse_axis in xml file. |
---|
15 | */ |
---|
16 | class CGenericAlgorithmTransformation; |
---|
17 | class CGrid; |
---|
18 | |
---|
19 | template<typename T> |
---|
20 | class CTransformation |
---|
21 | { |
---|
22 | public: |
---|
23 | typedef typename std::list<std::pair<ETranformationType, CTransformation<T>* > > TransformationMapTypes; |
---|
24 | typedef TransformationMapTypes TransMapTypes; |
---|
25 | |
---|
26 | public : |
---|
27 | /// Constructeurs /// |
---|
28 | CTransformation(void) {} |
---|
29 | virtual void checkValid(T* dest) {} |
---|
30 | |
---|
31 | std::vector<StdString> checkAuxInputs() { return checkAuxInputs_(); } |
---|
32 | static CTransformation<T>* createTransformation(ETranformationType transType, const StdString& id, xml::CXMLNode* node=0); |
---|
33 | static CTransformation<T>* getTransformation(ETranformationType transType, const StdString& id); |
---|
34 | |
---|
35 | virtual const string& getId(void) = 0 ; |
---|
36 | virtual ETranformationType getTransformationType(void)=0; |
---|
37 | virtual void inheritFrom(CTransformation<T>* src) = 0 ; |
---|
38 | |
---|
39 | virtual const string& getId_(void) { ERROR("string Transformation<T>::getId())",<< "unimplemented virtual function for child"); } ; |
---|
40 | virtual const string& getName(void) { ERROR("string Transformation<T>::getId())",<< "unimplemented virtual function for child"); } ; |
---|
41 | virtual const string& getDefName(void) { ERROR("string Transformation<T>::getId())",<< "unimplemented virtual function for child"); } ; |
---|
42 | virtual shared_ptr<CGenericAlgorithmTransformation> createAlgorithm(bool isSource, |
---|
43 | CGrid* gridDst, CGrid* gridSrc, |
---|
44 | int elementPositionInGrid, |
---|
45 | std::map<int, int>& elementPositionInGridSrc2ScalarPosition, |
---|
46 | std::map<int, int>& elementPositionInGridSrc2AxisPosition, |
---|
47 | std::map<int, int>& elementPositionInGridSrc2DomainPosition, |
---|
48 | std::map<int, int>& elementPositionInGridDst2ScalarPosition, |
---|
49 | std::map<int, int>& elementPositionInGridDst2AxisPosition, |
---|
50 | std::map<int, int>& elementPositionInGridDst2DomainPosition) =0 ; |
---|
51 | |
---|
52 | /// Destructeur /// |
---|
53 | public: |
---|
54 | virtual ~CTransformation(void) {} |
---|
55 | static void unregisterAllTransformations(); |
---|
56 | protected: |
---|
57 | typedef CTransformation<T>* (*createTransformationCallBack)(const StdString&, xml::CXMLNode*); |
---|
58 | typedef CTransformation<T>* (*getIdTransformationCallBack)(const StdString&); |
---|
59 | typedef std::map<ETranformationType, tuple<createTransformationCallBack,getIdTransformationCallBack>> callBackMap; |
---|
60 | static callBackMap* callBacks_; |
---|
61 | |
---|
62 | static bool registerTransformation(ETranformationType transType, tuple<createTransformationCallBack,getIdTransformationCallBack> callBackFunctions); |
---|
63 | static bool unregisterTransformation(ETranformationType transType); |
---|
64 | |
---|
65 | |
---|
66 | |
---|
67 | protected: |
---|
68 | virtual std::vector<StdString> checkAuxInputs_() { return std::vector<StdString>(); } |
---|
69 | |
---|
70 | }; // class CTransformation |
---|
71 | |
---|
72 | template<typename T> |
---|
73 | typename CTransformation<T>::callBackMap* CTransformation<T>::callBacks_ = 0; //CTransformation<T>::CallBackMap(); |
---|
74 | |
---|
75 | template<typename T> |
---|
76 | CTransformation<T>* CTransformation<T>::createTransformation(ETranformationType transType, const StdString& id, xml::CXMLNode* node) |
---|
77 | { |
---|
78 | int transTypeInt = transType; |
---|
79 | typename callBackMap::const_iterator it = (*callBacks_).find(transType); |
---|
80 | if ((*callBacks_).end() == it) |
---|
81 | { |
---|
82 | ERROR("CTransformation<T>::createTransformation(ETranformationType transType)", |
---|
83 | << "Transformation type " << transType |
---|
84 | << "doesn't exist. Please define."); |
---|
85 | } |
---|
86 | return (get<0>(it->second))(id,node); |
---|
87 | } |
---|
88 | |
---|
89 | template<typename T> |
---|
90 | CTransformation<T>* CTransformation<T>::getTransformation(ETranformationType transType, const StdString& id) |
---|
91 | { |
---|
92 | int transTypeInt = transType; |
---|
93 | typename callBackMap::const_iterator it = (*callBacks_).find(transType); |
---|
94 | if ((*callBacks_).end() == it) |
---|
95 | { |
---|
96 | ERROR("CTransformation<T>::getTransformation(ETranformationType transType, const StdString& id)", |
---|
97 | << "Transformation type " << transType |
---|
98 | << "doesn't exist. Please define."); |
---|
99 | } |
---|
100 | return (get<1>(it->second))(id); |
---|
101 | } |
---|
102 | |
---|
103 | template<typename T> |
---|
104 | bool CTransformation<T>::registerTransformation(ETranformationType transType, tuple<createTransformationCallBack, getIdTransformationCallBack> functions) |
---|
105 | { |
---|
106 | if (0 == callBacks_) callBacks_ = new callBackMap(); |
---|
107 | return (* callBacks_).insert(make_pair(transType, functions)).second; |
---|
108 | } |
---|
109 | |
---|
110 | template<typename T> |
---|
111 | bool CTransformation<T>::unregisterTransformation(ETranformationType transType) |
---|
112 | { |
---|
113 | int transTypeInt = transType; |
---|
114 | return (1 == (*callBacks_).erase(transType)); |
---|
115 | } |
---|
116 | |
---|
117 | template<typename T> |
---|
118 | void CTransformation<T>::unregisterAllTransformations(void) |
---|
119 | { |
---|
120 | if (0 != callBacks_) |
---|
121 | { |
---|
122 | callBacks_->clear(); |
---|
123 | delete callBacks_ ; |
---|
124 | } |
---|
125 | } |
---|
126 | |
---|
127 | } // namespace xios |
---|
128 | |
---|
129 | #endif // __XIOS_CTransformation__ |
---|