18 #ifndef __IGN_TRANSPORT_TOPICSTORAGE_HH_INCLUDED__ 19 #define __IGN_TRANSPORT_TOPICSTORAGE_HH_INCLUDED__ 52 if (this->data.find(_publisher.Topic()) == this->data.end())
55 this->data[_publisher.Topic()] =
56 std::map<std::string, std::vector<T>>();
60 auto &m = this->data[_publisher.Topic()];
61 if (m.find(_publisher.PUuid()) != m.end())
64 auto &v = m[_publisher.PUuid()];
65 auto found = std::find_if(v.begin(), v.end(),
68 return _pub.Addr() == _publisher.Addr() &&
69 _pub.NUuid() == _publisher.NUuid();
78 m[_publisher.PUuid()].push_back(T(_publisher));
85 public:
bool HasTopic(
const std::string &_topic)
const 87 return this->data.find(_topic) != this->data.end();
97 const std::string &_pUuid)
const 99 if (!this->HasTopic(_topic))
102 return this->data.at(_topic).find(_pUuid) !=
103 this->data.at(_topic).end();
111 for (
auto &topic : this->data)
113 for (
auto &proc : topic.second)
115 for (
auto &pub : proc.second)
117 if (pub.Addr() == _addr)
132 const std::string &_pUuid,
133 const std::string &_nUuid,
137 if (this->data.find(_topic) == this->data.end())
141 auto &m = this->data.at(_topic);
144 if (m.find(_pUuid) == m.end())
148 auto &v = m.at(_pUuid);
149 auto found = std::find_if(v.begin(), v.end(),
152 return _pub.NUuid() == _nUuid;
155 if (found != v.end())
170 std::map<std::string, std::vector<T>> &_info)
const 172 if (!this->HasTopic(_topic))
175 _info = this->data.at(_topic);
185 const std::string &_pUuid,
186 const std::string &_nUuid)
191 if (this->data.find(_topic) != this->data.end())
194 auto &m = this->data[_topic];
197 if (m.find(_pUuid) != m.end())
201 auto priorSize = v.size();
202 v.erase(std::remove_if(v.begin(), v.end(),
205 return _pub.NUuid() == _nUuid;
208 counter = priorSize - v.size();
214 this->data.erase(_topic);
229 for (
auto it = this->data.begin(); it != this->data.end();)
232 auto &m = it->second;
233 counter += m.erase(_pUuid);
235 this->data.erase(it++);
249 std::map<std::string, std::vector<T>> &_pubs)
const 254 for (
auto &topic : this->data)
257 auto &m = topic.second;
258 if (m.find(_pUuid) != m.end())
260 auto &v = m.at(_pUuid);
263 _pubs[topic.first].push_back(T(pub));
271 public:
void TopicList(std::vector<std::string> &_topics)
const 273 for (
auto &topic : this->data)
274 _topics.push_back(topic.first);
280 std::cout <<
"---" << std::endl;
281 for (
auto &topic : this->data)
283 std::cout <<
"[" << topic.first <<
"]" << std::endl;
284 auto &m = topic.second;
287 std::cout <<
"\tProc. UUID: " << proc.first << std::endl;
288 auto &v = proc.second;
289 for (
auto &publisher : v)
291 std::cout << publisher;
299 private: std::map<std::string,
300 std::map<std::string, std::vector<T>>> data;
bool AddPublisher(const T &_publisher)
Add a new address associated to a given topic and node UUID.
Definition: TopicStorage.hh:49
bool Publishers(const std::string &_topic, std::map< std::string, std::vector< T >> &_info) const
Get the map of publishers stored for a given topic.
Definition: TopicStorage.hh:169
void Print() const
Print all the information for debugging purposes.
Definition: TopicStorage.hh:278
#define IGNITION_VISIBLE
Use to represent "symbol visible" if supported.
Definition: Helpers.hh:56
bool Publisher(const std::string &_topic, const std::string &_pUuid, const std::string &_nUuid, T &_publisher) const
Get the address information for a given topic and node UUID.
Definition: TopicStorage.hh:131
bool DelPublishersByProc(const std::string &_pUuid)
Remove all the publishers associated to a given process.
Definition: TopicStorage.hh:224
bool HasTopic(const std::string &_topic) const
Return if there is any publisher stored for the given topic.
Definition: TopicStorage.hh:85
bool DelPublisherByNode(const std::string &_topic, const std::string &_pUuid, const std::string &_nUuid)
Remove a publisher associated to a given topic and UUID pair.
Definition: TopicStorage.hh:184
bool HasAnyPublishers(const std::string &_topic, const std::string &_pUuid) const
Return if there is any publisher stored for the given topic and process UUID.
Definition: TopicStorage.hh:96
bool HasPublisher(const std::string &_addr) const
Return if the requested publisher's address is stored.
Definition: TopicStorage.hh:109
void PublishersByProc(const std::string &_pUuid, std::map< std::string, std::vector< T >> &_pubs) const
Given a process UUID, the function returns the list of publishers contained in this process UUID with...
Definition: TopicStorage.hh:248
Definition: AdvertiseOptions.hh:25
Store address information about topics and provide convenient methods for adding new topics...
Definition: TopicStorage.hh:37
void TopicList(std::vector< std::string > &_topics) const
Get the list of topics currently stored.
Definition: TopicStorage.hh:271