18 #ifndef IGN_TRANSPORT_TOPICSTORAGE_HH_
19 #define IGN_TRANSPORT_TOPICSTORAGE_HH_
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();
96 public:
bool HasTopic(
const std::string &_topic,
97 const std::string &_type)
const
99 if (!this->HasTopic(_topic))
103 auto &m = this->data.at(_topic);
105 for (
auto const &procs : m)
108 auto &v = procs.second;
109 auto found = std::find_if(v.begin(), v.end(),
112 return _pub.MsgTypeName() == _type ||
117 if (found != v.end())
131 const std::string &_pUuid)
const
133 if (!this->HasTopic(_topic))
136 return this->data.at(_topic).find(_pUuid) !=
137 this->data.at(_topic).end();
145 for (
auto const &topic : this->data)
147 for (
auto const &proc : topic.second)
149 for (
auto const &pub : proc.second)
151 if (pub.Addr() == _addr)
166 const std::string &_pUuid,
167 const std::string &_nUuid,
171 if (this->data.find(_topic) == this->data.end())
175 auto &m = this->data.at(_topic);
178 if (m.find(_pUuid) == m.end())
182 auto &v = m.at(_pUuid);
183 auto found = std::find_if(v.begin(), v.end(),
186 return _pub.NUuid() == _nUuid;
189 if (found != v.end())
204 std::map<std::string, std::vector<T>> &_info)
const
206 if (!this->HasTopic(_topic))
209 _info = this->data.at(_topic);
219 const std::string &_pUuid,
220 const std::string &_nUuid)
225 if (this->data.find(_topic) != this->data.end())
228 auto &m = this->data[_topic];
231 if (m.find(_pUuid) != m.end())
235 auto priorSize = v.size();
236 v.erase(std::remove_if(v.begin(), v.end(),
239 return _pub.NUuid() == _nUuid;
242 counter = priorSize - v.size();
248 this->data.erase(_topic);
263 for (
auto it = this->data.begin(); it != this->data.end();)
266 auto &m = it->second;
267 counter += m.erase(_pUuid);
269 this->data.erase(it++);
283 std::map<std::string, std::vector<T>> &_pubs)
const
288 for (
auto const &topic : this->data)
291 auto &m = topic.second;
292 if (m.find(_pUuid) != m.end())
294 auto &v = m.at(_pUuid);
295 for (
auto const &pub : v)
297 _pubs[pub.NUuid()].push_back(T(pub));
309 const std::string &_nUuid,
310 std::vector<T> &_pubs)
const
315 for (
auto const &topic : this->data)
318 auto const &m = topic.second;
319 if (m.find(_pUuid) != m.end())
321 auto const &v = m.at(_pUuid);
322 for (
auto const &pub : v)
324 if (pub.NUuid() == _nUuid)
326 _pubs.push_back(T(pub));
335 public:
void TopicList(std::vector<std::string> &_topics)
const
337 for (
auto const &topic : this->data)
338 _topics.push_back(topic.first);
344 std::cout <<
"---" << std::endl;
345 for (
auto const &topic : this->data)
347 std::cout <<
"[" << topic.first <<
"]" << std::endl;
348 auto &m = topic.second;
349 for (
auto const &proc : m)
351 std::cout <<
"\tProc. UUID: " << proc.first << std::endl;
352 auto &v = proc.second;
353 for (
auto const &publisher : v)
355 std::cout << publisher;
363 private: std::map<std::string,
364 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 HasTopic(const std::string &_topic) const
Return if there is any publisher stored for the given topic.
Definition: TopicStorage.hh:85
void Print() const
Print all the information for debugging purposes.
Definition: TopicStorage.hh:342
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:130
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:165
bool HasTopic(const std::string &_topic, const std::string &_type) const
Return if there is any publisher stored for the given topic and type.
Definition: TopicStorage.hh:96
void PublishersByNode(const std::string &_pUuid, const std::string &_nUuid, std::vector< T > &_pubs) const
Given a process UUID and the node UUID, the function returns the list of publishers contained in the ...
Definition: TopicStorage.hh:308
bool DelPublishersByProc(const std::string &_pUuid)
Remove all the publishers associated to a given process.
Definition: TopicStorage.hh:258
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:282
void TopicList(std::vector< std::string > &_topics) const
Get the list of topics currently stored.
Definition: TopicStorage.hh:335
bool HasPublisher(const std::string &_addr) const
Return if the requested publisher's address is stored.
Definition: TopicStorage.hh:143
#define IGNITION_TRANSPORT_VISIBLE
Use to represent "symbol visible" if supported.
Definition: Helpers.hh:57
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:218
const std::string kGenericMessageType
The string type used for generic messages.
Definition: TransportTypes.hh:132
Store address information about topics and provide convenient methods for adding new topics...
Definition: TopicStorage.hh:37
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:203