HttpMessage.h
Go to the documentation of this file.
/* -*- C++ -*- */
/****************************************************************************
** Copyright (c) 2001-2014
**
** This file is part of the QuickFIX FIX Engine
**
** This file may be distributed under the terms of the quickfixengine.org
** license as defined by quickfixengine.org and appearing in the file
** LICENSE included in the packaging of this file.
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
** See http://www.quickfixengine.org/LICENSE for licensing information.
**
** Contact ask@quickfixengine.org if any conditions of this licensing are
** not clear to you.
**
****************************************************************************/
#ifndef FIX_HTTPMESSAGE
#define FIX_HTTPMESSAGE
#ifdef _MSC_VER
#pragma warning( disable: 4786 )
#endif
#include "Exceptions.h"
#include <map>
namespace FIX
{
class HttpMessage
{
public:
typedef std::map<std::string, std::string> Parameters;
HttpMessage();
HttpMessage( const std::string& string )
throw( InvalidMessage );
HttpMessage( const HttpMessage& copy )
{
m_root = copy.m_root;
m_parameters = copy.m_parameters;
}
public:
std::string toString() const;
std::string& toString( std::string& ) const;
void setString( const std::string& string )
throw( InvalidMessage );
void clear()
{
#if defined(_MSC_VER) && _MSC_VER < 1300
m_root = "";
#else
m_root.clear();
#endif
m_parameters.clear();
}
const std::string& getRootString() const
{ return m_root; }
const std::string getParameterString() const
{
std::string result;
Parameters::const_iterator i;
for( i = m_parameters.begin(); i != m_parameters.end(); ++i )
{
result += (i == m_parameters.begin()) ? "?" : "&";
result += i->first + "=" + i->second;
}
return result;
}
const Parameters& getParameters() const
{ return m_parameters; }
bool hasParameter( const std::string& key ) const
{
Parameters::const_iterator find = m_parameters.find( key );
return find != m_parameters.end();
}
const std::string& getParameter( const std::string& key ) const
throw( std::logic_error )
{
Parameters::const_iterator find = m_parameters.find( key );
if( find == m_parameters.end() )
throw std::logic_error( "Parameter " + key + " not found" );
return find->second;
}
void addParameter( const std::string& key, const std::string& value )
{
m_parameters[key] = value;
}
void removeParameter( const std::string& key )
{
m_parameters.erase( key );
}
static std::string createResponse( int error = 0, const std::string& text = "" );
private:
std::string m_root;
Parameters m_parameters;
};
inline std::ostream& operator <<
( std::ostream& stream, const HttpMessage& message )
{
std::string str;
stream << message.toString( str );
return stream;
}
}
#endif //FIX_HTTPMESSAGE
FIX::HttpMessage::removeParameter
void removeParameter(const std::string &key)
Definition: HttpMessage.h:111
FIX::HttpMessage::createResponse
static std::string createResponse(int error=0, const std::string &text="")
Definition: HttpMessage.cpp:86
FIX::HttpMessage::m_parameters
Parameters m_parameters
Definition: HttpMessage.h:120
FIX::HttpMessage::clear
void clear()
Definition: HttpMessage.h:63
FIX::HttpMessage::Parameters
std::map< std::string, std::string > Parameters
Definition: HttpMessage.h:40
FIX::HttpMessage::HttpMessage
HttpMessage(const HttpMessage &copy)
Definition: HttpMessage.h:48
FIX
Definition: Acceptor.cpp:34
FIX::HttpMessage::getParameterString
const std::string getParameterString() const
Definition: HttpMessage.h:76
FIX::HttpMessage::getParameters
const Parameters & getParameters() const
Definition: HttpMessage.h:88
FIX::HttpMessage::getParameter
const std::string & getParameter(const std::string &key) const
Definition: HttpMessage.h:97
FIX::HttpMessage::hasParameter
bool hasParameter(const std::string &key) const
Definition: HttpMessage.h:91
FIX::HttpMessage
HTTP Message that implemented GET functionality.
Definition: HttpMessage.h:37
FIX::HttpMessage::addParameter
void addParameter(const std::string &key, const std::string &value)
Definition: HttpMessage.h:106
FIX::HttpMessage::setString
void setString(const std::string &string)
Definition: HttpMessage.cpp:54
FIX::HttpMessage::HttpMessage
HttpMessage()
Definition: HttpMessage.cpp:34
FIX::HttpMessage::getRootString
const std::string & getRootString() const
Definition: HttpMessage.h:73
FIX::HttpMessage::toString
std::string toString() const
Get a string representation of the message.
Definition: HttpMessage.cpp:42
FIX::InvalidMessage
Not a recognizable message.
Definition: Exceptions.h:80
FIX::HttpMessage::m_root
std::string m_root
Definition: HttpMessage.h:119
Exceptions.h