[1558] | 1 | #include "extract_axis.hpp" |
---|
| 2 | #include "type.hpp" |
---|
| 3 | |
---|
| 4 | namespace xios { |
---|
| 5 | |
---|
| 6 | /// ////////////////////// Définitions ////////////////////// /// |
---|
| 7 | |
---|
| 8 | CExtractAxis::CExtractAxis(void) |
---|
| 9 | : CObjectTemplate<CExtractAxis>(), CExtractAxisAttributes(), CTransformation<CAxis>() |
---|
| 10 | { /* Ne rien faire de plus */ } |
---|
| 11 | |
---|
| 12 | CExtractAxis::CExtractAxis(const StdString & id) |
---|
| 13 | : CObjectTemplate<CExtractAxis>(id), CExtractAxisAttributes(), CTransformation<CAxis>() |
---|
| 14 | { /* Ne rien faire de plus */ } |
---|
| 15 | |
---|
| 16 | CExtractAxis::~CExtractAxis(void) |
---|
| 17 | {} |
---|
| 18 | |
---|
| 19 | CTransformation<CAxis>* CExtractAxis::create(const StdString& id, xml::CXMLNode* node) |
---|
| 20 | { |
---|
| 21 | CExtractAxis* extractAxis = CExtractAxisGroup::get("extract_axis_definition")->createChild(id); |
---|
| 22 | if (node) extractAxis->parse(*node); |
---|
| 23 | return static_cast<CTransformation<CAxis>*>(extractAxis); |
---|
| 24 | } |
---|
| 25 | |
---|
| 26 | bool CExtractAxis::registerTrans() |
---|
| 27 | { |
---|
| 28 | return registerTransformation(TRANS_EXTRACT_AXIS, CExtractAxis::create); |
---|
| 29 | } |
---|
| 30 | |
---|
| 31 | bool CExtractAxis::_dummyRegistered = CExtractAxis::registerTrans(); |
---|
| 32 | |
---|
| 33 | //---------------------------------------------------------------- |
---|
| 34 | |
---|
| 35 | StdString CExtractAxis::GetName(void) { return StdString("extract_axis"); } |
---|
| 36 | StdString CExtractAxis::GetDefName(void) { return StdString("extract_axis"); } |
---|
| 37 | ENodeType CExtractAxis::GetType(void) { return eExtractAxis; } |
---|
| 38 | |
---|
| 39 | void CExtractAxis::checkValid(CAxis* axisDest) |
---|
| 40 | { |
---|
| 41 | int axisIBegin, axisNi, axisGlobalSize; |
---|
| 42 | int begin, end, n; |
---|
| 43 | |
---|
| 44 | axisIBegin = axisDest->begin.getValue(); |
---|
| 45 | axisNi = axisDest->n.getValue(); |
---|
| 46 | axisGlobalSize = axisDest->n_glo.getValue(); |
---|
| 47 | |
---|
| 48 | bool extractByIndex = !this->index.isEmpty() && (0 != this->index.numElements()); |
---|
| 49 | |
---|
| 50 | if (extractByIndex) |
---|
| 51 | { |
---|
| 52 | begin = min(this->index); |
---|
| 53 | end = max(this->index); |
---|
| 54 | n = end - begin + 1; |
---|
| 55 | } |
---|
| 56 | else |
---|
| 57 | { |
---|
| 58 | begin = (this->begin.isEmpty()) ? 0 : this->begin.getValue(); |
---|
| 59 | n = (this->n.isEmpty()) ? axisGlobalSize : this->n.getValue(); |
---|
| 60 | end = begin+n-1; |
---|
| 61 | } |
---|
| 62 | |
---|
| 63 | if (begin < 0 || begin > axisGlobalSize - 1 || end < 0 || end > axisGlobalSize - 1 |
---|
| 64 | || n < 1 || n > axisGlobalSize || begin > end) |
---|
| 65 | ERROR("CExtractAxis::checkValid(CAxis* axisDest)", |
---|
| 66 | << "One or more attributes among 'begin' (" << begin << "), 'end' (" << end << "), 'n' (" << n << ") " |
---|
| 67 | << "of axis transformation [ id = '" << axisDest->getId() << "' , context = '" << CObjectFactory::GetCurrentContextId() << "' ] are not well specified"); |
---|
| 68 | |
---|
| 69 | if (extractByIndex && (!this->begin.isEmpty() || !this->n.isEmpty())) |
---|
| 70 | ERROR("CExtractAxis::checkValid(CAxis* axisDest)", |
---|
| 71 | << "Only one type of extract is accepted. Define extract by index with global_extract_index or define extract with begin and n. " |
---|
| 72 | << "Axis transformation [ id = '" << axisDest->getId() << "' , context = '" << CObjectFactory::GetCurrentContextId() << "' ] are not well specified"); |
---|
| 73 | |
---|
| 74 | this->begin.setValue(begin); |
---|
| 75 | this->n.setValue(n); |
---|
| 76 | |
---|
| 77 | } |
---|
| 78 | |
---|
| 79 | } |
---|