Fast DDS  Version 3.0.0
Fast DDS
Loading...
Searching...
No Matches
type_traits.hpp
1// Copyright 2023 Proyectos y Sistemas de Mantenimiento SL (eProsima).
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15#ifndef FASTDDS_DDS_XTYPES_DYNAMIC_TYPES_DETAIL__TYPE_TRAITS_HPP
16#define FASTDDS_DDS_XTYPES_DYNAMIC_TYPES_DETAIL__TYPE_TRAITS_HPP
17
18#include <memory>
19
20#include <fastdds/fastdds_dll.hpp>
21
22namespace eprosima {
23namespace fastdds {
24namespace dds {
25
26template<typename T>
27struct traits
28{
29 using ref_type = typename ::std::shared_ptr<T>;
30 using weak_ref_type = typename ::std::weak_ptr<T>;
31
32 template<typename _Tp, typename = typename
33 std::enable_if<std::is_base_of<T, _Tp>::value>::type>
34 inline static std::shared_ptr<_Tp> narrow (
35 ref_type obj)
36 {
37 return std::dynamic_pointer_cast<_Tp>(obj);
38 }
39
40 FASTDDS_EXPORTED_API static std::shared_ptr<T> make_shared();
41
42};
43
44template<typename T>
46{
47 using ref_type = typename ::std::shared_ptr<T>;
48 using weak_ref_type = typename ::std::weak_ptr<T>;
49
50 template<typename _Tp, typename = typename
51 std::enable_if<std::is_base_of<T, _Tp>::value>::type>
52 inline static std::shared_ptr<_Tp> narrow (
53 ref_type obj)
54 {
55 return std::dynamic_pointer_cast<_Tp>(obj);
56 }
57
58};
59
60} // namespace dds
61} // namespace fastdds
62} // namespace eprosima
63
64#endif // FASTDDS_DDS_XTYPES_DYNAMIC_TYPES_DETAIL__TYPE_TRAITS_HPP
65
Definition DomainParticipant.hpp:45
eProsima namespace.
Definition type_traits.hpp:46
typename ::std::shared_ptr< T > ref_type
Definition type_traits.hpp:47
typename ::std::weak_ptr< T > weak_ref_type
Definition type_traits.hpp:48
static std::shared_ptr< _Tp > narrow(ref_type obj)
Definition type_traits.hpp:52
Definition type_traits.hpp:28
typename ::std::shared_ptr< T > ref_type
Definition type_traits.hpp:29
typename ::std::weak_ptr< T > weak_ref_type
Definition type_traits.hpp:30
static std::shared_ptr< _Tp > narrow(ref_type obj)
Definition type_traits.hpp:34
static FASTDDS_EXPORTED_API std::shared_ptr< T > make_shared()