Apollo 10.0
自动驾驶开放平台
apollo::cyber::service_discovery::MultiValueWarehouse类 参考

#include <multi_value_warehouse.h>

类 apollo::cyber::service_discovery::MultiValueWarehouse 继承关系图:
apollo::cyber::service_discovery::MultiValueWarehouse 的协作图:

Public 类型

using RoleMap = std::unordered_multimap< uint64_t, RolePtr >
 

Public 成员函数

 MultiValueWarehouse ()
 
virtual ~MultiValueWarehouse ()
 
bool Add (uint64_t key, const RolePtr &role, bool ignore_if_exist=true) override
 
void Clear () override
 
std::size_t Size () override
 
void Remove (uint64_t key) override
 
void Remove (uint64_t key, const RolePtr &role) override
 
void Remove (const proto::RoleAttributes &target_attr) override
 
bool Search (uint64_t key) override
 
bool Search (uint64_t key, RolePtr *first_matched_role) override
 
bool Search (uint64_t key, proto::RoleAttributes *first_matched_role_attr) override
 
bool Search (uint64_t key, std::vector< RolePtr > *matched_roles) override
 
bool Search (uint64_t key, std::vector< proto::RoleAttributes > *matched_roles_attr) override
 
bool Search (const proto::RoleAttributes &target_attr) override
 
bool Search (const proto::RoleAttributes &target_attr, RolePtr *first_matched) override
 
bool Search (const proto::RoleAttributes &target_attr, proto::RoleAttributes *first_matched_role_attr) override
 
bool Search (const proto::RoleAttributes &target_attr, std::vector< RolePtr > *matched_roles) override
 
bool Search (const proto::RoleAttributes &target_attr, std::vector< proto::RoleAttributes > *matched_roles_attr) override
 
void GetAllRoles (std::vector< RolePtr > *roles) override
 
void GetAllRoles (std::vector< proto::RoleAttributes > *roles_attr) override
 
- Public 成员函数 继承自 apollo::cyber::service_discovery::WarehouseBase
 WarehouseBase ()
 
virtual ~WarehouseBase ()
 

详细描述

在文件 multi_value_warehouse.h31 行定义.

成员类型定义说明

◆ RoleMap

using apollo::cyber::service_discovery::MultiValueWarehouse::RoleMap = std::unordered_multimap<uint64_t, RolePtr>

在文件 multi_value_warehouse.h33 行定义.

构造及析构函数说明

◆ MultiValueWarehouse()

apollo::cyber::service_discovery::MultiValueWarehouse::MultiValueWarehouse ( )
inline

在文件 multi_value_warehouse.h35 行定义.

35{}

◆ ~MultiValueWarehouse()

virtual apollo::cyber::service_discovery::MultiValueWarehouse::~MultiValueWarehouse ( )
inlinevirtual

在文件 multi_value_warehouse.h36 行定义.

36{}

成员函数说明

◆ Add()

bool apollo::cyber::service_discovery::MultiValueWarehouse::Add ( uint64_t  key,
const RolePtr role,
bool  ignore_if_exist = true 
)
overridevirtual

实现了 apollo::cyber::service_discovery::WarehouseBase.

在文件 multi_value_warehouse.cc33 行定义.

34 {
35 WriteLockGuard<AtomicRWLock> lock(rw_lock_);
36 if (!ignore_if_exist) {
37 if (roles_.find(key) != roles_.end()) {
38 return false;
39 }
40 }
41 std::pair<uint64_t, RolePtr> role_pair(key, role);
42 roles_.insert(role_pair);
43 return true;
44}

◆ Clear()

void apollo::cyber::service_discovery::MultiValueWarehouse::Clear ( )
overridevirtual

实现了 apollo::cyber::service_discovery::WarehouseBase.

在文件 multi_value_warehouse.cc46 行定义.

46 {
47 WriteLockGuard<AtomicRWLock> lock(rw_lock_);
48 roles_.clear();
49}

◆ GetAllRoles() [1/2]

void apollo::cyber::service_discovery::MultiValueWarehouse::GetAllRoles ( std::vector< proto::RoleAttributes > *  roles_attr)
overridevirtual

实现了 apollo::cyber::service_discovery::WarehouseBase.

在文件 multi_value_warehouse.cc206 行定义.

206 {
207 RETURN_IF_NULL(roles_attr);
208 ReadLockGuard<AtomicRWLock> lock(rw_lock_);
209 for (auto& item : roles_) {
210 roles_attr->emplace_back(item.second->attributes());
211 }
212}
#define RETURN_IF_NULL(ptr)
Definition log.h:90

