#include <path.h>
Public Methods | |
Path () | |
Path (const Path &p, unsigned int l) | |
Construct path containing first l components of p. | |
bool | parse (const string &path_string) |
const string& | operator[] (unsigned int i) const |
unsigned int | size () const |
bool | operator== (const Path &p) const |
bool | operator< (const Path &p) const |
Private Attributes | |
vector<string> | path_ |
Friends | |
ostream& | operator<< (ostream &,const Path &path) |
|
Definition at line 10 of file path.h. 00010 {} |
|
Construct path containing first l components of p.
Definition at line 5 of file path.C. 00005 { 00006 unsigned int m(min(p.size(),n)); 00007 path_.resize(m); 00008 for (unsigned int i=0; i<m; ++i) 00009 path_[i] = p[i]; 00010 } |
|
Definition at line 13 of file path.C. Referenced by LogRecord::parse_path().
00013 { 00014 path_.clear(); 00015 /* Decode the parts of the ps into a vector. The first component of the 00016 vector will be empty if the ps starts with '/'. 00017 We also refuse to append empty strings to path_. This handles cases like 00018 "/a//b" which will result in <"","a","b">. 00019 00020 We use n0 to indicate the start position of a component and 00021 n1 to indicate the position just after the end of the component. 00022 */ 00023 string::size_type n0(ps.find_first_not_of('/')); 00024 00025 if (n0!=0) // the path starts with '/' which we encode as a first "/" component. 00026 path_.push_back(""); 00027 00028 if (n0==string::npos) // ps must be "/" 00029 return true; 00030 00031 string::size_type n1(string::npos); 00032 00033 /* The variable n0 points to the start of a component. We make n1 point to 00034 the next '/', if any. The component then is the substring starting at 00035 n0 and ending before n1. 00036 */ 00037 while ((n1=ps.find_first_of('/',n0))!=string::npos) { 00038 if (n1>n0) // only non-empty parts are stored. 00039 path_.push_back(ps.substr(n0,n1-n0)); 00040 n0 = n1+1; 00041 } 00042 // If ps does not end with '/', we must still add the final component. 00043 if (n0<ps.size()) 00044 path_.push_back(ps.substr(n0)); 00045 00046 return true; 00047 } |
|
Definition at line 16 of file path.h. 00016 { return path_[i]; } |
|
Definition at line 17 of file path.h. Referenced by Path(), and operator<<().
00017 { return path_.size(); } |
|
Definition at line 19 of file path.h. 00019 { return path_ == p.path_; } |
|
Definition at line 20 of file path.h. 00020 { return path_ < p.path_; } |
|
|
|
|