#include "filter_expr_node.hpp" #include "unary_arithmetic_filter.hpp" #include "binary_arithmetic_filter.hpp" #include "field.hpp" namespace xios { CFilterFieldExprNode::CFilterFieldExprNode(const std::string& fieldId) : fieldId(fieldId) { /* Nothing to do */ } boost::shared_ptr CFilterFieldExprNode::reduce(CGarbageCollector& gc, CField& thisField) const { boost::shared_ptr outputPin; if (fieldId == "this") outputPin = thisField.getSelfReference(gc); else if (CField::has(fieldId)) { CField* field = CField::get(fieldId); if (field == &thisField) ERROR("boost::shared_ptr CFilterFieldExprNode::reduce(CGarbageCollector& gc, CField& thisField) const", << "The field " << fieldId << " has an invalid reference to itself. " << "Use the keyword \"this\" if you want to reference the input data sent to this field."); field->buildFilterGraph(gc, false); outputPin = field->getInstantDataFilter(); } else ERROR("boost::shared_ptr CFilterFieldExprNode::reduce(CGarbageCollector& gc, CField& thisField) const", << "The field " << fieldId << " does not exist."); return outputPin; } CFilterTemporalFieldExprNode::CFilterTemporalFieldExprNode(const std::string& fieldId) : fieldId(fieldId) { /* Nothing to do */ } boost::shared_ptr CFilterTemporalFieldExprNode::reduce(CGarbageCollector& gc, CField& thisField) const { if (!CField::has(fieldId)) ERROR("boost::shared_ptr CFilterTemporalFieldExprNode::reduce(CGarbageCollector& gc, CField& thisField) const", << "The field " << fieldId << " does not exist."); CField* field = CField::get(fieldId); if (field == &thisField) ERROR("boost::shared_ptr CFilterFieldExprNode::reduce(CGarbageCollector& gc, CField& thisField) const", << "The field " << fieldId << " has an invalid reference to itself."); field->buildFilterGraph(gc, false); return field->getTemporalDataFilter(gc, thisField.freq_op.isEmpty() ? TimeStep : thisField.freq_op); } CFilterUnaryOpExprNode::CFilterUnaryOpExprNode(const std::string& opId, IFilterExprNode* child) : opId(opId) , child(child) { if (!child) ERROR("CFilterUnaryOpExprNode::CFilterUnaryOpExprNode(const std::string& opId, IFilterExprNode* child)", "Impossible to create the new expression node, an invalid child node was provided."); } boost::shared_ptr CFilterUnaryOpExprNode::reduce(CGarbageCollector& gc, CField& thisField) const { boost::shared_ptr filter(new CUnaryArithmeticFilter(gc, opId)); child->reduce(gc, thisField)->connectOutput(filter, 0); return filter; } CFilterScalarFieldOpExprNode::CFilterScalarFieldOpExprNode(IScalarExprNode* child1, const std::string& opId, IFilterExprNode* child2) : child1(child1) , opId(opId) , child2(child2) { if (!child1 || !child2) ERROR("CFilterScalarFieldOpExprNode::CFilterScalarFieldOpExprNode(IScalarExprNode* child1, const std::string& opId, IFilterExprNode* child2)", "Impossible to create the new expression node, an invalid child node was provided."); } boost::shared_ptr CFilterScalarFieldOpExprNode::reduce(CGarbageCollector& gc, CField& thisField) const { boost::shared_ptr filter(new CScalarFieldArithmeticFilter(gc, opId, child1->reduce())); child2->reduce(gc, thisField)->connectOutput(filter, 0); return filter; } CFilterFieldScalarOpExprNode::CFilterFieldScalarOpExprNode(IFilterExprNode* child1, const std::string& opId, IScalarExprNode* child2) : child1(child1) , opId(opId) , child2(child2) { if (!child1 || !child2) ERROR("CFilterFieldScalarOpExprNode::CFilterFieldScalarOpExprNode(IFilterExprNode* child1, const std::string& opId, IScalarExprNode* child2)", "Impossible to create the new expression node, an invalid child node was provided."); } boost::shared_ptr CFilterFieldScalarOpExprNode::reduce(CGarbageCollector& gc, CField& thisField) const { boost::shared_ptr filter(new CFieldScalarArithmeticFilter(gc, opId, child2->reduce())); child1->reduce(gc, thisField)->connectOutput(filter, 0); return filter; } CFilterFieldFieldOpExprNode::CFilterFieldFieldOpExprNode(IFilterExprNode* child1, const std::string& opId, IFilterExprNode* child2) : child1(child1) , opId(opId) , child2(child2) { if (!child1 || !child2) ERROR("CFilterFieldFieldOpExprNode::CFilterFieldFieldOpExprNode(IFilterExprNode* child1, const std::string& opId, IFilterExprNode* child2)", "Impossible to create the new expression node, an invalid child node was provided."); } boost::shared_ptr CFilterFieldFieldOpExprNode::reduce(CGarbageCollector& gc, CField& thisField) const { boost::shared_ptr filter(new CFieldFieldArithmeticFilter(gc, opId)); child1->reduce(gc, thisField)->connectOutput(filter, 0); child2->reduce(gc, thisField)->connectOutput(filter, 1); return filter; } }