cxxtools::net::Uri Class Reference

The Uri class represents a uniform resource identifier. More...

#include <cxxtools/net/uri.h>

Public Member Functions

 Uri ()
 Creates an empty Uri.
 Uri (const std::string &str)
 Parses the string str and set the elements of the Uri.
 Uri (const char *str)
void protocol (const std::string &protocol)
 Sets the protocol part of the Uri.
const std::string & protocol () const
 Returns the protocol part of the Uri.
void user (const std::string &user)
 Sets the user part of the Uri.
const std::string & user () const
 Returns the user part of the Uri.
void password (const std::string &password)
 Sets the password part of the Uri.
const std::string & password () const
 Returns the password part of the Uri.
void host (const std::string &host)
 Sets the host part of the Uri.
const std::string & host () const
 Returns the host part of the Uri.
void port (unsigned short int p)
 Sets the port part of the Uri.
unsigned short int port () const
 Returns the port part of the Uri.
void path (const std::string &path)
 Sets the path part of the Uri.
const std::string & path () const
 Returns the path part of the Uri.
void query (const std::string &query)
 Sets the query part of the Uri.
const std::string & query () const
 Returns the query part of the Uri.
void fragment (const std::string &fragment)
 Sets the fragment part of the Uri.
const std::string & fragment () const
 Returns the fragment part of the Uri.
std::string str () const
 Returns the Uri as a string.

Detailed Description

The Uri class represents a uniform resource identifier.

A Uri is used to identify a web resource.

This class can parse a string to split a uri into his parts or build a string from parts of the uri.

The syntax of a uri is:

  <scheme name> : <hierarchical part> [ ? <query> ] [ # <fragment> ]

A example is here:

  foo://username:password@example.com:8042/over/there/index.dtb?type=animal&name=narwhal#nose
  \_/   \______/ \______/ \_________/ \__/ \__________________/ \______________________/ \__/
   |       |                   |       |          |                      |                |
   |     user     password  hostname  port       path                  query          fragment
   |
   schema/protocol

Example use:

cxxtools::Uri u("http://www.tntnet.org/index.html");
std::cout << "host=" << u.host() << std::endl; // prints www.tntnet.org
u.path("cxxtools.html");
std::cout << "new uri " << u.str() << std::endl; // prints http://www.tntnet.org/cxxtools.html

Constructor & Destructor Documentation

cxxtools::net::Uri::Uri ( )
inline

Creates an empty Uri.

cxxtools::net::Uri::Uri ( const std::string &  str)
inline

Parses the string str and set the elements of the Uri.

cxxtools::net::Uri::Uri ( const char *  str)
inline

Member Function Documentation

void cxxtools::net::Uri::fragment ( const std::string &  fragment)
inline

Sets the fragment part of the Uri.

const std::string& cxxtools::net::Uri::fragment ( ) const
inline

Returns the fragment part of the Uri.

void cxxtools::net::Uri::host ( const std::string &  host)
inline

Sets the host part of the Uri.

const std::string& cxxtools::net::Uri::host ( ) const
inline

Returns the host part of the Uri.

void cxxtools::net::Uri::password ( const std::string &  password)
inline

Sets the password part of the Uri.

const std::string& cxxtools::net::Uri::password ( ) const
inline

Returns the password part of the Uri.

void cxxtools::net::Uri::path ( const std::string &  path)
inline

Sets the path part of the Uri.

const std::string& cxxtools::net::Uri::path ( ) const
inline

Returns the path part of the Uri.

void cxxtools::net::Uri::port ( unsigned short int  p)
inline

Sets the port part of the Uri.

unsigned short int cxxtools::net::Uri::port ( ) const
inline

Returns the port part of the Uri.

void cxxtools::net::Uri::protocol ( const std::string &  protocol)
inline

Sets the protocol part of the Uri.

const std::string& cxxtools::net::Uri::protocol ( ) const
inline

Returns the protocol part of the Uri.

void cxxtools::net::Uri::query ( const std::string &  query)
inline

Sets the query part of the Uri.

const std::string& cxxtools::net::Uri::query ( ) const
inline

Returns the query part of the Uri.

std::string cxxtools::net::Uri::str ( ) const

Returns the Uri as a string.

All optional parts are left out. The standard ports of http (80), https (443) and ftp (21) are also omitted.

void cxxtools::net::Uri::user ( const std::string &  user)
inline

Sets the user part of the Uri.

const std::string& cxxtools::net::Uri::user ( ) const
inline

Returns the user part of the Uri.


The documentation for this class was generated from the following file:
  • include/cxxtools/net/uri.h