[642] | 1 | #include "filter_expr_node.hpp" |
---|
| 2 | #include "unary_arithmetic_filter.hpp" |
---|
| 3 | #include "binary_arithmetic_filter.hpp" |
---|
[1158] | 4 | #include "ternary_arithmetic_filter.hpp" |
---|
[642] | 5 | #include "field.hpp" |
---|
| 6 | |
---|
| 7 | namespace xios |
---|
| 8 | { |
---|
| 9 | CFilterFieldExprNode::CFilterFieldExprNode(const std::string& fieldId) |
---|
| 10 | : fieldId(fieldId) |
---|
| 11 | { /* Nothing to do */ } |
---|
| 12 | |
---|
[1577] | 13 | |
---|
[1542] | 14 | std::shared_ptr<COutputPin> CFilterFieldExprNode::reduce(CGarbageCollector& gc, CField& thisField) const |
---|
[642] | 15 | { |
---|
[1542] | 16 | std::shared_ptr<COutputPin> outputPin; |
---|
[642] | 17 | |
---|
[1577] | 18 | if (fieldId == "this") outputPin = thisField.getSelfReference(gc); |
---|
| 19 | else |
---|
[642] | 20 | { |
---|
[1577] | 21 | string id ; |
---|
[642] | 22 | |
---|
[1577] | 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."); |
---|
[642] | 47 | } |
---|
| 48 | return outputPin; |
---|
| 49 | } |
---|
| 50 | |
---|
[1577] | 51 | |
---|
[643] | 52 | CFilterTemporalFieldExprNode::CFilterTemporalFieldExprNode(const std::string& fieldId) |
---|
| 53 | : fieldId(fieldId) |
---|
| 54 | { /* Nothing to do */ } |
---|
| 55 | |
---|
[1577] | 56 | |
---|
[1542] | 57 | std::shared_ptr<COutputPin> CFilterTemporalFieldExprNode::reduce(CGarbageCollector& gc, CField& thisField) const |
---|
[643] | 58 | { |
---|
[1542] | 59 | std::shared_ptr<COutputPin> outputPin; |
---|
[1158] | 60 | |
---|
| 61 | if (fieldId == "this") |
---|
| 62 | outputPin = thisField.getSelfTemporalDataFilter(gc, thisField.freq_op.isEmpty() ? TimeStep : thisField.freq_op); |
---|
[1577] | 63 | else |
---|
[1158] | 64 | { |
---|
[1577] | 65 | string id ; |
---|
[1158] | 66 | |
---|
[1577] | 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."); |
---|
[1158] | 92 | } |
---|
| 93 | return outputPin; |
---|
[643] | 94 | } |
---|
| 95 | |
---|
[1577] | 96 | |
---|
[642] | 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 | |
---|
[1542] | 106 | std::shared_ptr<COutputPin> CFilterUnaryOpExprNode::reduce(CGarbageCollector& gc, CField& thisField) const |
---|
[642] | 107 | { |
---|
[1542] | 108 | std::shared_ptr<CUnaryArithmeticFilter> filter(new CUnaryArithmeticFilter(gc, opId)); |
---|
[642] | 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 | |
---|
[1542] | 123 | std::shared_ptr<COutputPin> CFilterScalarFieldOpExprNode::reduce(CGarbageCollector& gc, CField& thisField) const |
---|
[642] | 124 | { |
---|
[1542] | 125 | std::shared_ptr<CScalarFieldArithmeticFilter> filter(new CScalarFieldArithmeticFilter(gc, opId, child1->reduce())); |
---|
[642] | 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 | |
---|
[1542] | 140 | std::shared_ptr<COutputPin> CFilterFieldScalarOpExprNode::reduce(CGarbageCollector& gc, CField& thisField) const |
---|
[642] | 141 | { |
---|
[1542] | 142 | std::shared_ptr<CFieldScalarArithmeticFilter> filter(new CFieldScalarArithmeticFilter(gc, opId, child2->reduce())); |
---|
[642] | 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 | |
---|
[1542] | 157 | std::shared_ptr<COutputPin> CFilterFieldFieldOpExprNode::reduce(CGarbageCollector& gc, CField& thisField) const |
---|
[642] | 158 | { |
---|
[1542] | 159 | std::shared_ptr<CFieldFieldArithmeticFilter> filter(new CFieldFieldArithmeticFilter(gc, opId)); |
---|
[642] | 160 | child1->reduce(gc, thisField)->connectOutput(filter, 0); |
---|
| 161 | child2->reduce(gc, thisField)->connectOutput(filter, 1); |
---|
| 162 | return filter; |
---|
| 163 | } |
---|
[1158] | 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 | |
---|
[1542] | 179 | std::shared_ptr<COutputPin> CFilterScalarScalarFieldOpExprNode::reduce(CGarbageCollector& gc, CField& thisField) const |
---|
[1158] | 180 | { |
---|
[1542] | 181 | std::shared_ptr<CScalarScalarFieldArithmeticFilter> filter(new CScalarScalarFieldArithmeticFilter(gc, opId, child1->reduce(),child2->reduce())); |
---|
[1158] | 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 | |
---|
[1542] | 198 | std::shared_ptr<COutputPin> CFilterScalarFieldScalarOpExprNode::reduce(CGarbageCollector& gc, CField& thisField) const |
---|
[1158] | 199 | { |
---|
[1542] | 200 | std::shared_ptr<CScalarFieldScalarArithmeticFilter> filter(new CScalarFieldScalarArithmeticFilter(gc, opId, child1->reduce(),child3->reduce())); |
---|
[1158] | 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 | |
---|
[1542] | 217 | std::shared_ptr<COutputPin> CFilterScalarFieldFieldOpExprNode::reduce(CGarbageCollector& gc, CField& thisField) const |
---|
[1158] | 218 | { |
---|
[1542] | 219 | std::shared_ptr<CScalarFieldFieldArithmeticFilter> filter(new CScalarFieldFieldArithmeticFilter(gc, opId, child1->reduce())); |
---|
[1158] | 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 | |
---|
[1542] | 238 | std::shared_ptr<COutputPin> CFilterFieldScalarScalarOpExprNode::reduce(CGarbageCollector& gc, CField& thisField) const |
---|
[1158] | 239 | { |
---|
[1542] | 240 | std::shared_ptr<CFieldScalarScalarArithmeticFilter> filter(new CFieldScalarScalarArithmeticFilter(gc, opId, child2->reduce(),child3->reduce())); |
---|
[1158] | 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 | |
---|
[1542] | 258 | std::shared_ptr<COutputPin> CFilterFieldScalarFieldOpExprNode::reduce(CGarbageCollector& gc, CField& thisField) const |
---|
[1158] | 259 | { |
---|
[1542] | 260 | std::shared_ptr<CFieldScalarFieldArithmeticFilter> filter(new CFieldScalarFieldArithmeticFilter(gc, opId, child2->reduce())); |
---|
[1158] | 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 | |
---|
[1542] | 279 | std::shared_ptr<COutputPin> CFilterFieldFieldScalarOpExprNode::reduce(CGarbageCollector& gc, CField& thisField) const |
---|
[1158] | 280 | { |
---|
[1542] | 281 | std::shared_ptr<CFieldFieldScalarArithmeticFilter> filter(new CFieldFieldScalarArithmeticFilter(gc, opId, child3->reduce())); |
---|
[1158] | 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 | |
---|
[1542] | 299 | std::shared_ptr<COutputPin> CFilterFieldFieldFieldOpExprNode::reduce(CGarbageCollector& gc, CField& thisField) const |
---|
[1158] | 300 | { |
---|
[1542] | 301 | std::shared_ptr<CFieldFieldFieldArithmeticFilter> filter(new CFieldFieldFieldArithmeticFilter(gc, opId)); |
---|
[1158] | 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 | |
---|
[642] | 308 | } |
---|