• Main Page
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

src/hpp/dds/core/refmacros.hpp

Go to the documentation of this file.
00001 #ifndef OMG_DDS_CORE_REFMACROS_HPP_
00002 #define OMG_DDS_CORE_REFMACROS_HPP_
00003 
00004 /* Copyright 2010, Object Management Group, Inc.
00005  * Copyright 2010, PrismTech, Corp.
00006  * Copyright 2010, Real-Time Innovations, Inc.
00007  * All rights reserved.
00008  *
00009  * Licensed under the Apache License, Version 2.0 (the "License");
00010  * you may not use this file except in compliance with the License.
00011  * You may obtain a copy of the License at
00012  *
00013  *     http://www.apache.org/licenses/LICENSE-2.0
00014  *
00015  * Unless required by applicable law or agreed to in writing, software
00016  * distributed under the License is distributed on an "AS IS" BASIS,
00017  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00018  * See the License for the specific language governing permissions and
00019  * limitations under the License.
00020  */
00021 
00022 #include <dds/core/macros.hpp>
00023 #include <dds/core/ref_traits.hpp>
00024 
00026 // Macros
00028 
00029 #define DECLARE_TYPE_TRAITS(TYPE) \
00030    typedef TYPE  TYPE##_T;\
00031    typedef typename ::dds::core::smart_ptr_traits<TYPE>::ref_type       TYPE##_REF_T;\
00032    typedef typename ::dds::core::smart_ptr_traits<TYPE>::weak_ref_type  TYPE##_WEAK_REF_T;
00033 
00034 
00035 /*
00036  * This macro defines all the methods that Reference Types have to implement
00037  */
00038 /*
00039  *
00040  *
00041  */
00043 // Defines all the types, methods and attributes required for a Reference type
00044 // without default ctor.
00045 //
00046 
00047 #define OMG_DDS_REF_TYPE_BASE(TYPE, BASE, DELEGATE)     \
00048 public: \
00049 typedef BASE< DELEGATE >                                                  BASE_T;\
00050 public:\
00051 explicit TYPE(DELEGATE_T* p)\
00052 : BASE< DELEGATE_T >(p) \
00053 {  }\
00054 public:\
00055 explicit TYPE(const DELEGATE_REF_T& ref) \
00056     : BASE<DELEGATE_T>(ref)\
00057       { }\
00058 \
00059 template <typename H__> \
00060 TYPE(const H__& h)    \
00061 : BASE< DELEGATE_T >(h) \
00062 { \
00063     OMG_DDS_STATIC_ASSERT((dds::core::is_base_of<typename TYPE::DELEGATE_T, typename H__::DELEGATE_T>::value)); \
00064     this->dds::core::Reference<DELEGATE>::impl_ = h.delegate();\
00065 }
00066 
00067 
00068 #define OMG_DDS_REF_TYPE_BASE_T(TYPE, BASE, T_PARAM, DELEGATE) \
00069 public: \
00070 typedef BASE< T_PARAM, DELEGATE > BASE_T; \
00071 public: \
00072 explicit TYPE(DELEGATE_T* p) \
00073     : BASE< T_PARAM, DELEGATE >(p) \
00074       {  } \
00075 public: \
00076 explicit TYPE(const DELEGATE_REF_T& ref) \
00077     : BASE< T_PARAM, DELEGATE >(ref) \
00078       { } \
00079 \
00080 template <typename H__> \
00081 TYPE(const H__& h) \
00082 : BASE< T_PARAM, DELEGATE >(h) \
00083 { \
00084     OMG_DDS_STATIC_ASSERT((dds::core::is_base_of<typename TYPE::DELEGATE_T, typename H__::DELEGATE_T>::value)); \
00085     this->dds::core::Reference< DELEGATE< T_PARAM > >::impl_ = h.delegate(); \
00086 }
00087 
00088 
00089 #define OMG_DDS_REF_TYPE_DELEGATE(TYPE, BASE, DELEGATE)     \
00090 public: \
00091 typedef DELEGATE                                                          DELEGATE_T;   \
00092 typedef typename ::dds::core::smart_ptr_traits< DELEGATE >::ref_type      DELEGATE_REF_T; \
00093 typedef typename ::dds::core::smart_ptr_traits< DELEGATE >::weak_ref_type DELEGATE_WEAK_REF_T; \
00094 \
00095 private:\
00096     const typename ::dds::core::Reference< DELEGATE >::DELEGATE_REF_T& impl() const \
00097     { return ::dds::core::Reference< DELEGATE >::impl_; }\
00098     typename ::dds::core::Reference< DELEGATE >::DELEGATE_REF_T& impl() \
00099     { return ::dds::core::Reference< DELEGATE >::impl_; }\
00100 \
00101 public:\
00102 template <typename T__> \
00103 TYPE& \
00104 operator=(const T__& rhs) {\
00105     OMG_DDS_STATIC_ASSERT((dds::core::is_base_of<typename TYPE::DELEGATE_T, typename T__::DELEGATE_T>::value));\
00106     if (this != (TYPE*)&rhs) \
00107         *this = TYPE(rhs); \
00108     return *this; \
00109 }
00110 
00111 
00112 #define OMG_DDS_REF_TYPE_DELEGATE_T(TYPE, BASE, T_PARAM, DELEGATE)     \
00113 public: \
00114 typedef DELEGATE< T_PARAM >                                               DELEGATE_T;   \
00115 typedef typename ::dds::core::smart_ptr_traits< DELEGATE< T_PARAM > >::ref_type \
00116 DELEGATE_REF_T; \
00117 typedef typename ::dds::core::smart_ptr_traits< DELEGATE< T_PARAM > >::weak_ref_type \
00118 DELEGATE_WEAK_REF_T; \
00119 \
00120 private:\
00121     const typename ::dds::core::Reference< DELEGATE< T_PARAM > >::DELEGATE_REF_T& impl() const \
00122     { return ::dds::core::Reference< DELEGATE< T_PARAM > >::impl_; }\
00123     typename ::dds::core::Reference< DELEGATE< T_PARAM > >::DELEGATE_REF_T& impl() \
00124     { return ::dds::core::Reference< DELEGATE< T_PARAM > >::impl_; }\
00125 \
00126 public:\
00127 template <typename T__> \
00128 TYPE& \
00129 operator=(const T__& rhs) {\
00130     OMG_DDS_STATIC_ASSERT((dds::core::is_base_of<typename TYPE::DELEGATE_T, typename T__::DELEGATE_T>::value));\
00131     if (this != (TYPE*)&rhs) \
00132         *this = TYPE(rhs); \
00133     return *this; \
00134 }
00135 
00136 
00137 #define OMG_DDS_REF_TYPE_NODC(TYPE, BASE, DELEGATE) \
00138 OMG_DDS_REF_TYPE_DELEGATE(TYPE, BASE, DELEGATE)     \
00139 OMG_DDS_REF_TYPE_BASE(TYPE, BASE, DELEGATE)         \
00140 public:
00141 
00142 
00143 #define OMG_DDS_REF_TYPE_NODC_T(TYPE, BASE, T_PARAM, DELEGATE) \
00144 OMG_DDS_REF_TYPE_DELEGATE_T(TYPE, BASE, T_PARAM, DELEGATE)     \
00145 OMG_DDS_REF_TYPE_BASE_T(TYPE, BASE, T_PARAM, DELEGATE)         \
00146 public:
00147 
00148 #define DDS_PTR_CTOR_REF_TYPE(TYPE, BASE, DELEGATE)     \
00149 public: \
00150 typedef BASE< DELEGATE >                                                  BASE_T;\
00151 typedef DELEGATE                                                          DELEGATE_T;   \
00152 typedef typename ::dds::core::smart_ptr_traits< DELEGATE >::ref_type      DELEGATE_REF_T; \
00153 typedef typename ::dds::core::smart_ptr_traits< DELEGATE >::weak_ref_type DELEGATE_WEAK_REF_T; \
00154 \
00155 private:\
00156     typename ::dds::core::Reference< DELEGATE >::DELEGATE_REF_T& impl() \
00157     { return ::dds::core::Reference< DELEGATE >::impl_; }\
00158 public:\
00159 explicit TYPE(DELEGATE_T* p)\
00160 : BASE< DELEGATE_T >(p) \
00161 {  }\
00162 template <typename PTR>\
00163 explicit TYPE(PTR* ptr) {\
00164     OMG_DDS_STATIC_ASSERT((dds::core::is_base_of<typename TYPE::DELEGATE_T, PTR>::value)); \
00165     this->dds::core::Reference< DELEGATE >::impl_.reset(ptr);\
00166 }\
00167 public:\
00168 explicit TYPE(const DELEGATE_REF_T& ref) \
00169     : BASE<DELEGATE_T>(ref)\
00170       { }\
00171 \
00172 template <typename H__> \
00173 explicit TYPE(const H__& h)    \
00174 : BASE< DELEGATE_T >(h) \
00175 { \
00176     OMG_DDS_STATIC_ASSERT((dds::core::is_base_of<typename TYPE::DELEGATE_T, typename H__::DELEGATE_T>::value)); \
00177     this->dds::core::Reference<DELEGATE>::impl_ = h.delegate();\
00178 } \
00179 public:\
00180 template <typename T__> \
00181 TYPE& \
00182 operator=(const T__& rhs) {\
00183     OMG_DDS_STATIC_ASSERT((dds::core::is_base_of<typename TYPE::DELEGATE_T, typename T__::DELEGATE_T>::value));\
00184     if (this != (TYPE*)&rhs) \
00185         *this = TYPE(rhs); \
00186     return *this; \
00187 } \
00188 public:
00189 
00190 
00192 // Declares a reference type equipped with a default ctor.
00193 //
00194 #define OMG_DDS_REF_TYPE(TYPE, BASE, DELEGATE)      \
00195    OMG_DDS_REF_TYPE_NODC(TYPE, BASE, DELEGATE) \
00196    TYPE() { }
00197 
00198 #define OMG_DDS_REF_TYPE_T(TYPE, BASE, T_PARAM, DELEGATE) \
00199    OMG_DDS_REF_TYPE_NODC_T(TYPE, BASE, T_PARAM, DELEGATE) \
00200    TYPE() { }
00201 
00202 
00203 #endif /* OMG_DDS_CORE_REFMACROS_HPP_ */

Generated on Tue Nov 9 2010 02:16:21 for dds-psm-cxx-doc by  doxygen 1.7.1