Gazebo Physics
API Reference
8.0.0
insert_drive_file
Tutorials
library_books
Classes
toc
Namespaces
insert_drive_file
Files
launch
Gazebo Website
Index
List
Hierarchy
Members: All
Members: Functions
Members: Variables
Members: Typedefs
Members: Enumerations
Members: Enumerator
List
Members
Functions
Typedefs
Variables
Enumerations
Enumerator
src
gz-physics
include
gz
physics
Entity.hh
Go to the documentation of this file.
1
/*
2
* Copyright (C) 2017 Open Source Robotics Foundation
3
*
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
* you may not use this file except in compliance with the License.
6
* You may obtain a copy of the License at
7
*
8
* http://www.apache.org/licenses/LICENSE-2.0
9
*
10
* Unless required by applicable law or agreed to in writing, software
11
* distributed under the License is distributed on an "AS IS" BASIS,
12
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
* See the License for the specific language governing permissions and
14
* limitations under the License.
15
*
16
*/
17
18
#ifndef GZ_PHYSICS_ENTITY_HH_
19
#define GZ_PHYSICS_ENTITY_HH_
20
21
#include <optional>
22
#include <limits>
23
#include <memory>
24
25
#include <gz/physics/Export.hh>
26
#include <gz/physics/detail/Identity.hh>
27
28
namespace
gz
29
{
30
namespace
physics
31
{
32
// Forward declaration
33
namespace
detail {
template
<
typename
,
typename
>
struct
DeterminePlugin; }
34
template
<
typename
>
struct
RequestFeatures;
35
38
const
std::size_t
INVALID_ENTITY_ID
=
39
std::numeric_limits<std::size_t>::max
();
40
41
template
<
typename
EntityT>
42
class
EntityPtr
43
{
44
public
:
EntityPtr
() =
default
;
45
public
:
EntityPtr
(
EntityPtr
&&) =
default
;
46
public
:
EntityPtr
&
operator=
(
EntityPtr
&&) =
default
;
47
public
:
~EntityPtr
() =
default
;
48
// Special handling for copy construction and copy assignment
49
public
:
EntityPtr
(
const
EntityPtr
&);
50
public
:
EntityPtr
&
operator=
(
const
EntityPtr
&);
51
53
public
:
EntityPtr
(
std::nullptr_t
);
54
56
public
:
EntityPtr
(std::nullopt_t);
57
59
public
:
EntityPtr
&
operator=
(
std::nullptr_t
);
60
62
public
:
EntityPtr
&
operator=
(std::nullopt_t);
63
69
public
:
template
<
typename
Pimpl>
70
EntityPtr
(
const
std::shared_ptr<Pimpl>
&_pimpl,
71
const
Identity &_identity);
72
77
public
:
template
<
typename
OtherEntityT>
78
EntityPtr
(
const
EntityPtr<OtherEntityT>
&_other);
79
84
public
:
template
<
typename
OtherEntityT>
85
EntityPtr
&
operator=
(
const
EntityPtr<OtherEntityT>
&_other);
86
92
public
: EntityT *
operator->
()
const
;
93
100
public
: EntityT &
operator*
()
const
;
101
104
public
:
bool
Valid
()
const
;
105
108
public
:
operator
bool()
const
;
109
115
public
:
std::size_t
Hash
()
const
;
116
125
public
:
template
<
typename
OtherEntityT>
126
bool
operator ==
(
const
EntityPtr<OtherEntityT>
&_other)
const
;
127
136
public
:
template
<
typename
OtherEntityT>
137
bool
operator <
(
const
EntityPtr<OtherEntityT>
&_other)
const
;
138
147
public
:
template
<
typename
OtherEntityT>
148
bool
operator >
(
const
EntityPtr<OtherEntityT>
&_other)
const
;
149
158
public
:
template
<
typename
OtherEntityT>
159
bool
operator !=
(
const
EntityPtr<OtherEntityT>
&_other)
const
;
160
169
public
:
template
<
typename
OtherEntityT>
170
bool
operator <=
(
const
EntityPtr<OtherEntityT>
&_other)
const
;
171
180
public
:
template
<
typename
OtherEntityT>
181
bool
operator >=
(
const
EntityPtr<OtherEntityT>
&_other)
const
;
182
197
private
:
mutable
std::optional<std::remove_const_t<EntityT>> entity;
198
199
200
// Declare these friendships so we can cast between different Entity types
201
template
<
typename
>
friend
class
EntityPtr
;
202
template
<
typename
>
friend
struct
RequestFeatures
;
203
};
204
215
template
<
typename
PolicyT,
typename
FeaturesT>
216
class
Entity
217
{
218
public
:
using
Policy
= PolicyT;
219
public
:
using
Features
= FeaturesT;
220
public
:
using
Pimpl
=
221
typename
detail::DeterminePlugin<Policy, Features>::type;
222
224
public
:
const
Identity &
FullIdentity
()
const
;
225
227
public
:
std::size_t
EntityID
()
const
;
228
231
public
:
const
std::shared_ptr<void>
&
EntityReference
()
const
;
232
240
// Notes for developers:
241
// - We provide a default constructor for this class so that the feature
242
// entity classes (which get virtually inherited) do not each need to
243
// call on the constructor of Entity. That would make it difficult
244
// to implement and maintain all the constructors of the different object
245
// feature classes.
246
// - Since all the features are virtually inherited, only the "final"
247
// inheriting class constructor needs to actually call this constructor.
248
// - The default argument for the identity will have an INVALID_ENTITY_ID
249
// value (which is the result of default-constructing Identity). If the
250
// Identity of an Entity is invalid, that implies that there is a bug in
251
// the construction of that Entity.
252
protected
:
Entity
(
253
const
std::shared_ptr<Pimpl>
&_pimpl =
nullptr
,
254
const
Identity &_identity = Identity());
255
264
protected
:
Entity
(
265
std::shared_ptr<Pimpl>
&&_pimpl,
266
const
Identity &_identity);
267
275
protected
:
template
<
typename
FeatureT>
276
typename
FeatureT::template Implementation<PolicyT> *
Interface
();
277
282
protected
:
template
<
typename
FeatureT>
283
const
typename
FeatureT::template Implementation<PolicyT> *
Interface
()
284
const
;
285
289
protected
:
std::shared_ptr<Pimpl>
pimpl
;
290
292
protected
: Identity
identity
;
293
295
public
:
virtual
~Entity
() =
default
;
296
297
// Allow EntityPtr to cast between EntityTypes
298
template
<
typename
>
friend
class
EntityPtr
;
299
template
<
typename
>
friend
struct
RequestFeatures
;
300
};
301
}
302
}
303
304
#include <gz/physics/detail/Entity.hh>
305
306
#endif