/home/tetron/hack/vos/libs/vos/vutil/url.hh
Go to the documentation of this file.00001 /* 00002 This file is part of the Virtual Object System of 00003 the Interreality project (http://interreality.org). 00004 00005 Copyright (C) 2001-2004 Peter Amstutz 00006 00007 This library is free software; you can redistribute it and/or 00008 modify it under the terms of the GNU Lesser General Public 00009 License as published by the Free Software Foundation; either 00010 version 2 of the License, or (at your option) any later version. 00011 00012 This library is distributed in the hope that it will be useful, 00013 but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00015 Lesser General Public License for more details. 00016 00017 You should have received a copy of the GNU Lesser General Public 00018 License along with this library; if not, write to the Free Software 00019 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00020 00021 Peter Amstutz <http://www.interreality.org> 00022 */ 00023 #ifndef _VUTIL_URL_HH_ 00024 #define _VUTIL_URL_HH_ 00025 00026 /** @file 00027 Defines URL class. 00028 */ 00029 00030 #include <string> 00031 #include <stdexcept> 00032 00033 #include <boost/thread/mutex.hpp> 00034 00035 #include <vos/vutil/vutildefs.hh> 00036 00037 namespace VUtil 00038 { 00039 /** @class BadURLError url.hh vos/vos/url.hh 00040 @ingroup libvutil 00041 */ 00042 class VUTIL_API BadURLError : public std::runtime_error { 00043 public: 00044 BadURLError(const std::string& s) : runtime_error(s) { } 00045 }; 00046 00047 /** @class URL url.hh vos/vos/url.hh 00048 @ingroup libvos 00049 A class implementing basic handling of Uniform Resource Locator 00050 (URL) expressions. 00051 */ 00052 class VUTIL_API URL 00053 { 00054 private: 00055 mutable boost::mutex url_mutex; 00056 00057 std::string protocol; 00058 std::string host; 00059 std::string port; 00060 std::string path; 00061 std::string hostandport; 00062 std::string allbutpath; 00063 00064 std::string urlstr; 00065 00066 static URL& defaults(); 00067 void makeURLstr(); 00068 00069 void parse(const std::string& s); 00070 public: 00071 00072 /** Construct a URL using the default fields. 00073 */ 00074 URL(); 00075 00076 /** Construct a URL using the supplied fields 00077 @param protocol the protocol field 00078 @param host the host field 00079 @param port the port field 00080 @param path everything after the port 00081 */ 00082 URL(const std::string& protocol, 00083 const std::string& host, 00084 const std::string& port, 00085 const std::string& path); 00086 00087 /** Construct a URL by parsing the supplied URL std::string. 00088 Empty fields will be filled 00089 in using the default if they are not found! 00090 @param url a URL in the usual form ("protocol://host:port/path") 00091 @throws BadURLError if 00092 */ 00093 URL(const std::string& url); 00094 00095 URL(const URL& url); 00096 00097 URL& operator=(const URL& u); 00098 URL& operator=(const std::string& s); 00099 00100 /** Get a std::string representation of the URL in the usual form 00101 ("protocol://host:port/path") 00102 @return the URL std::string 00103 */ 00104 std::string getString() const; 00105 00106 /** Set a URL object used to supply default fields used by the constructors. 00107 @param url an already-initialized URL object 00108 */ 00109 static void setDefaults(URL& url); 00110 00111 /** @return the protocol field */ 00112 std::string getProtocol() const; 00113 00114 /** @return the host field */ 00115 std::string getHost() const; 00116 00117 /** @return the port field */ 00118 std::string getPort() const; 00119 00120 /** @return the path field */ 00121 std::string getPath() const; 00122 00123 /** @return the host and port in the form "host:port" */ 00124 std::string getHostAndPort() const; 00125 00126 /** @return everything but the path in the form "proto://host:port" */ 00127 std::string getAllButPath() const; 00128 00129 /** @param p set the protocol field */ 00130 void setProtocol(const std::string& p); 00131 00132 /** @param h set the host field */ 00133 void setHost(const std::string& h); 00134 00135 /** @param p set the port field */ 00136 void setPort(const std::string& p); 00137 00138 /** @param p set the port field */ 00139 void setPort(unsigned int p); 00140 00141 /** @param p set the path field */ 00142 void setPath(const std::string& p); 00143 00144 /** @param hp set the host and port fields together, supplied in 00145 the form "host:port" */ 00146 void setHostAndPort(const std::string& hp); 00147 }; 00148 } 00149 00150 #endif 00151