CARLA
 
载入中...
搜索中...
未找到
AtomicActorSet.h
浏览该文件的文档.
1// Copyright (c) 2020 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 <mutex>
10#include <map>
11#include <vector>
12
13#include "carla/client/Actor.h"
14#include "carla/Memory.h"
15
16namespace carla {
17namespace traffic_manager {
18
19 namespace cc = carla::client;
22
24
25 private:
26
28 std::map<ActorId, ActorPtr> actor_set;
30
31 public:
32
34
35 std::vector<ActorPtr> GetList() {
36
37 std::lock_guard<std::mutex> lock(modification_mutex);
38 std::vector<ActorPtr> actor_list;
39 for (auto it = actor_set.begin(); it != actor_set.end(); ++it) {
40 actor_list.push_back(it->second);
41 }
42 return actor_list;
43 }
44
45 std::vector<ActorId> GetIDList() {
46
47 std::lock_guard<std::mutex> lock(modification_mutex);
48 std::vector<ActorId> actor_list;
49 for (auto it = actor_set.begin(); it != actor_set.end(); ++it) {
50 actor_list.push_back(it->first);
51 }
52 return actor_list;
53 }
54
55 void Insert(std::vector<ActorPtr> actor_list) {
56
57 std::lock_guard<std::mutex> lock(modification_mutex);
58 for (auto &actor: actor_list) {
59 actor_set.insert({actor->GetId(), actor});
60 }
62 }
63
64 void Remove(std::vector<ActorId> actor_id_list) {
65
66 std::lock_guard<std::mutex> lock(modification_mutex);
67 for (auto& actor_id: actor_id_list) {
68 if (actor_set.find(actor_id) != actor_set.end()){
69 actor_set.erase(actor_id);
70 }
71 }
73 }
74
75 void Destroy(ActorId actor_id) {
76
77 std::lock_guard<std::mutex> lock(modification_mutex);
78 if (actor_set.find(actor_id) != actor_set.end()) {
79 ActorPtr actor = actor_set.at(actor_id);
80 actor->Destroy();
81 actor_set.erase(actor_id);
83 }
84 }
85
86 int GetState() {
87
88 std::lock_guard<std::mutex> lock(modification_mutex);
89 return state_counter;
90 }
91
92 bool Contains(ActorId id) {
93
94 std::lock_guard<std::mutex> lock(modification_mutex);
95 return actor_set.find(id) != actor_set.end();
96 }
97
98 size_t Size() {
99
100 std::lock_guard<std::mutex> lock(modification_mutex);
101 return actor_set.size();
102 }
103
104 void Clear() {
105
106 std::lock_guard<std::mutex> lock(modification_mutex);
107 return actor_set.clear();
108 }
109
110 };
111
112} // namespace traffic_manager
113} // namespace carla
void Remove(std::vector< ActorId > actor_id_list)
std::map< ActorId, ActorPtr > actor_set
std::vector< ActorPtr > GetList()
void Insert(std::vector< ActorPtr > actor_list)
carla::SharedPtr< cc::Actor > ActorPtr
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
rpc::ActorId ActorId
Definition ActorId.h:18