Point Cloud Library (PCL)  1.11.0
types.h
1 /*
2  * Software License Agreement (BSD License)
3  *
4  * Point Cloud Library (PCL) - www.pointclouds.org
5  * Copyright (c) 2020-, OpenPerception
6  *
7  * All rights reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
12  *
13  * * Redistributions of source code must retain the above copyright
14  * notice, this list of conditions and the following disclaimer.
15  * * Redistributions in binary form must reproduce the above
16  * copyright notice, this list of conditions and the following
17  * disclaimer in the documentation and/or other materials provided
18  * with the distribution.
19  * * Neither the name of the copyright holder(s) nor the names of its
20  * contributors may be used to endorse or promote products derived
21  * from this software without specific prior written permission.
22  *
23  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
26  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
27  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
28  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
29  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
30  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
31  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
33  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34  * POSSIBILITY OF SUCH DAMAGE.
35  */
36 
37 #pragma once
38 
39 /**
40  * \file pcl/types.h
41  *
42  * \brief Defines basic non-point types used by PCL
43  * \ingroup common
44  */
45 
46 #include <pcl/pcl_macros.h>
47 
48 #include <vector>
49 
50 #include <cstdint>
51 
52 namespace pcl
53 {
54  using uint8_t PCL_DEPRECATED(1, 12, "use std::uint8_t instead of pcl::uint8_t") = std::uint8_t;
55  using int8_t PCL_DEPRECATED(1, 12, "use std::int8_t instead of pcl::int8_t") = std::int8_t;
56  using uint16_t PCL_DEPRECATED(1, 12, "use std::uint16_t instead of pcl::uint16_t") = std::uint16_t;
57  using int16_t PCL_DEPRECATED(1, 12, "use std::uint16_t instead of pcl::int16_t") = std::int16_t;
58  using uint32_t PCL_DEPRECATED(1, 12, "use std::uint32_t instead of pcl::uint32_t") = std::uint32_t;
59  using int32_t PCL_DEPRECATED(1, 12, "use std::int32_t instead of pcl::int32_t") = std::int32_t;
60  using uint64_t PCL_DEPRECATED(1, 12, "use std::uint64_t instead of pcl::uint64_t") = std::uint64_t;
61  using int64_t PCL_DEPRECATED(1, 12, "use std::int64_t instead of pcl::int64_t") = std::int64_t;
62  using int_fast16_t PCL_DEPRECATED(1, 12, "use std::int_fast16_t instead of pcl::int_fast16_t") = std::int_fast16_t;
63 
64 // temporary macros for customization. Only use for PCL < 1.12
65 // Aim is to remove macros and instead allow multiple index types to coexist together
66 #ifndef PCL_INDEX_SIZE
67 #if PCL_MINOR_VERSION <= 11
68 // sizeof returns bytes, while we measure size by bits in the template
69 #define PCL_INDEX_SIZE (sizeof(int) * 8)
70 #else
71 #define PCL_INDEX_SIZE 32
72 #endif // PCL_MINOR_VERSION
73 #endif // PCL_INDEX_SIZE
74 
75 #ifndef PCL_INDEX_SIGNED
76 #define PCL_INDEX_SIGNED true
77 #endif
78 
79  namespace detail {
80  /**
81  * \brief int_type::type refers to an integral type that satisfies template parameters
82  * \tparam Bits number of bits in the integral type
83  * \tparam Signed signed or unsigned nature of the type
84  */
85  template <std::size_t Bits, bool Signed = true>
86  struct int_type { using type = void; };
87 
88  /**
89  * \brief helper type to use for `int_type::type`
90  * \see int_type
91  */
92  template <std::size_t Bits, bool Signed = true>
94 
95  template <>
96  struct int_type<8, true> { using type = std::int8_t; };
97  template <>
98  struct int_type<8, false> { using type = std::uint8_t; };
99  template <>
100  struct int_type<16, true> { using type = std::int16_t; };
101  template <>
102  struct int_type<16, false> { using type = std::uint16_t; };
103  template <>
104  struct int_type<32, true> { using type = std::int32_t; };
105  template <>
106  struct int_type<32, false> { using type = std::uint32_t; };
107  template <>
108  struct int_type<64, true> { using type = std::int64_t; };
109  template <>
110  struct int_type<64, false> { using type = std::uint64_t; };
111 
112  /**
113  * \brief number of bits in PCL's index type
114  *
115  * For PCL 1.11, please use PCL_INDEX_SIZE to choose a size best suited for your needs.
116  * PCL 1.12 will come with default 32, along with client code compile time choice
117  *
118  * PCL 1.11 has a default size = sizeof(int)
119  */
120  constexpr std::uint8_t index_type_size = PCL_INDEX_SIZE;
121 
122  /**
123  * \brief signed/unsigned nature of PCL's index type
124  * For PCL 1.11, please use PCL_INDEX_SIGNED to choose a type best suited for your needs.
125  * PCL 1.12 will come with default signed, along with client code compile time choice
126  * Default: signed
127  */
128  constexpr bool index_type_signed = PCL_INDEX_SIGNED;
129 } // namespace detail
130 
131  /**
132  * \brief Type used for an index in PCL
133  *
134  * Default index_t = int for PCL 1.11, std::int32_t for PCL >= 1.12
135  */
137  static_assert(!std::is_void<index_t>::value, "`index_t` can't have type `void`");
138 
139  /**
140  * \brief Type used for indices in PCL
141  */
142  using Indices = std::vector<index_t>;
143 } // namespace pcl
144 
std::int32_t int32_t
Definition: types.h:59
int_type::type refers to an integral type that satisfies template parameters
Definition: types.h:86
std::int16_t int16_t
Definition: types.h:57
std::uint64_t uint64_t
Definition: types.h:60
constexpr std::uint8_t index_type_size
number of bits in PCL's index type
Definition: types.h:120
std::uint32_t uint32_t
Definition: types.h:58
std::vector< index_t > Indices
Type used for indices in PCL.
Definition: types.h:142
std::uint16_t uint16_t
Definition: types.h:56
detail::int_type_t< detail::index_type_size, detail::index_type_signed > index_t
Type used for an index in PCL.
Definition: types.h:136
typename int_type< Bits, Signed >::type int_type_t
helper type to use for int_type::type
Definition: types.h:93
std::int_fast16_t int_fast16_t
Definition: types.h:62
std::int64_t int64_t
Definition: types.h:61
std::int8_t int8_t
Definition: types.h:55
std::uint8_t uint8_t
Definition: types.h:54
constexpr bool index_type_signed
signed/unsigned nature of PCL's index type For PCL 1.11, please use PCL_INDEX_SIGNED to choose a type...
Definition: types.h:128