12 #include <boost/iterator/transform_iterator.hpp> 37 template <
typename RangeT>
42 template <
typename RangeT>
43 std::vector<ActorId>
GetMissingIds(
const RangeT &range)
const;
50 template <
typename RangeT>
51 std::vector<rpc::Actor>
GetActorsById(
const RangeT &range)
const;
59 std::unordered_map<ActorId, rpc::Actor>
_actors;
67 std::lock_guard<std::mutex> lock(
_mutex);
69 _actors.emplace(
id, std::move(actor));
72 template <
typename RangeT>
76 return std::make_pair(
id, std::move(actor));
78 auto make_iterator = [&make_a_pair](
auto it) {
79 return boost::make_transform_iterator(std::make_move_iterator(it), make_a_pair);
81 std::lock_guard<std::mutex> lock(
_mutex);
82 _actors.insert(make_iterator(std::begin(range)), make_iterator(std::end(range)));
85 template <
typename RangeT>
87 std::vector<ActorId> result;
88 result.reserve(range.size());
89 std::lock_guard<std::mutex> lock(
_mutex);
90 std::copy_if(std::begin(range), std::end(range), std::back_inserter(result), [
this](
auto id) {
97 std::lock_guard<std::mutex> lock(
_mutex);
105 template <
typename RangeT>
107 std::vector<rpc::Actor> result;
108 result.reserve(range.size());
109 std::lock_guard<std::mutex> lock(
_mutex);
110 for (
auto &&
id : range) {
113 result.emplace_back(it->second);
120 std::lock_guard<std::mutex> lock(
_mutex);
This file contains definitions of common data structures used in traffic manager. ...
Keeps a list of actor descriptions to avoid requesting each time the descriptions to the server...
std::vector< rpc::Actor > GetActorsById(const RangeT &range) const
Retrieve the actors matching the ids in range.
boost::optional< rpc::Actor > GetActorById(ActorId id) const
Retrieve the actor matching id, or empty optional if actor is not cached.
void Insert(rpc::Actor actor)
Inserts an actor into the list.
void InsertRange(RangeT range)
Inserts a range containing actors.
Inherit (privately) to suppress copy construction and assignment.
std::vector< ActorId > GetMissingIds(const RangeT &range) const
Return the actor ids present in range that haven't been added to this list.
std::unordered_map< ActorId, rpc::Actor > _actors