source: XIOS/dev/dev_olga/src/parse_expr/filter_expr_node.cpp @ 1577

Last change on this file since 1577 was 1577, checked in by oabramkina, 3 years ago

Backporting r1573-r1575 to dev.

File size: 13.0 KB
Line 
1#include "filter_expr_node.hpp"
2#include "unary_arithmetic_filter.hpp"
3#include "binary_arithmetic_filter.hpp"
4#include "ternary_arithmetic_filter.hpp"
5#include "field.hpp"
6
7namespace xios
8{
9  CFilterFieldExprNode::CFilterFieldExprNode(const std::string& fieldId)
10    : fieldId(fieldId)
11  { /* Nothing to do */ }
12
13 
14  std::shared_ptr<COutputPin> CFilterFieldExprNode::reduce(CGarbageCollector& gc, CField& thisField) const
15  {
16    std::shared_ptr<COutputPin> outputPin;
17
18    if (fieldId == "this") outputPin = thisField.getSelfReference(gc);
19    else
20    {
21      string id ;
22
23      if (fieldId == "this_ref")
24      {
25        if (thisField.field_ref.isEmpty())
26        {
27          ERROR("shared_ptr<COutputPin> CFilterFieldExprNode::reduce(CGarbageCollector& gc, CField& thisField) const",
28                << "field_ref attribute is empty.");
29        }
30        else id = thisField.field_ref ;
31      }
32      else id= fieldId ;
33       
34      if (CField::has(id))
35      {
36        CField* field = CField::get(id);
37        if (field == &thisField)
38          ERROR("shared_ptr<COutputPin> CFilterFieldExprNode::reduce(CGarbageCollector& gc, CField& thisField) const",
39                << "The field " << id << " has an invalid reference to itself. "
40                << "Use the keyword \"this\" if you want to reference the input data sent to this field.");
41
42        field->buildFilterGraph(gc, false);
43        outputPin = field->getInstantDataFilter();
44      }
45      else ERROR("boost::shared_ptr<COutputPin> CFilterFieldExprNode::reduce(CGarbageCollector& gc, CField& thisField) const",
46                  << "The field " << id << " does not exist.");
47    }
48    return outputPin;
49  }
50
51
52  CFilterTemporalFieldExprNode::CFilterTemporalFieldExprNode(const std::string& fieldId)
53    : fieldId(fieldId)
54  { /* Nothing to do */ }
55
56
57  std::shared_ptr<COutputPin> CFilterTemporalFieldExprNode::reduce(CGarbageCollector& gc, CField& thisField) const
58  {
59    std::shared_ptr<COutputPin> outputPin;
60
61    if (fieldId == "this")
62      outputPin = thisField.getSelfTemporalDataFilter(gc, thisField.freq_op.isEmpty() ? TimeStep : thisField.freq_op);
63    else
64    {
65      string id ;
66
67      if (fieldId == "this_ref")
68      {
69        if (thisField.field_ref.isEmpty())
70        {
71          ERROR("shared_ptr<COutputPin> CFilterFieldExprNode::reduce(CGarbageCollector& gc, CField& thisField) const",
72                << "field_ref attribute is empty.");
73        }
74        else id = thisField.field_ref ;
75      }
76      else id = fieldId ;
77
78      if (CField::has(id))
79      {
80        CField* field = CField::get(id);
81        if (field == &thisField)
82          ERROR("shared_ptr<COutputPin> CFilterTemporalFieldExprNode::reduce(CGarbageCollector& gc, CField& thisField) const",
83                << "The field " << fieldId << " has an invalid reference to itself. "
84                << "Use the keyword \"this\" if you want to reference the input data sent to this field.");
85
86        field->buildFilterGraph(gc, false);
87        outputPin = field->getTemporalDataFilter(gc, thisField.freq_op.isEmpty() ? TimeStep : thisField.freq_op);
88      }
89      else
90        ERROR("shared_ptr<COutputPin> CFilterTemporalFieldExprNode::reduce(CGarbageCollector& gc, CField& thisField) const",
91              << "The field " << fieldId << " does not exist.");
92    }
93    return outputPin;
94  }
95
96
97  CFilterUnaryOpExprNode::CFilterUnaryOpExprNode(const std::string& opId, IFilterExprNode* child)
98    : opId(opId)
99    , child(child)
100  {
101    if (!child)
102      ERROR("CFilterUnaryOpExprNode::CFilterUnaryOpExprNode(const std::string& opId, IFilterExprNode* child)",
103            "Impossible to create the new expression node, an invalid child node was provided.");
104  }
105
106  std::shared_ptr<COutputPin> CFilterUnaryOpExprNode::reduce(CGarbageCollector& gc, CField& thisField) const
107  {
108    std::shared_ptr<CUnaryArithmeticFilter> filter(new CUnaryArithmeticFilter(gc, opId));
109    child->reduce(gc, thisField)->connectOutput(filter, 0);
110    return filter;
111  }
112
113  CFilterScalarFieldOpExprNode::CFilterScalarFieldOpExprNode(IScalarExprNode* child1, const std::string& opId, IFilterExprNode* child2)
114    : child1(child1)
115    , opId(opId)
116    , child2(child2)
117  {
118    if (!child1 || !child2)
119      ERROR("CFilterScalarFieldOpExprNode::CFilterScalarFieldOpExprNode(IScalarExprNode* child1, const std::string& opId, IFilterExprNode* child2)",
120            "Impossible to create the new expression node, an invalid child node was provided.");
121  }
122
123  std::shared_ptr<COutputPin> CFilterScalarFieldOpExprNode::reduce(CGarbageCollector& gc, CField& thisField) const
124  {
125    std::shared_ptr<CScalarFieldArithmeticFilter> filter(new CScalarFieldArithmeticFilter(gc, opId, child1->reduce()));
126    child2->reduce(gc, thisField)->connectOutput(filter, 0);
127    return filter;
128  }
129
130  CFilterFieldScalarOpExprNode::CFilterFieldScalarOpExprNode(IFilterExprNode* child1, const std::string& opId, IScalarExprNode* child2)
131    : child1(child1)
132    , opId(opId)
133    , child2(child2)
134  {
135    if (!child1 || !child2)
136      ERROR("CFilterFieldScalarOpExprNode::CFilterFieldScalarOpExprNode(IFilterExprNode* child1, const std::string& opId, IScalarExprNode* child2)",
137            "Impossible to create the new expression node, an invalid child node was provided.");
138  }
139
140  std::shared_ptr<COutputPin> CFilterFieldScalarOpExprNode::reduce(CGarbageCollector& gc, CField& thisField) const
141  {
142    std::shared_ptr<CFieldScalarArithmeticFilter> filter(new CFieldScalarArithmeticFilter(gc, opId, child2->reduce()));
143    child1->reduce(gc, thisField)->connectOutput(filter, 0);
144    return filter;
145  }
146
147  CFilterFieldFieldOpExprNode::CFilterFieldFieldOpExprNode(IFilterExprNode* child1, const std::string& opId, IFilterExprNode* child2)
148    : child1(child1)
149    , opId(opId)
150    , child2(child2)
151  {
152    if (!child1 || !child2)
153      ERROR("CFilterFieldFieldOpExprNode::CFilterFieldFieldOpExprNode(IFilterExprNode* child1, const std::string& opId, IFilterExprNode* child2)",
154            "Impossible to create the new expression node, an invalid child node was provided.");
155  }
156
157  std::shared_ptr<COutputPin> CFilterFieldFieldOpExprNode::reduce(CGarbageCollector& gc, CField& thisField) const
158  {
159    std::shared_ptr<CFieldFieldArithmeticFilter> filter(new CFieldFieldArithmeticFilter(gc, opId));
160    child1->reduce(gc, thisField)->connectOutput(filter, 0);
161    child2->reduce(gc, thisField)->connectOutput(filter, 1);
162    return filter;
163  }
164
165
166
167
168  CFilterScalarScalarFieldOpExprNode::CFilterScalarScalarFieldOpExprNode(IScalarExprNode* child1, const std::string& opId, IScalarExprNode* child2, IFilterExprNode* child3)
169    : child1(child1)
170    , opId(opId)
171    , child2(child2)
172    , child3(child3)
173  {
174    if (!child1 || !child2 || !child3)
175      ERROR("  CFilterScalarScalarFieldOpExprNode::CFilterScalarScalarFieldOpExprNode(IScalarExprNode* child1, const std::string& opId, IScalarExprNode* child2, IFilterExprNode* child3)",
176            "Impossible to create the new expression node, an invalid child node was provided.");
177  }
178
179  std::shared_ptr<COutputPin> CFilterScalarScalarFieldOpExprNode::reduce(CGarbageCollector& gc, CField& thisField) const
180  {
181    std::shared_ptr<CScalarScalarFieldArithmeticFilter> filter(new CScalarScalarFieldArithmeticFilter(gc, opId, child1->reduce(),child2->reduce()));
182    child3->reduce(gc, thisField)->connectOutput(filter, 0);
183    return filter;
184  }
185
186
187  CFilterScalarFieldScalarOpExprNode::CFilterScalarFieldScalarOpExprNode(IScalarExprNode* child1, const std::string& opId, IFilterExprNode* child2, IScalarExprNode* child3)
188    : child1(child1)
189    , opId(opId)
190    , child2(child2)
191    , child3(child3)
192  {
193    if (!child1 || !child2 || !child3)
194      ERROR("  CFilterScalarFieldScalarOpExprNode::CFilterScalarFieldScalarOpExprNode(IScalarExprNode* child1, const std::string& opId, IFilterExprNode* child2, IScalarExprNode* child3)",
195            "Impossible to create the new expression node, an invalid child node was provided.");
196  }
197
198  std::shared_ptr<COutputPin> CFilterScalarFieldScalarOpExprNode::reduce(CGarbageCollector& gc, CField& thisField) const
199  {
200    std::shared_ptr<CScalarFieldScalarArithmeticFilter> filter(new CScalarFieldScalarArithmeticFilter(gc, opId, child1->reduce(),child3->reduce()));
201    child2->reduce(gc, thisField)->connectOutput(filter, 0);
202    return filter;
203  }
204
205
206  CFilterScalarFieldFieldOpExprNode::CFilterScalarFieldFieldOpExprNode(IScalarExprNode* child1, const std::string& opId, IFilterExprNode* child2, IFilterExprNode* child3)
207    : child1(child1)
208    , opId(opId)
209    , child2(child2)
210    , child3(child3)
211  {
212    if (!child1 || !child2 || !child3)
213      ERROR("  CFilterScalarFieldFieldOpExprNode::CFilterScalarFieldFieldOpExprNode(IScalarExprNode* child1, const std::string& opId, IFilterExprNode* child2, IFilterExprNode* child3)",
214            "Impossible to create the new expression node, an invalid child node was provided.");
215  }
216
217  std::shared_ptr<COutputPin> CFilterScalarFieldFieldOpExprNode::reduce(CGarbageCollector& gc, CField& thisField) const
218  {
219    std::shared_ptr<CScalarFieldFieldArithmeticFilter> filter(new CScalarFieldFieldArithmeticFilter(gc, opId, child1->reduce()));
220    child2->reduce(gc, thisField)->connectOutput(filter, 0);
221    child3->reduce(gc, thisField)->connectOutput(filter, 1);
222    return filter;
223  }
224
225
226
227  CFilterFieldScalarScalarOpExprNode::CFilterFieldScalarScalarOpExprNode(IFilterExprNode* child1, const std::string& opId, IScalarExprNode* child2, IScalarExprNode* child3)
228    : child1(child1)
229    , opId(opId)
230    , child2(child2)
231    , child3(child3)
232  {
233    if (!child1 || !child2 || !child3)
234      ERROR("  CFilterFieldScalarScalarOpExprNode::CFilterFieldScalarScalarOpExprNode(IFilterExprNode* child1, const std::string& opId, IScalarExprNode* child2, IScalarExprNode* child3)",
235            "Impossible to create the new expression node, an invalid child node was provided.");
236  }
237
238  std::shared_ptr<COutputPin> CFilterFieldScalarScalarOpExprNode::reduce(CGarbageCollector& gc, CField& thisField) const
239  {
240    std::shared_ptr<CFieldScalarScalarArithmeticFilter> filter(new CFieldScalarScalarArithmeticFilter(gc, opId, child2->reduce(),child3->reduce()));
241    child1->reduce(gc, thisField)->connectOutput(filter, 0);
242    return filter;
243  }
244
245
246
247  CFilterFieldScalarFieldOpExprNode::CFilterFieldScalarFieldOpExprNode(IFilterExprNode* child1, const std::string& opId, IScalarExprNode* child2, IFilterExprNode* child3)
248    : child1(child1)
249    , opId(opId)
250    , child2(child2)
251    , child3(child3)
252  {
253    if (!child1 || !child2 || !child3)
254      ERROR("  CFilterFieldScalarFieldOpExprNode::CFilterFieldScalarFieldOpExprNode(IFilterExprNode* child1, const std::string& opId, IScalarExprNode* child2, IFilterExprNode* child3)",
255            "Impossible to create the new expression node, an invalid child node was provided.");
256  }
257
258  std::shared_ptr<COutputPin> CFilterFieldScalarFieldOpExprNode::reduce(CGarbageCollector& gc, CField& thisField) const
259  {
260    std::shared_ptr<CFieldScalarFieldArithmeticFilter> filter(new CFieldScalarFieldArithmeticFilter(gc, opId, child2->reduce()));
261    child1->reduce(gc, thisField)->connectOutput(filter, 0);
262    child3->reduce(gc, thisField)->connectOutput(filter, 1);
263    return filter;
264  }
265
266
267
268  CFilterFieldFieldScalarOpExprNode::CFilterFieldFieldScalarOpExprNode(IFilterExprNode* child1, const std::string& opId, IFilterExprNode* child2, IScalarExprNode* child3)
269    : child1(child1)
270    , opId(opId)
271    , child2(child2)
272    , child3(child3)
273  {
274    if (!child1 || !child2 || !child3)
275      ERROR("  CFilterFieldFieldScalarOpExprNode::CFilterFieldFieldScalarOpExprNode(IFilterExprNode* child1, const std::string& opId, IFilterExprNode* child2, IScalarExprNode* child3)",
276            "Impossible to create the new expression node, an invalid child node was provided.");
277  }
278
279  std::shared_ptr<COutputPin> CFilterFieldFieldScalarOpExprNode::reduce(CGarbageCollector& gc, CField& thisField) const
280  {
281    std::shared_ptr<CFieldFieldScalarArithmeticFilter> filter(new CFieldFieldScalarArithmeticFilter(gc, opId, child3->reduce()));
282    child1->reduce(gc, thisField)->connectOutput(filter, 0);
283    child2->reduce(gc, thisField)->connectOutput(filter, 1);
284    return filter;
285  }
286
287
288  CFilterFieldFieldFieldOpExprNode::CFilterFieldFieldFieldOpExprNode(IFilterExprNode* child1, const std::string& opId, IFilterExprNode* child2, IFilterExprNode* child3)
289    : child1(child1)
290    , opId(opId)
291    , child2(child2)
292    , child3(child3)
293  {
294    if (!child1 || !child2 || !child3)
295      ERROR("  CFilterFieldFieldFieldOpExprNode::CFilterFieldFieldFieldOpExprNode(IFilterExprNode* child1, const std::string& opId, IFilterExprNode* child2, IFilterExprNode* child3)",
296            "Impossible to create the new expression node, an invalid child node was provided.");
297  }
298
299  std::shared_ptr<COutputPin> CFilterFieldFieldFieldOpExprNode::reduce(CGarbageCollector& gc, CField& thisField) const
300  {
301    std::shared_ptr<CFieldFieldFieldArithmeticFilter> filter(new CFieldFieldFieldArithmeticFilter(gc, opId));
302    child1->reduce(gc, thisField)->connectOutput(filter, 0);
303    child2->reduce(gc, thisField)->connectOutput(filter, 1);
304    child3->reduce(gc, thisField)->connectOutput(filter, 2);
305    return filter;
306  }
307 
308}
Note: See TracBrowser for help on using the repository browser.