SAGA C++ API 1.6
|
00001 // Copyright (c) 2005-2011 Hartmut Kaiser 00002 // 00003 // Use, modification and distribution is subject to the Boost Software 00004 // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at 00005 // http://www.boost.org/LICENSE_1_0.txt) 00006 00007 #include <string> 00008 #include <iostream> 00009 00010 #include <saga/saga/url.hpp> 00011 #include <saga/saga/detail/call.hpp> 00012 #include <saga/impl/url.hpp> 00013 #include <saga/impl/exception.hpp> 00014 #include <saga/impl/session.hpp> 00015 00017 namespace saga 00018 { 00019 url::url (std::string const & urlstr) 00020 : saga::object (new impl::url (urlstr)) 00021 { 00022 } 00023 00024 url::url (char const * urlstr) 00025 : saga::object (new impl::url (std::string(urlstr))) 00026 { 00027 } 00028 00029 url::url (std::string const & urlstr, adaptors::nocheck) 00030 : saga::object (new impl::url(urlstr, adaptors::nocheck())) 00031 { 00032 } 00033 00034 url::url (impl::url *impl) 00035 : saga::object (impl) 00036 { 00037 } 00038 00039 url::url (saga::object obj) 00040 : saga::object (obj.clone()) 00041 { 00042 if (this->get_type() != saga::object::URL) 00043 { 00044 SAGA_THROW("Bad type conversion.", saga::BadParameter); 00045 } 00046 } 00047 00048 url::url (saga::url const& rhs) 00049 : saga::object (rhs.clone()) 00050 { 00051 } 00052 00053 url::url (void) 00054 : saga::object (new impl::url("")) 00055 { 00056 } 00057 00058 url::~url (void) 00059 { 00060 } 00061 00062 url& url::operator=(char const * urlstr) 00063 { 00064 set_url(urlstr); 00065 return *this; 00066 } 00067 00068 url& url::operator=(std::string const & urlstr) 00069 { 00070 set_url(urlstr); 00071 return *this; 00072 } 00073 00074 url& url::operator=(url const& rhs) 00075 { 00076 if (&rhs != this) 00077 this->saga::object::operator=(rhs.clone()); 00078 return *this; 00079 } 00080 00081 url& url::operator=(object const& rhs) 00082 { 00083 if (rhs.get_type() != saga::object::URL) 00084 { 00085 SAGA_THROW("Bad type conversion.", saga::BadParameter); 00086 } 00087 00088 if (&rhs != this) 00089 this->saga::object::operator=(rhs.clone()); 00090 00091 return *this; 00092 } 00093 00094 saga::impl::url* url::get_impl() const 00095 { 00096 typedef saga::object base_type; 00097 return static_cast<impl::url*>(this->base_type::get_impl()); 00098 } 00099 00100 TR1::shared_ptr <saga::impl::url> url::get_impl_sp() const 00101 { 00102 typedef saga::object base_type; 00103 return TR1::static_pointer_cast<impl::url>(this->base_type::get_impl_sp()); 00104 } 00105 00106 saga::object url::clone (void) const 00107 { 00108 return get_impl()->clone(); 00109 } 00110 00111 std::string url::get_url (void) const 00112 { 00113 return get_impl()->get_url_escaped(); 00114 } 00115 00116 void url::set_url(std::string const & url) 00117 { 00118 get_impl()->set_url(url); 00119 } 00120 00121 std::string url::get_string (void) const 00122 { 00123 return get_impl()->get_url_escaped(true); 00124 } 00125 00126 std::string url::get_url_escaped(bool hide_password) const 00127 { 00128 return get_impl()->get_url_escaped(hide_password); 00129 } 00130 00131 void url::set_string(std::string const & url) 00132 { 00133 get_impl()->set_url(url); 00134 } 00135 00136 std::string url::get_authority (void) const 00137 { 00138 return get_impl()->get_authority (); 00139 } 00140 00141 std::string url::get_scheme (void) const 00142 { 00143 return get_impl()->get_scheme (); 00144 } 00145 00146 std::string url::get_host (void) const 00147 { 00148 return get_impl()->get_host (); 00149 } 00150 00151 int url::get_port (void) const 00152 { 00153 return get_impl()->get_port (); 00154 } 00155 00156 std::string url::get_fragment (void) const 00157 { 00158 return get_impl()->get_fragment_escaped(); 00159 } 00160 00161 std::string url::get_path(void) const 00162 { 00163 return get_impl()->get_path_escaped(); 00164 } 00165 00166 std::string url::get_query (void) const 00167 { 00168 return get_impl()->get_query_escaped(); 00169 } 00170 00171 std::string url::get_userinfo (void) const 00172 { 00173 return get_impl()->get_userinfo (); 00174 } 00175 00176 std::string url::get_username (void) const 00177 { 00178 return get_impl()->get_username (); 00179 } 00180 00181 std::string url::get_password (void) const 00182 { 00183 return get_impl()->get_password (); 00184 } 00185 00186 void url::set_scheme (std::string const & scheme) 00187 { 00188 get_impl()->change_scheme (scheme); 00189 } 00190 00191 void url::set_scheme_specific_part (std::string const & scheme_specific_part) 00192 { 00193 get_impl()->change_scheme_specific_part (scheme_specific_part); 00194 } 00195 00196 void url::set_host (std::string const & host) 00197 { 00198 get_impl()->change_host (host); 00199 } 00200 00201 void url::set_port (int port) 00202 { 00203 get_impl()->change_port (port); 00204 } 00205 00206 void url::set_authority (std::string const & auth) 00207 { 00208 return get_impl()->set_authority (auth); 00209 } 00210 00211 void url::set_fragment (std::string const & fragment) 00212 { 00213 get_impl()->change_fragment (fragment); 00214 } 00215 00216 void url::set_path (std::string const & path) 00217 { 00218 get_impl()->change_path (path); 00219 } 00220 00221 void url::set_query (std::string const & query) 00222 { 00223 get_impl()->change_query (query); 00224 } 00225 00226 void url::set_userinfo(std::string const & userinfo) 00227 { 00228 get_impl()->change_userinfo (userinfo); 00229 } 00230 00231 void url::set_username(std::string const & username) 00232 { 00233 get_impl()->change_username (username); 00234 } 00235 00236 void url::set_password(std::string const & password) 00237 { 00238 get_impl()->change_password (password); 00239 } 00240 00241 std::ostream& operator<< (std::ostream& os, url const& u) 00242 { 00243 os << u.get_string(); 00244 return os; 00245 } 00246 00247 std::istream& operator>> (std::istream& is, url& u) 00248 { 00249 std::string s; 00250 is >> s; 00251 u = s; 00252 return is; 00253 } 00254 00255 bool operator== (saga::url const& lhs, saga::url const& rhs) 00256 { 00257 return lhs.get_url_escaped() == rhs.get_url_escaped(); 00258 } 00259 00260 bool operator!= (saga::url const& lhs, saga::url const& rhs) 00261 { 00262 return ! (lhs.get_url_escaped() == rhs.get_url_escaped()); 00263 } 00264 00265 bool operator< (saga::url const& lhs, saga::url const& rhs) 00266 { 00267 return lhs.get_url_escaped() < rhs.get_url_escaped(); 00268 } 00269 00270 std::string url::unescape(std::string const&in) 00271 { 00272 return saga::impl::unescape_url(in); 00273 } 00274 00275 std::string url::escape(std::string const&in) 00276 { 00277 return saga::impl::escape_url(in); 00278 } 00279 00281 saga::task 00282 url::translatepriv(std::string scheme, saga::task_base::Sync) const 00283 { 00284 return get_impl()->translate_impl(detail::get_the_session(), scheme, true); 00285 } 00286 00287 saga::task 00288 url::translatepriv(std::string scheme, saga::task_base::Async) const 00289 { 00290 return saga::detail::run(get_impl()->translate_impl( 00291 detail::get_the_session(), scheme)); 00292 } 00293 00294 saga::task 00295 url::translatepriv(std::string scheme, saga::task_base::Task) const 00296 { 00297 return get_impl()->translate_impl(detail::get_the_session(), scheme); 00298 } 00299 00300 saga::task 00301 url::translatepriv(saga::session s, std::string scheme, saga::task_base::Sync) const 00302 { 00303 return get_impl()->translate_impl(s, scheme, true); 00304 } 00305 00306 saga::task 00307 url::translatepriv(saga::session s, std::string scheme, saga::task_base::Async) const 00308 { 00309 return saga::detail::run(get_impl()->translate_impl(s, scheme)); 00310 } 00311 00312 saga::task 00313 url::translatepriv(saga::session s, std::string scheme, saga::task_base::Task) const 00314 { 00315 return get_impl()->translate_impl(s, scheme); 00316 } 00317 00318 } // namespace saga 00320