Changeset 2514
- Timestamp:
- 03/03/10 19:52:08 (6 months ago)
- Location:
- trunk
- Files:
-
- 11 modified
-
ingen/src/client/ClientStore.cpp (modified) (1 diff)
-
ingen/src/client/ObjectModel.cpp (modified) (1 diff)
-
ingen/src/engine/events/RequestMetadata.cpp (modified) (1 diff)
-
ingen/src/engine/events/SetMetadata.cpp (modified) (1 diff)
-
ingen/src/engine/GraphObjectImpl.cpp (modified) (1 diff)
-
ingen/src/engine/HTTPEngineReceiver.cpp (modified) (1 diff)
-
ingen/src/serialisation/Parser.cpp (modified) (1 diff)
-
ingen/src/shared/ClashAvoider.cpp (modified) (1 diff)
-
raul/raul/Path.hpp (modified) (10 diffs)
-
raul/src/Path.cpp (modified) (3 diffs)
-
raul/wscript (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ingen/src/client/ClientStore.cpp
r2491 r2514 178 178 ClientStore::resource(const URI& uri) 179 179 { 180 if ( uri.scheme() == Path::scheme && Path::is_valid(uri.str()))180 if (Path::is_path(uri)) 181 181 return object(uri.str()); 182 182 else -
trunk/ingen/src/client/ObjectModel.cpp
r2423 r2514 32 32 , _meta(ResourceImpl::meta_uri(path)) 33 33 , _path(path) 34 , _symbol((path == Path::root ) ? "root" : path.symbol())34 , _symbol((path == Path::root()) ? "root" : path.symbol()) 35 35 { 36 36 } -
trunk/ingen/src/engine/events/RequestMetadata.cpp
r2492 r2514 60 60 RequestMetadata::pre_process() 61 61 { 62 const bool is_object = (_uri.scheme() == Path::scheme && Path::is_valid(_uri.str()));62 const bool is_object = Path::is_path(_uri); 63 63 if (_request->client()) { 64 64 if (is_object) -
trunk/ingen/src/engine/events/SetMetadata.cpp
r2492 r2514 100 100 typedef Properties::const_iterator iterator; 101 101 102 bool is_graph_object = (_subject.scheme() == Path::scheme && Path::is_valid(_subject.str()));102 const bool is_graph_object = Path::is_path(_subject); 103 103 104 104 _object = is_graph_object -
trunk/ingen/src/engine/GraphObjectImpl.cpp
r2468 r2514 30 30 31 31 GraphObjectImpl::GraphObjectImpl(GraphObjectImpl* parent, const Symbol& symbol) 32 : ResourceImpl(parent ? parent->path().child(symbol) : Raul::Path::root .child(symbol))32 : ResourceImpl(parent ? parent->path().child(symbol) : Raul::Path::root()) 33 33 , _parent(parent) 34 34 , _path(parent ? parent->path().child(symbol) : "/") -
trunk/ingen/src/engine/HTTPEngineReceiver.cpp
r2429 r2514 118 118 // Special GET paths 119 119 if (msg->method == SOUP_METHOD_GET) { 120 if (path == Path::root .str() || path.empty()) {120 if (path == Path::root().str() || path.empty()) { 121 121 const string r = string("@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .\n") 122 122 .append("\n<> rdfs:seeAlso <plugins> ;") -
trunk/ingen/src/serialisation/Parser.cpp
r2451 r2514 300 300 if (URI::is_valid(subject_str)) { 301 301 if (subject == document_uri) 302 subject_str = Path::root .str();302 subject_str = Path::root().str(); 303 303 parse_properties(world, target, model, subject, subject_str); 304 304 } -
trunk/ingen/src/shared/ClashAvoider.cpp
r2445 r2514 32 32 ClashAvoider::map_uri(const Raul::URI& in) 33 33 { 34 if ( in.scheme() == Path::scheme && Path::is_valid(in.str()))34 if (Path::is_path(in)) 35 35 return map_path(in.str()); 36 36 else -
trunk/raul/raul/Path.hpp
r2408 r2514 33 33 /** A URI which is a path (for example a filesystem or OSC path). 34 34 * 35 * A Path always has the special URI scheme "path:".36 *37 35 * This enforces that a Path is a valid path, where each fragment is a valid 38 36 * Symbol, separated by exactly one slash (/). … … 40 38 * A path is divided by slashes (/). The first character MUST be a slash, and 41 39 * the last character MUST NOT be a slash (except in the special case of the 42 * root path "/", which is the only valid single-character path). The path: 43 * scheme is added automatically (since a Patch is actually a URI). 40 * root path "/", which is the only valid single-character path). A Path 41 * is actually a URI, the relative path is appended to the root URI 42 * automatically, so a Patch can always be used as a URI. 44 43 * 45 44 * \ingroup raul … … 56 55 }; 57 56 58 static const std::string scheme; 59 static const std::string prefix; 60 static const size_t prefix_len; 61 static const Path root; 57 /** Return the root path. 58 * The default root path is the URI "path:/" 59 * 60 * A Path is either the root path, or a child of a root path (i.e. the root 61 * path followed by a sequence of Symbols separated by '/') 62 */ 63 static const Path root(); 64 65 /** Set the root path. 66 * The default root path is the URI "path:/" 67 * 68 * Note this should be done on application start up. Changing the root 69 * path while any Path objects exist will break things horribly; don't! 70 * 71 * The root can be set to any URI, there are no restrictions on valid 72 * characters and such like there are for relative paths (but it must be 73 * a valid URI, i.e. begin with a scheme, and in particular not begin 74 * with '/'). Relative paths are appended to the root path's URI, 75 * i.e. every Path, as a string, begins with the root URI. The part after 76 * that is a strict path (a sequence of Symbols separated by '/'). 77 */ 78 static void set_root(const Raul::URI& uri); 79 80 static bool is_path(const Raul::URI& uri); 62 81 63 82 /** Construct an uninitialzed path, because the STL is annoying. */ 64 Path() : URI(root ) {}83 Path() : URI(root()) {} 65 84 66 85 /** Construct a Path from an std::string. … … 69 88 * use is_valid first to check. 70 89 */ 71 Path(const std::basic_string<char>& path) 72 : URI((path.find(":") == std::string::npos) ? prefix + path : path) 73 { 74 if (!is_valid(str())) 75 throw BadPath(str()); 76 } 90 Path(const std::basic_string<char>& path); 77 91 78 92 /** Construct a Path from a C string. … … 81 95 * use is_valid first to check. 82 96 */ 83 Path(const char* cpath) 84 : URI((std::string(cpath).find(":") == std::string::npos) ? prefix + cpath : cpath) 85 { 86 if (!is_valid(str())) 87 throw BadPath(str()); 88 } 97 Path(const char* cpath); 98 99 100 /** Construct a Path from another path. 101 * 102 * This is faster than constructing a path from the other path's string 103 * representation, since validity checking is avoided. 104 */ 105 Path(const Path& copy) : URI(copy) {} 89 106 90 107 static bool is_valid(const std::basic_string<char>& path); … … 100 117 static void replace_invalid_chars(std::string& str, size_t start, bool replace_slash = false); 101 118 102 bool is_root() const { return (*this) == root ; }119 bool is_root() const { return (*this) == root(); } 103 120 104 121 bool is_child_of(const Path& parent) const; … … 124 141 */ 125 142 inline const char* symbol() const { 126 if ((*this) != root ) {143 if ((*this) != root()) { 127 144 const char* last_slash = strrchr(c_str(), '/'); 128 145 if (last_slash) { … … 139 156 */ 140 157 inline Path parent() const { 141 if ((*this) == root ) {158 if ((*this) == root()) { 142 159 return *this; 143 160 } else { 144 161 const std::string str(this->str()); 145 const size_t last_slash = str.find_last_of('/'); 146 return (last_slash == prefix_len) ? root : str.substr(0, last_slash); 162 const size_t first_slash = str.find('/'); 163 const size_t last_slash = str.find_last_of('/'); 164 return (first_slash == last_slash) ? root() : str.substr(0, last_slash); 147 165 } 148 166 } … … 175 193 inline const std::string base() const { 176 194 std::string ret = str(); 177 if ((*this) == root && ret[ret.length() - 1] == '/')195 if ((*this) == root() && ret[ret.length() - 1] == '/') 178 196 return ret; 179 197 else … … 195 213 return ( child == parent || (child.length() > parent.length() && 196 214 (!std::strncmp(parent.c_str(), child.c_str(), parent.length()) 197 && (parent == root || child.str()[parent.length()] == '/'))) ); 198 } 215 && (parent == root() || child.str()[parent.length()] == '/'))) ); 216 } 217 218 private: 219 inline Path(bool unchecked, const URI& uri) : URI(uri) {} 199 220 }; 200 221 -
trunk/raul/src/Path.cpp
r2408 r2514 22 22 namespace Raul { 23 23 24 const string Path::scheme = "path"; 25 const string Path::prefix = Path::scheme + ":"; 26 const size_t Path::prefix_len = prefix.length(); 27 const Path Path::root = Path::prefix + "/"; 24 static URI root_uri("path:/"); 25 26 const Path Path::root() { return Path(true, root_uri); } 27 void Path::set_root(const Raul::URI& uri) { root_uri = uri.str(); } 28 29 bool 30 Path::is_path(const Raul::URI& uri) 31 { 32 return uri.length() >= root_uri.length() 33 && uri.substr(0, root_uri.length()) == root_uri.str() 34 && Path::is_valid(uri.str()); 35 } 36 37 38 Path::Path(const std::basic_string<char>& path) 39 : URI(path[0] == '/' ? root_uri.str() + path.substr(1) : path) 40 { 41 if (!is_valid(str())) 42 throw BadPath(str()); 43 } 44 45 46 Path::Path(const char* cpath) 47 : URI(cpath[0] == '/' ? root_uri.str() + (cpath + 1) : cpath) 48 { 49 if (!is_valid(str())) 50 throw BadPath(str()); 51 } 52 28 53 29 54 bool 30 55 Path::is_valid(const std::basic_string<char>& path_str) 31 56 { 32 const size_t colon = path_str.find(":"); 33 const string path = (colon == string::npos) ? path_str : path_str.substr(colon + 1); 34 35 if (path.length() == 0) 36 return false; 57 if (path_str.length() == 0) 58 return false; 59 60 if (path_str == root_uri.str()) 61 return true; 62 63 if (path_str[0] != '/' && 64 (path_str.length() < root_uri.length() 65 || path_str.substr(0, root_uri.length()) != root_uri.str())) 66 return false; 67 68 const string path = (path_str[0] == '/') 69 ? path_str 70 : path_str.substr(root_uri.length() - 1); 37 71 38 72 // Must start with a / … … 67 101 /** Convert a string to a valid full path. 68 102 * 69 * This will make a best effort at turning @a str into a complete, valid 70 * Path, and will always return one. 103 * The returned string is a valid relative path without the root prefix, 104 * i.e. the returned string starts with '/' followed by valid symbols, 105 * each separated by '/'. 71 106 */ 72 107 string … … 74 109 { 75 110 if (str.length() == 0) 76 return root.str(); // this might not be wise? 77 78 string path = (str.substr(0, prefix_len) == prefix) ? str : prefix + str; 79 size_t start = prefix_len + 1; 111 return root().chop_scheme(); // this might not be wise? 112 113 const size_t first_slash = str.find('/'); 114 string path = (first_slash == string::npos) 115 ? string("/").append(str) 116 : str.substr(first_slash); 80 117 81 118 // Must start with a / 82 if (path. at(start)!= '/')119 if (path.empty() || path[0] != '/') 83 120 path = string("/").append(path); 84 121 85 122 // Must not end with a slash unless "/" 86 if (path .length() > prefix_len + 1 && path.at(path.length()-1)== '/')87 path = path.substr(0, path.length() -1); // chop trailing slash88 89 assert(path.find_last_of( "/") != string::npos);90 91 replace_invalid_chars(path, start, false);123 if (path != "/" && path[path.length() - 1] == '/') 124 path = path.substr(0, path.length() - 1); // chop trailing slash 125 126 assert(path.find_last_of('/') != string::npos); 127 128 replace_invalid_chars(path, 0, false); 92 129 93 130 assert(is_valid(path)); -
trunk/raul/wscript
r2467 r2514 5 5 6 6 # Version of this package (even if built as a child) 7 RAUL_VERSION = '0.6. 4'7 RAUL_VERSION = '0.6.5' 8 8 9 9 # Library version (UNIX style major, minor, micro) … … 20 20 # 0.6.3 = 6,0,0 (unreleased) 21 21 # 0.6.4 = 7,0,0 (unreleased) 22 RAUL_LIB_VERSION = '7.0.0' 22 # 0.6.5 = 8,0,0 (unreleased) 23 RAUL_LIB_VERSION = '8.0.0' 23 24 24 25 # Variables for 'waf dist'
