OpenSplice ISO C++ 2 DCPS  v6.x
ISO C++ 2 OpenSplice Data Distribution Service Data-Centric Publish-Subscribe API
ReferenceImpl.hpp
Go to the documentation of this file.
1 /*
2  * Vortex OpenSplice
3  *
4  * This software and documentation are Copyright 2006 to 2021 ADLINK
5  * Technology Limited, its affiliated companies and licensors. All rights
6  * reserved.
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  *
20  */
21 #ifndef OSPL_DDS_CORE_REFERENCE_IMPL_HPP_
22 #define OSPL_DDS_CORE_REFERENCE_IMPL_HPP_
23 
28 /*
29  * OMG PSM class declaration
30  */
31 #include <dds/core/Reference.hpp>
32 #include <org/opensplice/core/ReportUtils.hpp>
33 
34 // Implementation
35 template <typename DELEGATE>
37 {
38 }
39 
40 template <typename DELEGATE>
42 {
43 }
44 
45 template <typename DELEGATE>
46 template <typename D>
48 {
49  ISOCPP_REPORT_STACK_DDS_BEGIN(*this);
50  impl_ = OSPL_CXX11_STD_MODULE::dynamic_pointer_cast<DELEGATE_T>(ref.impl_);
51  if (impl_ != ref.impl_) {
52  throw dds::core::IllegalOperationError(std::string("Attempted invalid cast: ") + typeid(ref).name() + " to " + typeid(*this).name());
53  }
54 }
55 
56 template <typename DELEGATE>
58 {
59 }
60 
61 template <typename DELEGATE>
62 dds::core::Reference<DELEGATE>::Reference(const DELEGATE_REF_T& p) : impl_(p)
63 {
64  //OMG_DDS_LOG("MM", "Reference(DELEGATE_REF_T& p)");
65 }
66 
67 template <typename DELEGATE>
69 {
70 }
71 
72 template <typename DELEGATE>
73 dds::core::Reference<DELEGATE>::operator DELEGATE_REF_T() const
74 {
75  ISOCPP_REPORT_STACK_NC_BEGIN();
76  ISOCPP_BOOL_CHECK_AND_THROW(impl_, ISOCPP_NULL_REFERENCE_ERROR, "Reference[%d] == dds::core::null", __LINE__);
77  return impl_;
78 }
79 
80 template <typename DELEGATE>
81 template <typename R>
82 bool
84 {
85  ISOCPP_REPORT_STACK_DDS_BEGIN(*this);
86  bool equal = false;
87  if (this->is_nil() && ref.is_nil()) {
88  /* Both delegates are null. */
89  equal = true;
90  } else if (!this->is_nil() && !ref.is_nil()) {
91  /* Check delegates. */
92  equal = (this->delegate() == ref.delegate());
93  }
94  return equal;
95 }
96 
97 template <typename DELEGATE>
98 template <typename R>
99 bool
101 {
102  ISOCPP_REPORT_STACK_DDS_BEGIN(*this);
103  return !(*this == ref);
104 }
105 
106 template <typename DELEGATE>
107 template <typename D>
110 {
112  if(this != (Reference*)&that)
113  {
114  *this = Reference<DELEGATE_T>(that);
115  }
116  return *this;
117 }
118 
119 template <typename DELEGATE>
120 template <typename R>
123 {
125  if(this != (Reference*)&rhs)
126  {
127  *this = Reference<DELEGATE_T>(rhs);
128  }
129  return *this;
130 }
131 
132 template <typename DELEGATE>
135 {
136  DELEGATE_REF_T tmp;
137  impl_ = tmp;
138  return *this;
139 }
140 
141 template <typename DELEGATE>
142 bool
144 {
145  return impl_.get() == 0;
146 }
147 
148 template <typename DELEGATE>
149 bool
151 {
152  return this->is_nil();
153 }
154 
155 template <typename DELEGATE>
156 bool
158 {
159  return !(this->is_nil());
160 }
161 
162 template <typename DELEGATE>
165 {
166  ISOCPP_BOOL_CHECK_AND_THROW(impl_, ISOCPP_NULL_REFERENCE_ERROR, "Reference[%d] == dds::core::null", __LINE__);
167  return impl_;
168 }
169 
170 template <typename DELEGATE>
173 {
174  ISOCPP_BOOL_CHECK_AND_THROW(impl_, ISOCPP_NULL_REFERENCE_ERROR, "Reference[%d] == dds::core::null", __LINE__);
175  return impl_;
176 }
177 
178 template <typename DELEGATE>
179 DELEGATE*
181 {
182  ISOCPP_BOOL_CHECK_AND_THROW(impl_, ISOCPP_NULL_REFERENCE_ERROR, "Reference[%d] == dds::core::null", __LINE__);
183  return impl_.get();
184 }
185 
186 template <typename DELEGATE>
187 const DELEGATE*
189 {
190  ISOCPP_BOOL_CHECK_AND_THROW(impl_, ISOCPP_NULL_REFERENCE_ERROR, "Reference[%d] == dds::core::null", __LINE__);
191  return impl_.get();
192 }
193 
194 template <typename DELEGATE>
196 const typename dds::core::Reference<DELEGATE>::DELEGATE_REF_T& () const
197 {
198  ISOCPP_BOOL_CHECK_AND_THROW(impl_, ISOCPP_NULL_REFERENCE_ERROR, "Reference[%d] == dds::core::null", __LINE__);
199  return impl_;
200 }
201 
202 template <typename DELEGATE>
205 {
206  ISOCPP_BOOL_CHECK_AND_THROW(impl_, ISOCPP_NULL_REFERENCE_ERROR, "Reference[%d] == dds::core::null", __LINE__);
207  return impl_;
208 }
209 
210 template <typename DELEGATE>
211 void dds::core::Reference<DELEGATE>::set_ref(DELEGATE_T* p)
212 {
213  impl_.reset(p);
214 }
215 
216 
218 {
219  return r.is_nil();
220 }
221 
223 {
224  return !r.is_nil();
225 }
226 
227 // End of implementation
228 
229 #endif /* OSPL_DDS_CORE_REFERENCE_IMPL_HPP_ */
Exception: An operation was invoked on an inappropriate object or at an inappropriate time...
Definition: Exception.hpp:149
void value(DDT &dd, uint32_t mid, const T &v)
Reference & operator=(const Reference< D > &that)
This class is used to create dds::core::null objects.
Definition: types.hpp:49
#define OMG_DDS_STATIC_ASSERT
Definition: macros.hpp:25
bool operator!=(const R &ref) const
Base class for reference-counted objects.
Definition: Reference.hpp:94
bool operator==(const R &ref) const