[642] | 1 | #include "filter_expr_node.hpp" |
---|
| 2 | #include "unary_arithmetic_filter.hpp" |
---|
| 3 | #include "binary_arithmetic_filter.hpp" |
---|
| 4 | #include "field.hpp" |
---|
| 5 | |
---|
| 6 | namespace xios |
---|
| 7 | { |
---|
| 8 | CFilterFieldExprNode::CFilterFieldExprNode(const std::string& fieldId) |
---|
| 9 | : fieldId(fieldId) |
---|
| 10 | { /* Nothing to do */ } |
---|
| 11 | |
---|
| 12 | boost::shared_ptr<COutputPin> CFilterFieldExprNode::reduce(CGarbageCollector& gc, CField& thisField) const |
---|
| 13 | { |
---|
| 14 | boost::shared_ptr<COutputPin> outputPin; |
---|
| 15 | |
---|
| 16 | if (fieldId == "this") |
---|
| 17 | outputPin = thisField.getSelfReference(gc); |
---|
| 18 | else if (CField::has(fieldId)) |
---|
| 19 | { |
---|
| 20 | CField* field = CField::get(fieldId); |
---|
| 21 | if (field == &thisField) |
---|
| 22 | ERROR("boost::shared_ptr<COutputPin> CFilterFieldExprNode::reduce(CGarbageCollector& gc, CField& thisField) const", |
---|
| 23 | << "The field " << fieldId << " has an invalid reference to itself. " |
---|
| 24 | << "Use the keyword \"this\" if you want to reference the input data sent to this field."); |
---|
| 25 | |
---|
| 26 | field->buildFilterGraph(gc, false); |
---|
| 27 | outputPin = field->getInstantDataFilter(); |
---|
| 28 | } |
---|
| 29 | else |
---|
| 30 | ERROR("boost::shared_ptr<COutputPin> CFilterFieldExprNode::reduce(CGarbageCollector& gc, CField& thisField) const", |
---|
| 31 | << "The field " << fieldId << " does not exist."); |
---|
| 32 | |
---|
| 33 | return outputPin; |
---|
| 34 | } |
---|
| 35 | |
---|
[643] | 36 | CFilterTemporalFieldExprNode::CFilterTemporalFieldExprNode(const std::string& fieldId) |
---|
| 37 | : fieldId(fieldId) |
---|
| 38 | { /* Nothing to do */ } |
---|
| 39 | |
---|
| 40 | boost::shared_ptr<COutputPin> CFilterTemporalFieldExprNode::reduce(CGarbageCollector& gc, CField& thisField) const |
---|
| 41 | { |
---|
[1001] | 42 | boost::shared_ptr<COutputPin> outputPin; |
---|
| 43 | |
---|
| 44 | if (fieldId == "this") |
---|
| 45 | outputPin = thisField.getSelfTemporalDataFilter(gc, thisField.freq_op.isEmpty() ? TimeStep : thisField.freq_op); |
---|
| 46 | else if (CField::has(fieldId)) |
---|
| 47 | { |
---|
| 48 | CField* field = CField::get(fieldId); |
---|
| 49 | if (field == &thisField) |
---|
| 50 | ERROR("boost::shared_ptr<COutputPin> CFilterTemporalFieldExprNode::reduce(CGarbageCollector& gc, CField& thisField) const", |
---|
| 51 | << "The field " << fieldId << " has an invalid reference to itself. " |
---|
| 52 | << "Use the keyword \"this\" if you want to reference the input data sent to this field."); |
---|
| 53 | |
---|
| 54 | field->buildFilterGraph(gc, false); |
---|
| 55 | outputPin = field->getTemporalDataFilter(gc, thisField.freq_op.isEmpty() ? TimeStep : thisField.freq_op); |
---|
| 56 | } |
---|
| 57 | else |
---|
[643] | 58 | ERROR("boost::shared_ptr<COutputPin> CFilterTemporalFieldExprNode::reduce(CGarbageCollector& gc, CField& thisField) const", |
---|
| 59 | << "The field " << fieldId << " does not exist."); |
---|
| 60 | |
---|
[1001] | 61 | return outputPin; |
---|
[643] | 62 | } |
---|
| 63 | |
---|
[642] | 64 | CFilterUnaryOpExprNode::CFilterUnaryOpExprNode(const std::string& opId, IFilterExprNode* child) |
---|
| 65 | : opId(opId) |
---|
| 66 | , child(child) |
---|
| 67 | { |
---|
| 68 | if (!child) |
---|
| 69 | ERROR("CFilterUnaryOpExprNode::CFilterUnaryOpExprNode(const std::string& opId, IFilterExprNode* child)", |
---|
| 70 | "Impossible to create the new expression node, an invalid child node was provided."); |
---|
| 71 | } |
---|
| 72 | |
---|
| 73 | boost::shared_ptr<COutputPin> CFilterUnaryOpExprNode::reduce(CGarbageCollector& gc, CField& thisField) const |
---|
| 74 | { |
---|
| 75 | boost::shared_ptr<CUnaryArithmeticFilter> filter(new CUnaryArithmeticFilter(gc, opId)); |
---|
| 76 | child->reduce(gc, thisField)->connectOutput(filter, 0); |
---|
| 77 | return filter; |
---|
| 78 | } |
---|
| 79 | |
---|
| 80 | CFilterScalarFieldOpExprNode::CFilterScalarFieldOpExprNode(IScalarExprNode* child1, const std::string& opId, IFilterExprNode* child2) |
---|
| 81 | : child1(child1) |
---|
| 82 | , opId(opId) |
---|
| 83 | , child2(child2) |
---|
| 84 | { |
---|
| 85 | if (!child1 || !child2) |
---|
| 86 | ERROR("CFilterScalarFieldOpExprNode::CFilterScalarFieldOpExprNode(IScalarExprNode* child1, const std::string& opId, IFilterExprNode* child2)", |
---|
| 87 | "Impossible to create the new expression node, an invalid child node was provided."); |
---|
| 88 | } |
---|
| 89 | |
---|
| 90 | boost::shared_ptr<COutputPin> CFilterScalarFieldOpExprNode::reduce(CGarbageCollector& gc, CField& thisField) const |
---|
| 91 | { |
---|
| 92 | boost::shared_ptr<CScalarFieldArithmeticFilter> filter(new CScalarFieldArithmeticFilter(gc, opId, child1->reduce())); |
---|
| 93 | child2->reduce(gc, thisField)->connectOutput(filter, 0); |
---|
| 94 | return filter; |
---|
| 95 | } |
---|
| 96 | |
---|
| 97 | CFilterFieldScalarOpExprNode::CFilterFieldScalarOpExprNode(IFilterExprNode* child1, const std::string& opId, IScalarExprNode* child2) |
---|
| 98 | : child1(child1) |
---|
| 99 | , opId(opId) |
---|
| 100 | , child2(child2) |
---|
| 101 | { |
---|
| 102 | if (!child1 || !child2) |
---|
| 103 | ERROR("CFilterFieldScalarOpExprNode::CFilterFieldScalarOpExprNode(IFilterExprNode* child1, const std::string& opId, IScalarExprNode* child2)", |
---|
| 104 | "Impossible to create the new expression node, an invalid child node was provided."); |
---|
| 105 | } |
---|
| 106 | |
---|
| 107 | boost::shared_ptr<COutputPin> CFilterFieldScalarOpExprNode::reduce(CGarbageCollector& gc, CField& thisField) const |
---|
| 108 | { |
---|
| 109 | boost::shared_ptr<CFieldScalarArithmeticFilter> filter(new CFieldScalarArithmeticFilter(gc, opId, child2->reduce())); |
---|
| 110 | child1->reduce(gc, thisField)->connectOutput(filter, 0); |
---|
| 111 | return filter; |
---|
| 112 | } |
---|
| 113 | |
---|
| 114 | CFilterFieldFieldOpExprNode::CFilterFieldFieldOpExprNode(IFilterExprNode* child1, const std::string& opId, IFilterExprNode* child2) |
---|
| 115 | : child1(child1) |
---|
| 116 | , opId(opId) |
---|
| 117 | , child2(child2) |
---|
| 118 | { |
---|
| 119 | if (!child1 || !child2) |
---|
| 120 | ERROR("CFilterFieldFieldOpExprNode::CFilterFieldFieldOpExprNode(IFilterExprNode* child1, const std::string& opId, IFilterExprNode* child2)", |
---|
| 121 | "Impossible to create the new expression node, an invalid child node was provided."); |
---|
| 122 | } |
---|
| 123 | |
---|
| 124 | boost::shared_ptr<COutputPin> CFilterFieldFieldOpExprNode::reduce(CGarbageCollector& gc, CField& thisField) const |
---|
| 125 | { |
---|
| 126 | boost::shared_ptr<CFieldFieldArithmeticFilter> filter(new CFieldFieldArithmeticFilter(gc, opId)); |
---|
| 127 | child1->reduce(gc, thisField)->connectOutput(filter, 0); |
---|
| 128 | child2->reduce(gc, thisField)->connectOutput(filter, 1); |
---|
| 129 | return filter; |
---|
| 130 | } |
---|
| 131 | } |
---|