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