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