11 #ifndef HPP_SERVICE_ENTITY_ID_HPP_
12 #define HPP_SERVICE_ENTITY_ID_HPP_
14 #include "rtixmlutils/rtixmlutils_object.h"
16 namespace rti {
namespace service {
18 class EntityFullNameIterator {
21 EntityFullNameIterator(
22 const std::string& full_name)
23 : full_name_(full_name), substring_pos_(0), next_substring_pos_(0)
28 ~EntityFullNameIterator()
34 size_t name_length = next_substring_pos_ - substring_pos_;
35 if (next_substring_pos_ != full_name_.length()) {
36 name_length -= strlen(RTIXMLUTILS_OBJECT_NAME_SEPARATOR);
44 return substring_pos_ == full_name_.length();
47 EntityFullNameIterator& end()
49 substring_pos_ = full_name_.length();
50 next_substring_pos_ = substring_pos_;
55 EntityFullNameIterator& begin()
58 next_substring_pos_ = first_position();
66 size_t parent_length = substring_pos_ == 0
68 : substring_pos_ - strlen(RTIXMLUTILS_OBJECT_NAME_SEPARATOR);
69 return full_name_.substr(0, parent_length);
72 std::string operator*()
const
75 return full_name_.substr(substring_pos_, length());
78 EntityFullNameIterator& operator++()
84 EntityFullNameIterator& operator--()
90 friend bool operator==(
91 const EntityFullNameIterator &s1,
92 const EntityFullNameIterator &s2)
94 return s1.substring_pos_ == s2.substring_pos_
95 && s1.next_substring_pos_ == s2.next_substring_pos_
96 && s1.full_name_.c_str() == s2.full_name_.c_str();
99 friend bool operator!=(
100 const EntityFullNameIterator &s1,
101 const EntityFullNameIterator &s2)
111 substring_pos_ = next_substring_pos_;
112 next_substring_pos_ = full_name_.find(
113 RTIXMLUTILS_OBJECT_NAME_SEPARATOR,
114 next_substring_pos_);
115 if (next_substring_pos_ != std::string::npos) {
116 next_substring_pos_ += strlen(RTIXMLUTILS_OBJECT_NAME_SEPARATOR);
118 next_substring_pos_ = full_name_.length();
124 next_substring_pos_ = substring_pos_;
125 if (!is_last() && substring_pos_ != 0) {
126 substring_pos_ -= strlen(RTIXMLUTILS_OBJECT_NAME_SEPARATOR) + 1;
128 substring_pos_ = full_name_.rfind(
129 RTIXMLUTILS_OBJECT_NAME_SEPARATOR,
131 if (substring_pos_ == std::string::npos
132 || substring_pos_ == 0) {
135 substring_pos_ += strlen(RTIXMLUTILS_OBJECT_NAME_SEPARATOR);
139 size_t first_position()
141 size_t substring_pos = 0;
142 if (full_name_.find(RTIXMLUTILS_OBJECT_NAME_SEPARATOR, 0) == 0) {
143 substring_pos += strlen(RTIXMLUTILS_OBJECT_NAME_SEPARATOR);
145 return substring_pos;
149 const std::string& full_name_;
150 size_t substring_pos_;
151 size_t next_substring_pos_;
154 template<
typename ENTITY_KIND_TYPE>
157 typedef EntityFullNameIterator name_iterator;
161 EntityId(
const std::string& the_full_name, ENTITY_KIND_TYPE the_kind)
162 : full_name_(the_full_name), kind_(the_kind)
168 return kind_ == ENTITY_KIND_TYPE::count_;
171 name_iterator begin()
const
173 return EntityFullNameIterator(full_name_);
176 name_iterator end()
const
178 return EntityFullNameIterator(full_name_).end();
181 const std::string& full_name()
const
186 const std::string name()
const
191 const std::string parent_name()
const
193 return (--end()).parent();
196 const ENTITY_KIND_TYPE& kind()
const
201 static EntityId<ENTITY_KIND_TYPE> nil()
203 static EntityId<ENTITY_KIND_TYPE> nil(
205 ENTITY_KIND_TYPE::count_);
211 std::string full_name_;
212 ENTITY_KIND_TYPE kind_;
218 #endif //HPP_SERVICE_ENTITY_ID_HPP_