source: XIOS/dev/branch_yushan/src/transformation/Functions/reduction.cpp @ 1103

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

save modif. Todo: axis, domain, mesh, scalar, transformation

File size: 2.9 KB
Line 
1#include "reduction.hpp"
2#include "sum_reduction.hpp"
3#include "min_reduction.hpp"
4#include "max_reduction.hpp"
5#include "extract.hpp"
6#include "average_reduction.hpp"
7
8namespace xios {
9
10CReductionAlgorithm::CallBackMap* CReductionAlgorithm::reductionCreationCallBacks_ = 0;
11//std::map<StdString,EReductionType> CReductionAlgorithm::ReductionOperations = std::map<StdString,EReductionType>();
12std::map<StdString,EReductionType> *CReductionAlgorithm::ReductionOperations_ptr = 0; 
13
14// bool CReductionAlgorithm::initReductionOperation(std::map<StdString,EReductionType>& m)
15// {
16//   // So so stupid way to intialize operation but it works ...
17//   m["sum"] = TRANS_REDUCE_SUM;
18//   CSumReductionAlgorithm::registerTrans();
19
20//   m["min"] = TRANS_REDUCE_MIN;
21//   CMinReductionAlgorithm::registerTrans();
22
23//   m["max"] = TRANS_REDUCE_MAX;
24//   CMaxReductionAlgorithm::registerTrans();
25
26//   m["extract"] = TRANS_REDUCE_EXTRACT;
27//   CExtractReductionAlgorithm::registerTrans();
28
29//   m["average"] = TRANS_REDUCE_AVERAGE;
30//   CAverageReductionAlgorithm::registerTrans();
31// }
32
33bool CReductionAlgorithm::initReductionOperation(std::map<StdString,EReductionType>* m)
34{
35  if(m==NULL) m=new std::map<StdString,EReductionType>();
36  // So so stupid way to intialize operation but it works ...
37  (*m)["sum"] = TRANS_REDUCE_SUM;
38  CSumReductionAlgorithm::registerTrans();
39
40  (*m)["min"] = TRANS_REDUCE_MIN;
41  CMinReductionAlgorithm::registerTrans();
42
43  (*m)["max"] = TRANS_REDUCE_MAX;
44  CMaxReductionAlgorithm::registerTrans();
45
46  (*m)["extract"] = TRANS_REDUCE_EXTRACT;
47  CExtractReductionAlgorithm::registerTrans();
48
49  (*m)["average"] = TRANS_REDUCE_AVERAGE;
50  CAverageReductionAlgorithm::registerTrans();
51}
52
53//bool CReductionAlgorithm::_dummyInit = CReductionAlgorithm::initReductionOperation(CReductionAlgorithm::ReductionOperations);
54bool CReductionAlgorithm::_dummyInit = CReductionAlgorithm::initReductionOperation(CReductionAlgorithm::ReductionOperations_ptr);
55
56CReductionAlgorithm* CReductionAlgorithm::createOperation(EReductionType reduceType)
57{
58  int reduceTypeInt = reduceType;
59  if (0 == reductionCreationCallBacks_)
60    reductionCreationCallBacks_ = new CallBackMap();
61
62  CallBackMap::const_iterator it = (*reductionCreationCallBacks_).find(reduceType);
63  if ((*reductionCreationCallBacks_).end() == it)
64  {
65     ERROR("CReductionAlgorithm::createOperation(EReductionType reduceType)",
66           << "Operation type " << reduceType
67           << "doesn't exist. Please define.");
68  }
69  return (it->second)();
70}
71
72bool CReductionAlgorithm::registerOperation(EReductionType reduceType, CreateOperationCallBack createFn)
73{
74  if (0 == reductionCreationCallBacks_)
75    reductionCreationCallBacks_ = new CallBackMap();
76
77  return (*reductionCreationCallBacks_).insert(make_pair(reduceType, createFn)).second;
78}
79
80bool CReductionAlgorithm::unregisterOperation(EReductionType reduceType)
81{
82  int reduceTypeInt = reduceType;
83  return (1 == (*reductionCreationCallBacks_).erase(reduceType));
84}
85
86
87}
Note: See TracBrowser for help on using the repository browser.