mirror of
https://github.com/kidfromjupiter/nearby.git
synced 2026-09-16 07:36:10 -04:00
Migrate observer_list.h from location/nearby to third_party/nearby
PiperOrigin-RevId: 500240685
This commit is contained in:
committed by
Copybara-Service
parent
4ac64743b9
commit
05a6fbf20c
@@ -417,6 +417,7 @@ let package = Package(
|
||||
"internal/platform/BUILD",
|
||||
"internal/analytics/BUILD",
|
||||
"internal/network/BUILD",
|
||||
"internal/base/BUILD",
|
||||
// tests
|
||||
"connections/listeners_test.cc",
|
||||
"connections/strategy_test.cc",
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
licenses(["notice"])
|
||||
|
||||
cc_library(
|
||||
name = "base",
|
||||
srcs = [
|
||||
],
|
||||
hdrs = [
|
||||
"observer_list.h",
|
||||
],
|
||||
copts = [
|
||||
"-Ithird_party",
|
||||
],
|
||||
visibility = [
|
||||
"//internal:__pkg__",
|
||||
"//location/nearby/cpp/fastpair:__subpackages__",
|
||||
],
|
||||
deps = [
|
||||
"@com_google_absl//absl/container:flat_hash_set",
|
||||
],
|
||||
)
|
||||
@@ -0,0 +1,58 @@
|
||||
// Copyright 2021 Google LLC
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#ifndef THIRD_PARTY_NEARBY_INTERNAL_BASE_OBSERVER_LIST_H_
|
||||
#define THIRD_PARTY_NEARBY_INTERNAL_BASE_OBSERVER_LIST_H_
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "absl/container/flat_hash_set.h"
|
||||
|
||||
namespace nearby {
|
||||
|
||||
template <class ObserverType>
|
||||
class ObserverList {
|
||||
public:
|
||||
using iterator = typename absl::flat_hash_set<ObserverType*>::iterator;
|
||||
using const_iterator =
|
||||
typename absl::flat_hash_set<ObserverType*>::const_iterator;
|
||||
|
||||
void AddObserver(ObserverType* observer) { observers_.emplace(observer); }
|
||||
|
||||
void RemoveObserver(ObserverType* observer) { observers_.erase(observer); }
|
||||
|
||||
bool HasObserver(ObserverType* observer) {
|
||||
return observers_.contains(observer);
|
||||
}
|
||||
|
||||
void Clear() { observers_.clear(); }
|
||||
|
||||
bool empty() const { return observers_.empty(); }
|
||||
|
||||
int size() const { return observers_.size(); }
|
||||
|
||||
// Supports iterators
|
||||
iterator begin() { return observers_.begin(); }
|
||||
iterator end() { return observers_.end(); }
|
||||
const_iterator begin() const { return observers_.begin(); }
|
||||
const_iterator end() const { return observers_.end(); }
|
||||
|
||||
private:
|
||||
absl::flat_hash_set<ObserverType*> observers_;
|
||||
};
|
||||
|
||||
} // namespace nearby
|
||||
|
||||
#endif // THIRD_PARTY_NEARBY_INTERNAL_BASE_OBSERVER_LIST_H_
|
||||
Reference in New Issue
Block a user