[933] | 1 | /*! |
---|
| 2 | \file grid_transformation_factory_impl.hpp |
---|
| 3 | \author Ha NGUYEN |
---|
| 4 | \since 23 June 2016 |
---|
| 5 | \date 23 June 2016 |
---|
| 6 | |
---|
| 7 | \brief Helper class to create different transformations. |
---|
| 8 | */ |
---|
| 9 | #ifndef __XIOS_GRID_TRANSFORMATION_FACTORY_HPP__ |
---|
| 10 | #define __XIOS_GRID_TRANSFORMATION_FACTORY_HPP__ |
---|
| 11 | |
---|
| 12 | #include "xios_spl.hpp" |
---|
| 13 | #include "exception.hpp" |
---|
| 14 | #include "transformation.hpp" |
---|
| 15 | |
---|
| 16 | namespace xios { |
---|
| 17 | |
---|
| 18 | class CGrid; |
---|
| 19 | class CGenericAlgorithmTransformation; |
---|
| 20 | |
---|
| 21 | |
---|
| 22 | /*! |
---|
| 23 | \class CGridTransformationFactory |
---|
| 24 | This class is a helper class to chose a algorithm (transformation) from the alogrithm list of |
---|
| 25 | specific grid. |
---|
| 26 | */ |
---|
| 27 | template<typename T> |
---|
| 28 | class CGridTransformationFactory |
---|
| 29 | { |
---|
| 30 | public: |
---|
| 31 | /** Default constructor */ |
---|
| 32 | CGridTransformationFactory() {} |
---|
| 33 | virtual ~CGridTransformationFactory() {} |
---|
| 34 | |
---|
| 35 | static CGenericAlgorithmTransformation* createTransformation(ETranformationType transType, |
---|
| 36 | CGrid* gridDst, CGrid* gridSrc, |
---|
| 37 | CTransformation<T>* transformation, |
---|
| 38 | int elementPositionInGrid, |
---|
| 39 | std::map<int, int>& elementPositionInGridSrc2ScalarPosition, |
---|
| 40 | std::map<int, int>& elementPositionInGridSrc2AxisPosition, |
---|
| 41 | std::map<int, int>& elementPositionInGridSrc2DomainPosition, |
---|
| 42 | std::map<int, int>& elementPositionInGridDst2ScalarPosition, |
---|
| 43 | std::map<int, int>& elementPositionInGridDst2AxisPosition, |
---|
| 44 | std::map<int, int>& elementPositionInGridDst2DomainPosition); |
---|
| 45 | |
---|
| 46 | public: |
---|
| 47 | typedef CGenericAlgorithmTransformation* (*CreateTransformationCallBack)(CGrid* gridDst, CGrid* gridSrc, |
---|
| 48 | CTransformation<T>* transformation, |
---|
| 49 | int elementPositionInGrid, |
---|
| 50 | std::map<int, int>& elementPositionInGridSrc2ScalarPosition, |
---|
| 51 | std::map<int, int>& elementPositionInGridSrc2AxisPosition, |
---|
| 52 | std::map<int, int>& elementPositionInGridSrc2DomainPosition, |
---|
| 53 | std::map<int, int>& elementPositionInGridDst2ScalarPosition, |
---|
| 54 | std::map<int, int>& elementPositionInGridDst2AxisPosition, |
---|
| 55 | std::map<int, int>& elementPositionInGridDst2DomainPosition); |
---|
| 56 | |
---|
| 57 | typedef std::map<ETranformationType, CreateTransformationCallBack> CallBackMap; |
---|
| 58 | static CallBackMap* transformationCreationCallBacks_; |
---|
| 59 | static bool registerTransformation(ETranformationType transType, CreateTransformationCallBack createFn); |
---|
| 60 | static bool unregisterTransformation(ETranformationType transType); |
---|
| 61 | static bool initializeTransformation_; |
---|
| 62 | }; |
---|
| 63 | |
---|
| 64 | template<typename T> |
---|
| 65 | typename CGridTransformationFactory<T>::CallBackMap* CGridTransformationFactory<T>::transformationCreationCallBacks_ = 0; |
---|
| 66 | template<typename T> |
---|
| 67 | bool CGridTransformationFactory<T>::initializeTransformation_ = false; |
---|
| 68 | |
---|
| 69 | template<typename T> |
---|
| 70 | CGenericAlgorithmTransformation* CGridTransformationFactory<T>::createTransformation(ETranformationType transType, |
---|
| 71 | CGrid* gridDst, CGrid* gridSrc, |
---|
| 72 | CTransformation<T>* transformation, |
---|
| 73 | int elementPositionInGrid, |
---|
| 74 | std::map<int, int>& elementPositionInGridSrc2ScalarPosition, |
---|
| 75 | std::map<int, int>& elementPositionInGridSrc2AxisPosition, |
---|
| 76 | std::map<int, int>& elementPositionInGridSrc2DomainPosition, |
---|
| 77 | std::map<int, int>& elementPositionInGridDst2ScalarPosition, |
---|
| 78 | std::map<int, int>& elementPositionInGridDst2AxisPosition, |
---|
| 79 | std::map<int, int>& elementPositionInGridDst2DomainPosition) |
---|
| 80 | { |
---|
| 81 | typename CallBackMap::const_iterator it = (*transformationCreationCallBacks_).find(transType); |
---|
| 82 | if ((*transformationCreationCallBacks_).end() == it) |
---|
| 83 | { |
---|
| 84 | ERROR("CGridTransformationFactory::createTransformation(ETranformationType transType)", |
---|
| 85 | << "Transformation type " << transType |
---|
| 86 | << "doesn't exist. Please define."); |
---|
| 87 | } |
---|
| 88 | return (it->second)(gridDst, gridSrc, transformation, elementPositionInGrid, |
---|
| 89 | elementPositionInGridSrc2ScalarPosition, |
---|
| 90 | elementPositionInGridSrc2AxisPosition, |
---|
| 91 | elementPositionInGridSrc2DomainPosition, |
---|
| 92 | elementPositionInGridDst2ScalarPosition, |
---|
| 93 | elementPositionInGridDst2AxisPosition, |
---|
| 94 | elementPositionInGridDst2DomainPosition); |
---|
| 95 | } |
---|
| 96 | |
---|
| 97 | template<typename T> |
---|
| 98 | bool CGridTransformationFactory<T>::registerTransformation(ETranformationType transType, CreateTransformationCallBack createFn) |
---|
| 99 | { |
---|
| 100 | if (0 == transformationCreationCallBacks_) |
---|
| 101 | transformationCreationCallBacks_ = new CallBackMap(); |
---|
| 102 | |
---|
| 103 | return (*transformationCreationCallBacks_).insert(make_pair(transType, createFn)).second; |
---|
| 104 | } |
---|
| 105 | |
---|
| 106 | template<typename T> |
---|
| 107 | bool CGridTransformationFactory<T>::unregisterTransformation(ETranformationType transType) |
---|
| 108 | { |
---|
| 109 | return (1 == (*transformationCreationCallBacks_).erase(transType)); |
---|
| 110 | } |
---|
| 111 | |
---|
| 112 | |
---|
| 113 | } |
---|
| 114 | #endif // __XIOS_GRID_TRANSFORMATION_FACTORY_HPP__ |
---|