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 | |
---|

8 | namespace xios { |
---|

9 | |
---|

10 | CReductionAlgorithm::CallBackMap* CReductionAlgorithm::reductionCreationCallBacks_ = 0; |
---|

11 | std::map<StdString,EReductionType> CReductionAlgorithm::ReductionOperations = std::map<StdString,EReductionType>(); |
---|

12 | bool CReductionAlgorithm::initReductionOperation(std::map<StdString,EReductionType>& m) |
---|

13 | { |
---|

14 | // So so stupid way to intialize operation but it works ... |
---|

15 | m["sum"] = TRANS_REDUCE_SUM; |
---|

16 | CSumReductionAlgorithm::registerTrans(); |
---|

17 | |
---|

18 | m["min"] = TRANS_REDUCE_MIN; |
---|

19 | CMinReductionAlgorithm::registerTrans(); |
---|

20 | |
---|

21 | m["max"] = TRANS_REDUCE_MAX; |
---|

22 | CMaxReductionAlgorithm::registerTrans(); |
---|

23 | |
---|

24 | m["extract"] = TRANS_REDUCE_EXTRACT; |
---|

25 | CExtractReductionAlgorithm::registerTrans(); |
---|

26 | |
---|

27 | m["average"] = TRANS_REDUCE_AVERAGE; |
---|

28 | CAverageReductionAlgorithm::registerTrans(); |
---|

29 | |
---|

30 | return true; |
---|

31 | } |
---|

32 | |
---|

33 | bool CReductionAlgorithm::_dummyInit = CReductionAlgorithm::initReductionOperation(CReductionAlgorithm::ReductionOperations); |
---|

34 | |
---|

35 | CReductionAlgorithm* CReductionAlgorithm::createOperation(EReductionType reduceType) |
---|

36 | { |
---|

37 | int reduceTypeInt = reduceType; |
---|

38 | CallBackMap::const_iterator it = (*reductionCreationCallBacks_).find(reduceType); |
---|

39 | if ((*reductionCreationCallBacks_).end() == it) |
---|

40 | { |
---|

41 | ERROR("CReductionAlgorithm::createOperation(EReductionType reduceType)", |
---|

42 | << "Operation type " << reduceType |
---|

43 | << "doesn't exist. Please define."); |
---|

44 | } |
---|

45 | return (it->second)(); |
---|

46 | } |
---|

47 | |
---|

48 | bool CReductionAlgorithm::registerOperation(EReductionType reduceType, CreateOperationCallBack createFn) |
---|

49 | { |
---|

50 | if (0 == reductionCreationCallBacks_) |
---|

51 | reductionCreationCallBacks_ = new CallBackMap(); |
---|

52 | |
---|

53 | return (*reductionCreationCallBacks_).insert(make_pair(reduceType, createFn)).second; |
---|

54 | } |
---|

55 | |
---|

56 | bool CReductionAlgorithm::unregisterOperation(EReductionType reduceType) |
---|

57 | { |
---|

58 | int reduceTypeInt = reduceType; |
---|

59 | return (1 == (*reductionCreationCallBacks_).erase(reduceType)); |
---|

60 | } |
---|

61 | |
---|

62 | |
---|

63 | } |
---|