33 #include <boost/format.hpp>
37 using namespace boost;
41 const char Scope::COMPONENT_SEPARATOR =
'/';
54 string& normalizedString) {
56 throw invalid_argument(
"Empty scope string given.");
58 string::const_iterator prev = s.begin();
60 if (*prev != Scope::COMPONENT_SEPARATOR) {
61 throw invalid_argument(
64 "Invalid scope syntax for '%1%': has to begin with '%2%'")
65 % s % Scope::COMPONENT_SEPARATOR));
71 string::const_iterator next = prev + 1;
72 for (; next != s.end(); ++next) {
75 if (*next == Scope::COMPONENT_SEPARATOR) {
76 if (distance(prev, next) == 1) {
77 throw invalid_argument(
80 "Invalid scope syntax for '%1%' at char %2%: zero-length component between two '%3%'")
81 % s % distance(s.begin(), next)
82 % Scope::COMPONENT_SEPARATOR));
84 components.push_back(
string(prev + 1, next));
90 else if (!((
'a' <= *next && *next <=
'z')
91 || (
'A' <= *next && *next <=
'Z')
92 || (
'0' <= *next && *next <=
'9')
93 || (*next ==
'_') || (*next ==
'-'))) {
94 throw invalid_argument(
97 "Invalid scope syntax for '%1%' at char %2%: invalid character '%3%'")
98 % s % distance(s.begin(), next) % *next));
103 if (prev + 1 != next) {
104 components.push_back(
string(prev + 1, next));
109 normalizedString = s;
110 if (*(--s.end()) != Scope::COMPONENT_SEPARATOR) {
111 normalizedString += Scope::COMPONENT_SEPARATOR;
116 Scope::Scope(
const string& s) :
151 for (vector<string>::const_iterator it = childScope.
components.begin();
166 for (
size_t i = 0; i < other.
components.size(); ++i) {
181 for (
size_t i = 0; i <
components.size(); ++i) {
191 unsigned int scopesize = 1;
192 for (vector<string>::const_iterator it =
components.begin();
194 scopesize += it->size() + 1;
200 for (vector<string>::const_iterator it =
components.begin();
202 std::copy(it->begin(), it->end(), cursor);
203 cursor += it->size();
210 vector<Scope> result;
215 for (
size_t requiredComponents = 0;
217 ++requiredComponents) {
220 for (
size_t i = 0; i < requiredComponents; ++i) {
224 result.push_back(super);
231 result.push_back(*
this);
246 return stream <<
"Scope[" << scope.
toString() <<
"]";
bool isSubScopeOf(const Scope &other) const
Tests whether this scope is a sub-scope of the given other scope, which means that the other scope is...
const std::string & toString() const
Reconstructs a fully formal string representation of the scope with leading an trailing slashes...
Scope()
Creates a scope representing "/".
void verifyAndSplit(const string &s, vector< string > &components, string &normalizedString)
Validate that s satisfies the regular expression /([-_a-zA-Z0-9]+/)* and splits it at '/' characters...
void updateStringCache()
Updates the contents of scopestring based on components.
const std::vector< std::string > & getComponents() const
Returns all components of the scope as an ordered list.
ostream & operator<<(ostream &stream, const MetaData &meta)
bool operator==(const Scope &other) const
static const char COMPONENT_SEPARATOR
virtual ~Scope()
Destructor.
bool operator<(const Scope &other) const
Scope concat(const Scope &childScope) const
Creates a new scope that is a sub-scope of this one with the subordinated scope described by the give...
bool isSuperScopeOf(const Scope &other) const
Inverse operation of isSubScopeOf.
std::vector< Scope > superScopes(const bool &includeSelf=false) const
Generates all super scopes of this scope including the root scope "/".
std::vector< std::string > components
Scope is a descriptor for a hierarchical channel of the unified bus.