OpenSplice ISO C++ 2 DCPS  v6.x
ISO C++ 2 OpenSplice Data Distribution Service Data-Centric Publish-Subscribe API
ref_traits.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_DETAIL_REF_TRAITS_HPP_
22 #define OSPL_DDS_CORE_DETAIL_REF_TRAITS_HPP_
23 
28 // Implementation
29 
30 #include <dds/core/types.hpp>
31 #include <dds/core/Exception.hpp>
32 
33 /* Compiling explicitly w/ C++ 11 support */
34 #if defined(OSPL_USE_CXX11)
35 # include <memory>
36 # include <type_traits>
37 # define OSPL_CXX11_STD_MODULE ::std
38 
39 /* Compiling to use Tech Report 1 headers */
40 #elif defined(OSPL_USE_TR1)
41 # ifdef _MSC_VER
42 # include <memory>
43 # include <type_traits>
44 # else
45 # include <tr1/memory>
46 # include <tr1/type_traits>
47 # endif
48 # define OSPL_CXX11_STD_MODULE ::std::tr1
49 
50 /* Compiling with boost */
51 #elif defined(OSPL_USE_BOOST)
52 # include <boost/shared_ptr.hpp>
53 # include <boost/weak_ptr.hpp>
54 # include <boost/type_traits.hpp>
55 # define OSPL_CXX11_STD_MODULE ::boost
56 
57 #else
58 # error "macros.hpp header not included or other unexpected misconfiguration"
59 #endif
60 
61 template <typename T1, typename T2>
62 struct dds::core::is_base_of :
63 #if defined (OSPL_USE_BOOST) && ! defined (BOOST_TT_IS_BASE_OF_HPP_INCLUDED)
64 # include "boost/type_traits/is_base_and_derived.hpp"
65  ::boost::detail::is_base_and_derived_impl<T1, T2> { }; // Really old boost had no is_base_of
66 #else
67  public OSPL_CXX11_STD_MODULE::is_base_of<T1, T2> { };
68 #endif
69 
70 template <typename T1, typename T2>
71 struct dds::core::is_same : public OSPL_CXX11_STD_MODULE::is_same<T1, T1> { };
72 
73 template <typename T>
74 struct dds::core::smart_ptr_traits
75 {
76  typedef OSPL_CXX11_STD_MODULE::shared_ptr<T> ref_type;
77  typedef OSPL_CXX11_STD_MODULE::weak_ptr<T> weak_ref_type;
78 };
79 
80 template <typename TO, typename FROM>
81 TO dds::core::polymorphic_cast(FROM& from)
82 {
83  typename TO::DELEGATE_REF_T dr =
84  OSPL_CXX11_STD_MODULE::dynamic_pointer_cast< typename TO::DELEGATE_T>(from.delegate());
85  TO to(dr);
86 
87  if(to == dds::core::null)
88  {
89  throw dds::core::InvalidDowncastError("Attempted invalid downcast.");
90  }
91  return to;
92 }
93 
94 
95 // End of implementation
98 #endif /* OSPL_DDS_CORE_DETAIL_REF_TRAITS_HPP_ */
Exception: Application has attempted to cast incompatible types.
Definition: Exception.hpp:307