[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; |
---|
| 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(); |
---|
[895] | 23 | |
---|
| 24 | m["extract"] = TRANS_REDUCE_EXTRACT; |
---|
| 25 | CExtractReductionAlgorithm::registerTrans(); |
---|
[979] | 26 | |
---|
| 27 | m["average"] = TRANS_REDUCE_AVERAGE; |
---|
| 28 | CAverageReductionAlgorithm::registerTrans(); |
---|
[888] | 29 | } |
---|
| 30 | |
---|
| 31 | bool CReductionAlgorithm::_dummyInit = CReductionAlgorithm::initReductionOperation(CReductionAlgorithm::ReductionOperations); |
---|
| 32 | |
---|
| 33 | CReductionAlgorithm* CReductionAlgorithm::createOperation(EReductionType reduceType) |
---|
| 34 | { |
---|
| 35 | int reduceTypeInt = reduceType; |
---|
[904] | 36 | CallBackMap::const_iterator it = (*reductionCreationCallBacks_).find(reduceType); |
---|
[888] | 37 | if ((*reductionCreationCallBacks_).end() == it) |
---|
| 38 | { |
---|
| 39 | ERROR("CReductionAlgorithm::createOperation(EReductionType reduceType)", |
---|
| 40 | << "Operation type " << reduceType |
---|
| 41 | << "doesn't exist. Please define."); |
---|
| 42 | } |
---|
| 43 | return (it->second)(); |
---|
| 44 | } |
---|
| 45 | |
---|
| 46 | bool CReductionAlgorithm::registerOperation(EReductionType reduceType, CreateOperationCallBack createFn) |
---|
| 47 | { |
---|
| 48 | if (0 == reductionCreationCallBacks_) |
---|
| 49 | reductionCreationCallBacks_ = new CallBackMap(); |
---|
| 50 | |
---|
| 51 | return (*reductionCreationCallBacks_).insert(make_pair(reduceType, createFn)).second; |
---|
| 52 | } |
---|
| 53 | |
---|
| 54 | bool CReductionAlgorithm::unregisterOperation(EReductionType reduceType) |
---|
| 55 | { |
---|
| 56 | int reduceTypeInt = reduceType; |
---|
| 57 | return (1 == (*reductionCreationCallBacks_).erase(reduceType)); |
---|
| 58 | } |
---|
| 59 | |
---|
| 60 | |
---|
| 61 | } |
---|