[625] | 1 | #ifndef __XIOS_CTransformation__ |
---|
| 2 | #define __XIOS_CTransformation__ |
---|
[619] | 3 | |
---|
[625] | 4 | #include "xios_spl.hpp" |
---|
[934] | 5 | #include "xml_node.hpp" |
---|
[621] | 6 | #include "transformation_enum.hpp" |
---|
[619] | 7 | |
---|
| 8 | namespace xios { |
---|
| 9 | |
---|
| 10 | ///-------------------------------------------------------------- |
---|
| 11 | /*! |
---|
| 12 | \class CTransformation |
---|
[621] | 13 | This class describes inverse_axis in xml file. |
---|
[619] | 14 | */ |
---|
[621] | 15 | template<typename T> |
---|
[619] | 16 | class CTransformation |
---|
| 17 | { |
---|
[621] | 18 | public: |
---|
[622] | 19 | typedef typename std::list<std::pair<ETranformationType, CTransformation<T>* > > TransformationMapTypes; |
---|
[621] | 20 | typedef TransformationMapTypes TransMapTypes; |
---|
[619] | 21 | |
---|
| 22 | public : |
---|
| 23 | /// Constructeurs /// |
---|
[621] | 24 | CTransformation(void) {} |
---|
[895] | 25 | virtual void checkValid(T* dest) {} |
---|
[619] | 26 | |
---|
[827] | 27 | std::vector<StdString> checkAuxInputs() { return checkAuxInputs_(); } |
---|
[836] | 28 | static CTransformation<T>* createTransformation(ETranformationType transType, const StdString& id, xml::CXMLNode* node=0); |
---|
[827] | 29 | |
---|
[619] | 30 | /// Destructeur /// |
---|
[621] | 31 | virtual ~CTransformation(void) {} |
---|
[827] | 32 | |
---|
| 33 | protected: |
---|
[836] | 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: |
---|
[827] | 42 | virtual std::vector<StdString> checkAuxInputs_() { return std::vector<StdString>(); } |
---|
[619] | 43 | }; // class CTransformation |
---|
| 44 | |
---|
[836] | 45 | template<typename T> |
---|
[840] | 46 | typename CTransformation<T>::CallBackMap* CTransformation<T>::transformationCreationCallBacks_ = 0; //CTransformation<T>::CallBackMap(); |
---|
[836] | 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 | |
---|
[619] | 78 | } // namespace xios |
---|
| 79 | |
---|
[625] | 80 | #endif // __XIOS_CTransformation__ |
---|