[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 | |
---|
[1575] | 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 | |
---|
[1575] | 18 | if (fieldId == "this") outputPin = thisField.getSelfReference(gc); |
---|
| 19 | else |
---|
[642] | 20 | { |
---|
[1575] | 21 | string id ; |
---|
[642] | 22 | |
---|
[1575] | 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 | |
---|
[1869] | 42 | bool ret=field->buildWorkflowGraph(gc); |
---|
| 43 | if (ret) outputPin = field->getInstantDataFilter(); // if dependency is complete build the graph other return nullptr |
---|
[1575] | 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 | |
---|
[1575] | 51 | |
---|
[643] | 52 | CFilterTemporalFieldExprNode::CFilterTemporalFieldExprNode(const std::string& fieldId) |
---|
| 53 | : fieldId(fieldId) |
---|
| 54 | { /* Nothing to do */ } |
---|
| 55 | |
---|
[1575] | 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); |
---|
[1575] | 63 | else |
---|
[1158] | 64 | { |
---|
[1575] | 65 | string id ; |
---|
[1158] | 66 | |
---|
[1575] | 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 | |
---|
[1869] | 86 | bool ret=field->buildWorkflowGraph(gc); |
---|
| 87 | if (ret) outputPin = field->getTemporalDataFilter(gc, thisField.freq_op.isEmpty() ? TimeStep : thisField.freq_op); |
---|
[1575] | 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 | |
---|
[1575] | 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)); |
---|
[1869] | 109 | auto ret=child->reduce(gc, thisField) ; |
---|
| 110 | if (ret) ret->connectOutput(filter, 0); |
---|
| 111 | else filter.reset() ; |
---|
[642] | 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 | |
---|
[1542] | 125 | std::shared_ptr<COutputPin> CFilterScalarFieldOpExprNode::reduce(CGarbageCollector& gc, CField& thisField) const |
---|
[642] | 126 | { |
---|
[1542] | 127 | std::shared_ptr<CScalarFieldArithmeticFilter> filter(new CScalarFieldArithmeticFilter(gc, opId, child1->reduce())); |
---|
[1869] | 128 | |
---|
| 129 | auto ret=child2->reduce(gc, thisField) ; |
---|
| 130 | if (ret) ret->connectOutput(filter, 0); |
---|
| 131 | else filter.reset() ; |
---|
[642] | 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 | |
---|
[1542] | 145 | std::shared_ptr<COutputPin> CFilterFieldScalarOpExprNode::reduce(CGarbageCollector& gc, CField& thisField) const |
---|
[642] | 146 | { |
---|
[1542] | 147 | std::shared_ptr<CFieldScalarArithmeticFilter> filter(new CFieldScalarArithmeticFilter(gc, opId, child2->reduce())); |
---|
[1869] | 148 | auto ret=child1->reduce(gc, thisField) ; |
---|
| 149 | if (ret) ret->connectOutput(filter, 0); |
---|
| 150 | else filter.reset() ; |
---|
[642] | 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 | |
---|
[1542] | 164 | std::shared_ptr<COutputPin> CFilterFieldFieldOpExprNode::reduce(CGarbageCollector& gc, CField& thisField) const |
---|
[642] | 165 | { |
---|
[1542] | 166 | std::shared_ptr<CFieldFieldArithmeticFilter> filter(new CFieldFieldArithmeticFilter(gc, opId)); |
---|
[1869] | 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() ; |
---|
[642] | 175 | return filter; |
---|
| 176 | } |
---|
[1158] | 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 | |
---|
[1542] | 192 | std::shared_ptr<COutputPin> CFilterScalarScalarFieldOpExprNode::reduce(CGarbageCollector& gc, CField& thisField) const |
---|
[1158] | 193 | { |
---|
[1542] | 194 | std::shared_ptr<CScalarScalarFieldArithmeticFilter> filter(new CScalarScalarFieldArithmeticFilter(gc, opId, child1->reduce(),child2->reduce())); |
---|
[1869] | 195 | auto ret=child3->reduce(gc, thisField) ; |
---|
| 196 | if (ret) ret->connectOutput(filter, 0); |
---|
| 197 | else filter.reset() ; |
---|
[1158] | 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 | |
---|
[1542] | 213 | std::shared_ptr<COutputPin> CFilterScalarFieldScalarOpExprNode::reduce(CGarbageCollector& gc, CField& thisField) const |
---|
[1158] | 214 | { |
---|
[1542] | 215 | std::shared_ptr<CScalarFieldScalarArithmeticFilter> filter(new CScalarFieldScalarArithmeticFilter(gc, opId, child1->reduce(),child3->reduce())); |
---|
[1869] | 216 | auto ret=child2->reduce(gc, thisField); |
---|
| 217 | if (ret) ret->connectOutput(filter, 0); |
---|
| 218 | else filter.reset() ; |
---|
[1158] | 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 | |
---|
[1542] | 234 | std::shared_ptr<COutputPin> CFilterScalarFieldFieldOpExprNode::reduce(CGarbageCollector& gc, CField& thisField) const |
---|
[1158] | 235 | { |
---|
[1542] | 236 | std::shared_ptr<CScalarFieldFieldArithmeticFilter> filter(new CScalarFieldFieldArithmeticFilter(gc, opId, child1->reduce())); |
---|
[1869] | 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() ; |
---|
[1158] | 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 | |
---|
[1542] | 261 | std::shared_ptr<COutputPin> CFilterFieldScalarScalarOpExprNode::reduce(CGarbageCollector& gc, CField& thisField) const |
---|
[1158] | 262 | { |
---|
[1542] | 263 | std::shared_ptr<CFieldScalarScalarArithmeticFilter> filter(new CFieldScalarScalarArithmeticFilter(gc, opId, child2->reduce(),child3->reduce())); |
---|
[1869] | 264 | auto ret = child1->reduce(gc, thisField) ; |
---|
| 265 | if (ret) ret->connectOutput(filter, 0); |
---|
| 266 | else filter.reset() ; |
---|
[1158] | 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 | |
---|
[1542] | 283 | std::shared_ptr<COutputPin> CFilterFieldScalarFieldOpExprNode::reduce(CGarbageCollector& gc, CField& thisField) const |
---|
[1158] | 284 | { |
---|
[1542] | 285 | std::shared_ptr<CFieldScalarFieldArithmeticFilter> filter(new CFieldScalarFieldArithmeticFilter(gc, opId, child2->reduce())); |
---|
[1869] | 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() ; |
---|
[1158] | 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 | |
---|
[1542] | 310 | std::shared_ptr<COutputPin> CFilterFieldFieldScalarOpExprNode::reduce(CGarbageCollector& gc, CField& thisField) const |
---|
[1158] | 311 | { |
---|
[1542] | 312 | std::shared_ptr<CFieldFieldScalarArithmeticFilter> filter(new CFieldFieldScalarArithmeticFilter(gc, opId, child3->reduce())); |
---|
[1869] | 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() ; |
---|
[1158] | 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 | |
---|
[1542] | 336 | std::shared_ptr<COutputPin> CFilterFieldFieldFieldOpExprNode::reduce(CGarbageCollector& gc, CField& thisField) const |
---|
[1158] | 337 | { |
---|
[1542] | 338 | std::shared_ptr<CFieldFieldFieldArithmeticFilter> filter(new CFieldFieldFieldArithmeticFilter(gc, opId)); |
---|
[1869] | 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() ; |
---|
[1158] | 349 | return filter; |
---|
| 350 | } |
---|
| 351 | |
---|
[642] | 352 | } |
---|