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

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

log OK with threads

File size: 2.9 KB
RevLine 
[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
8namespace 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;
[1128]36      static CallBackMap* transformationCreationCallBacks_; 
[1072]37      //#pragma omp threadprivate(transformationCreationCallBacks_)
[836]38
39      static bool registerTransformation(ETranformationType transType, CreateTransformationCallBack createFn);
40      static bool unregisterTransformation(ETranformationType transType);
41
42    protected:
[827]43      virtual std::vector<StdString> checkAuxInputs_() { return std::vector<StdString>(); }
[619]44  }; // class CTransformation
45
[836]46  template<typename T>
[1128]47  typename CTransformation<T>::CallBackMap* CTransformation<T>::transformationCreationCallBacks_ = 0;//CTransformation<T>::CallBackMap();
[836]48
49  template<typename T>
50  CTransformation<T>* CTransformation<T>::createTransformation(ETranformationType transType, const StdString& id, xml::CXMLNode* node)
51  {
52    int transTypeInt = transType;
[1109]53
[836]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
[619]80} // namespace xios
81
[625]82#endif // __XIOS_CTransformation__
Note: See TracBrowser for help on using the repository browser.