source: XIOS/dev/dev_ym/XIOS_COUPLING/src/transformation/transformation.hpp @ 1984

Last change on this file since 1984 was 1984, checked in by ymipsl, 4 years ago

intermediate commit for new tranformation engine?
YM

  • Property svn:executable set to *
File size: 4.1 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      static CTransformation<T>* getTransformation(ETranformationType transType, const StdString& id);
30
31      virtual const string& getId(void) = 0 ;
32      virtual ETranformationType getTransformationType(void)=0;
33      virtual void inheritFrom(CTransformation<T>* src) = 0 ;
34
35      virtual const string& getId_(void) { ERROR("string Transformation<T>::getId())",<< "unimplemented virtual function for child"); } ;
36      virtual const string& getName(void) { ERROR("string Transformation<T>::getId())",<< "unimplemented virtual function for child"); } ;
37      virtual const string& getDefName(void) { ERROR("string Transformation<T>::getId())",<< "unimplemented virtual function for child"); } ;
38      /// Destructeur ///
39    public:
40      virtual ~CTransformation(void) {}
41
42    protected:
43      typedef CTransformation<T>* (*createTransformationCallBack)(const StdString&, xml::CXMLNode*);
44      typedef CTransformation<T>* (*getIdTransformationCallBack)(const StdString&);
45      typedef std::map<ETranformationType, tuple<createTransformationCallBack,getIdTransformationCallBack>> callBackMap;
46      static callBackMap* callBacks_;
47
48      static bool registerTransformation(ETranformationType transType, tuple<createTransformationCallBack,getIdTransformationCallBack> callBackFunctions);
49      static bool unregisterTransformation(ETranformationType transType);
50
51    protected:
52      virtual std::vector<StdString> checkAuxInputs_() { return std::vector<StdString>(); }
53
54  }; // class CTransformation
55
56  template<typename T>
57  typename CTransformation<T>::callBackMap* CTransformation<T>::callBacks_ = 0; //CTransformation<T>::CallBackMap();
58
59  template<typename T>
60  CTransformation<T>* CTransformation<T>::createTransformation(ETranformationType transType, const StdString& id, xml::CXMLNode* node)
61  {
62    int transTypeInt = transType;
63    typename callBackMap::const_iterator it = (*callBacks_).find(transType);
64    if ((*callBacks_).end() == it)
65    {
66       ERROR("CTransformation<T>::createTransformation(ETranformationType transType)",
67             << "Transformation type " << transType
68             << "doesn't exist. Please define.");
69    }
70    return (get<0>(it->second))(id,node);
71  }
72
73  template<typename T>
74  CTransformation<T>* CTransformation<T>::getTransformation(ETranformationType transType, const StdString& id)
75  {
76    int transTypeInt = transType;
77    typename callBackMap::const_iterator it = (*callBacks_).find(transType);
78    if ((*callBacks_).end() == it)
79    {
80       ERROR("CTransformation<T>::getTransformation(ETranformationType transType, const StdString& id)",
81             << "Transformation type " << transType
82             << "doesn't exist. Please define.");
83    }
84    return (get<1>(it->second))(id);
85  }
86
87  template<typename T>
88  bool CTransformation<T>::registerTransformation(ETranformationType transType,  tuple<createTransformationCallBack, getIdTransformationCallBack> functions)
89  {
90    if (0 == callBacks_) callBacks_ = new callBackMap();
91    return (* callBacks_).insert(make_pair(transType, functions)).second;
92  }
93
94  template<typename T>
95  bool CTransformation<T>::unregisterTransformation(ETranformationType transType)
96  {
97    int transTypeInt = transType;
98    return (1 == (*callBacks_).erase(transType));
99  }
100
101} // namespace xios
102
103#endif // __XIOS_CTransformation__
Note: See TracBrowser for help on using the repository browser.