SAGA Adaptor CPI v.1.0
url.cpp
Go to the documentation of this file.
00001 //  Copyright (c) 2005-2009 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();
00124   }
00125 
00126   void url::set_string(std::string const & url)
00127   {
00128     get_impl()->set_url(url);
00129   }
00130   
00131   std::string url::get_authority (void) const
00132   {
00133     return get_impl()->get_authority ();
00134   }
00135   
00136   std::string url::get_scheme (void) const
00137   {
00138     return get_impl()->get_scheme ();
00139   }
00140   
00141   std::string url::get_host (void) const
00142   {
00143     return get_impl()->get_host ();
00144   }
00145   
00146   int url::get_port (void) const
00147   {
00148     return get_impl()->get_port ();
00149   }
00150   
00151   std::string url::get_fragment (void) const
00152   {
00153     return get_impl()->get_fragment_escaped();
00154   }
00155   
00156   std::string url::get_path(void) const
00157   {
00158     return get_impl()->get_path_escaped();
00159   }
00160 
00161   std::string url::get_query (void) const
00162   {
00163     return get_impl()->get_query_escaped();
00164   }
00165 
00166   std::string url::get_userinfo (void) const
00167   {
00168     return get_impl()->get_userinfo ();
00169   }
00170 
00171   std::string url::get_username (void) const
00172   {
00173     return get_impl()->get_username ();
00174   }
00175 
00176   std::string url::get_password (void) const
00177   {
00178     return get_impl()->get_password ();
00179   }
00180 
00181   void url::set_scheme (std::string const & scheme)
00182   {
00183     get_impl()->change_scheme (scheme);
00184   }
00185 
00186   void url::set_scheme_specific_part (std::string const & scheme_specific_part)
00187   {
00188     get_impl()->change_scheme_specific_part (scheme_specific_part);
00189   }
00190 
00191   void url::set_host (std::string const & host)
00192   {
00193     get_impl()->change_host (host);
00194   }
00195 
00196   void url::set_port (int port)
00197   {
00198     get_impl()->change_port (port);
00199   }
00200   
00201   void url::set_fragment (std::string const & fragment)
00202   {
00203     get_impl()->change_fragment (fragment);
00204   }
00205 
00206   void url::set_path (std::string const & path)
00207   {
00208     get_impl()->change_path (path);
00209   }
00210 
00211   void url::set_query (std::string const & query)
00212   {
00213     get_impl()->change_query (query);
00214   }
00215 
00216   void url::set_userinfo(std::string const & userinfo)
00217   {
00218     get_impl()->change_userinfo (userinfo);
00219   }
00220 
00221   void url::set_username(std::string const & username)
00222   {
00223     get_impl()->change_username (username);
00224   }
00225 
00226   void url::set_password(std::string const & password)
00227   {
00228     get_impl()->change_password (password);
00229   }
00230 
00231   std::ostream& operator<< (std::ostream& os, url const& u)
00232   {
00233     os << u.get_string();
00234     return os;
00235   }
00236 
00237   std::istream& operator>> (std::istream& is, url& u)
00238   {
00239     std::string s;
00240     is >> s;
00241     u = s;
00242     return is;
00243   }
00244 
00245   bool operator== (saga::url const& lhs, saga::url const& rhs)
00246   {
00247       return lhs.get_string() == rhs.get_string();
00248   }
00249   
00250   bool operator!= (saga::url const& lhs, saga::url const& rhs)
00251   {
00252       return ! (lhs.get_string() == rhs.get_string());
00253   }
00254   
00255   bool operator< (saga::url const& lhs, saga::url const& rhs)
00256   {
00257       return lhs.get_string() < rhs.get_string();
00258   }
00259 
00260   std::string url::unescape(std::string const&in)
00261   {
00262       return saga::impl::unescape_url(in);
00263   }
00264   
00265   std::string url::escape(std::string const&in)
00266   {
00267       return saga::impl::escape_url(in);
00268   }
00269 
00271   saga::task 
00272   url::translatepriv(std::string scheme, saga::task_base::Sync) const
00273   {
00274     return get_impl()->translate_impl(detail::get_the_session(), scheme, true);
00275   }
00276 
00277   saga::task 
00278   url::translatepriv(std::string scheme, saga::task_base::Async) const
00279   {
00280     return saga::detail::run(get_impl()->translate_impl(
00281         detail::get_the_session(), scheme));
00282   }
00283 
00284   saga::task 
00285   url::translatepriv(std::string scheme, saga::task_base::Task) const
00286   {
00287     return get_impl()->translate_impl(detail::get_the_session(), scheme);
00288   }
00289 
00290   saga::task 
00291   url::translatepriv(saga::session s, std::string scheme, saga::task_base::Sync) const
00292   {
00293     return get_impl()->translate_impl(s, scheme, true);
00294   }
00295 
00296   saga::task 
00297   url::translatepriv(saga::session s, std::string scheme, saga::task_base::Async) const
00298   {
00299     return saga::detail::run(get_impl()->translate_impl(s, scheme));
00300   }
00301 
00302   saga::task 
00303   url::translatepriv(saga::session s, std::string scheme, saga::task_base::Task) const
00304   {
00305     return get_impl()->translate_impl(s, scheme);
00306   }
00307 
00308 } // namespace saga
00310 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines