source: XIOS/trunk/src/filter/binary_arithmetic_filter.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: 1.9 KB
Line 
1#include "binary_arithmetic_filter.hpp"
2
3namespace xios
4{
5  CScalarFieldArithmeticFilter::CScalarFieldArithmeticFilter(CGarbageCollector& gc, const std::string& op, double value)
6    : CFilter(gc, 1, this)
7    , op(operatorExpr.getOpScalarField(op))
8    , value(value)
9  { /* Nothing to do */ };
10
11  CDataPacketPtr CScalarFieldArithmeticFilter::apply(std::vector<CDataPacketPtr> data)
12  {
13    CDataPacketPtr packet(new CDataPacket);
14    packet->timestamp = data[0]->timestamp;
15    packet->status = data[0]->status;
16
17    if (packet->status == CDataPacket::NO_ERROR)
18      packet->data.reference(op(value, data[0]->data));
19
20    return packet;
21  }
22
23  CFieldScalarArithmeticFilter::CFieldScalarArithmeticFilter(CGarbageCollector& gc, const std::string& op, double value)
24    : CFilter(gc, 1, this)
25    , op(operatorExpr.getOpFieldScalar(op))
26    , value(value)
27  { /* Nothing to do */ };
28
29  CDataPacketPtr CFieldScalarArithmeticFilter::apply(std::vector<CDataPacketPtr> data)
30  {
31    CDataPacketPtr packet(new CDataPacket);
32    packet->timestamp = data[0]->timestamp;
33    packet->status = data[0]->status;
34
35    if (packet->status == CDataPacket::NO_ERROR)
36      packet->data.reference(op(data[0]->data, value));
37
38    return packet;
39  }
40
41  CFieldFieldArithmeticFilter::CFieldFieldArithmeticFilter(CGarbageCollector& gc, const std::string& op)
42    : CFilter(gc, 1, this)
43    , op(operatorExpr.getOpFieldField(op))
44  { /* Nothing to do */ };
45
46  CDataPacketPtr CFieldFieldArithmeticFilter::apply(std::vector<CDataPacketPtr> data)
47  {
48    CDataPacketPtr packet(new CDataPacket);
49    packet->timestamp = data[0]->timestamp;
50
51    if (data[0]->status != CDataPacket::NO_ERROR)
52      packet->status = data[0]->status;
53    else if (data[1]->status != CDataPacket::NO_ERROR)
54      packet->status = data[1]->status;
55    else
56    {
57      packet->status = CDataPacket::NO_ERROR;
58      packet->data.reference(op(data[0]->data, data[1]->data));
59    }
60
61    return packet;
62  }
63} // namespace xios
Note: See TracBrowser for help on using the repository browser.