source: XIOS/dev/dev_ym/XIOS_COUPLING/src/parse_expr/filter_expr_node.cpp @ 1878

Last change on this file since 1878 was 1869, checked in by ymipsl, 4 years ago

Some update...

YM

File size: 13.9 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        bool ret=field->buildWorkflowGraph(gc);
43        if (ret) outputPin = field->getInstantDataFilter(); // if dependency is complete build the graph other return nullptr
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        bool ret=field->buildWorkflowGraph(gc);
87        if (ret) 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    auto ret=child->reduce(gc, thisField) ;
110    if (ret) ret->connectOutput(filter, 0);
111    else filter.reset() ;
112    return filter;
113  }
114
115  CFilterScalarFieldOpExprNode::CFilterScalarFieldOpExprNode(IScalarExprNode* child1, const std::string& opId, IFilterExprNode* child2)
116    : child1(child1)
117    , opId(opId)
118    , child2(child2)
119  {
120    if (!child1 || !child2)
121      ERROR("CFilterScalarFieldOpExprNode::CFilterScalarFieldOpExprNode(IScalarExprNode* child1, const std::string& opId, IFilterExprNode* child2)",
122            "Impossible to create the new expression node, an invalid child node was provided.");
123  }
124
125  std::shared_ptr<COutputPin> CFilterScalarFieldOpExprNode::reduce(CGarbageCollector& gc, CField& thisField) const
126  {
127    std::shared_ptr<CScalarFieldArithmeticFilter> filter(new CScalarFieldArithmeticFilter(gc, opId, child1->reduce()));
128   
129    auto ret=child2->reduce(gc, thisField) ;
130    if (ret) ret->connectOutput(filter, 0);
131    else filter.reset() ;
132    return filter;
133  }
134
135  CFilterFieldScalarOpExprNode::CFilterFieldScalarOpExprNode(IFilterExprNode* child1, const std::string& opId, IScalarExprNode* child2)
136    : child1(child1)
137    , opId(opId)
138    , child2(child2)
139  {
140    if (!child1 || !child2)
141      ERROR("CFilterFieldScalarOpExprNode::CFilterFieldScalarOpExprNode(IFilterExprNode* child1, const std::string& opId, IScalarExprNode* child2)",
142            "Impossible to create the new expression node, an invalid child node was provided.");
143  }
144
145  std::shared_ptr<COutputPin> CFilterFieldScalarOpExprNode::reduce(CGarbageCollector& gc, CField& thisField) const
146  {
147    std::shared_ptr<CFieldScalarArithmeticFilter> filter(new CFieldScalarArithmeticFilter(gc, opId, child2->reduce()));
148    auto ret=child1->reduce(gc, thisField) ;
149    if (ret) ret->connectOutput(filter, 0);
150    else filter.reset() ;
151    return filter;
152  }
153
154  CFilterFieldFieldOpExprNode::CFilterFieldFieldOpExprNode(IFilterExprNode* child1, const std::string& opId, IFilterExprNode* child2)
155    : child1(child1)
156    , opId(opId)
157    , child2(child2)
158  {
159    if (!child1 || !child2)
160      ERROR("CFilterFieldFieldOpExprNode::CFilterFieldFieldOpExprNode(IFilterExprNode* child1, const std::string& opId, IFilterExprNode* child2)",
161            "Impossible to create the new expression node, an invalid child node was provided.");
162  }
163
164  std::shared_ptr<COutputPin> CFilterFieldFieldOpExprNode::reduce(CGarbageCollector& gc, CField& thisField) const
165  {
166    std::shared_ptr<CFieldFieldArithmeticFilter> filter(new CFieldFieldArithmeticFilter(gc, opId));
167    auto ret1 = child1->reduce(gc, thisField);
168    auto ret2 = child2->reduce(gc, thisField);
169    if (ret1 && ret2) 
170    {
171      ret1->connectOutput(filter, 0) ;
172      ret2->connectOutput(filter, 1) ;
173    }
174    else filter.reset() ;
175    return filter;
176  }
177
178
179
180
181  CFilterScalarScalarFieldOpExprNode::CFilterScalarScalarFieldOpExprNode(IScalarExprNode* child1, const std::string& opId, IScalarExprNode* child2, IFilterExprNode* child3)
182    : child1(child1)
183    , opId(opId)
184    , child2(child2)
185    , child3(child3)
186  {
187    if (!child1 || !child2 || !child3)
188      ERROR("  CFilterScalarScalarFieldOpExprNode::CFilterScalarScalarFieldOpExprNode(IScalarExprNode* child1, const std::string& opId, IScalarExprNode* child2, IFilterExprNode* child3)",
189            "Impossible to create the new expression node, an invalid child node was provided.");
190  }
191
192  std::shared_ptr<COutputPin> CFilterScalarScalarFieldOpExprNode::reduce(CGarbageCollector& gc, CField& thisField) const
193  {
194    std::shared_ptr<CScalarScalarFieldArithmeticFilter> filter(new CScalarScalarFieldArithmeticFilter(gc, opId, child1->reduce(),child2->reduce()));
195    auto ret=child3->reduce(gc, thisField) ;
196    if (ret) ret->connectOutput(filter, 0);
197    else filter.reset() ;
198    return filter;
199  }
200
201
202  CFilterScalarFieldScalarOpExprNode::CFilterScalarFieldScalarOpExprNode(IScalarExprNode* child1, const std::string& opId, IFilterExprNode* child2, IScalarExprNode* child3)
203    : child1(child1)
204    , opId(opId)
205    , child2(child2)
206    , child3(child3)
207  {
208    if (!child1 || !child2 || !child3)
209      ERROR("  CFilterScalarFieldScalarOpExprNode::CFilterScalarFieldScalarOpExprNode(IScalarExprNode* child1, const std::string& opId, IFilterExprNode* child2, IScalarExprNode* child3)",
210            "Impossible to create the new expression node, an invalid child node was provided.");
211  }
212
213  std::shared_ptr<COutputPin> CFilterScalarFieldScalarOpExprNode::reduce(CGarbageCollector& gc, CField& thisField) const
214  {
215    std::shared_ptr<CScalarFieldScalarArithmeticFilter> filter(new CScalarFieldScalarArithmeticFilter(gc, opId, child1->reduce(),child3->reduce()));
216    auto ret=child2->reduce(gc, thisField);
217    if (ret) ret->connectOutput(filter, 0);
218    else filter.reset() ;
219    return filter;
220  }
221
222
223  CFilterScalarFieldFieldOpExprNode::CFilterScalarFieldFieldOpExprNode(IScalarExprNode* child1, const std::string& opId, IFilterExprNode* child2, IFilterExprNode* child3)
224    : child1(child1)
225    , opId(opId)
226    , child2(child2)
227    , child3(child3)
228  {
229    if (!child1 || !child2 || !child3)
230      ERROR("  CFilterScalarFieldFieldOpExprNode::CFilterScalarFieldFieldOpExprNode(IScalarExprNode* child1, const std::string& opId, IFilterExprNode* child2, IFilterExprNode* child3)",
231            "Impossible to create the new expression node, an invalid child node was provided.");
232  }
233
234  std::shared_ptr<COutputPin> CFilterScalarFieldFieldOpExprNode::reduce(CGarbageCollector& gc, CField& thisField) const
235  {
236    std::shared_ptr<CScalarFieldFieldArithmeticFilter> filter(new CScalarFieldFieldArithmeticFilter(gc, opId, child1->reduce()));
237    auto ret1=child2->reduce(gc, thisField);
238    auto ret2=child3->reduce(gc, thisField);
239    if (ret1 && ret2)
240    {
241      ret1->connectOutput(filter, 0);
242      ret2->connectOutput(filter, 1);
243    }
244    else filter.reset() ;
245    return filter;
246  }
247
248
249
250  CFilterFieldScalarScalarOpExprNode::CFilterFieldScalarScalarOpExprNode(IFilterExprNode* child1, const std::string& opId, IScalarExprNode* child2, IScalarExprNode* child3)
251    : child1(child1)
252    , opId(opId)
253    , child2(child2)
254    , child3(child3)
255  {
256    if (!child1 || !child2 || !child3)
257      ERROR("  CFilterFieldScalarScalarOpExprNode::CFilterFieldScalarScalarOpExprNode(IFilterExprNode* child1, const std::string& opId, IScalarExprNode* child2, IScalarExprNode* child3)",
258            "Impossible to create the new expression node, an invalid child node was provided.");
259  }
260
261  std::shared_ptr<COutputPin> CFilterFieldScalarScalarOpExprNode::reduce(CGarbageCollector& gc, CField& thisField) const
262  {
263    std::shared_ptr<CFieldScalarScalarArithmeticFilter> filter(new CFieldScalarScalarArithmeticFilter(gc, opId, child2->reduce(),child3->reduce()));
264    auto ret = child1->reduce(gc, thisField) ;
265    if (ret) ret->connectOutput(filter, 0);
266    else filter.reset() ;
267    return filter;
268  }
269
270
271
272  CFilterFieldScalarFieldOpExprNode::CFilterFieldScalarFieldOpExprNode(IFilterExprNode* child1, const std::string& opId, IScalarExprNode* child2, IFilterExprNode* child3)
273    : child1(child1)
274    , opId(opId)
275    , child2(child2)
276    , child3(child3)
277  {
278    if (!child1 || !child2 || !child3)
279      ERROR("  CFilterFieldScalarFieldOpExprNode::CFilterFieldScalarFieldOpExprNode(IFilterExprNode* child1, const std::string& opId, IScalarExprNode* child2, IFilterExprNode* child3)",
280            "Impossible to create the new expression node, an invalid child node was provided.");
281  }
282
283  std::shared_ptr<COutputPin> CFilterFieldScalarFieldOpExprNode::reduce(CGarbageCollector& gc, CField& thisField) const
284  {
285    std::shared_ptr<CFieldScalarFieldArithmeticFilter> filter(new CFieldScalarFieldArithmeticFilter(gc, opId, child2->reduce()));
286    auto ret1 = child1->reduce(gc, thisField);
287    auto ret2 = child3->reduce(gc, thisField);
288    if (ret1 && ret2)
289    {
290      ret1 -> connectOutput(filter, 0);
291      ret2 -> connectOutput(filter, 1);
292    }
293    else filter.reset() ;
294    return filter;
295  }
296
297
298
299  CFilterFieldFieldScalarOpExprNode::CFilterFieldFieldScalarOpExprNode(IFilterExprNode* child1, const std::string& opId, IFilterExprNode* child2, IScalarExprNode* child3)
300    : child1(child1)
301    , opId(opId)
302    , child2(child2)
303    , child3(child3)
304  {
305    if (!child1 || !child2 || !child3)
306      ERROR("  CFilterFieldFieldScalarOpExprNode::CFilterFieldFieldScalarOpExprNode(IFilterExprNode* child1, const std::string& opId, IFilterExprNode* child2, IScalarExprNode* child3)",
307            "Impossible to create the new expression node, an invalid child node was provided.");
308  }
309
310  std::shared_ptr<COutputPin> CFilterFieldFieldScalarOpExprNode::reduce(CGarbageCollector& gc, CField& thisField) const
311  {
312    std::shared_ptr<CFieldFieldScalarArithmeticFilter> filter(new CFieldFieldScalarArithmeticFilter(gc, opId, child3->reduce()));
313    auto ret1 = child1->reduce(gc, thisField);
314    auto ret2 = child2->reduce(gc, thisField);
315    if (ret1 && ret2)
316    {
317      ret1->connectOutput(filter, 0);
318      ret2->connectOutput(filter, 1);
319    }
320    else filter.reset() ;
321    return filter;
322  }
323
324
325  CFilterFieldFieldFieldOpExprNode::CFilterFieldFieldFieldOpExprNode(IFilterExprNode* child1, const std::string& opId, IFilterExprNode* child2, IFilterExprNode* child3)
326    : child1(child1)
327    , opId(opId)
328    , child2(child2)
329    , child3(child3)
330  {
331    if (!child1 || !child2 || !child3)
332      ERROR("  CFilterFieldFieldFieldOpExprNode::CFilterFieldFieldFieldOpExprNode(IFilterExprNode* child1, const std::string& opId, IFilterExprNode* child2, IFilterExprNode* child3)",
333            "Impossible to create the new expression node, an invalid child node was provided.");
334  }
335
336  std::shared_ptr<COutputPin> CFilterFieldFieldFieldOpExprNode::reduce(CGarbageCollector& gc, CField& thisField) const
337  {
338    std::shared_ptr<CFieldFieldFieldArithmeticFilter> filter(new CFieldFieldFieldArithmeticFilter(gc, opId));
339    auto ret1=child1->reduce(gc, thisField);
340    auto ret2=child2->reduce(gc, thisField);
341    auto ret3=child3->reduce(gc, thisField);
342    if (ret1 && ret2 && ret3)
343    {
344      ret1->connectOutput(filter, 0);
345      ret2->connectOutput(filter, 1);
346      ret3->connectOutput(filter, 2);
347    }
348    else filter.reset() ;
349    return filter;
350  }
351 
352}
Note: See TracBrowser for help on using the repository browser.