CARLA
 
载入中...
搜索中...
未找到
ActorVariant.h
浏览该文件的文档.
1// Copyright (c) 2017 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 "carla/Debug.h"
10#include "carla/Memory.h"
11#include "carla/client/Actor.h"
13#include "carla/rpc/Actor.h"
14
15#ifdef _MSC_VER
16#pragma warning(push)
17#pragma warning(disable:4583)
18#pragma warning(disable:4582)
19#include <boost/variant2/variant.hpp>
20#pragma warning(pop)
21#else
22#include <boost/variant2/variant.hpp>
23#endif
24
25namespace carla {
26namespace client {
27namespace detail {
28
29 /// Holds an Actor, but only instantiates it when needed.
31 public:
32
34 : _value(actor) {}
35
38
40 _value = actor;
41 return *this;
42 }
43
45 _value = actor;
46 return *this;
47 }
48
50 if (_value.index() == 0u) {
51 MakeActor(episode);
52 }
53 DEBUG_ASSERT(_value.index() == 1u);
54 return boost::variant2::get<SharedPtr<client::Actor>>(_value);
55 }
56
57 const rpc::Actor &Serialize() const {
58 return boost::variant2::visit(Visitor(), _value);
59 }
60
61 ActorId GetId() const {
62 return Serialize().id;
63 }
64
66 return Serialize().parent_id;
67 }
68
69 const std::string &GetTypeId() const {
70 return Serialize().description.id;
71 }
72
73 bool operator==(ActorVariant rhs) const {
74 return GetId() == rhs.GetId();
75 }
76
77 bool operator!=(ActorVariant rhs) const {
78 return !(*this == rhs);
79 }
80
81 private:
82
83 struct Visitor {
84 const rpc::Actor &operator()(const rpc::Actor &actor) const {
85 return actor;
86 }
88 return actor->Serialize();
89 }
90 };
91
92 void MakeActor(EpisodeProxy episode) const;
93
94 mutable boost::variant2::variant<rpc::Actor, SharedPtr<client::Actor>> _value;
95 };
96
97} // namespace detail
98} // namespace client
99} // namespace carla
#define DEBUG_ASSERT(predicate)
Definition Debug.h:66
Holds an Actor, but only instantiates it when needed.
bool operator==(ActorVariant rhs) const
void MakeActor(EpisodeProxy episode) const
bool operator!=(ActorVariant rhs) const
const rpc::Actor & Serialize() const
ActorVariant(SharedPtr< client::Actor > actor)
boost::variant2::variant< rpc::Actor, SharedPtr< client::Actor > > _value
ActorVariant & operator=(SharedPtr< client::Actor > actor)
ActorVariant & operator=(rpc::Actor actor)
const std::string & GetTypeId() const
SharedPtr< client::Actor > Get(EpisodeProxy episode) const
ActorId parent_id
Definition rpc/Actor.h:27
ActorDescription description
Definition rpc/Actor.h:29
This file contains definitions of common data structures used in traffic manager.
Definition Carla.cpp:133
boost::shared_ptr< T > SharedPtr
Use this SharedPtr (boost::shared_ptr) to keep compatibility with boost::python, but it would be nice...
Definition Memory.h:20
const rpc::Actor & operator()(const SharedPtr< const client::Actor > &actor) const
const rpc::Actor & operator()(const rpc::Actor &actor) const