libmoost
/home/mhx/git/github/libmoost/include/moost/murcl/uri_elements.hpp
Go to the documentation of this file.
00001 /* vim:set ts=3 sw=3 sts=3 et: */
00037 #ifndef FM_LAST_MOOST_MURCL_URI_ELEMENTS_HPP__
00038 #define FM_LAST_MOOST_MURCL_URI_ELEMENTS_HPP__
00039 
00040 #include <string>
00041 #include <sstream>
00042 #include <map>
00043 
00044 #include <curl/curl.h>
00045 
00046 #include <boost/lexical_cast.hpp>
00047 
00048 #include "uri_params.hpp"
00049 #include "uri_scheme.hpp"
00050 #include "uri_encoder.hpp"
00051 
00052 namespace moost { namespace murcl {
00053 
00057 class uri_elements
00058 {
00059 public:
00068    uri_elements(
00069       uri_scheme const & scheme,
00070       std::string const & host
00071     )
00072       : scheme_(scheme.get())
00073       , host_(host)
00074       , port_(boost::lexical_cast<std::string>(scheme.get_port()))
00075    {
00076       encode();
00077    }
00078 
00089   uri_elements(
00090       uri_scheme const & scheme,
00091       std::string const & host,
00092       std::string const & path
00093     )
00094       : scheme_(scheme.get())
00095       , host_(host)
00096       , port_(boost::lexical_cast<std::string>(scheme.get_port()))
00097       , path_(path)
00098    {
00099       encode();
00100    }
00101 
00114    uri_elements(
00115       uri_scheme const & scheme,
00116       std::string const & host,
00117       std::string const & path,
00118       uri_params const & params
00119     )
00120       : scheme_(scheme.get())
00121       , host_(host)
00122       , port_(boost::lexical_cast<std::string>(scheme.get_port()))
00123       , path_(path)
00124       , params_(params)
00125    {
00126       encode();
00127    }
00128 
00141    uri_elements(
00142       uri_scheme const & scheme,
00143       std::string const & host,
00144       std::string const & path,
00145       uri_params::map_t const & map
00146     )
00147       : scheme_(scheme.get())
00148       , host_(host)
00149       , port_(boost::lexical_cast<std::string>(scheme.get_port()))
00150       , path_(path)
00151       , params_(uri_params(map))
00152    {
00153       encode();
00154    }
00155 
00162    std::string const & get_scheme() const
00163    {
00164       return scheme_;
00165    }
00166 
00173    std::string const & get_host() const
00174    {
00175       return host_;
00176    }
00177 
00184    std::string const & get_port() const
00185    {
00186       return port_;
00187    }
00188 
00195    std::string const & get_path() const
00196    {
00197       return path_;
00198    }
00199 
00206    std::string const & get_params() const
00207    {
00208       return params_;
00209    }
00210 
00211 private:
00212    // uri encode stuff
00213    void encode()
00214    {
00215       // scheme should not need to be encoded
00216       uri_encoder::encode(host_);
00217       uri_encoder::encode(path_);
00218       // params don't need encoding as the uri_params class takes care of that
00219    }
00220 
00221    std::string const scheme_;
00222    std::string const host_;
00223    std::string const port_;
00224    std::string const path_;
00225    std::string const params_;
00226  };
00227 
00228 }}
00229 
00230 
00231 #endif // FM_LAST_MOOST_MURCL_URI_ELEMENTS_HPP__