CARLA
Toggle main menu visibility
Loading...
Searching...
No Matches
LibCarla
source
carla
sensor
CompileTimeTypeMap.h
Go to the documentation of this file.
1
// Copyright (c) 2026 Computer Vision Center (CVC) at the Universitat Autonoma
2
// de Barcelona (UAB).
3
//
4
// This work is licensed under the terms of the MIT license.
5
// For a copy, see <https://opensource.org/licenses/MIT>.
6
7
#pragma once
8
9
#include <type_traits>
10
#include <utility>
11
12
namespace
carla
{
13
namespace
sensor
{
14
15
namespace
detail
{
16
17
/// Private implementation of the CompileTimeTypeMap.
18
template
<
size_t
Size,
typename
...>
19
struct
CompileTimeTypeMapImpl
;
20
21
/// Specialization for an empty map, it is retrieved when a key cannot be
22
/// found.
23
template
<
size_t
Size>
24
struct
CompileTimeTypeMapImpl<Size>
{
25
26
template
<
typename
InKey>
27
struct
get
{
28
using
type
= void;
29
static
constexpr
size_t
index
= Size;
30
};
31
32
template
<
size_t
Index>
33
struct
get_by_index
{
34
using
type
= void;
35
using
key
= void;
36
};
37
};
38
39
template
<
size_t
Size,
typename
Key,
typename
Value,
typename
... Rest>
40
struct
CompileTimeTypeMapImpl
<Size,
std
::pair<Key, Value>, Rest...> {
41
42
static
constexpr
size_t
current_index
() {
43
return
Size - 1u -
sizeof
...(Rest);
44
}
45
46
// Recursively call this struct until the InKey matches an element.
47
template
<
typename
InKey>
48
struct
get
{
49
using
type
=
typename
std::conditional<
50
std::is_same<InKey, Key>::value,
51
Value,
52
typename
CompileTimeTypeMapImpl
<Size, Rest...>::template
get<InKey>::type
53
>
::type
;
54
static
constexpr
size_t
index
=
55
std::is_same<InKey, Key>::value ?
56
current_index
() :
57
CompileTimeTypeMapImpl
<Size, Rest...>::template
get
<InKey>::
index
;
58
};
59
60
// Recursively call this struct until the Index matches an element.
61
template
<
size_t
Index>
62
struct
get_by_index
{
63
using
type
=
typename
std::conditional<
64
Index ==
current_index
(),
65
Value,
66
typename
CompileTimeTypeMapImpl
<Size, Rest...>::template
get_by_index<Index>::type
67
>
::type
;
68
69
using
key
=
typename
std::conditional<
70
Index ==
current_index
(),
71
Key,
72
typename
CompileTimeTypeMapImpl
<Size, Rest...>::template
get_by_index<Index>::key
73
>
::type
;
74
};
75
};
76
77
}
// namespace detail
78
79
/// A compile time structure for mapping two types. Lookup elements by Key or
80
/// by Index.
81
///
82
/// Example usage:
83
///
84
/// using MyMap = CompileTimeTypeMap<std::pair<A, B>, std::pair<C, D>>;
85
/// using type_B = MyMap::get<A>::type;
86
/// constexpr size_t index_B = MyMap::get<A>::index;
87
/// using type_B_too = MyMap::get_by_index<index_B>::type;
88
///
89
template
<
typename
... Items>
90
struct
CompileTimeTypeMap
{
91
92
static
constexpr
size_t
size
() {
93
return
sizeof
...(Items);
94
}
95
96
template
<
typename
InKey>
97
using
get
=
typename
detail::CompileTimeTypeMapImpl
<
sizeof
...(Items), Items...>::template
get<InKey>
;
98
99
template
<
size_t
Index>
100
using
get_by_index
=
typename
detail::CompileTimeTypeMapImpl
<
sizeof
...(Items), Items...>::template
get_by_index<Index>
;
101
};
102
103
}
// namespace sensor
104
}
// namespace carla
carla::sensor::detail
Definition
CompileTimeTypeMap.h:15
carla::sensor
Definition
client/detail/Client.h:58
carla
This file contains definitions of common data structures used in traffic manager.
Definition
SignComponent.h:21
std
Definition
CarlaRecorderCollision.h:31
carla::sensor::CompileTimeTypeMap
A compile time structure for mapping two types.
Definition
CompileTimeTypeMap.h:90
carla::sensor::CompileTimeTypeMap::get_by_index
typename detail::CompileTimeTypeMapImpl< sizeof...(Items), Items... >::template get_by_index< Index > get_by_index
Definition
CompileTimeTypeMap.h:100
carla::sensor::CompileTimeTypeMap::size
static constexpr size_t size()
Definition
CompileTimeTypeMap.h:92
carla::sensor::CompileTimeTypeMap::get
typename detail::CompileTimeTypeMapImpl< sizeof...(Items), Items... >::template get< InKey > get
Definition
CompileTimeTypeMap.h:97
carla::sensor::detail::CompileTimeTypeMapImpl< Size, std::pair< Key, Value >, Rest... >::current_index
static constexpr size_t current_index()
Definition
CompileTimeTypeMap.h:42
carla::sensor::detail::CompileTimeTypeMapImpl< Size, std::pair< Key, Value >, Rest... >::get_by_index
Definition
CompileTimeTypeMap.h:62
carla::sensor::detail::CompileTimeTypeMapImpl< Size, std::pair< Key, Value >, Rest... >::get_by_index::key
typename std::conditional< Index==current_index(), Key, typename CompileTimeTypeMapImpl< Size, Rest... >::template get_by_index< Index >::key >::type key
Definition
CompileTimeTypeMap.h:69
carla::sensor::detail::CompileTimeTypeMapImpl< Size, std::pair< Key, Value >, Rest... >::get_by_index::type
typename std::conditional< Index==current_index(), Value, typename CompileTimeTypeMapImpl< Size, Rest... >::template get_by_index< Index >::type >::type type
Definition
CompileTimeTypeMap.h:63
carla::sensor::detail::CompileTimeTypeMapImpl< Size, std::pair< Key, Value >, Rest... >::get
Definition
CompileTimeTypeMap.h:48
carla::sensor::detail::CompileTimeTypeMapImpl< Size, std::pair< Key, Value >, Rest... >::get::type
typename std::conditional< std::is_same< InKey, Key >::value, Value, typename CompileTimeTypeMapImpl< Size, Rest... >::template get< InKey >::type >::type type
Definition
CompileTimeTypeMap.h:49
carla::sensor::detail::CompileTimeTypeMapImpl< Size, std::pair< Key, Value >, Rest... >::get::index
static constexpr size_t index
Definition
CompileTimeTypeMap.h:54
carla::sensor::detail::CompileTimeTypeMapImpl< Size >::get_by_index
Definition
CompileTimeTypeMap.h:33
carla::sensor::detail::CompileTimeTypeMapImpl< Size >::get_by_index::type
void type
Definition
CompileTimeTypeMap.h:34
carla::sensor::detail::CompileTimeTypeMapImpl< Size >::get_by_index::key
void key
Definition
CompileTimeTypeMap.h:35
carla::sensor::detail::CompileTimeTypeMapImpl< Size >::get
Definition
CompileTimeTypeMap.h:27
carla::sensor::detail::CompileTimeTypeMapImpl< Size >::get::type
void type
Definition
CompileTimeTypeMap.h:28
carla::sensor::detail::CompileTimeTypeMapImpl< Size >::get::index
static constexpr size_t index
Definition
CompileTimeTypeMap.h:29
carla::sensor::detail::CompileTimeTypeMapImpl
Private implementation of the CompileTimeTypeMap.
Definition
CompileTimeTypeMap.h:19
Generated by
1.18.0