Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Compound List | File List | Namespace Members | Compound Members | File Members | Related Pages | Examples

vos/corelibs/vos/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-2003 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 <tetron@interreality.org>
00022 */
00023 #ifndef _URL_HH_
00024 #define _URL_HH_
00025 
00026 /** @file
00027     Defines URL.
00028 */
00029 
00030 #include <vos/corelibs/vos/vosdefs.hh>
00031 
00032 #include <string>
00033 #include <stdexcept>
00034 
00035 
00036 namespace VOS
00037 {
00038 /** @class URL url.hh vos/corelibs/vos/url.hh
00039  * A class implementing basic handling of Uniform Resource Locator
00040     (URL) expressions.
00041  */
00042 class VOS_API URL
00043 {
00044 private:
00045     string protocol;
00046     string host;
00047     string port;
00048     string path;
00049     string urlstr;
00050     string hostandport;
00051     static URL defaults;
00052     void makeURLstr();
00053 public:
00054     class BadURLError : public runtime_error {
00055     public:
00056         BadURLError(const string& s) : runtime_error(s) { }
00057     };
00058 
00059     /** Construct a URL using the default fields.
00060      */
00061     URL();
00062 
00063     /** Construct a URL using the supplied fields
00064         @param protocol the protocol field
00065         @param host the host field
00066         @param port the port field
00067         @param path everything after the port
00068      */
00069     URL(const string& protocol,
00070         const string& host,
00071         const string& port,
00072         const string& path);
00073 
00074     /** Construct a URL by parsing the supplied URL string.
00075         Empty fields will be filled
00076         in using the default if they are not found!
00077         @param url a URL in the usual form ("protocol://host:port/path")
00078         @throws BadURLError if
00079     */
00080     URL(const string& url) throw (BadURLError);
00081 
00082 
00083     /** Get a string representation of the URL in the usual form
00084         ("protocol://host:port/path")
00085         @return the URL string
00086      */
00087     const string& getString() const;
00088 
00089     /** Set a URL object used to supply default fields used by the constructors.
00090         @param url an already-initialized URL object
00091     */
00092     static void setDefaults(const URL& url);
00093 
00094     /** @return the protocol field */
00095     const string& getProtocol() const;
00096 
00097     /** @return the host field */
00098     const string& getHost() const;
00099 
00100     /** @return the port field */
00101     const string& getPort() const;
00102 
00103     /** @return the path field */
00104     const string& getPath() const;
00105 
00106     /** @return the host and port in the form "host:port" */
00107     const string& getHostAndPort() const;
00108 
00109     /** @param p set the protocol field */
00110     void setProtocol(const string& p);
00111 
00112     /** @param h set the host field */
00113     void setHost(const string& h);
00114 
00115     /** @param p set the port field */
00116     void setPort(const string& p);
00117 
00118     /** @param p set the path field */
00119     void setPath(const string& p);
00120 
00121     /** @param hp set the host and port fields together, supplied in
00122         the form "host:port" */
00123     void setHostAndPort(const string& hp);
00124 };
00125 }
00126 
00127 #endif

Generated on Tue Aug 12 03:55:42 2003 for Interreality Project - VOS by doxygen 1.3.2