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