Class for easy extraction of CGI-parameters. More...

#include <cxxtools/cgi.h>

Inheritance diagram for cxxtools::Cgi:
cxxtools::QueryParams

Public Member Functions

 Cgi ()
 constructor reads parameters from server
- Public Member Functions inherited from cxxtools::QueryParams
 QueryParams ()
 default constructor
 QueryParams (const std::string &url)
 QueryParams (const char *url)
void parse_url (const std::string &url)
 read parameters from url
void parse_url (const char *url)
 read parameters from url
void parse_url (std::istream &url_stream)
 read parameters from stream
const std::string & param (size_type n) const
 get unnamed parameter by number (no range-check!)
size_type paramcount () const
 get number of unnamed parameters
const std::string & operator[] (size_type n) const
 get unnamed parameter with operator[] (no range-check!)
QueryParamsadd (const std::string &value)
 add unnamed parameter
QueryParamsremove ()
 remove unnamed parameter
QueryParamsset (const std::string &value)
 set unnamed parameter
const std::string & param (const std::string &name, size_type n=0) const
 get nth named parameter.
std::string param (const std::string &name, size_type n, const std::string &def) const
 get nth named parameter with default value.
std::string param (const std::string &name, const std::string &def) const
 get named parameter or default value.
size_type paramcount (const std::string &name) const
 get number of parameters with the given name
std::string operator[] (const std::string &name) const
 get first named parameter with operator[]
bool has (const std::string &name) const
 checks if the named parameter exists
QueryParamsadd (const std::string &name, const std::string &value)
 add named parameter
QueryParamsremove (const std::string &name)
 remove named parameter
QueryParamsset (const std::string &name, const std::string &value)
 sets named parameter
QueryParamsadd (const QueryParams &other)
template<typename output_iterator >
void getNames (output_iterator o) const
 returns all names of parameters
void clear ()
 removes all data
bool empty () const
 returns true, when no parameters exist (named and unnamed)
const_iterator begin () const
 get iterator to unnamed parameters
const_iterator begin (const std::string &name) const
 get iterator to named parameter
const_iterator end () const
 get end-iterator (named and unnamed)
std::string getUrl () const
 get parameters as url

Static Public Member Functions

static std::string header ()
static std::string header (const std::string &type)

Additional Inherited Members

- Public Types inherited from cxxtools::QueryParams
typedef std::vector< value_typevalues_type
typedef values_type::size_type size_type

Detailed Description

Class for easy extraction of CGI-parameters.

This class reads automatically GET- and POST-parameters from stdin and the environvariable QUERY_STRING, like CGI-programs do. This eases writing CGI-programs in C++.

example:

int main()
{
cxxtools::Cgi q; // this parses all input-parameters
std::cout << q.header
<< "<html>\n"
<< "<body>\n"
<< "<form>\n"
<< "<input type=\"text\" name=\"v\"><br>\n"
<< "<input type=\"submit\"><br>\n"
<< "<hr>\n"
<< "</form>\n"
<< "you entered: <b>" << q["v"] << "</b>\n"
<< "</body>"
<< "</html>";
}

Constructor & Destructor Documentation

cxxtools::Cgi::Cgi ( )

constructor reads parameters from server

Member Function Documentation

static std::string cxxtools::Cgi::header ( )
inlinestatic
static std::string cxxtools::Cgi::header ( const std::string &  type)
inlinestatic

The documentation for this class was generated from the following file: