11 #ifndef HPP_SERVICE_ENTITY_ID_HPP_
12 #define HPP_SERVICE_ENTITY_ID_HPP_
14 #include "rtixmlutils/rtixmlutils_object.h"
16 #include <rti/service/log/LogConfig.hpp>
18 namespace rti {
namespace service {
20 class EntityFullNameIterator {
23 EntityFullNameIterator(
const std::string& full_name)
24 : full_name_(full_name), substring_pos_(0), next_substring_pos_(0)
29 ~EntityFullNameIterator()
35 return substring_pos_ == full_name_.length();
38 EntityFullNameIterator& end()
40 substring_pos_ = full_name_.length();
41 next_substring_pos_ = substring_pos_;
46 EntityFullNameIterator& last()
48 next_substring_pos_ = full_name_.length();
49 substring_pos_ = next_substring_pos_;
51 for (; substring_pos_ > 0; --substring_pos_) {
52 if (full_name_[substring_pos_] ==
'\"') {
53 size_t opening_quotes = full_name_.rfind(
56 if (opening_quotes == std::string::npos) {
59 "detected unbalanced escaped name. Missing closing '\"'?");
62 substring_pos_ = opening_quotes;
64 }
else if (full_name_.find(
65 RTIXMLUTILS_OBJECT_NAME_SEPARATOR,
66 substring_pos_) == substring_pos_) {
67 substring_pos_ += strlen(RTIXMLUTILS_OBJECT_NAME_SEPARATOR);
77 size_t parent_length = (substring_pos_ == 0)
79 : substring_pos_ - strlen(RTIXMLUTILS_OBJECT_NAME_SEPARATOR);
80 return full_name_.substr(0, parent_length);
83 std::string operator*()
const
85 size_t substring_pos = substring_pos_;
86 size_t name_length = next_substring_pos_ - substring_pos_;
88 && full_name_[substring_pos_ + name_length - 1] ==
'\"'
89 && full_name_[substring_pos_] ==
'\"') {
94 return full_name_.substr(substring_pos, name_length);
97 EntityFullNameIterator& operator++()
103 std::string escaped()
105 size_t substring_pos = substring_pos_;
106 size_t name_length = next_substring_pos_ - substring_pos_;
108 return full_name_.substr(substring_pos, name_length);
111 friend bool operator==(
112 const EntityFullNameIterator &s1,
113 const EntityFullNameIterator &s2)
115 return s1.substring_pos_ == s2.substring_pos_
116 && s1.next_substring_pos_ == s2.next_substring_pos_
117 && s1.full_name_.c_str() == s2.full_name_.c_str();
120 friend bool operator!=(
121 const EntityFullNameIterator &s1,
122 const EntityFullNameIterator &s2)
133 RTIXMLUTILS_OBJECT_NAME_SEPARATOR,
134 next_substring_pos_) == next_substring_pos_) {
135 next_substring_pos_ += strlen(RTIXMLUTILS_OBJECT_NAME_SEPARATOR);
138 substring_pos_ = next_substring_pos_;
140 for (; next_substring_pos_ < full_name_.length(); ++next_substring_pos_) {
141 if (full_name_[next_substring_pos_] ==
'\"') {
142 size_t closing_quotes = full_name_.find(
144 next_substring_pos_ + 1);
145 if (closing_quotes == std::string::npos) {
148 "detected unbalanced escaped name. Missing closing '\"'?");
151 next_substring_pos_ = closing_quotes;
153 }
else if (full_name_.find(
154 RTIXMLUTILS_OBJECT_NAME_SEPARATOR,
155 next_substring_pos_) == next_substring_pos_) {
162 const std::string& full_name_;
163 size_t substring_pos_;
164 size_t next_substring_pos_;
167 template<
typename ENTITY_KIND_TYPE>
170 typedef EntityFullNameIterator name_iterator;
174 EntityId(
const std::string& the_full_name, ENTITY_KIND_TYPE the_kind)
175 : full_name_(the_full_name), kind_(the_kind)
181 return kind_ == ENTITY_KIND_TYPE::count_;
184 name_iterator begin()
const
186 return EntityFullNameIterator(full_name_);
189 name_iterator end()
const
191 return EntityFullNameIterator(full_name_).end();
194 const std::string& full_name()
const
199 const std::string name()
const
201 return (*EntityFullNameIterator(full_name_).last());
204 const std::string parent_name()
const
206 return EntityFullNameIterator(full_name_).last().parent();
209 const ENTITY_KIND_TYPE& kind()
const
214 static EntityId<ENTITY_KIND_TYPE> nil()
216 static EntityId<ENTITY_KIND_TYPE> nil(
218 ENTITY_KIND_TYPE::count_);
223 friend bool operator==(
224 const EntityId<ENTITY_KIND_TYPE>& left,
225 const EntityId<ENTITY_KIND_TYPE>& right)
227 return left.kind_ == right.kind_
228 && left.full_name_ == right.full_name_;
232 std::string full_name_;
233 ENTITY_KIND_TYPE kind_;
239 #endif //HPP_SERVICE_ENTITY_ID_HPP_