OpenDDS  Snapshot(2023/04/28-20:55)
ContentFilteredTopicImpl.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_CONTENTFILTEREDTOPICIMPL_H
9 #define OPENDDS_DCPS_CONTENTFILTEREDTOPICIMPL_H
10 
11 #ifndef OPENDDS_NO_CONTENT_FILTERED_TOPIC
12 
13 #include "TopicDescriptionImpl.h"
14 #include "FilterEvaluator.h"
15 #include "PoolAllocator.h"
16 #include "TypeSupportImpl.h"
17 
18 #if !defined (ACE_LACKS_PRAGMA_ONCE)
19 #pragma once
20 #endif /* ACE_LACKS_PRAGMA_ONCE */
21 
23 
24 namespace OpenDDS {
25 namespace DCPS {
26 
27 class DataReaderImpl;
28 
30  : public virtual OpenDDS::DCPS::LocalObject<DDS::ContentFilteredTopic>
31  , public virtual TopicDescriptionImpl {
32 public:
33  ContentFilteredTopicImpl(const char* name, DDS::Topic_ptr related_topic,
34  const char* filter_expression, DomainParticipantImpl* participant);
35 
37 
38  char* get_filter_expression();
39 
40  DDS::ReturnCode_t get_expression_parameters(DDS::StringSeq& parameters);
41 
42  DDS::ReturnCode_t set_expression_parameters(const DDS::StringSeq& parameters);
43 
44  DDS::Topic_ptr get_related_topic();
45 
46  /**
47  * Returns true if the sample matches the filter.
48  */
49  template<typename Sample>
50  bool filter(const Sample& s, bool sample_only_has_key_fields) const
51  {
53  /*
54  * Omit the sample from results if the filter references non-key fields
55  * and the sample only has key fields.
56  */
57  TypeSupportImpl* const ts = dynamic_cast<TypeSupportImpl*>(type_support_.in());
58  if (!ts || (sample_only_has_key_fields && filter_eval_.has_non_key_fields(*ts))) {
59  return false;
60  }
61  return filter_eval_.eval(s, expression_parameters_);
62  }
63 
64  void add_reader(DataReaderImpl& reader);
65  void remove_reader(DataReaderImpl& reader);
66 
67  const char* get_filter_class_name () const
68  {
69  return filter_eval_.usesExtendedGrammar () ? "OPENDDSSQL" : "DDSSQL";
70  }
71 
72 private:
76  DDS::Topic_var related_topic_;
78  Readers readers_;
79 
80  /// Concurrent access to expression_parameters_ and readers_
82 };
83 
84 } // namespace DCPS
85 } // namespace OpenDDS
86 
88 
89 #endif // OPENDDS_NO_CONTENT_FILTERED_TOPIC
90 
91 #endif
Implements the OpenDDS::DCPS::DomainParticipant interfaces.
ACE_Recursive_Thread_Mutex lock_
Concurrent access to expression_parameters_ and readers_.
bool filter(const Sample &s, bool sample_only_has_key_fields) const
#define OpenDDS_Dcps_Export
Definition: dcps_export.h:24
ACE_Guard< ACE_Thread_Mutex > lock_
#define OPENDDS_STRING
#define ACE_GUARD_RETURN(MUTEX, OBJ, LOCK, RETURN)
Implements the DDS::DataReader interface.
const char *const name
Definition: debug.cpp:60
Implements the DDS::TopicDescription interface.
#define OPENDDS_END_VERSIONED_NAMESPACE_DECL
typedef OPENDDS_VECTOR(ActionConnectionRecord) ConnectionRecords
The Internal API and Implementation of OpenDDS.
Definition: AddressCache.h:28
sequence< string > StringSeq
Definition: DdsDcpsCore.idl:50