23namespace service_discovery {
25using base::AtomicRWLock;
26using base::ReadLockGuard;
27using base::WriteLockGuard;
28using proto::RoleAttributes;
31 bool ignore_if_exist) {
33 if (!ignore_if_exist) {
34 if (roles_.find(key) != roles_.end()) {
59 auto search = roles_.find(key);
60 if (search == roles_.end()) {
63 if (!search->second->Match(role->attributes())) {
71 for (
auto it = roles_.begin(); it != roles_.end();) {
72 auto curr_role = it->second;
73 if (curr_role->Match(target_attr)) {
74 it = roles_.erase(it);
89 auto search = roles_.find(key);
90 if (search == roles_.end()) {
93 *first_matched_role = search->second;
101 if (!
Search(key, &role)) {
104 first_matched_role_attr->CopyFrom(role->attributes());
109 std::vector<RolePtr>* matched_roles) {
112 if (!
Search(key, &role)) {
115 matched_roles->emplace_back(role);
120 uint64_t key, std::vector<RoleAttributes>* matched_roles_attr) {
123 if (!
Search(key, &role)) {
126 matched_roles_attr->emplace_back(role->attributes());
132 return Search(target_attr, &role);
139 for (
auto& item : roles_) {
140 if (item.second->Match(target_attr)) {
141 *first_matched_role = item.second;
152 if (!
Search(target_attr, &role)) {
155 first_matched_role_attr->CopyFrom(role->attributes());
160 std::vector<RolePtr>* matched_roles) {
164 for (
auto& item : roles_) {
165 if (item.second->Match(target_attr)) {
166 matched_roles->emplace_back(item.second);
175 std::vector<RoleAttributes>* matched_roles_attr) {
179 for (
auto& item : roles_) {
180 if (item.second->Match(target_attr)) {
181 matched_roles_attr->emplace_back(item.second->attributes());
191 for (
auto& item : roles_) {
192 roles->emplace_back(item.second);
197 std::vector<RoleAttributes>* roles_attr) {
200 for (
auto& item : roles_) {
201 roles_attr->emplace_back(item.second->attributes());
std::size_t Size() override
void GetAllRoles(std::vector< RolePtr > *roles) override
void Remove(uint64_t key) override
bool Search(uint64_t key) override
bool Add(uint64_t key, const RolePtr &role, bool ignore_if_exist=true) override
#define RETURN_VAL_IF_NULL(ptr, val)
#define RETURN_IF_NULL(ptr)
std::shared_ptr< RoleBase > RolePtr