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 | |
---|
8 | namespace xios { |
---|
9 | |
---|
10 | ///-------------------------------------------------------------- |
---|
11 | /*! |
---|
12 | \class CTransformation |
---|
13 | This class describes inverse_axis in xml file. |
---|
14 | */ |
---|
15 | template<typename T> |
---|
16 | class CTransformation |
---|
17 | { |
---|
18 | public: |
---|
19 | typedef typename std::list<std::pair<ETranformationType, CTransformation<T>* > > TransformationMapTypes; |
---|
20 | typedef TransformationMapTypes TransMapTypes; |
---|
21 | |
---|
22 | public : |
---|
23 | /// Constructeurs /// |
---|
24 | CTransformation(void) {} |
---|
25 | virtual void checkValid(T* dest) {} |
---|
26 | |
---|
27 | std::vector<StdString> checkAuxInputs() { return checkAuxInputs_(); } |
---|
28 | static CTransformation<T>* createTransformation(ETranformationType transType, const StdString& id, xml::CXMLNode* node=0); |
---|
29 | |
---|
30 | /// Destructeur /// |
---|
31 | virtual ~CTransformation(void) {} |
---|
32 | |
---|
33 | protected: |
---|
34 | typedef CTransformation<T>* (*CreateTransformationCallBack)(const StdString&, xml::CXMLNode*); |
---|
35 | typedef std::map<ETranformationType, CreateTransformationCallBack> CallBackMap; |
---|
36 | static CallBackMap* transformationCreationCallBacks_; |
---|
37 | //#pragma omp threadprivate(transformationCreationCallBacks_) |
---|
38 | |
---|
39 | static bool registerTransformation(ETranformationType transType, CreateTransformationCallBack createFn); |
---|
40 | static bool unregisterTransformation(ETranformationType transType); |
---|
41 | |
---|
42 | protected: |
---|
43 | virtual std::vector<StdString> checkAuxInputs_() { return std::vector<StdString>(); } |
---|
44 | }; // class CTransformation |
---|
45 | |
---|
46 | template<typename T> |
---|
47 | typename CTransformation<T>::CallBackMap* CTransformation<T>::transformationCreationCallBacks_ = 0; //CTransformation<T>::CallBackMap(); |
---|
48 | |
---|
49 | template<typename T> |
---|
50 | CTransformation<T>* CTransformation<T>::createTransformation(ETranformationType transType, const StdString& id, xml::CXMLNode* node) |
---|
51 | { |
---|
52 | int transTypeInt = transType; |
---|
53 | typename CallBackMap::const_iterator it = (*transformationCreationCallBacks_).find(transType); |
---|
54 | if ((*transformationCreationCallBacks_).end() == it) |
---|
55 | { |
---|
56 | ERROR("CTransformation<T>::createTransformation(ETranformationType transType)", |
---|
57 | << "Transformation type " << transType |
---|
58 | << "doesn't exist. Please define."); |
---|
59 | } |
---|
60 | return (it->second)(id,node); |
---|
61 | } |
---|
62 | |
---|
63 | template<typename T> |
---|
64 | bool CTransformation<T>::registerTransformation(ETranformationType transType, CreateTransformationCallBack createFn) |
---|
65 | { |
---|
66 | if (0 == transformationCreationCallBacks_) |
---|
67 | transformationCreationCallBacks_ = new CallBackMap(); |
---|
68 | |
---|
69 | return (*transformationCreationCallBacks_).insert(make_pair(transType, createFn)).second; |
---|
70 | } |
---|
71 | |
---|
72 | template<typename T> |
---|
73 | bool CTransformation<T>::unregisterTransformation(ETranformationType transType) |
---|
74 | { |
---|
75 | int transTypeInt = transType; |
---|
76 | return (1 == (*transformationCreationCallBacks_).erase(transType)); |
---|
77 | } |
---|
78 | |
---|
79 | } // namespace xios |
---|
80 | |
---|
81 | #endif // __XIOS_CTransformation__ |
---|