HttpMessage.h
Go to the documentation of this file.
1 /* -*- C++ -*- */
2 
3 /****************************************************************************
4 ** Copyright (c) 2001-2014
5 **
6 ** This file is part of the QuickFIX FIX Engine
7 **
8 ** This file may be distributed under the terms of the quickfixengine.org
9 ** license as defined by quickfixengine.org and appearing in the file
10 ** LICENSE included in the packaging of this file.
11 **
12 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
13 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
14 **
15 ** See http://www.quickfixengine.org/LICENSE for licensing information.
16 **
17 ** Contact ask@quickfixengine.org if any conditions of this licensing are
18 ** not clear to you.
19 **
20 ****************************************************************************/
21 
22 #ifndef FIX_HTTPMESSAGE
23 #define FIX_HTTPMESSAGE
24 
25 #ifdef _MSC_VER
26 #pragma warning( disable: 4786 )
27 #endif
28 
29 #include "Exceptions.h"
30 #include <map>
31 
32 namespace FIX
33 {
37 class HttpMessage
38 {
39 public:
40  typedef std::map<std::string, std::string> Parameters;
41 
42  HttpMessage();
43 
45  HttpMessage( const std::string& string )
46  throw( InvalidMessage );
47 
48  HttpMessage( const HttpMessage& copy )
49  {
50  m_root = copy.m_root;
51  m_parameters = copy.m_parameters;
52  }
53 
54 public:
56  std::string toString() const;
58  std::string& toString( std::string& ) const;
59 
60  void setString( const std::string& string )
61  throw( InvalidMessage );
62 
63  void clear()
64  {
65 #if defined(_MSC_VER) && _MSC_VER < 1300
66  m_root = "";
67 #else
68  m_root.clear();
69 #endif
70  m_parameters.clear();
71  }
72 
73  const std::string& getRootString() const
74  { return m_root; }
75 
76  const std::string getParameterString() const
77  {
78  std::string result;
79  Parameters::const_iterator i;
80  for( i = m_parameters.begin(); i != m_parameters.end(); ++i )
81  {
82  result += (i == m_parameters.begin()) ? "?" : "&";
83  result += i->first + "=" + i->second;
84  }
85  return result;
86  }
87 
88  const Parameters& getParameters() const
89  { return m_parameters; }
90 
91  bool hasParameter( const std::string& key ) const
92  {
93  Parameters::const_iterator find = m_parameters.find( key );
94  return find != m_parameters.end();
95  }
96 
97  const std::string& getParameter( const std::string& key ) const
98  throw( std::logic_error )
99  {
100  Parameters::const_iterator find = m_parameters.find( key );
101  if( find == m_parameters.end() )
102  throw std::logic_error( "Parameter " + key + " not found" );
103  return find->second;
104  }
105 
106  void addParameter( const std::string& key, const std::string& value )
107  {
108  m_parameters[key] = value;
109  }
110 
111  void removeParameter( const std::string& key )
112  {
113  m_parameters.erase( key );
114  }
115 
116  static std::string createResponse( int error = 0, const std::string& text = "" );
117 
118 private:
119  std::string m_root;
121 };
124 inline std::ostream& operator <<
125 ( std::ostream& stream, const HttpMessage& message )
126 {
127  std::string str;
128  stream << message.toString( str );
129  return stream;
130 }
131 }
132 
133 #endif //FIX_HTTPMESSAGE
FIX::HttpMessage::m_parameters
Parameters m_parameters
Definition: HttpMessage.h:154
FIX::HttpMessage::createResponse
static std::string createResponse(int error=0, const std::string &text="")
Definition: HttpMessage.cpp:103
FIX::HttpMessage::clear
void clear()
Definition: HttpMessage.h:97
FIX::HttpMessage::removeParameter
void removeParameter(const std::string &key)
Definition: HttpMessage.h:145
FIX::HttpMessage::Parameters
std::map< std::string, std::string > Parameters
Definition: HttpMessage.h:74
FIX::HttpMessage::getParameters
const Parameters & getParameters() const
Definition: HttpMessage.h:122
FIX::HttpMessage
HTTP Message that implemented GET functionality.
Definition: HttpMessage.h:54
FIX::HttpMessage::getParameterString
const std::string getParameterString() const
Definition: HttpMessage.h:110
FIX::HttpMessage::getParameter
const std::string & getParameter(const std::string &key) const
Definition: HttpMessage.h:131
FIX
Definition: Acceptor.cpp:34
FIX::HttpMessage::setString
void setString(const std::string &string)
Definition: HttpMessage.cpp:71
FIX::HttpMessage::toString
std::string toString() const
Get a string representation of the message.
Definition: HttpMessage.cpp:59
FIX::HttpMessage::hasParameter
bool hasParameter(const std::string &key) const
Definition: HttpMessage.h:125
FIX::HttpMessage::addParameter
void addParameter(const std::string &key, const std::string &value)
Definition: HttpMessage.h:140
Exceptions.h
FIX::HttpMessage::m_root
std::string m_root
Definition: HttpMessage.h:153
FIX::InvalidMessage
Not a recognizable message.
Definition: Exceptions.h:97
FIX::HttpMessage::HttpMessage
HttpMessage()
Definition: HttpMessage.cpp:51
FIX::HttpMessage::getRootString
const std::string & getRootString() const
Definition: HttpMessage.h:107

Generated on Wed Apr 29 2020 19:41:30 for QuickFIX by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2001