source: XIOS/dev/branch_yushan_merged/src/transformation/Functions/reduction.cpp @ 1153

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

save modif

File size: 3.3 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
14bool 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
33
34bool CReductionAlgorithm::initReductionOperation()
35{
36  if(CReductionAlgorithm::ReductionOperations_ptr == NULL) CReductionAlgorithm::ReductionOperations_ptr = new std::map<StdString,EReductionType>();
37  // So so stupid way to intialize operation but it works ...
38  (*CReductionAlgorithm::ReductionOperations_ptr)["sum"] = TRANS_REDUCE_SUM;
39  CSumReductionAlgorithm::registerTrans();
40
41  (*CReductionAlgorithm::ReductionOperations_ptr)["min"] = TRANS_REDUCE_MIN;
42  CMinReductionAlgorithm::registerTrans();
43
44  (*CReductionAlgorithm::ReductionOperations_ptr)["max"] = TRANS_REDUCE_MAX;
45  CMaxReductionAlgorithm::registerTrans();
46
47  (*CReductionAlgorithm::ReductionOperations_ptr)["extract"] = TRANS_REDUCE_EXTRACT;
48  CExtractReductionAlgorithm::registerTrans();
49
50  (*CReductionAlgorithm::ReductionOperations_ptr)["average"] = TRANS_REDUCE_AVERAGE;
51  CAverageReductionAlgorithm::registerTrans();
52
53  printf("*CReductionAlgorithm::ReductionOperations_ptr = %p\t %p\n", *CReductionAlgorithm::ReductionOperations_ptr, &(*CReductionAlgorithm::ReductionOperations_ptr));
54}
55
56//bool CReductionAlgorithm::_dummyInit = CReductionAlgorithm::initReductionOperation(CReductionAlgorithm::ReductionOperations);
57bool CReductionAlgorithm::_dummyInit = CReductionAlgorithm::initReductionOperation();
58
59CReductionAlgorithm* CReductionAlgorithm::createOperation(EReductionType reduceType)
60{
61  int reduceTypeInt = reduceType;
62  //if (0 == reductionCreationCallBacks_)
63  //  reductionCreationCallBacks_ = new CallBackMap();
64
65  CallBackMap::const_iterator it = (*reductionCreationCallBacks_).find(reduceType);
66  if ((*reductionCreationCallBacks_).end() == it)
67  {
68     ERROR("CReductionAlgorithm::createOperation(EReductionType reduceType)",
69           << "Operation type " << reduceType
70           << "doesn't exist. Please define.");
71  }
72  return (it->second)();
73}
74
75bool CReductionAlgorithm::registerOperation(EReductionType reduceType, CreateOperationCallBack createFn)
76{
77  if (0 == reductionCreationCallBacks_)
78    reductionCreationCallBacks_ = new CallBackMap();
79
80  return (*reductionCreationCallBacks_).insert(make_pair(reduceType, createFn)).second;
81}
82
83bool CReductionAlgorithm::unregisterOperation(EReductionType reduceType)
84{
85  int reduceTypeInt = reduceType;
86  return (1 == (*reductionCreationCallBacks_).erase(reduceType));
87}
88
89
90}
Note: See TracBrowser for help on using the repository browser.