source: XIOS/dev/branch_yushan/src/parse_expr/filter_expr_node.cpp @ 1037

Last change on this file since 1037 was 1037, checked in by yushan, 7 years ago

initialize the branch

File size: 5.2 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  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  {
42    if (!CField::has(fieldId))
43      ERROR("boost::shared_ptr<COutputPin> CFilterTemporalFieldExprNode::reduce(CGarbageCollector& gc, CField& thisField) const",
44            << "The field " << fieldId << " does not exist.");
45
46    CField* field = CField::get(fieldId);
47    if (field == &thisField)
48      ERROR("boost::shared_ptr<COutputPin> CFilterFieldExprNode::reduce(CGarbageCollector& gc, CField& thisField) const",
49            << "The field " << fieldId << " has an invalid reference to itself.");
50
51    field->buildFilterGraph(gc, false);
52    return field->getTemporalDataFilter(gc, thisField.freq_op.isEmpty() ? TimeStep : thisField.freq_op);
53  }
54
55  CFilterUnaryOpExprNode::CFilterUnaryOpExprNode(const std::string& opId, IFilterExprNode* child)
56    : opId(opId)
57    , child(child)
58  {
59    if (!child)
60      ERROR("CFilterUnaryOpExprNode::CFilterUnaryOpExprNode(const std::string& opId, IFilterExprNode* child)",
61            "Impossible to create the new expression node, an invalid child node was provided.");
62  }
63
64  boost::shared_ptr<COutputPin> CFilterUnaryOpExprNode::reduce(CGarbageCollector& gc, CField& thisField) const
65  {
66    boost::shared_ptr<CUnaryArithmeticFilter> filter(new CUnaryArithmeticFilter(gc, opId));
67    child->reduce(gc, thisField)->connectOutput(filter, 0);
68    return filter;
69  }
70
71  CFilterScalarFieldOpExprNode::CFilterScalarFieldOpExprNode(IScalarExprNode* child1, const std::string& opId, IFilterExprNode* child2)
72    : child1(child1)
73    , opId(opId)
74    , child2(child2)
75  {
76    if (!child1 || !child2)
77      ERROR("CFilterScalarFieldOpExprNode::CFilterScalarFieldOpExprNode(IScalarExprNode* child1, const std::string& opId, IFilterExprNode* child2)",
78            "Impossible to create the new expression node, an invalid child node was provided.");
79  }
80
81  boost::shared_ptr<COutputPin> CFilterScalarFieldOpExprNode::reduce(CGarbageCollector& gc, CField& thisField) const
82  {
83    boost::shared_ptr<CScalarFieldArithmeticFilter> filter(new CScalarFieldArithmeticFilter(gc, opId, child1->reduce()));
84    child2->reduce(gc, thisField)->connectOutput(filter, 0);
85    return filter;
86  }
87
88  CFilterFieldScalarOpExprNode::CFilterFieldScalarOpExprNode(IFilterExprNode* child1, const std::string& opId, IScalarExprNode* child2)
89    : child1(child1)
90    , opId(opId)
91    , child2(child2)
92  {
93    if (!child1 || !child2)
94      ERROR("CFilterFieldScalarOpExprNode::CFilterFieldScalarOpExprNode(IFilterExprNode* child1, const std::string& opId, IScalarExprNode* child2)",
95            "Impossible to create the new expression node, an invalid child node was provided.");
96  }
97
98  boost::shared_ptr<COutputPin> CFilterFieldScalarOpExprNode::reduce(CGarbageCollector& gc, CField& thisField) const
99  {
100    boost::shared_ptr<CFieldScalarArithmeticFilter> filter(new CFieldScalarArithmeticFilter(gc, opId, child2->reduce()));
101    child1->reduce(gc, thisField)->connectOutput(filter, 0);
102    return filter;
103  }
104
105  CFilterFieldFieldOpExprNode::CFilterFieldFieldOpExprNode(IFilterExprNode* child1, const std::string& opId, IFilterExprNode* child2)
106    : child1(child1)
107    , opId(opId)
108    , child2(child2)
109  {
110    if (!child1 || !child2)
111      ERROR("CFilterFieldFieldOpExprNode::CFilterFieldFieldOpExprNode(IFilterExprNode* child1, const std::string& opId, IFilterExprNode* child2)",
112            "Impossible to create the new expression node, an invalid child node was provided.");
113  }
114
115  boost::shared_ptr<COutputPin> CFilterFieldFieldOpExprNode::reduce(CGarbageCollector& gc, CField& thisField) const
116  {
117    boost::shared_ptr<CFieldFieldArithmeticFilter> filter(new CFieldFieldArithmeticFilter(gc, opId));
118    child1->reduce(gc, thisField)->connectOutput(filter, 0);
119    child2->reduce(gc, thisField)->connectOutput(filter, 1);
120    return filter;
121  }
122}
Note: See TracBrowser for help on using the repository browser.