◆ GetAllRoles() [2/2]

void apollo::cyber::service_discovery::MultiValueWarehouse::GetAllRoles ( std::vector< RolePtr > *  roles)
overridevirtual

实现了 apollo::cyber::service_discovery::WarehouseBase.

在文件 multi_value_warehouse.cc198 行定义.

198 {
199 RETURN_IF_NULL(roles);
200 ReadLockGuard<AtomicRWLock> lock(rw_lock_);
201 for (auto& item : roles_) {
202 roles->emplace_back(item.second);
203 }
204}

◆ Remove() [1/3]

void apollo::cyber::service_discovery::MultiValueWarehouse::Remove ( const proto::RoleAttributes target_attr)
overridevirtual

实现了 apollo::cyber::service_discovery::WarehouseBase.

在文件 multi_value_warehouse.cc73 行定义.

73 {
74 WriteLockGuard<AtomicRWLock> lock(rw_lock_);
75 for (auto it = roles_.begin(); it != roles_.end();) {
76 auto curr_role = it->second;
77 if (curr_role->Match(target_attr)) {
78 it = roles_.erase(it);
79 } else {
80 ++it;
81 }
82 }
83}

◆ Remove() [2/3]

void apollo::cyber::service_discovery::MultiValueWarehouse::Remove ( uint64_t  key)
overridevirtual

实现了 apollo::cyber::service_discovery::WarehouseBase.

在文件 multi_value_warehouse.cc56 行定义.

56 {
57 WriteLockGuard<AtomicRWLock> lock(rw_lock_);
58 roles_.erase(key);
59}

◆ Remove() [3/3]

void apollo::cyber::service_discovery::MultiValueWarehouse::Remove ( uint64_t  key,
const RolePtr role 
)
overridevirtual

实现了 apollo::cyber::service_discovery::WarehouseBase.

在文件 multi_value_warehouse.cc61 行定义.

61 {
62 WriteLockGuard<AtomicRWLock> lock(rw_lock_);
63 auto range = roles_.equal_range(key);
64 for (auto it = range.first; it != range.second;) {
65 if (it->second->Match(role->attributes())) {
66 it = roles_.erase(it);
67 } else {
68 ++it;
69 }
70 }
71}

◆ Search() [1/10]

bool apollo::cyber::service_discovery::MultiValueWarehouse::Search ( const proto::RoleAttributes target_attr)
overridevirtual

实现了 apollo::cyber::service_discovery::WarehouseBase.

在文件 multi_value_warehouse.cc140 行定义.

140 {
141 RolePtr role;
142 return Search(target_attr, &role);
143}
std::shared_ptr< RoleBase > RolePtr
Definition role.h:31

◆ Search() [2/10]

bool apollo::cyber::service_discovery::MultiValueWarehouse::Search ( const proto::RoleAttributes target_attr,
proto::RoleAttributes first_matched_role_attr 
)
overridevirtual

实现了 apollo::cyber::service_discovery::WarehouseBase.

在文件 multi_value_warehouse.cc158 行定义.

159 {
160 RETURN_VAL_IF_NULL(first_matched_role_attr, false);
161 RolePtr role;
162 if (!Search(target_attr, &role)) {
163 return false;
164 }
165 first_matched_role_attr->CopyFrom(role->attributes());
166 return true;
167}
#define RETURN_VAL_IF_NULL(ptr, val)
Definition log.h:98

◆ Search() [3/10]

bool apollo::cyber::service_discovery::MultiValueWarehouse::Search ( const proto::RoleAttributes target_attr,
RolePtr first_matched 
)
overridevirtual

实现了 apollo::cyber::service_discovery::WarehouseBase.

在文件 multi_value_warehouse.cc145 行定义.

146 {
147 RETURN_VAL_IF_NULL(first_matched_role, false);
148 ReadLockGuard<AtomicRWLock> lock(rw_lock_);
149 for (auto& item : roles_) {
150 if (item.second->Match(target_attr)) {
151 *first_matched_role = item.second;
152 return true;
153 }
154 }
155 return false;
156}

◆ Search() [4/10]

bool apollo::cyber::service_discovery::MultiValueWarehouse::Search ( const proto::RoleAttributes target_attr,
std::vector< proto::RoleAttributes > *  matched_roles_attr 
)
overridevirtual

实现了 apollo::cyber::service_discovery::WarehouseBase.

在文件 multi_value_warehouse.cc183 行定义.

