OpenDDS  Snapshot(2023/04/28-20:55)
TopicDescriptionImpl.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_TOPIC_DESCRIPTION_IMPL_H
9 #define OPENDDS_DCPS_TOPIC_DESCRIPTION_IMPL_H
10 
11 #include "Atomic.h"
12 #include "Definitions.h"
13 #include "LocalObject.h"
14 
15 #include <dds/DdsDcpsTopicC.h>
16 #include <dds/DdsDcpsTypeSupportExtC.h>
17 
18 #include <ace/SString.h>
19 
20 #if !defined (ACE_LACKS_PRAGMA_ONCE)
21 #pragma once
22 #endif /* ACE_LACKS_PRAGMA_ONCE */
23 
25 
26 namespace OpenDDS {
27 namespace DCPS {
28 
29 class DomainParticipantImpl;
30 
31 /**
32 * @class TopicDescriptionImpl
33 *
34 * @brief Implements the DDS::TopicDescription interface.
35 *
36 * See the DDS specification, OMG formal/2015-04-10, for a description of
37 * the interface this class is implementing.
38 *
39 */
41  : public virtual OpenDDS::DCPS::LocalObject<DDS::TopicDescription> {
42 public:
43  TopicDescriptionImpl(const char* topic_name,
44  const char* type_name,
45  TypeSupport_ptr type_support,
46  DomainParticipantImpl* participant);
47 
48  virtual ~TopicDescriptionImpl();
49 
50  virtual char * get_type_name();
51 
52  virtual char * get_name();
53 
54  virtual DDS::DomainParticipant_ptr get_participant();
55 
56  /** This method is not defined in the IDL and is defined for
57  * internal use.
58  * Return the type support of the topic.
59  */
60  OpenDDS::DCPS::TypeSupport_ptr get_type_support();
61 
62  bool has_entity_refs() const {
63  return entity_refs_ > 0;
64  }
65 
66  void add_entity_ref() {
68  ++entity_refs_;
69  }
70 
72  --entity_refs_;
74  }
75 
76 protected:
77  /// The name of the topic.
79  /// The datatype of the topic.
81 
82  /// The participant that creates this topic.
84 
85  /// The type_support for this topic.
86  OpenDDS::DCPS::TypeSupport_var type_support_;
87 
88  /// The number of entities using this topic
90 };
91 
92 template <typename Topic>
94 {
95 public:
97  : topic_(topic)
98  {
99  if (topic_) {
100  topic_->add_entity_ref();
101  }
102  }
103 
105  {
106  if (topic_) {
107  topic_->remove_entity_ref();
108  }
109  }
110 
112  : topic_(other.topic_)
113  {
114  if (topic_) {
115  topic_->add_entity_ref();
116  }
117  }
118 
120  {
121  TopicDescriptionPtr tmp(other);
122  std::swap(this->topic_, tmp.topic_);
123  return *this;
124  }
125 
127  {
128  TopicDescriptionPtr tmp(other);
129  std::swap(this->topic_, tmp.topic_);
130  return *this;
131  }
132 
133  Topic* operator->() const
134  {
135  return topic_;
136  }
137 
138  Topic* get() const
139  {
140  return topic_;
141  }
142 
143  operator bool() const
144  {
145  return topic_;
146  }
147 
148 private:
150 };
151 
152 } // namespace DCPS
153 } // namespace OpenDDS
154 
156 
157 #endif /* OPENDDS_DCPS_TOPIC_DESCRIPTION_IMPL_H */
void swap(MessageBlock &lhs, MessageBlock &rhs)
Implements the OpenDDS::DCPS::DomainParticipant interfaces.
Atomic< ACE_UINT32 > entity_refs_
The number of entities using this topic.
TopicDescriptionPtr(const TopicDescriptionPtr &other)
TopicDescriptionPtr & operator=(Topic *other)
#define OpenDDS_Dcps_Export
Definition: dcps_export.h:24
ACE_CString type_name_
The datatype of the topic.
ACE_CString topic_name_
The name of the topic.
virtual void _add_ref()
Definition: RcObject.h:69
OpenDDS::DCPS::TypeSupport_var type_support_
The type_support for this topic.
TopicDescriptionPtr & operator=(const TopicDescriptionPtr &other)
virtual void _remove_ref()
Definition: RcObject.h:74
DomainParticipantImpl * participant_
The participant that creates this topic.
Implements the DDS::TopicDescription interface.
#define OPENDDS_END_VERSIONED_NAMESPACE_DECL
The Internal API and Implementation of OpenDDS.
Definition: AddressCache.h:28