OpenDDS  Snapshot(2023/04/28-20:55)
FilterEvaluator.h
Go to the documentation of this file.
1 /*
2  *
3  *
4  * Distributed under the OpenDDS License.
5  * See: http://www.opendds.org/license.html
6  */
7 
8 #ifndef OPENDDS_DCPS_FILTER_EVALUATOR_H
9 #define OPENDDS_DCPS_FILTER_EVALUATOR_H
10 
11 #include "Definitions.h"
12 
13 #ifndef OPENDDS_NO_CONTENT_SUBSCRIPTION_PROFILE
14 
15 #include "dds/DdsDcpsInfrastructureC.h"
16 #include "PoolAllocator.h"
17 #include "Comparator_T.h"
18 #include "RcObject.h"
19 
20 #include <dds/DdsDynamicDataC.h>
21 
22 #include <string>
23 
25 
26 namespace OpenDDS {
27 namespace DCPS {
28 
29 class MetaStruct;
30 class TypeSupportImpl;
31 
32 template<typename T>
33 const MetaStruct& getMetaStruct();
34 
35 template<typename T>
37 
39  Value(bool b, bool conversion_preferred = false);
40  Value(int i, bool conversion_preferred = false);
41  Value(unsigned int u, bool conversion_preferred = false);
42  Value(ACE_INT64 l, bool conversion_preferred = false);
43  Value(ACE_UINT64 m, bool conversion_preferred = false);
44  Value(char c, bool conversion_preferred = false);
45  Value(double f, bool conversion_preferred = false);
46  Value(ACE_CDR::LongDouble ld, bool conversion_preferred = false);
47 #ifdef NONNATIVE_LONGDOUBLE
48  Value(long double ld, bool conversion_preferred = false);
49 #endif
50  Value(const char* s, bool conversion_preferred = false);
51  Value(const std::string& s, bool conversion_preferred = false);
52 #ifdef DDS_HAS_WCHAR
53  Value(const std::wstring& s, bool conversion_preferred = false);
54 #endif
55  Value(const TAO::String_Manager& s, bool conversion_preferred = false);
56  Value(const TAO::WString_Manager& s, bool conversion_preferred = false);
57 
58  ~Value();
59  Value(const Value& v);
60  Value& operator=(const Value& v);
61  void swap(Value& other);
62 
63  bool operator==(const Value& v) const;
64  bool operator<(const Value& v) const;
65  bool like(const Value& v) const;
66  Value operator%(const Value& v) const;
67 
68  enum Type {VAL_BOOL, VAL_INT, VAL_UINT, VAL_I64, VAL_UI64, VAL_FLOAT,
69  VAL_LNGDUB, VAL_LARGEST_NUMERIC = VAL_LNGDUB,
70  VAL_CHAR, VAL_STRING};
71  bool convert(Type t);
72  static void conversion(Value& lhs, Value& rhs);
73  template<typename T> T& get();
74  template<typename T> const T& get() const;
75 
77  union {
78  bool b_;
79  int i_;
80  unsigned int u_;
83  char c_;
84  double f_;
86  const char* s_;
87  };
89 };
90 
92 public:
93 
94  struct AstNodeWrapper;
95 
96  FilterEvaluator(const char* filter, bool allowOrderBy);
97 
98  explicit FilterEvaluator(const AstNodeWrapper& yardNode);
99 
100  ~FilterEvaluator();
101 
102  OPENDDS_VECTOR(OPENDDS_STRING) getOrderBys() const;
103 
104  bool hasFilter() const;
105 
106  bool usesExtendedGrammar() const { return extended_grammar_; }
107 
108  size_t number_parameters() const { return number_parameters_; }
109 
110  bool has_non_key_fields(const TypeSupportImpl& ts) const;
111 
112  /**
113  * Returns true if the unserialized sample matches the filter.
114  */
115  template<typename T>
116  bool eval(const T& sample, const DDS::StringSeq& params) const
117  {
118  DeserializedForEval data(&sample, getMetaStruct<T>(), params);
119  return eval_i(data);
120  }
121 
122  /**
123  * Returns true if the serialized sample matches the filter.
124  */
125  bool eval(ACE_Message_Block* serializedSample, Encoding encoding,
126  const TypeSupportImpl& typeSupport,
127  const DDS::StringSeq& params) const
128  {
129  SerializedForEval data(serializedSample, typeSupport, params, encoding);
130  return eval_i(data);
131  }
132 
133  class EvalNode;
134  class Operand;
135 
137  DataForEval(const MetaStruct& meta, const DDS::StringSeq& params)
138  : meta_(meta), params_(params) {}
139  virtual ~DataForEval();
140  virtual Value lookup(const char* field) const = 0;
143  private:
144  DataForEval(const DataForEval&);
145  DataForEval& operator=(const DataForEval&);
146  };
147 
148 private:
150  FilterEvaluator& operator=(const FilterEvaluator&);
151 
152  EvalNode* walkAst(const AstNodeWrapper& node);
153  Operand* walkOperand(const AstNodeWrapper& node);
154 
156  DeserializedForEval(const void* data, const MetaStruct& meta,
157  const DDS::StringSeq& params)
158  : DataForEval(meta, params), deserialized_(data) {}
159  virtual ~DeserializedForEval();
160  Value lookup(const char* field) const;
161  const void* const deserialized_;
162  };
163 
165  SerializedForEval(ACE_Message_Block* data, const TypeSupportImpl& type_support,
166  const DDS::StringSeq& params, Encoding encoding);
167  Value lookup(const char* field) const;
171  mutable OPENDDS_MAP(OPENDDS_STRING, Value) cache_;
173  };
174 
175  bool eval_i(DataForEval& data) const;
176 
179  OPENDDS_VECTOR(OPENDDS_STRING) order_bys_;
180  /// Number of parameters used in the filter, this should
181  /// match the number of values passed when evaluating the filter
183 
184 };
185 
187 public:
188  virtual ~MetaStruct();
189 
190  virtual Value getValue(const void* stru, const char* fieldSpec) const = 0;
191  virtual Value getValue(Serializer& ser, const char* fieldSpec, const TypeSupportImpl* ts = 0) const = 0;
192 
193  virtual ComparatorBase::Ptr create_qc_comparator(const char* fieldSpec,
194  ComparatorBase::Ptr next) const = 0;
195 
196  ComparatorBase::Ptr create_qc_comparator(const char* fieldSpec) const
197  { return create_qc_comparator(fieldSpec, ComparatorBase::Ptr()); }
198 
199 #ifndef OPENDDS_NO_MULTI_TOPIC
200  virtual size_t numDcpsKeys() const = 0;
201 
202  virtual bool compare(const void* lhs, const void* rhs,
203  const char* fieldSpec) const = 0;
204 
205  virtual const char** getFieldNames() const = 0;
206 
207  virtual void assign(void* lhs, const char* lhsFieldSpec,
208  const void* rhs, const char* rhsFieldSpec,
209  const MetaStruct& rhsMeta) const = 0;
210 
211  virtual const void* getRawField(const void* stru,
212  const char* fieldSpec) const = 0;
213 
214  virtual void* allocate() const = 0;
215  virtual void deallocate(void* stru) const = 0;
216 #endif /* OPENDDS_NO_MULTI_TOPIC */
217 };
218 
219 /// Each user-defined struct type will have an instantiation of this template
220 /// generated by opendds_idl.
221 template<typename T>
223 
224 } }
225 
227 
228 #endif // OPENDDS_NO_CONTENT_SUBSCRIPTION_PROFILE
229 #endif
keeps the details of yard out of the FilterEvaluator header file
void swap(MessageBlock &lhs, MessageBlock &rhs)
ComparatorBase::Ptr create_qc_comparator(const char *fieldSpec) const
#define OpenDDS_Dcps_Export
Definition: dcps_export.h:24
bool operator==(const DisjointSequence::OrderedRanges< T > &a, const DisjointSequence::OrderedRanges< T > &b)
ACE_CDR::LongDouble ld_
#define OPENDDS_STRING
Class to serialize and deserialize data for DDS.
Definition: Serializer.h:369
String_Manager_T< CORBA::Char > String_Manager
bool eval(ACE_Message_Block *serializedSample, Encoding encoding, const TypeSupportImpl &typeSupport, const DDS::StringSeq &params) const
unsigned long long ACE_UINT64
const MetaStruct & getMetaStruct()
bool eval(const T &sample, const DDS::StringSeq &params) const
#define OPENDDS_END_VERSIONED_NAMESPACE_DECL
String_Manager_T< CORBA::WChar > WString_Manager
long long ACE_INT64
void assign(EntityId_t &dest, const EntityId_t &src)
Definition: GuidUtils.h:157
typedef OPENDDS_VECTOR(ActionConnectionRecord) ConnectionRecords
DataForEval(const MetaStruct &meta, const DDS::StringSeq &params)
const DCPS::Encoding encoding(DCPS::Encoding::KIND_UNALIGNED_CDR, DCPS::ENDIAN_BIG)
The Internal API and Implementation of OpenDDS.
Definition: AddressCache.h:28
typedef OPENDDS_MAP(OPENDDS_STRING, OPENDDS_STRING) ValueMap
Helper types and functions for config file parsing.
DeserializedForEval(const void *data, const MetaStruct &meta, const DDS::StringSeq &params)
bool operator<(const GUID_t &lhs, const GUID_t &rhs)
Definition: GuidUtils.h:80
sequence< string > StringSeq
Definition: DdsDcpsCore.idl:50