ICalculator.hpp
1 #ifndef DM_ICALCULATOR_HPP_INCLUDED
2 #define DM_ICALCULATOR_HPP_INCLUDED
3 
4 #ifdef _MSC_VER
5  #pragma once
6 #endif
7 
8 #include "DM/IGeometry.hpp"
9 
10 DM_NAMESPACE_BEGIN
11 
12 /// \brief Generic calculator for evaluating formulas or manipulating objects based on the OPALS \ref ref_filter_generic "generic filter syntax"
13 class DM_API ICalculator : public ObjectBase
14 {
15 public:
16 
17  /// Choose the supported language features:
18  /// the fewer features that are supported, the more concise the error messages will be.
19  struct Dialect
20  {
21  enum Type
22  {
23  vector = 1, ///< support parsing nodes related to vector data: coordinates, addInfos
24  raster = vector << 1, ///< support parsing nodes related to raster data: r[idx]
25  ternaryConditional = raster << 1, ///< support the ternary operator ? :
26  assignment = ternaryConditional << 1, ///< support the assignment operator =
27  neighbors = assignment << 1, ///< support neighbors
28  full = (neighbors<<1)-1 ///< full language support
29  };
30  };
31 
32  /// The result type of the calculator.
33  /// If custom attributes are to be queried, the result type is unknown beforehand.
35  {
36  enum Type
37  {
38  arithmetic,
39  string,
40  unknown
41  };
42  };
43 
44 
45  static ICalculator* New();
46  static ICalculator* New(const char *stringRepresentation, Dialect::Type = Dialect::vector );
47 
48  virtual ~ICalculator() {}
49 
50  virtual ICalculator* clone() const = 0;
51 
52  // consider the passed values as invalid for the respective raster indices (raster bands, NO_DATA values).
53  virtual void rasterNoData( const double *raster, unsigned sRaster ) const = 0;
54 
55  // const arguments
56  virtual double resultDouble( const IGeometry &geom ) const = 0;
57  virtual double resultDouble( const double *raster, unsigned sRaster ) const = 0;
58  virtual double resultDouble( const IGeometry &geom, const double *raster, unsigned sRaster ) const = 0;
59  virtual double resultDouble( const IGeometry &geom, const double *raster, unsigned sRaster,
60  const IGeometry **neighbors, unsigned sNeighbors ) const = 0;
61 
62  // mutable arguments
63  virtual double resultDouble( IGeometry &geom ) const = 0;
64  virtual double resultDouble( double *raster, unsigned sRaster ) const = 0;
65  virtual double resultDouble( IGeometry &geom, double *raster, unsigned sRaster ) const = 0;
66  virtual double resultDouble( IGeometry &geom, double *raster, unsigned sRaster,
67  IGeometry **neighbors, unsigned sNeighbors ) const = 0;
68 
69  // return true if anywhere in the filter, a raster is used; false otherwise
70  virtual bool queriesRasters() const = 0;
71  /// return true if anywhere in the filter, a neighbor is used; false otherwise
72  virtual bool queriesNeighbors() const = 0;
73  /// return true if one or more of the top-level nodes are assignments; false otherwise
74  virtual bool containsAssignment() const = 0;
75 
76  virtual DataTypeSuperset::Type typeSuperset() const = 0;
77 
78  virtual void print(std::ostream&) const = 0;
79 };
80 
81 typedef Handle< ICalculator > CalculatorHandle;
82 
83 DM_API ICalculator::Dialect::Type operator| ( const ICalculator::Dialect::Type &left, const ICalculator::Dialect::Type &right );
84 
85 DM_NAMESPACE_END
86 
87 #endif //DM_ICALCULATOR_HPP_INCLUDED