OpenDDS  Snapshot(2023/04/28-20:55)
QueryConditionImpl.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_QUERYCONDITIONIMPL_H
9 #define OPENDDS_DCPS_QUERYCONDITIONIMPL_H
10 
11 #ifndef OPENDDS_NO_QUERY_CONDITION
12 
13 #include "dds/DdsDcpsSubscriptionC.h"
14 #include "ReadConditionImpl.h"
15 #include "FilterEvaluator.h"
16 #include "PoolAllocator.h"
17 
18 #if !defined (ACE_LACKS_PRAGMA_ONCE)
19 #pragma once
20 #endif /* ACE_LACKS_PRAGMA_ONCE */
21 
22 #include <vector>
23 
25 
26 namespace OpenDDS {
27 namespace DCPS {
28 
29 class DataReaderImpl;
30 class TypeSupportImpl;
31 
33  : public virtual OpenDDS::DCPS::LocalObject<DDS::QueryCondition>
34  , public virtual ReadConditionImpl {
35 public:
38  const char* query_expression);
39 
40  virtual ~QueryConditionImpl() {}
41 
42  char* get_query_expression();
43 
44  DDS::ReturnCode_t get_query_parameters(DDS::StringSeq& query_parameters);
45 
46  DDS::ReturnCode_t set_query_parameters(
47  const DDS::StringSeq& query_parameters);
48 
49  CORBA::Boolean get_trigger_value();
50 
51  std::vector<OPENDDS_STRING> getOrderBys() const;
52 
53  bool hasFilter() const;
54 
55  /**
56  * Returns true if the sample matches the query.
57  */
58  template<typename Sample>
59  bool filter(const Sample& s, bool sample_only_has_key_fields) const
60  {
62  /*
63  * Omit the sample from results if the query references non-key fields
64  * and the sample only has key fields.
65  */
66  TypeSupportImpl* const ts = get_type_support();
67  if (!ts || (sample_only_has_key_fields && evaluator_.has_non_key_fields(*ts))) {
68  if (DCPS_debug_level > 8) {
70  ACE_TEXT("(%P|%t) QueryConditionImpl::filter: ")
71  ACE_TEXT("Sample has been filtered because the query ")
72  ACE_TEXT("references fields that are not readable\n")
73  ));
74  }
75  return false;
76  }
77  return evaluator_.eval(s, query_parameters_);
78  }
79 
80 private:
81  TypeSupportImpl* get_type_support() const;
82 
86  /// Concurrent access to query_parameters_
88 };
89 
90 } // namespace DCPS
91 } // namespace OpenDDS
92 
94 
95 #endif // OPENDDS_NO_QUERY_CONDITION
96 
97 #endif
local interface<%TYPE%> inout ::DDS::SampleInfoSeq in long in ::DDS::SampleStateMask sample_states
Definition: IDLTemplate.txt:72
#define ACE_DEBUG(X)
local interface<%TYPE%> inout ::DDS::SampleInfoSeq in long in ::DDS::SampleStateMask in ::DDS::ViewStateMask in ::DDS::InstanceStateMask instance_states
Definition: IDLTemplate.txt:72
#define OpenDDS_Dcps_Export
Definition: dcps_export.h:24
ACE_Recursive_Thread_Mutex lock_
Concurrent access to query_parameters_.
unsigned long InstanceStateMask
ACE_Guard< ACE_Thread_Mutex > lock_
local interface<%TYPE%> inout ::DDS::SampleInfoSeq in long in ::DDS::SampleStateMask in ::DDS::ViewStateMask view_states
Definition: IDLTemplate.txt:72
LM_DEBUG
ACE_CDR::Boolean Boolean
#define ACE_GUARD_RETURN(MUTEX, OBJ, LOCK, RETURN)
Implements the DDS::DataReader interface.
bool filter(const Sample &s, bool sample_only_has_key_fields) const
unsigned long SampleStateMask
ACE_TEXT("TCP_Factory")
OpenDDS_Dcps_Export unsigned int DCPS_debug_level
Definition: debug.cpp:30
#define OPENDDS_END_VERSIONED_NAMESPACE_DECL
The Internal API and Implementation of OpenDDS.
Definition: AddressCache.h:28
unsigned long ViewStateMask
sequence< string > StringSeq
Definition: DdsDcpsCore.idl:50