source: XIOS/dev/branch_yushan/src/node/transformation.hpp @ 1109

Last change on this file since 1109 was 1109, checked in by yushan, 7 years ago

test_omp OK

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