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