185 {
186 RETURN_VAL_IF_NULL(matched_roles_attr, false);
187 bool find = false;
188 ReadLockGuard<AtomicRWLock> lock(rw_lock_);
189 for (auto& item : roles_) {
190 if (item.second->Match(target_attr)) {
191 matched_roles_attr->emplace_back(item.second->attributes());
192 find = true;
193 }
194 }
195 return find;
196}

◆ Search() [5/10]

bool apollo::cyber::service_discovery::MultiValueWarehouse::Search ( const proto::RoleAttributes target_attr,
std::vector< RolePtr > *  matched_roles 
)
overridevirtual

实现了 apollo::cyber::service_discovery::WarehouseBase.

在文件 multi_value_warehouse.cc169 行定义.

170 {
171 RETURN_VAL_IF_NULL(matched_roles, false);
172 bool find = false;
173 ReadLockGuard<AtomicRWLock> lock(rw_lock_);
174 for (auto& item : roles_) {
175 if (item.second->Match(target_attr)) {
176 matched_roles->emplace_back(item.second);
177 find = true;
178 }
179 }
180 return find;
181}

◆ Search() [6/10]

bool apollo::cyber::service_discovery::MultiValueWarehouse::Search ( uint64_t  key)
overridevirtual

实现了 apollo::cyber::service_discovery::WarehouseBase.

在文件 multi_value_warehouse.cc85 行定义.

85 {
86 RolePtr role;
87 return Search(key, &role);
88}

◆ Search() [7/10]

bool apollo::cyber::service_discovery::MultiValueWarehouse::Search ( uint64_t  key,
proto::RoleAttributes first_matched_role_attr 
)
overridevirtual

实现了 apollo::cyber::service_discovery::WarehouseBase.

在文件 multi_value_warehouse.cc101 行定义.

102 {
103 RETURN_VAL_IF_NULL(first_matched_role_attr, false);
104 RolePtr role;
105 if (!Search(key, &role)) {
106 return false;
107 }
108 first_matched_role_attr->CopyFrom(role->attributes());
109 return true;
110}

◆ Search() [8/10]

bool apollo::cyber::service_discovery::MultiValueWarehouse::Search ( uint64_t  key,
RolePtr first_matched_role 
)
overridevirtual

实现了 apollo::cyber::service_discovery::WarehouseBase.

在文件 multi_value_warehouse.cc90 行定义.

90 {
91 RETURN_VAL_IF_NULL(first_matched_role, false);
92 ReadLockGuard<AtomicRWLock> lock(rw_lock_);
93 auto search = roles_.find(key);
94 if (search == roles_.end()) {
95 return false;
96 }
97 *first_matched_role = search->second;
98 return true;
99}

◆ Search() [9/10]

bool apollo::cyber::service_discovery::MultiValueWarehouse::Search ( uint64_t  key,
std::vector< proto::RoleAttributes > *  matched_roles_attr 
)
overridevirtual

实现了 apollo::cyber::service_discovery::WarehouseBase.

在文件 multi_value_warehouse.cc126 行定义.

127 {
128 RETURN_VAL_IF_NULL(matched_roles_attr, false);
129 bool find = false;
130 ReadLockGuard<AtomicRWLock> lock(rw_lock_);
131 auto range = roles_.equal_range(key);
132 for_each(range.first, range.second,
133 [&matched_roles_attr, &find](RoleMap::value_type& item) {
134 matched_roles_attr->emplace_back(item.second->attributes());
135 find = true;
136 });
137 return find;
138}

◆ Search() [10/10]

bool apollo::cyber::service_discovery::MultiValueWarehouse::Search ( uint64_t  key,
std::vector< RolePtr > *  matched_roles 
)
overridevirtual

实现了 apollo::cyber::service_discovery::WarehouseBase.

在文件 multi_value_warehouse.cc112 行定义.

113 {
114 RETURN_VAL_IF_NULL(matched_roles, false);
115 bool find = false;
116 ReadLockGuard<AtomicRWLock> lock(rw_lock_);
117 auto range = roles_.equal_range(key);
118 for_each(range.first, range.second,
119 [&matched_roles, &find](RoleMap::value_type& item) {
120 matched_roles->emplace_back(item.second);
121 find = true;
122 });
123 return find;
124}

◆ Size()

std::size_t apollo::cyber::service_discovery::MultiValueWarehouse::Size ( )
overridevirtual

实现了 apollo::cyber::service_discovery::WarehouseBase.

在文件 multi_value_warehouse.cc51 行定义.

51 {
52 ReadLockGuard<AtomicRWLock> lock(rw_lock_);
53 return roles_.size();
54}

该类的文档由以下文件生成: