LCOV - code coverage report
Current view: top level - DCPS - FilterEvaluator.h (source / functions) Hit Total Coverage
Test: coverage.info Lines: 0 16 0.0 %
Date: 2023-04-30 01:32:43 Functions: 0 60 0.0 %

          Line data    Source code
       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             : 
      24             : OPENDDS_BEGIN_VERSIONED_NAMESPACE_DECL
      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>
      36             : struct MarshalTraits;
      37             : 
      38             : struct OpenDDS_Dcps_Export Value {
      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             : 
      76             :   Type type_;
      77             :   union {
      78             :     bool b_;
      79             :     int i_;
      80             :     unsigned int u_;
      81             :     ACE_INT64 l_;
      82             :     ACE_UINT64 m_;
      83             :     char c_;
      84             :     double f_;
      85             :     ACE_CDR::LongDouble ld_;
      86             :     const char* s_;
      87             :   };
      88             :   bool conversion_preferred_;
      89             : };
      90             : 
      91             : class OpenDDS_Dcps_Export FilterEvaluator : public virtual RcObject {
      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           0 :   bool usesExtendedGrammar() const { return extended_grammar_; }
     107             : 
     108           0 :   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           0 :   bool eval(const T& sample, const DDS::StringSeq& params) const
     117             :   {
     118           0 :     DeserializedForEval data(&sample, getMetaStruct<T>(), params);
     119           0 :     return eval_i(data);
     120           0 :   }
     121             : 
     122             :   /**
     123             :    * Returns true if the serialized sample matches the filter.
     124             :    */
     125           0 :   bool eval(ACE_Message_Block* serializedSample, Encoding encoding,
     126             :             const TypeSupportImpl& typeSupport,
     127             :             const DDS::StringSeq& params) const
     128             :   {
     129           0 :     SerializedForEval data(serializedSample, typeSupport, params, encoding);
     130           0 :     return eval_i(data);
     131           0 :   }
     132             : 
     133             :   class EvalNode;
     134             :   class Operand;
     135             : 
     136             :   struct OpenDDS_Dcps_Export DataForEval {
     137           0 :     DataForEval(const MetaStruct& meta, const DDS::StringSeq& params)
     138           0 :       : meta_(meta), params_(params) {}
     139             :     virtual ~DataForEval();
     140             :     virtual Value lookup(const char* field) const = 0;
     141             :     const MetaStruct& meta_;
     142             :     const DDS::StringSeq& params_;
     143             :   private:
     144             :     DataForEval(const DataForEval&);
     145             :     DataForEval& operator=(const DataForEval&);
     146             :   };
     147             : 
     148             : private:
     149             :   FilterEvaluator(const FilterEvaluator&);
     150             :   FilterEvaluator& operator=(const FilterEvaluator&);
     151             : 
     152             :   EvalNode* walkAst(const AstNodeWrapper& node);
     153             :   Operand* walkOperand(const AstNodeWrapper& node);
     154             : 
     155             :   struct OpenDDS_Dcps_Export DeserializedForEval : DataForEval {
     156           0 :     DeserializedForEval(const void* data, const MetaStruct& meta,
     157             :                         const DDS::StringSeq& params)
     158           0 :       : DataForEval(meta, params), deserialized_(data) {}
     159             :     virtual ~DeserializedForEval();
     160             :     Value lookup(const char* field) const;
     161             :     const void* const deserialized_;
     162             :   };
     163             : 
     164             :   struct SerializedForEval : DataForEval {
     165             :     SerializedForEval(ACE_Message_Block* data, const TypeSupportImpl& type_support,
     166             :                       const DDS::StringSeq& params, Encoding encoding);
     167             :     Value lookup(const char* field) const;
     168             :     ACE_Message_Block* serialized_;
     169             :     Encoding encoding_;
     170             :     const TypeSupportImpl& type_support_;
     171             :     mutable OPENDDS_MAP(OPENDDS_STRING, Value) cache_;
     172             :     Extensibility exten_;
     173             :   };
     174             : 
     175             :   bool eval_i(DataForEval& data) const;
     176             : 
     177             :   bool extended_grammar_;
     178             :   EvalNode* filter_root_;
     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
     182             :   size_t number_parameters_;
     183             : 
     184             : };
     185             : 
     186             : class OpenDDS_Dcps_Export MetaStruct {
     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           0 :   ComparatorBase::Ptr create_qc_comparator(const char* fieldSpec) const
     197           0 :   { 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>
     222             : struct MetaStructImpl;
     223             : 
     224             : }  }
     225             : 
     226             : OPENDDS_END_VERSIONED_NAMESPACE_DECL
     227             : 
     228             : #endif // OPENDDS_NO_CONTENT_SUBSCRIPTION_PROFILE
     229             : #endif

Generated by: LCOV version 1.16