Index Source Files Annotated Class List Alphabetical Class List Class Hierarchy Graphical Class Hierarchy

# HttpMessage.h

Go to the documentation of this file.

    00001 /* -*- C++ -*- */
    00002
    00003 /****************************************************************************
    00004 ** Copyright (c) quickfixengine.org  All rights reserved.
    00005 **
    00006 ** This file is part of the QuickFIX FIX Engine
    00007 **
    00008 ** This file may be distributed under the terms of the quickfixengine.org
    00009 ** license as defined by quickfixengine.org and appearing in the file
    00010 ** LICENSE included in the packaging of this file.
    00011 **
    00012 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
    00013 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
    00014 **
    00015 ** See http://www.quickfixengine.org/LICENSE for licensing information.
    00016 **
    00017 ** Contact ask@quickfixengine.org if any conditions of this licensing are
    00018 ** not clear to you.
    00019 **
    00020 ****************************************************************************/
    00021
    00022 #ifndef FIX_HTTPMESSAGE
    00023 #define FIX_HTTPMESSAGE
    00024
    00025 #ifdef _MSC_VER
    00026 #pragma warning( disable: 4786 )
    00027 #endif
    00028
    00029 #include "Exceptions.h"
    00030 #include <map>
    00031
    00032 namespace FIX
    00033 {
    00037 class HttpMessage
    00038 {
    00039 public:
    00040   typedef std::map<std::string, std::string> Parameters;
    00041
    00042   HttpMessage();
    00043
    00045   HttpMessage( const std::string& string )
    00046   throw( InvalidMessage );
    00047
    00048   HttpMessage( const HttpMessage& copy )
    00049   {
    00050     m_root = copy.m_root;
    00051     m_parameters = copy.m_parameters;
    00052   }
    00053
    00054 public:
    00056   std::string toString() const;
    00058   std::string& toString( std::string& ) const;
    00059
    00060   void setString( const std::string& string )
    00061   throw( InvalidMessage );
    00062
    00063   void clear()
    00064   {
    00065 #if defined(_MSC_VER) && _MSC_VER < 1300
    00066     m_root = "";
    00067 #else
    00068     m_root.clear();
    00069 #endif
    00070     m_parameters.clear();
    00071   }
    00072
    00073   const std::string& getRootString() const
    00074   { return m_root; }
    00075
    00076   const std::string getParameterString() const
    00077   {
    00078     std::string result;
    00079     Parameters::const_iterator i;
    00080     for( i = m_parameters.begin(); i != m_parameters.end(); ++i )
    00081     {
    00082       result += (i == m_parameters.begin()) ? "?" : "&";
    00083       result += i->first + "=" + i->second;
    00084     }
    00085     return result;
    00086   }
    00087
    00088   const Parameters& getParameters() const
    00089   { return m_parameters; }
    00090
    00091   bool hasParameter( const std::string& key ) const
    00092   {
    00093     Parameters::const_iterator find = m_parameters.find( key );
    00094     return find != m_parameters.end();
    00095   }
    00096
    00097   const std::string& getParameter( const std::string& key ) const
    00098   throw( std::logic_error )
    00099   {
    00100     Parameters::const_iterator find = m_parameters.find( key );
    00101     if( find == m_parameters.end() )
    00102       throw std::logic_error( "Parameter " + key + " not found" );
    00103     return find->second;
    00104   }
    00105
    00106   void addParameter( const std::string& key, const std::string& value )
    00107   {
    00108     m_parameters[key] = value;
    00109   }
    00110
    00111   void removeParameter( const std::string& key )
    00112   {
    00113     m_parameters.erase( key );
    00114   }
    00115
    00116   static std::string createResponse( int error = 0, const std::string& text = "" );
    00117
    00118 private:
    00119   std::string m_root;
    00120   Parameters m_parameters;
    00121 };
    00124 inline std::ostream& operator <<
    00125 ( std::ostream& stream, const HttpMessage& message )
    00126 {
    00127   std::string str;
    00128   stream << message.toString( str );
    00129   return stream;
    00130 }
    00131 }
    00132
    00133 #endif //FIX_HTTPMESSAGE