source: XIOS/trunk/src/parse_expr/filter_expr_node.cpp @ 642

Last change on this file since 642 was 642, checked in by rlacroix, 9 years ago

Use the filter infrastructure to handle the expressions

Parse the expressions to get a new tree representation that can be converted to a filter graph based on new arithmetic filters.

Temporal operations are still unsupported.

File size: 4.3 KB
Line 
1#include "filter_expr_node.hpp"
2#include "unary_arithmetic_filter.hpp"
3#include "binary_arithmetic_filter.hpp"
4#include "field.hpp"
5
6namespace 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
36  CFilterUnaryOpExprNode::CFilterUnaryOpExprNode(const std::string& opId, IFilterExprNode* child)
37    : opId(opId)
38    , child(child)
39  {
40    if (!child)
41      ERROR("CFilterUnaryOpExprNode::CFilterUnaryOpExprNode(const std::string& opId, IFilterExprNode* child)",
42            "Impossible to create the new expression node, an invalid child node was provided.");
43  }
44
45  boost::shared_ptr<COutputPin> CFilterUnaryOpExprNode::reduce(CGarbageCollector& gc, CField& thisField) const
46  {
47    boost::shared_ptr<CUnaryArithmeticFilter> filter(new CUnaryArithmeticFilter(gc, opId));
48    child->reduce(gc, thisField)->connectOutput(filter, 0);
49    return filter;
50  }
51
52  CFilterScalarFieldOpExprNode::CFilterScalarFieldOpExprNode(IScalarExprNode* child1, const std::string& opId, IFilterExprNode* child2)
53    : child1(child1)
54    , opId(opId)
55    , child2(child2)
56  {
57    if (!child1 || !child2)
58      ERROR("CFilterScalarFieldOpExprNode::CFilterScalarFieldOpExprNode(IScalarExprNode* child1, const std::string& opId, IFilterExprNode* child2)",
59            "Impossible to create the new expression node, an invalid child node was provided.");
60  }
61
62  boost::shared_ptr<COutputPin> CFilterScalarFieldOpExprNode::reduce(CGarbageCollector& gc, CField& thisField) const
63  {
64    boost::shared_ptr<CScalarFieldArithmeticFilter> filter(new CScalarFieldArithmeticFilter(gc, opId, child1->reduce()));
65    child2->reduce(gc, thisField)->connectOutput(filter, 0);
66    return filter;
67  }
68
69  CFilterFieldScalarOpExprNode::CFilterFieldScalarOpExprNode(IFilterExprNode* child1, const std::string& opId, IScalarExprNode* child2)
70    : child1(child1)
71    , opId(opId)
72    , child2(child2)
73  {
74    if (!child1 || !child2)
75      ERROR("CFilterFieldScalarOpExprNode::CFilterFieldScalarOpExprNode(IFilterExprNode* child1, const std::string& opId, IScalarExprNode* child2)",
76            "Impossible to create the new expression node, an invalid child node was provided.");
77  }
78
79  boost::shared_ptr<COutputPin> CFilterFieldScalarOpExprNode::reduce(CGarbageCollector& gc, CField& thisField) const
80  {
81    boost::shared_ptr<CFieldScalarArithmeticFilter> filter(new CFieldScalarArithmeticFilter(gc, opId, child2->reduce()));
82    child1->reduce(gc, thisField)->connectOutput(filter, 0);
83    return filter;
84  }
85
86  CFilterFieldFieldOpExprNode::CFilterFieldFieldOpExprNode(IFilterExprNode* child1, const std::string& opId, IFilterExprNode* child2)
87    : child1(child1)
88    , opId(opId)
89    , child2(child2)
90  {
91    if (!child1 || !child2)
92      ERROR("CFilterFieldFieldOpExprNode::CFilterFieldFieldOpExprNode(IFilterExprNode* child1, const std::string& opId, IFilterExprNode* child2)",
93            "Impossible to create the new expression node, an invalid child node was provided.");
94  }
95
96  boost::shared_ptr<COutputPin> CFilterFieldFieldOpExprNode::reduce(CGarbageCollector& gc, CField& thisField) const
97  {
98    boost::shared_ptr<CFieldFieldArithmeticFilter> filter(new CFieldFieldArithmeticFilter(gc, opId));
99    child1->reduce(gc, thisField)->connectOutput(filter, 0);
100    child2->reduce(gc, thisField)->connectOutput(filter, 1);
101    return filter;
102  }
103}
Note: See TracBrowser for help on using the repository browser.