Changeset 2514

Show
Ignore:
Timestamp:
03/03/10 19:52:08 (6 months ago)
Author:
drobilla
Message:

Remove Raul::Path::root, Raul::Path::prefix, and Raul:Path::scheme from public API.
Add ability to modify root path from application code (before any paths are created).

Location:
trunk
Files:
11 modified

Legend:

Unmodified
Added
Removed
  • trunk/ingen/src/client/ClientStore.cpp

    r2491 r2514  
    178178ClientStore::resource(const URI& uri) 
    179179{ 
    180         if (uri.scheme() == Path::scheme && Path::is_valid(uri.str())) 
     180        if (Path::is_path(uri)) 
    181181                return object(uri.str()); 
    182182        else 
  • trunk/ingen/src/client/ObjectModel.cpp

    r2423 r2514  
    3232        , _meta(ResourceImpl::meta_uri(path)) 
    3333        , _path(path) 
    34         , _symbol((path == Path::root) ? "root" : path.symbol()) 
     34        , _symbol((path == Path::root()) ? "root" : path.symbol()) 
    3535{ 
    3636} 
  • trunk/ingen/src/engine/events/RequestMetadata.cpp

    r2492 r2514  
    6060RequestMetadata::pre_process() 
    6161{ 
    62         const bool is_object = (_uri.scheme() == Path::scheme && Path::is_valid(_uri.str())); 
     62        const bool is_object = Path::is_path(_uri); 
    6363        if (_request->client()) { 
    6464                if (is_object) 
  • trunk/ingen/src/engine/events/SetMetadata.cpp

    r2492 r2514  
    100100        typedef Properties::const_iterator iterator; 
    101101 
    102         bool is_graph_object = (_subject.scheme() == Path::scheme && Path::is_valid(_subject.str())); 
     102        const bool is_graph_object = Path::is_path(_subject); 
    103103 
    104104        _object = is_graph_object 
  • trunk/ingen/src/engine/GraphObjectImpl.cpp

    r2468 r2514  
    3030 
    3131GraphObjectImpl::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()) 
    3333        , _parent(parent) 
    3434        , _path(parent ? parent->path().child(symbol) : "/") 
  • trunk/ingen/src/engine/HTTPEngineReceiver.cpp

    r2429 r2514  
    118118        // Special GET paths 
    119119        if (msg->method == SOUP_METHOD_GET) { 
    120                 if (path == Path::root.str() || path.empty()) { 
     120                if (path == Path::root().str() || path.empty()) { 
    121121                        const string r = string("@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .\n") 
    122122                                .append("\n<> rdfs:seeAlso <plugins> ;") 
  • trunk/ingen/src/serialisation/Parser.cpp

    r2451 r2514  
    300300                        if (URI::is_valid(subject_str)) { 
    301301                                if (subject == document_uri) 
    302                                         subject_str = Path::root.str(); 
     302                                        subject_str = Path::root().str(); 
    303303                                parse_properties(world, target, model, subject, subject_str); 
    304304                        } 
  • trunk/ingen/src/shared/ClashAvoider.cpp

    r2445 r2514  
    3232ClashAvoider::map_uri(const Raul::URI& in) 
    3333{ 
    34         if (in.scheme() == Path::scheme && Path::is_valid(in.str())) 
     34        if (Path::is_path(in)) 
    3535                return map_path(in.str()); 
    3636        else 
  • trunk/raul/raul/Path.hpp

    r2408 r2514  
    3333/** A URI which is a path (for example a filesystem or OSC path). 
    3434 * 
    35  * A Path always has the special URI scheme "path:". 
    36  * 
    3735 * This enforces that a Path is a valid path, where each fragment is a valid 
    3836 * Symbol, separated by exactly one slash (/). 
     
    4038 * A path is divided by slashes (/).  The first character MUST be a slash, and 
    4139 * 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. 
    4443 * 
    4544 * \ingroup raul 
     
    5655        }; 
    5756 
    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); 
    6281 
    6382        /** Construct an uninitialzed path, because the STL is annoying. */ 
    64         Path() : URI(root) {} 
     83        Path() : URI(root()) {} 
    6584 
    6685        /** Construct a Path from an std::string. 
     
    6988         * use is_valid first to check. 
    7089         */ 
    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); 
    7791 
    7892        /** Construct a Path from a C string. 
     
    8195         * use is_valid first to check. 
    8296         */ 
    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) {} 
    89106 
    90107        static bool is_valid(const std::basic_string<char>& path); 
     
    100117        static void replace_invalid_chars(std::string& str, size_t start, bool replace_slash = false); 
    101118 
    102         bool is_root() const { return (*this) == root; } 
     119        bool is_root() const { return (*this) == root(); } 
    103120 
    104121        bool is_child_of(const Path& parent) const; 
     
    124141         */ 
    125142        inline const char* symbol() const { 
    126                 if ((*this) != root) { 
     143                if ((*this) != root()) { 
    127144                        const char* last_slash = strrchr(c_str(), '/'); 
    128145                        if (last_slash) { 
     
    139156         */ 
    140157        inline Path parent() const { 
    141                 if ((*this) == root) { 
     158                if ((*this) == root()) { 
    142159                        return *this; 
    143160                } else { 
    144161                        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); 
    147165                } 
    148166        } 
     
    175193        inline const std::string base() const { 
    176194                std::string ret = str(); 
    177                 if ((*this) == root && ret[ret.length() - 1] == '/') 
     195                if ((*this) == root() && ret[ret.length() - 1] == '/') 
    178196                        return ret; 
    179197                else 
     
    195213                return ( child == parent || (child.length() > parent.length() && 
    196214                                (!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 
     218private: 
     219        inline Path(bool unchecked, const URI& uri) : URI(uri) {} 
    199220}; 
    200221 
  • trunk/raul/src/Path.cpp

    r2408 r2514  
    2222namespace Raul { 
    2323 
    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 + "/"; 
     24static URI root_uri("path:/"); 
     25 
     26const Path Path::root()                         { return Path(true, root_uri); } 
     27void       Path::set_root(const Raul::URI& uri) { root_uri = uri.str(); } 
     28 
     29bool 
     30Path::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 
     38Path::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 
     46Path::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 
    2853 
    2954bool 
    3055Path::is_valid(const std::basic_string<char>& path_str) 
    3156{ 
    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); 
    3771 
    3872        // Must start with a / 
     
    67101/** Convert a string to a valid full path. 
    68102 * 
    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 '/'. 
    71106 */ 
    72107string 
     
    74109{ 
    75110        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); 
    80117 
    81118        // Must start with a / 
    82         if (path.at(start) != '/') 
     119        if (path.empty() || path[0] != '/') 
    83120                path = string("/").append(path); 
    84121 
    85122        // 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 slash 
    88  
    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); 
    92129 
    93130        assert(is_valid(path)); 
  • trunk/raul/wscript

    r2467 r2514  
    55 
    66# Version of this package (even if built as a child) 
    7 RAUL_VERSION = '0.6.4' 
     7RAUL_VERSION = '0.6.5' 
    88 
    99# Library version (UNIX style major, minor, micro) 
     
    2020#   0.6.3 = 6,0,0 (unreleased) 
    2121#   0.6.4 = 7,0,0 (unreleased) 
    22 RAUL_LIB_VERSION = '7.0.0' 
     22#   0.6.5 = 8,0,0 (unreleased) 
     23RAUL_LIB_VERSION = '8.0.0' 
    2324 
    2425# Variables for 'waf dist'