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 | |
---|
38 | static bool registerTransformation(ETranformationType transType, CreateTransformationCallBack createFn); |
---|
39 | static bool unregisterTransformation(ETranformationType transType); |
---|
40 | |
---|
41 | protected: |
---|
42 | virtual std::vector<StdString> checkAuxInputs_() { return std::vector<StdString>(); } |
---|
43 | }; // class CTransformation |
---|
44 | |
---|
45 | template<typename T> |
---|
46 | typename CTransformation<T>::CallBackMap* CTransformation<T>::transformationCreationCallBacks_ = 0; //CTransformation<T>::CallBackMap(); |
---|
47 | |
---|
48 | template<typename T> |
---|
49 | CTransformation<T>* CTransformation<T>::createTransformation(ETranformationType transType, const StdString& id, xml::CXMLNode* node) |
---|
50 | { |
---|
51 | int transTypeInt = transType; |
---|
52 | typename CallBackMap::const_iterator it = (*transformationCreationCallBacks_).find(transType); |
---|
53 | if ((*transformationCreationCallBacks_).end() == it) |
---|
54 | { |
---|
55 | ERROR("CTransformation<T>::createTransformation(ETranformationType transType)", |
---|
56 | << "Transformation type " << transType |
---|
57 | << "doesn't exist. Please define."); |
---|
58 | } |
---|
59 | return (it->second)(id,node); |
---|
60 | } |
---|
61 | |
---|
62 | template<typename T> |
---|
63 | bool CTransformation<T>::registerTransformation(ETranformationType transType, CreateTransformationCallBack createFn) |
---|
64 | { |
---|
65 | if (0 == transformationCreationCallBacks_) |
---|
66 | transformationCreationCallBacks_ = new CallBackMap(); |
---|
67 | |
---|
68 | return (*transformationCreationCallBacks_).insert(make_pair(transType, createFn)).second; |
---|
69 | } |
---|
70 | |
---|
71 | template<typename T> |
---|
72 | bool CTransformation<T>::unregisterTransformation(ETranformationType transType) |
---|
73 | { |
---|
74 | int transTypeInt = transType; |
---|
75 | return (1 == (*transformationCreationCallBacks_).erase(transType)); |
---|
76 | } |
---|
77 | |
---|
78 | } // namespace xios |
---|
79 | |
---|
80 | #endif // __XIOS_CTransformation__ |
---|