00001
00007 #ifndef ___PATHSPECIFICATION_H___
00008 #define ___PATHSPECIFICATION_H___
00009
00010 #include "stringutils.h"
00011 #include "stringparser.h"
00012
00013
00014
00024 class PathSpecification {
00025 public:
00026 typedef StringParser::arglist NameList;
00027
00029 PathSpecification(const string& s)
00030 : rooted(s.length()>=2 && s[0]==':' && s[1]==':')
00031 {
00032 assert (String::replace_all(s,string(" "),string("")) == s);
00033 const string with_spaces = String::replace_all(s,string("::"),string(" "));
00034
00035
00036 StringParser sp;
00037 sp.parse(with_spaces,names);
00038 }
00039
00041 const string last() const
00042 { return (names.empty()? string() : names.back()); }
00043
00045 const string first() const
00046 { return (names.empty()? string() : names.front()); }
00047
00049 const bool isrooted() const { return rooted; }
00050
00052 const NameList& all() const
00053 { return names; }
00054
00056 const NameList allbutlast() const {
00057 return (names.begin()==names.end()? NameList() :
00058 NameList(names.begin(),names.end()-1));
00059 }
00060
00061 private:
00062 NameList names;
00063 bool rooted;
00064 };
00065
00066
00067
00068 #endif