Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | Static Protected Attributes | Private Types | Private Member Functions | Static Private Member Functions | Friends | List of all members
FIX::Message Class Reference

Base class for all FIX messages. More...

#include <Message.h>

Inheritance diagram for FIX::Message:
Inheritance graph
[legend]
Collaboration diagram for FIX::Message:
Collaboration graph
[legend]

Public Member Functions

 Message ()
 
 Message (const std::string &string, bool validate=true) throw ( InvalidMessage )
 Construct a message from a string. More...
 
 Message (const std::string &string, const FIX::DataDictionary &dataDictionary, bool validate=true) throw ( InvalidMessage )
 Construct a message from a string using a data dictionary. More...
 
 Message (const std::string &string, const FIX::DataDictionary &sessionDataDictionary, const FIX::DataDictionary &applicationDataDictionary, bool validate=true) throw ( InvalidMessage )
 Construct a message from a string using a session and application data dictionary. More...
 
 Message (const Message &copy)
 
void addGroup (const FIX::Group &group)
 
void replaceGroup (unsigned num, const FIX::Group &group)
 
GroupgetGroup (unsigned num, FIX::Group &group) const throw ( FieldNotFound )
 
void removeGroup (unsigned num, const FIX::Group &group)
 
void removeGroup (const FIX::Group &group)
 
bool hasGroup (const FIX::Group &group) const
 
bool hasGroup (unsigned num, const FIX::Group &group) const
 
std::string toString (int beginStringField=FIELD::BeginString, int bodyLengthField=FIELD::BodyLength, int checkSumField=FIELD::CheckSum) const
 Get a string representation of the message. More...
 
std::string & toString (std::string &, int beginStringField=FIELD::BeginString, int bodyLengthField=FIELD::BodyLength, int checkSumField=FIELD::CheckSum) const
 Get a string representation without making a copy. More...
 
std::string toXML () const
 Get a XML representation of the message. More...
 
std::string & toXML (std::string &) const
 Get a XML representation without making a copy. More...
 
void reverseRoute (const Header &)
 Add header informations depending on a source message. More...
 
void setString (const std::string &string) throw ( InvalidMessage )
 Set a message based on a string representation This will fill in the fields on the message by parsing out the string that is passed in. More...
 
void setString (const std::string &string, bool validate) throw ( InvalidMessage )
 
void setString (const std::string &string, bool validate, const FIX::DataDictionary *pDataDictionary) throw ( InvalidMessage )
 
void setString (const std::string &string, bool validate, const FIX::DataDictionary *pSessionDataDictionary, const FIX::DataDictionary *pApplicationDataDictionary) throw ( InvalidMessage )
 
void setGroup (const std::string &msg, const FieldBase &field, const std::string &string, std::string::size_type &pos, FieldMap &map, const DataDictionary &dataDictionary)
 
bool setStringHeader (const std::string &string)
 Set a messages header from a string This is an optimization that can be used to get useful information from the header of a FIX string without parsing the whole thing. More...
 
const HeadergetHeader () const
 Getter for the message header. More...
 
HeadergetHeader ()
 Mutable getter for the message header. More...
 
const TrailergetTrailer () const
 Getter for the message trailer. More...
 
TrailergetTrailer ()
 Mutable getter for the message trailer. More...
 
bool hasValidStructure (int &field) const
 
int bodyLength (int beginStringField=FIELD::BeginString, int bodyLengthField=FIELD::BodyLength, int checkSumField=FIELD::CheckSum) const
 
int checkSum (int checkSumField=FIELD::CheckSum) const
 
bool isAdmin () const
 
bool isApp () const
 
bool isEmpty ()
 
void clear ()
 
SessionID getSessionID (const std::string &qualifier="") const throw ( FieldNotFound )
 Returns the session ID of the intended recipient. More...
 
void setSessionID (const SessionID &sessionID)
 Sets the session ID of the intended recipient. More...
 
- Public Member Functions inherited from FIX::FieldMap
 FieldMap (const message_order &order=message_order(message_order::normal))
 
 FieldMap (const int order[])
 
 FieldMap (const FieldMap &copy)
 
virtual ~FieldMap ()
 
FieldMapoperator= (const FieldMap &rhs)
 
void setField (const FieldBase &field, bool overwrite=true) throw ( RepeatedTag )
 Set a field without type checking. More...
 
void setField (int field, const std::string &value) throw ( RepeatedTag, NoTagValue )
 Set a field without a field class. More...
 
bool getFieldIfSet (FieldBase &field) const
 Get a field if set. More...
 
FieldBasegetField (FieldBase &field) const throw ( FieldNotFound )
 Get a field without type checking. More...
 
const std::string & getField (int field) const throw ( FieldNotFound )
 Get a field without a field class. More...
 
const FieldBasegetFieldRef (int field) const throw ( FieldNotFound )
 Get direct access to a field through a reference. More...
 
const FieldBase *const getFieldPtr (int field) const throw ( FieldNotFound )
 Get direct access to a field through a pointer. More...
 
bool isSetField (const FieldBase &field) const
 Check to see if a field is set. More...
 
bool isSetField (int field) const
 Check to see if a field is set by referencing its number. More...
 
void removeField (int field)
 Remove a field. If field is not present, this is a no-op. More...
 
void addGroup (int field, const FieldMap &group, bool setCount=true)
 Add a group. More...
 
void addGroupPtr (int field, FieldMap *group, bool setCount=true)
 Acquire ownership of Group object. More...
 
void replaceGroup (int num, int field, const FieldMap &group)
 Replace a specific instance of a group. More...
 
FieldMapgetGroup (int num, int field, FieldMap &group) const throw ( FieldNotFound )
 Get a specific instance of a group. More...
 
FieldMapgetGroupRef (int num, int field) const throw ( FieldNotFound )
 Get direct access to a field through a reference. More...
 
FieldMapgetGroupPtr (int num, int field) const throw ( FieldNotFound )
 Get direct access to a field through a pointer. More...
 
void removeGroup (int num, int field)
 Remove a specific instance of a group. More...
 
void removeGroup (int field)
 Remove all instances of a group. More...
 
bool hasGroup (int field) const
 Check to see any instance of a group exists. More...
 
bool hasGroup (int num, int field) const
 Check to see if a specific instance of a group exists. More...
 
size_t groupCount (int field) const
 Count the number of instance of a group. More...
 
void clear ()
 Clear all fields from the map. More...
 
bool isEmpty ()
 Check if map contains any fields. More...
 
size_t totalFields () const
 
std::string & calculateString (std::string &) const
 
int calculateLength (int beginStringField=FIELD::BeginString, int bodyLengthField=FIELD::BodyLength, int checkSumField=FIELD::CheckSum) const
 
int calculateTotal (int checkSumField=FIELD::CheckSum) const
 
iterator begin () const
 
iterator end () const
 
g_iterator g_begin () const
 
g_iterator g_end () const
 

Static Public Member Functions

static bool InitializeXML (const std::string &string)
 Set global data dictionary for encoding messages into XML. More...
 
static bool isAdminMsgType (const MsgType &msgType)
 
static ApplVerID toApplVerID (const BeginString &value)
 
static BeginString toBeginString (const ApplVerID &applVerID)
 
static bool isHeaderField (int field)
 
static bool isHeaderField (const FieldBase &field, const DataDictionary *pD=0)
 
static bool isTrailerField (int field)
 
static bool isTrailerField (const FieldBase &field, const DataDictionary *pD=0)
 

Protected Member Functions

 Message (const BeginString &beginString, const MsgType &msgType)
 

Protected Attributes

Header m_header
 
Trailer m_trailer
 
bool m_validStructure
 
int m_field
 

Static Protected Attributes

static std::auto_ptr< DataDictionarys_dataDictionary
 

Private Types

enum  field_type { header, body, trailer }
 

Private Member Functions

FieldBase extractField (const std::string &string, std::string::size_type &pos, const DataDictionary *pSessionDD=0, const DataDictionary *pAppDD=0, const Group *pGroup=0)
 
void validate ()
 
std::string toXMLFields (const FieldMap &fields, int space) const
 

Static Private Member Functions

static bool IsDataField (int field, const DataDictionary *pSessionDD, const DataDictionary *pAppDD)
 

Friends

class DataDictionary
 
class Session
 

Additional Inherited Members

- Public Types inherited from FIX::FieldMap
typedef std::multimap< int, FieldBase, message_order, ALLOCATOR< std::pair< const int, FieldBase > > > Fields
 
typedef std::map< int, std::vector< FieldMap *>, std::less< int >, ALLOCATOR< std::pair< const int, std::vector< FieldMap *> > > > Groups
 
typedef Fields::const_iterator iterator
 
typedef iterator const_iterator
 
typedef Groups::const_iterator g_iterator
 
typedef Groups::const_iterator g_const_iterator
 

Detailed Description

Base class for all FIX messages.

A message consists of three field maps. One for the header, the body, and the trailer.

Definition at line 67 of file Message.h.

Member Enumeration Documentation

◆ field_type

Enumerator
header 
body 
trailer 

Definition at line 72 of file Message.h.

Constructor & Destructor Documentation

◆ Message() [1/6]

FIX::Message::Message ( )

Definition at line 35 of file Message.cpp.

36 : m_validStructure( true ) {}
bool m_validStructure
Definition: Message.h:340

◆ Message() [2/6]

FIX::Message::Message ( const std::string &  string,
bool  validate = true 
)
throw (InvalidMessage
)

Construct a message from a string.

Definition at line 38 of file Message.cpp.

References setString(), and validate().

40 : m_validStructure( true )
41 {
42  setString( string, validate );
43 }
void validate()
Definition: Message.cpp:489
void setString(const std::string &string)
Set a message based on a string representation This will fill in the fields on the message by parsing...
Definition: Message.h:162
bool m_validStructure
Definition: Message.h:340

◆ Message() [3/6]

FIX::Message::Message ( const std::string &  string,
const FIX::DataDictionary dataDictionary,
bool  validate = true 
)
throw (InvalidMessage
)

Construct a message from a string using a data dictionary.

Definition at line 45 of file Message.cpp.

References setString(), and validate().

49 : m_validStructure( true )
50 {
51  setString( string, validate, &dataDictionary, &dataDictionary );
52 }
void validate()
Definition: Message.cpp:489
void setString(const std::string &string)
Set a message based on a string representation This will fill in the fields on the message by parsing...
Definition: Message.h:162
bool m_validStructure
Definition: Message.h:340

◆ Message() [4/6]

FIX::Message::Message ( const std::string &  string,
const FIX::DataDictionary sessionDataDictionary,
const FIX::DataDictionary applicationDataDictionary,
bool  validate = true 
)
throw (InvalidMessage
)

Construct a message from a string using a session and application data dictionary.

Definition at line 54 of file Message.cpp.

References isAdmin(), setString(), setStringHeader(), and validate().

59 : m_validStructure( true )
60 {
61  setStringHeader( string );
62  if( isAdmin() )
63  setString( string, validate, &sessionDataDictionary, &sessionDataDictionary );
64  else
65  setString( string, validate, &sessionDataDictionary, &applicationDataDictionary );
66 }
bool setStringHeader(const std::string &string)
Set a messages header from a string This is an optimization that can be used to get useful informatio...
Definition: Message.cpp:380
void validate()
Definition: Message.cpp:489
void setString(const std::string &string)
Set a message based on a string representation This will fill in the fields on the message by parsing...
Definition: Message.h:162
bool m_validStructure
Definition: Message.h:340
bool isAdmin() const
Definition: Message.h:219

◆ Message() [5/6]

FIX::Message::Message ( const Message copy)
inline

Definition at line 91 of file Message.h.

References m_field, m_header, m_trailer, and m_validStructure.

92  : FieldMap( copy )
93  {
94  m_header = copy.m_header;
95  m_trailer = copy.m_trailer;
96  m_validStructure = copy.m_validStructure;
97  m_field = copy.m_field;
98  }
int m_field
Definition: Message.h:341
FieldMap(const message_order &order=message_order(message_order::normal))
Definition: FieldMap.h:64
Header m_header
Definition: Message.h:338
bool m_validStructure
Definition: Message.h:340
Trailer m_trailer
Definition: Message.h:339

◆ Message() [6/6]

FIX::Message::Message ( const BeginString &  beginString,
const MsgType &  msgType 
)
inlineprotected

Definition at line 127 of file Message.h.

References FIX::FIELD::BeginString, FIX::FIELD::BodyLength, and FIX::FIELD::CheckSum.

128  : m_validStructure( true )
129  {
130  m_header.setField( beginString );
131  m_header.setField( msgType );
132  }
void setField(const FieldBase &field, bool overwrite=true)
Set a field without type checking.
Definition: FieldMap.h:79
Header m_header
Definition: Message.h:338
bool m_validStructure
Definition: Message.h:340

Member Function Documentation

◆ addGroup()

void FIX::Message::addGroup ( const FIX::Group group)
inline

Definition at line 103 of file Message.h.

References FIX::FieldMap::addGroup(), and FIX::Group::field().

104  { FieldMap::addGroup( group.field(), group ); }
int field() const
Definition: Group.h:56
void addGroup(int field, const FieldMap &group, bool setCount=true)
Add a group.
Definition: FieldMap.cpp:58

◆ bodyLength()

int FIX::Message::bodyLength ( int  beginStringField = FIELD::BeginString,
int  bodyLengthField = FIELD::BodyLength,
int  checkSumField = FIELD::CheckSum 
) const
inline

Definition at line 205 of file Message.h.

References FIX::FieldMap::calculateLength().

Referenced by toString(), and validate().

208  { return m_header.calculateLength(beginStringField, bodyLengthField, checkSumField)
209  + calculateLength(beginStringField, bodyLengthField, checkSumField)
210  + m_trailer.calculateLength(beginStringField, bodyLengthField, checkSumField);
211  }
int calculateLength(int beginStringField=FIELD::BeginString, int bodyLengthField=FIELD::BodyLength, int checkSumField=FIELD::CheckSum) const
Definition: FieldMap.cpp:194
Header m_header
Definition: Message.h:338
Trailer m_trailer
Definition: Message.h:339

◆ checkSum()

int FIX::Message::checkSum ( int  checkSumField = FIELD::CheckSum) const
inline

Definition at line 213 of file Message.h.

References FIX::FieldMap::calculateTotal().

Referenced by toString(), and validate().

214  { return ( m_header.calculateTotal(checkSumField)
215  + calculateTotal(checkSumField)
216  + m_trailer.calculateTotal(checkSumField) ) % 256;
217  }
int calculateTotal(int checkSumField=FIELD::CheckSum) const
Definition: FieldMap.cpp:218
Header m_header
Definition: Message.h:338
Trailer m_trailer
Definition: Message.h:339

◆ clear()

void FIX::Message::clear ( )
inline

Definition at line 242 of file Message.h.

References FIX::FieldMap::clear().

Referenced by setString(), and setStringHeader().

243  {
244  m_field = 0;
245  m_header.clear();
246  FieldMap::clear();
247  m_trailer.clear();
248  }
int m_field
Definition: Message.h:341
Header m_header
Definition: Message.h:338
Trailer m_trailer
Definition: Message.h:339
void clear()
Clear all fields from the map.
Definition: FieldMap.cpp:143

◆ extractField()

FIX::FieldBase FIX::Message::extractField ( const std::string &  string,
std::string::size_type &  pos,
const DataDictionary pSessionDD = 0,
const DataDictionary pAppDD = 0,
const Group pGroup = 0 
)
private

Definition at line 531 of file Message.cpp.

References FIX::FieldMap::begin(), FIX::IntConvertor::convert(), FIX::FieldMap::getField(), IsDataField(), FIX::FieldMap::isSetField(), FIX::FIELD::Signature, and FIX::FIELD::SignatureLength.

Referenced by setGroup(), setString(), and setStringHeader().

534 {
535  std::string::const_iterator const tagStart = string.begin() + pos;
536  std::string::const_iterator const strEnd = string.end();
537 
538  std::string::const_iterator const equalSign = std::find( tagStart, strEnd, '=' );
539  if( equalSign == strEnd )
540  throw InvalidMessage("Equal sign not found in field");
541 
542  int field = 0;
543  IntConvertor::convert( tagStart, equalSign, field );
544 
545  std::string::const_iterator const valueStart = equalSign + 1;
546 
547  std::string::const_iterator soh = std::find( valueStart, strEnd, '\001' );
548  if ( soh == strEnd )
549  throw InvalidMessage("SOH not found at end of field");
550 
551  if ( IsDataField( field, pSessionDD, pAppDD ) )
552  {
553  // Assume length field is 1 less.
554  int lenField = field - 1;
555  // Special case for Signature which violates above assumption.
556  if ( field == FIELD::Signature ) lenField = FIELD::SignatureLength;
557 
558  if ( pGroup && pGroup->isSetField( lenField ) )
559  {
560  const std::string& fieldLength = pGroup->getField( lenField );
561  soh = valueStart + atol( fieldLength.c_str() );
562  }
563  else if ( isSetField( lenField ) )
564  {
565  const std::string& fieldLength = getField( lenField );
566  soh = valueStart + atol( fieldLength.c_str() );
567  }
568  }
569 
570  std::string::const_iterator const tagEnd = soh + 1;
571  pos = std::distance( string.begin(), tagEnd );
572 
573  return FieldBase (
574  field,
575  valueStart,
576  soh,
577  tagStart,
578  tagEnd );
579 }
bool isSetField(const FieldBase &field) const
Check to see if a field is set.
Definition: FieldMap.h:144
iterator begin() const
Definition: FieldMap.h:214
static bool IsDataField(int field, const DataDictionary *pSessionDD, const DataDictionary *pAppDD)
Definition: Message.h:320
static std::string convert(signed_int value)
FieldBase & getField(FieldBase &field) const
Get a field without type checking.
Definition: FieldMap.h:112
const int SignatureLength
const int Signature

◆ getGroup()

Group& FIX::Message::getGroup ( unsigned  num,
FIX::Group group 
) const
throw (FieldNotFound
)
inline

Definition at line 109 of file Message.h.

References FIX::FieldMap::clear(), and FIX::FieldMap::getGroup().

110  { group.clear();
111  return static_cast < Group& >
112  ( FieldMap::getGroup( num, group.field(), group ) );
113  }
int field() const
Definition: Group.h:56
void clear()
Clear all fields from the map.
Definition: FieldMap.cpp:143
FieldMap & getGroup(int num, int field, FieldMap &group) const
Get a specific instance of a group.
Definition: FieldMap.h:163

◆ getHeader() [1/2]

const Header& FIX::Message::getHeader ( ) const
inline

◆ getHeader() [2/2]

Header& FIX::Message::getHeader ( )
inline

Mutable getter for the message header.

Definition at line 194 of file Message.h.

194 { return m_header; }
Header m_header
Definition: Message.h:338

◆ getSessionID()

SessionID FIX::Message::getSessionID ( const std::string &  qualifier = "") const
throw (FieldNotFound
)

Returns the session ID of the intended recipient.

Definition at line 468 of file Message.cpp.

References FIX::FIELD::BeginString, FIX::FieldMap::getField(), getHeader(), FIX::FIELD::SenderCompID, and FIX::FIELD::TargetCompID.

470 {
471  BeginString beginString;
472  SenderCompID senderCompID;
473  TargetCompID targetCompID;
474 
475  getHeader().getField( beginString );
476  getHeader().getField( senderCompID );
477  getHeader().getField( targetCompID );
478 
479  return SessionID( beginString, senderCompID, targetCompID, qualifier );
480 }
const Header & getHeader() const
Getter for the message header.
Definition: Message.h:192
FieldBase & getField(FieldBase &field) const
Get a field without type checking.
Definition: FieldMap.h:112
const int TargetCompID
const int SenderCompID
const int BeginString

◆ getTrailer() [1/2]

const Trailer& FIX::Message::getTrailer ( ) const
inline

Getter for the message trailer.

Definition at line 196 of file Message.h.

Referenced by setString(), and toXML().

196 { return m_trailer; }
Trailer m_trailer
Definition: Message.h:339

◆ getTrailer() [2/2]

Trailer& FIX::Message::getTrailer ( )
inline

Mutable getter for the message trailer.

Definition at line 198 of file Message.h.

198 { return m_trailer; }
Trailer m_trailer
Definition: Message.h:339

◆ hasGroup() [1/2]

bool FIX::Message::hasGroup ( const FIX::Group group) const
inline

Definition at line 120 of file Message.h.

References FIX::Group::field(), and FIX::FieldMap::hasGroup().

121  { return FieldMap::hasGroup( group.field() ); }
bool hasGroup(int field) const
Check to see any instance of a group exists.
Definition: FieldMap.cpp:129
int field() const
Definition: Group.h:56

◆ hasGroup() [2/2]

bool FIX::Message::hasGroup ( unsigned  num,
const FIX::Group group 
) const
inline

Definition at line 122 of file Message.h.

References FIX::Group::field(), and FIX::FieldMap::hasGroup().

123  { return FieldMap::hasGroup( num, group.field() ); }
bool hasGroup(int field) const
Check to see any instance of a group exists.
Definition: FieldMap.cpp:129
int field() const
Definition: Group.h:56

◆ hasValidStructure()

bool FIX::Message::hasValidStructure ( int &  field) const
inline

Definition at line 200 of file Message.h.

201  { field = m_field;
202  return m_validStructure;
203  }
int m_field
Definition: Message.h:341
bool m_validStructure
Definition: Message.h:340

◆ InitializeXML()

bool FIX::Message::InitializeXML ( const std::string &  string)
static

Set global data dictionary for encoding messages into XML.

Definition at line 68 of file Message.cpp.

References DataDictionary, and s_dataDictionary.

69 {
70  try
71  {
72  std::auto_ptr<DataDictionary> p =
73  std::auto_ptr<DataDictionary>(new DataDictionary(url));
74  s_dataDictionary = p;
75  return true;
76  }
77  catch( ConfigError& )
78  { return false; }
79 }
static std::auto_ptr< DataDictionary > s_dataDictionary
Definition: Message.h:342
friend class DataDictionary
Definition: Message.h:69

◆ isAdmin()

bool FIX::Message::isAdmin ( ) const
inline

Definition at line 219 of file Message.h.

References FIELD_GET_REF, and FIX::FIELD::MsgType.

Referenced by FIX::MessageCracker::crack(), and Message().

220  {
222  {
223  const MsgType& msgType = FIELD_GET_REF( m_header, MsgType );
224  return isAdminMsgType( msgType );
225  }
226  return false;
227  }
bool isSetField(const FieldBase &field) const
Check to see if a field is set.
Definition: FieldMap.h:144
static bool isAdminMsgType(const MsgType &msgType)
Definition: Message.h:250
Header m_header
Definition: Message.h:338
#define FIELD_GET_REF(MAP, FLD)
Definition: FieldMap.h:238
const int MsgType

◆ isAdminMsgType()

static bool FIX::Message::isAdminMsgType ( const MsgType &  msgType)
inlinestatic

Definition at line 250 of file Message.h.

Referenced by FIX::Session::fromCallback(), FIX::Session::nextResendRequest(), and FIX::Session::sendRaw().

251  { if ( msgType.getValue().length() != 1 ) return false;
252  return strchr
253  ( "0A12345",
254  msgType.getValue().c_str() [ 0 ] ) != 0;
255  }

◆ isApp()

bool FIX::Message::isApp ( ) const
inline

Definition at line 229 of file Message.h.

References FIELD_GET_REF, and FIX::FIELD::MsgType.

Referenced by FIX::Session::next().

230  {
232  {
233  const MsgType& msgType = FIELD_GET_REF( m_header, MsgType );
234  return !isAdminMsgType( msgType );
235  }
236  return false;
237  }
bool isSetField(const FieldBase &field) const
Check to see if a field is set.
Definition: FieldMap.h:144
static bool isAdminMsgType(const MsgType &msgType)
Definition: Message.h:250
Header m_header
Definition: Message.h:338
#define FIELD_GET_REF(MAP, FLD)
Definition: FieldMap.h:238
const int MsgType

◆ IsDataField()

static bool FIX::Message::IsDataField ( int  field,
const DataDictionary pSessionDD,
const DataDictionary pAppDD 
)
inlinestaticprivate

Definition at line 320 of file Message.h.

References FIX::DataDictionary::isDataField().

Referenced by extractField().

324  {
325  if( (pSessionDD && pSessionDD->isDataField( field )) ||
326  (pAppDD && pAppDD != pSessionDD && pAppDD->isDataField( field )) )
327  {
328  return true;
329  }
330 
331  return false;
332  }

◆ isEmpty()

bool FIX::Message::isEmpty ( )
inline

Definition at line 239 of file Message.h.

References FIX::FieldMap::isEmpty().

240  { return m_header.isEmpty() && FieldMap::isEmpty() && m_trailer.isEmpty(); }
bool isEmpty()
Check if map contains any fields.
Definition: FieldMap.cpp:157
Header m_header
Definition: Message.h:338
Trailer m_trailer
Definition: Message.h:339

◆ isHeaderField() [1/2]

bool FIX::Message::isHeaderField ( int  field)
static

Definition at line 400 of file Message.cpp.

References FIX::FIELD::ApplVerID, FIX::FIELD::BeginString, FIX::FIELD::BodyLength, FIX::FIELD::CstmApplVerID, FIX::FIELD::DeliverToCompID, FIX::FIELD::DeliverToLocationID, FIX::FIELD::DeliverToSubID, FIX::FIELD::LastMsgSeqNumProcessed, FIX::FIELD::MessageEncoding, FIX::FIELD::MsgSeqNum, FIX::FIELD::MsgType, FIX::FIELD::NoHops, FIX::FIELD::OnBehalfOfCompID, FIX::FIELD::OnBehalfOfLocationID, FIX::FIELD::OnBehalfOfSendingTime, FIX::FIELD::OnBehalfOfSubID, FIX::FIELD::OrigSendingTime, FIX::FIELD::PossDupFlag, FIX::FIELD::PossResend, FIX::FIELD::SecureDataLen, FIX::FIELD::SenderCompID, FIX::FIELD::SenderLocationID, FIX::FIELD::SenderSubID, FIX::FIELD::SendingTime, FIX::FIELD::TargetCompID, FIX::FIELD::TargetLocationID, FIX::FIELD::TargetSubID, FIX::FIELD::XmlData, and FIX::FIELD::XmlDataLen.

Referenced by isHeaderField(), FIX::DataDictionary::iterate(), setString(), and setStringHeader().

401 {
402  switch ( field )
403  {
404  case FIELD::BeginString:
405  case FIELD::BodyLength:
406  case FIELD::MsgType:
407  case FIELD::SenderCompID:
408  case FIELD::TargetCompID:
412  case FIELD::MsgSeqNum:
413  case FIELD::SenderSubID:
415  case FIELD::TargetSubID:
421  case FIELD::PossDupFlag:
422  case FIELD::PossResend:
423  case FIELD::SendingTime:
425  case FIELD::XmlDataLen:
426  case FIELD::XmlData:
430  case FIELD::ApplVerID:
432  case FIELD::NoHops:
433  return true;
434  default:
435  return false;
436  };
437 }
const int ApplVerID
const int SecureDataLen
const int OrigSendingTime
const int DeliverToLocationID
const int CstmApplVerID
const int OnBehalfOfCompID
const int NoHops
const int OnBehalfOfLocationID
const int OnBehalfOfSubID
const int PossResend
const int LastMsgSeqNumProcessed
const int TargetLocationID
const int SendingTime
const int XmlData
const int DeliverToSubID
const int SenderSubID
const int TargetCompID
const int SenderLocationID
const int MessageEncoding
const int SenderCompID
const int XmlDataLen
const int DeliverToCompID
const int PossDupFlag
const int TargetSubID
const int OnBehalfOfSendingTime
const int BeginString
const int MsgSeqNum
const int BodyLength
const int MsgType

◆ isHeaderField() [2/2]

bool FIX::Message::isHeaderField ( const FieldBase field,
const DataDictionary pD = 0 
)
static

Definition at line 439 of file Message.cpp.

References FIX::FieldBase::getField(), FIX::DataDictionary::isHeaderField(), and isHeaderField().

441 {
442  if ( isHeaderField( field.getField() ) ) return true;
443  if ( pD ) return pD->isHeaderField( field.getField() );
444  return false;
445 }
static bool isHeaderField(int field)
Definition: Message.cpp:400

◆ isTrailerField() [1/2]

bool FIX::Message::isTrailerField ( int  field)
static

Definition at line 447 of file Message.cpp.

References FIX::FIELD::CheckSum, FIX::FIELD::Signature, and FIX::FIELD::SignatureLength.

Referenced by isTrailerField(), FIX::DataDictionary::iterate(), and setString().

448 {
449  switch ( field )
450  {
452  case FIELD::Signature:
453  case FIELD::CheckSum:
454  return true;
455  default:
456  return false;
457  };
458 }
const int SignatureLength
const int Signature
const int CheckSum

◆ isTrailerField() [2/2]

bool FIX::Message::isTrailerField ( const FieldBase field,
const DataDictionary pD = 0 
)
static

Definition at line 460 of file Message.cpp.

References FIX::FieldBase::getField(), FIX::DataDictionary::isTrailerField(), and isTrailerField().

462 {
463  if ( isTrailerField( field.getField() ) ) return true;
464  if ( pD ) return pD->isTrailerField( field.getField() );
465  return false;
466 }
static bool isTrailerField(int field)
Definition: Message.cpp:447

◆ removeGroup() [1/2]

void FIX::Message::removeGroup ( unsigned  num,
const FIX::Group group 
)
inline

Definition at line 115 of file Message.h.

References FIX::Group::field(), and FIX::FieldMap::removeGroup().

116  { FieldMap::removeGroup( num, group.field() ); }
void removeGroup(int num, int field)
Remove a specific instance of a group.
Definition: FieldMap.cpp:86
int field() const
Definition: Group.h:56

◆ removeGroup() [2/2]

void FIX::Message::removeGroup ( const FIX::Group group)
inline

Definition at line 117 of file Message.h.

References FIX::Group::field(), and FIX::FieldMap::removeGroup().

118  { FieldMap::removeGroup( group.field() ); }
void removeGroup(int num, int field)
Remove a specific instance of a group.
Definition: FieldMap.cpp:86
int field() const
Definition: Group.h:56

◆ replaceGroup()

void FIX::Message::replaceGroup ( unsigned  num,
const FIX::Group group 
)
inline

Definition at line 106 of file Message.h.

References FIX::Group::field(), and FIX::FieldMap::replaceGroup().

107  { FieldMap::replaceGroup( num, group.field(), group ); }
int field() const
Definition: Group.h:56
void replaceGroup(int num, int field, const FieldMap &group)
Replace a specific instance of a group.
Definition: FieldMap.cpp:77

◆ reverseRoute()

void FIX::Message::reverseRoute ( const Header header)

Add header informations depending on a source message.

This can be used to add routing informations like OnBehalfOfCompID and DeliverToCompID to a message.

Definition at line 81 of file Message.cpp.

References FIX::FIELD::BeginString, FIX::BeginString_FIX41, FIX::FIELD::DeliverToCompID, FIX::FIELD::DeliverToLocationID, FIX::FIELD::DeliverToSubID, FIX::FieldMap::getFieldIfSet(), m_header, FIX::FIELD::OnBehalfOfCompID, FIX::FIELD::OnBehalfOfLocationID, FIX::FIELD::OnBehalfOfSubID, FIX::FieldMap::removeField(), FIX::FIELD::SenderCompID, FIX::FieldMap::setField(), and FIX::FIELD::TargetCompID.

Referenced by FIX::Session::generateReject().

82 {
83  // required routing tags
84  BeginString beginString;
85  SenderCompID senderCompID;
86  TargetCompID targetCompID;
87 
88  m_header.removeField( beginString.getField() );
89  m_header.removeField( senderCompID.getField() );
90  m_header.removeField( targetCompID.getField() );
91 
92  if( header.getFieldIfSet( beginString ) )
93  {
94  if( beginString.getValue().size() )
95  m_header.setField( beginString );
96 
97  OnBehalfOfLocationID onBehalfOfLocationID;
98  DeliverToLocationID deliverToLocationID;
99 
100  m_header.removeField( onBehalfOfLocationID.getField() );
101  m_header.removeField( deliverToLocationID.getField() );
102 
103  if( beginString >= BeginString_FIX41 )
104  {
105  if( header.getFieldIfSet( onBehalfOfLocationID ) )
106  {
107  if( onBehalfOfLocationID.getValue().size() )
108  m_header.setField( DeliverToLocationID( onBehalfOfLocationID ) );
109  }
110 
111  if( header.getFieldIfSet( deliverToLocationID ) )
112  {
113  if( deliverToLocationID.getValue().size() )
114  m_header.setField( OnBehalfOfLocationID( deliverToLocationID ) );
115  }
116  }
117  }
118 
119  if( header.getFieldIfSet( senderCompID ) )
120  {
121  if( senderCompID.getValue().size() )
122  m_header.setField( TargetCompID( senderCompID ) );
123  }
124 
125  if( header.getFieldIfSet( targetCompID ) )
126  {
127  if( targetCompID.getValue().size() )
128  m_header.setField( SenderCompID( targetCompID ) );
129  }
130 
131  // optional routing tags
132  OnBehalfOfCompID onBehalfOfCompID;
133  OnBehalfOfSubID onBehalfOfSubID;
134  DeliverToCompID deliverToCompID;
135  DeliverToSubID deliverToSubID;
136 
137  m_header.removeField( onBehalfOfCompID.getField() );
138  m_header.removeField( onBehalfOfSubID.getField() );
139  m_header.removeField( deliverToCompID.getField() );
140  m_header.removeField( deliverToSubID.getField() );
141 
142  if( header.getFieldIfSet( onBehalfOfCompID ) )
143  {
144  if( onBehalfOfCompID.getValue().size() )
145  m_header.setField( DeliverToCompID( onBehalfOfCompID ) );
146  }
147 
148  if( header.getFieldIfSet( onBehalfOfSubID ) )
149  {
150  if( onBehalfOfSubID.getValue().size() )
151  m_header.setField( DeliverToSubID( onBehalfOfSubID ) );
152  }
153 
154  if( header.getFieldIfSet( deliverToCompID ) )
155  {
156  if( deliverToCompID.getValue().size() )
157  m_header.setField( OnBehalfOfCompID( deliverToCompID ) );
158  }
159 
160  if( header.getFieldIfSet( deliverToSubID ) )
161  {
162  if( deliverToSubID.getValue().size() )
163  m_header.setField( OnBehalfOfSubID( deliverToSubID ) );
164  }
165 }
const int DeliverToLocationID
const int OnBehalfOfCompID
const int OnBehalfOfLocationID
const int OnBehalfOfSubID
const int DeliverToSubID
const int TargetCompID
void setField(const FieldBase &field, bool overwrite=true)
Set a field without type checking.
Definition: FieldMap.h:79
void removeField(int field)
Remove a field. If field is not present, this is a no-op.
Definition: FieldMap.cpp:117
const char BeginString_FIX41[]
Definition: Values.h:35
const int SenderCompID
const int DeliverToCompID
Header m_header
Definition: Message.h:338
const int BeginString

◆ setGroup()

void FIX::Message::setGroup ( const std::string &  msg,
const FieldBase field,
const std::string &  string,
std::string::size_type &  pos,
FieldMap map,
const DataDictionary dataDictionary 
)

Definition at line 336 of file Message.cpp.

References FIX::FieldMap::addGroupPtr(), extractField(), FIX::FieldBase::getField(), FIX::DataDictionary::getGroup(), FIX::DataDictionary::getOrderedFields(), and FIX::DataDictionary::isField().

Referenced by setString().

340 {
341  int group = field.getField();
342  int delim;
343  const DataDictionary* pDD = 0;
344  if ( !dataDictionary.getGroup( msg, group, delim, pDD ) ) return ;
345  std::auto_ptr<Group> pGroup;
346 
347  while ( pos < string.size() )
348  {
349  std::string::size_type oldPos = pos;
350  FieldBase field = extractField( string, pos, &dataDictionary, &dataDictionary, pGroup.get() );
351 
352  // Start a new group because...
353  if (// found delimiter
354  (field.getField() == delim) ||
355  // no delimiter, but field belongs to group OR field already processed
356  (pDD->isField( field.getField() ) && (pGroup.get() == 0 || pGroup->isSetField( field.getField() )) ))
357  {
358  if ( pGroup.get() )
359  {
360  map.addGroupPtr( group, pGroup.release(), false );
361  }
362  pGroup.reset( new Group( field.getField(), delim, pDD->getOrderedFields() ) );
363  }
364  else if ( !pDD->isField( field.getField() ) )
365  {
366  if ( pGroup.get() )
367  {
368  map.addGroupPtr( group, pGroup.release(), false );
369  }
370  pos = oldPos;
371  return ;
372  }
373 
374  if ( !pGroup.get() ) return ;
375  pGroup->setField( field, false );
376  setGroup( msg, field, string, pos, *pGroup, *pDD );
377  }
378 }
void setGroup(const std::string &msg, const FieldBase &field, const std::string &string, std::string::size_type &pos, FieldMap &map, const DataDictionary &dataDictionary)
Definition: Message.cpp:336
FieldBase extractField(const std::string &string, std::string::size_type &pos, const DataDictionary *pSessionDD=0, const DataDictionary *pAppDD=0, const Group *pGroup=0)
Definition: Message.cpp:531
void setField(int field)
Definition: Field.h:93
friend class DataDictionary
Definition: Message.h:69

◆ setSessionID()

void FIX::Message::setSessionID ( const SessionID sessionID)

Sets the session ID of the intended recipient.

Definition at line 482 of file Message.cpp.

References FIX::SessionID::getBeginString(), getHeader(), FIX::SessionID::getSenderCompID(), FIX::SessionID::getTargetCompID(), and FIX::FieldMap::setField().

483 {
484  getHeader().setField( sessionID.getBeginString() );
485  getHeader().setField( sessionID.getSenderCompID() );
486  getHeader().setField( sessionID.getTargetCompID() );
487 }
const Header & getHeader() const
Getter for the message header.
Definition: Message.h:192
void setField(const FieldBase &field, bool overwrite=true)
Set a field without type checking.
Definition: FieldMap.h:79

◆ setString() [1/4]

void FIX::Message::setString ( const std::string &  string)
throw (InvalidMessage
)
inline

Set a message based on a string representation This will fill in the fields on the message by parsing out the string that is passed in.

It will return true on success and false on failure.

Definition at line 162 of file Message.h.

Referenced by Message().

164  { setString(string, true); }
void setString(const std::string &string)
Set a message based on a string representation This will fill in the fields on the message by parsing...
Definition: Message.h:162

◆ setString() [2/4]

void FIX::Message::setString ( const std::string &  string,
bool  validate 
)
throw (InvalidMessage
)
inline

Definition at line 165 of file Message.h.

167  { setString(string, validate, 0); }
void validate()
Definition: Message.cpp:489
void setString(const std::string &string)
Set a message based on a string representation This will fill in the fields on the message by parsing...
Definition: Message.h:162

◆ setString() [3/4]

void FIX::Message::setString ( const std::string &  string,
bool  validate,
const FIX::DataDictionary pDataDictionary 
)
throw (InvalidMessage
)
inline

Definition at line 168 of file Message.h.

172  { setString(string, validate, pDataDictionary, pDataDictionary); }
void validate()
Definition: Message.cpp:489
void setString(const std::string &string)
Set a message based on a string representation This will fill in the fields on the message by parsing...
Definition: Message.h:162

◆ setString() [4/4]

void FIX::Message::setString ( const std::string &  string,
bool  validate,
const FIX::DataDictionary pSessionDataDictionary,
const FIX::DataDictionary pApplicationDataDictionary 
)
throw (InvalidMessage
)

Definition at line 265 of file Message.cpp.

References FIX::FIELD::BeginString, body, FIX::FIELD::BodyLength, clear(), extractField(), FIX::FieldBase::getField(), getHeader(), FIX::FieldBase::getString(), getTrailer(), header, FIX::headerOrder, isHeaderField(), isTrailerField(), m_field, m_header, m_trailer, m_validStructure, FIX::FIELD::MsgType, FIX::FieldMap::setField(), setGroup(), trailer, and validate().

270 {
271  clear();
272 
273  std::string::size_type pos = 0;
274  int count = 0;
275  std::string msg;
276 
277  static int const headerOrder[] =
278  {
282  };
283 
284  field_type type = header;
285 
286  while ( pos < string.size() )
287  {
288  FieldBase field = extractField( string, pos, pSessionDataDictionary, pApplicationDataDictionary );
289  if ( count < 3 && headerOrder[ count++ ] != field.getField() )
290  if ( doValidation ) throw InvalidMessage("Header fields out of order");
291 
292  if ( isHeaderField( field, pSessionDataDictionary ) )
293  {
294  if ( type != header )
295  {
296  if(m_field == 0) m_field = field.getField();
297  m_validStructure = false;
298  }
299 
300  if ( field.getField() == FIELD::MsgType )
301  msg = field.getString();
302 
303  m_header.setField( field, false );
304 
305  if ( pSessionDataDictionary )
306  setGroup( "_header_", field, string, pos, getHeader(), *pSessionDataDictionary );
307  }
308  else if ( isTrailerField( field, pSessionDataDictionary ) )
309  {
310  type = trailer;
311  m_trailer.setField( field, false );
312 
313  if ( pSessionDataDictionary )
314  setGroup( "_trailer_", field, string, pos, getTrailer(), *pSessionDataDictionary );
315  }
316  else
317  {
318  if ( type == trailer )
319  {
320  if(m_field == 0) m_field = field.getField();
321  m_validStructure = false;
322  }
323 
324  type = body;
325  setField( field, false );
326 
327  if ( pApplicationDataDictionary )
328  setGroup( msg, field, string, pos, *this, *pApplicationDataDictionary );
329  }
330  }
331 
332  if ( doValidation )
333  validate();
334 }
void validate()
Definition: Message.cpp:489
void setGroup(const std::string &msg, const FieldBase &field, const std::string &string, std::string::size_type &pos, FieldMap &map, const DataDictionary &dataDictionary)
Definition: Message.cpp:336
const Header & getHeader() const
Getter for the message header.
Definition: Message.h:192
FieldBase extractField(const std::string &string, std::string::size_type &pos, const DataDictionary *pSessionDD=0, const DataDictionary *pAppDD=0, const Group *pGroup=0)
Definition: Message.cpp:531
const Trailer & getTrailer() const
Getter for the message trailer.
Definition: Message.h:196
void setField(const FieldBase &field, bool overwrite=true)
Set a field without type checking.
Definition: FieldMap.h:79
int m_field
Definition: Message.h:341
void clear()
Definition: Message.h:242
Header m_header
Definition: Message.h:338
const int BeginString
const int BodyLength
const int MsgType
static bool isHeaderField(int field)
Definition: Message.cpp:400
static bool isTrailerField(int field)
Definition: Message.cpp:447
bool m_validStructure
Definition: Message.h:340
static int const headerOrder[]
Definition: Message.h:40
Trailer m_trailer
Definition: Message.h:339

◆ setStringHeader()

bool FIX::Message::setStringHeader ( const std::string &  string)

Set a messages header from a string This is an optimization that can be used to get useful information from the header of a FIX string without parsing the whole thing.

Definition at line 380 of file Message.cpp.

References clear(), extractField(), FIX::FieldBase::getField(), FIX::headerOrder, isHeaderField(), m_header, and FIX::FieldMap::setField().

Referenced by FIX::Acceptor::getSession(), FIX::Session::lookupSession(), Message(), and FIX::Session::nextResendRequest().

381 {
382  clear();
383 
384  std::string::size_type pos = 0;
385  int count = 0;
386 
387  while ( pos < string.size() )
388  {
389  FieldBase field = extractField( string, pos );
390  if ( count < 3 && headerOrder[ count++ ] != field.getField() )
391  return false;
392 
393  if ( isHeaderField( field ) )
394  m_header.setField( field, false );
395  else break;
396  }
397  return true;
398 }
FieldBase extractField(const std::string &string, std::string::size_type &pos, const DataDictionary *pSessionDD=0, const DataDictionary *pAppDD=0, const Group *pGroup=0)
Definition: Message.cpp:531
void setField(const FieldBase &field, bool overwrite=true)
Set a field without type checking.
Definition: FieldMap.h:79
void clear()
Definition: Message.h:242
Header m_header
Definition: Message.h:338
static bool isHeaderField(int field)
Definition: Message.cpp:400
static int const headerOrder[]
Definition: Message.h:40

◆ toApplVerID()

static ApplVerID FIX::Message::toApplVerID ( const BeginString &  value)
inlinestatic

Definition at line 257 of file Message.h.

References FIX::FIELD::ApplVerID, FIX::ApplVerID_FIX40, FIX::ApplVerID_FIX41, FIX::ApplVerID_FIX42, FIX::ApplVerID_FIX43, FIX::ApplVerID_FIX44, FIX::ApplVerID_FIX50, FIX::ApplVerID_FIX50SP1, FIX::ApplVerID_FIX50SP2, FIX::BeginString_FIX40, FIX::BeginString_FIX41, FIX::BeginString_FIX42, FIX::BeginString_FIX43, FIX::BeginString_FIX44, and FIX::BeginString_FIX50.

Referenced by FIX::SessionFactory::create(), FIX::Session::next(), FIX::SessionFactory::processFixDataDictionary(), and FIX::SessionFactory::processFixtDataDictionaries().

258  {
259  if( value == BeginString_FIX40 )
260  return ApplVerID(ApplVerID_FIX40);
261  if( value == BeginString_FIX41 )
262  return ApplVerID(ApplVerID_FIX41);
263  if( value == BeginString_FIX42 )
264  return ApplVerID(ApplVerID_FIX42);
265  if( value == BeginString_FIX43 )
266  return ApplVerID(ApplVerID_FIX43);
267  if( value == BeginString_FIX44 )
268  return ApplVerID(ApplVerID_FIX44);
269  if( value == BeginString_FIX50 )
270  return ApplVerID(ApplVerID_FIX50);
271  if( value == "FIX.5.0SP1" )
273  if( value == "FIX.5.0SP2" )
275  return ApplVerID(ApplVerID(value));
276  }
const int ApplVerID
const char BeginString_FIX44[]
Definition: Values.h:32
const char ApplVerID_FIX44[]
Definition: FixValues.h:816
const char BeginString_FIX42[]
Definition: Values.h:34
const char BeginString_FIX50[]
Definition: Values.h:31
const char BeginString_FIX43[]
Definition: Values.h:33
const char ApplVerID_FIX40[]
Definition: FixValues.h:811
const char ApplVerID_FIX43[]
Definition: FixValues.h:815
const char ApplVerID_FIX50SP1[]
Definition: FixValues.h:807
const char BeginString_FIX41[]
Definition: Values.h:35
const char BeginString_FIX40[]
Definition: Values.h:36
const char ApplVerID_FIX50SP2[]
Definition: FixValues.h:809
const char ApplVerID_FIX42[]
Definition: FixValues.h:814
const char ApplVerID_FIX50[]
Definition: FixValues.h:810
const char ApplVerID_FIX41[]
Definition: FixValues.h:812

◆ toBeginString()

static BeginString FIX::Message::toBeginString ( const ApplVerID &  applVerID)
inlinestatic

Definition at line 278 of file Message.h.

References FIX::ApplVerID_FIX40, FIX::ApplVerID_FIX41, FIX::ApplVerID_FIX42, FIX::ApplVerID_FIX43, FIX::ApplVerID_FIX44, FIX::ApplVerID_FIX50, FIX::ApplVerID_FIX50SP1, FIX::ApplVerID_FIX50SP2, FIX::FIELD::BeginString, FIX::BeginString_FIX40, FIX::BeginString_FIX41, FIX::BeginString_FIX42, FIX::BeginString_FIX43, FIX::BeginString_FIX44, and FIX::BeginString_FIX50.

279  {
280  if( applVerID == ApplVerID_FIX40 )
282  else if( applVerID == ApplVerID_FIX41 )
284  else if( applVerID == ApplVerID_FIX42 )
286  else if( applVerID == ApplVerID_FIX43 )
288  else if( applVerID == ApplVerID_FIX44 )
290  else if( applVerID == ApplVerID_FIX50 )
292  else if( applVerID == ApplVerID_FIX50SP1 )
294  else if( applVerID == ApplVerID_FIX50SP2 )
296  else
297  return BeginString("");
298  }
const char BeginString_FIX44[]
Definition: Values.h:32
const char ApplVerID_FIX44[]
Definition: FixValues.h:816
const char BeginString_FIX42[]
Definition: Values.h:34
const char BeginString_FIX50[]
Definition: Values.h:31
const char BeginString_FIX43[]
Definition: Values.h:33
const char ApplVerID_FIX40[]
Definition: FixValues.h:811
const char ApplVerID_FIX43[]
Definition: FixValues.h:815
const char ApplVerID_FIX50SP1[]
Definition: FixValues.h:807
const char BeginString_FIX41[]
Definition: Values.h:35
const int BeginString
const char BeginString_FIX40[]
Definition: Values.h:36
const char ApplVerID_FIX50SP2[]
Definition: FixValues.h:809
const char ApplVerID_FIX42[]
Definition: FixValues.h:814
const char ApplVerID_FIX50[]
Definition: FixValues.h:810
const char ApplVerID_FIX41[]
Definition: FixValues.h:812

◆ toString() [1/2]

std::string FIX::Message::toString ( int  beginStringField = FIELD::BeginString,
int  bodyLengthField = FIELD::BodyLength,
int  checkSumField = FIELD::CheckSum 
) const

Get a string representation of the message.

Definition at line 167 of file Message.cpp.

Referenced by FIX::Session::nextResendRequest(), and FIX::Session::sendRaw().

170 {
171  std::string str;
172  return toString( str, beginStringField, bodyLengthField, checkSumField );
173 }
std::string toString(int beginStringField=FIELD::BeginString, int bodyLengthField=FIELD::BodyLength, int checkSumField=FIELD::CheckSum) const
Get a string representation of the message.
Definition: Message.cpp:167

◆ toString() [2/2]

std::string & FIX::Message::toString ( std::string &  str,
int  beginStringField = FIELD::BeginString,
int  bodyLengthField = FIELD::BodyLength,
int  checkSumField = FIELD::CheckSum 
) const

Get a string representation without making a copy.

Definition at line 175 of file Message.cpp.

References bodyLength(), FIX::FieldMap::calculateString(), checkSum(), m_header, m_trailer, and FIX::FieldMap::setField().

179 {
180  int length = bodyLength( beginStringField, bodyLengthField, checkSumField );
181  m_header.setField( IntField(bodyLengthField, length) );
182  m_trailer.setField( CheckSumField(checkSumField, checkSum(checkSumField)) );
183 
184 #if defined(_MSC_VER) && _MSC_VER < 1300
185  str = "";
186 #else
187  str.clear();
188 #endif
189 
190  /*small speculation about the space needed for FIX string*/
191  str.reserve( length + 64 );
192 
193  m_header.calculateString( str );
195  m_trailer.calculateString( str );
196 
197  return str;
198 }
int checkSum(int checkSumField=FIELD::CheckSum) const
Definition: Message.h:213
int bodyLength(int beginStringField=FIELD::BeginString, int bodyLengthField=FIELD::BodyLength, int checkSumField=FIELD::CheckSum) const
Definition: Message.h:205
void setField(const FieldBase &field, bool overwrite=true)
Set a field without type checking.
Definition: FieldMap.h:79
std::string & calculateString(std::string &) const
Definition: FieldMap.cpp:176
Header m_header
Definition: Message.h:338
Trailer m_trailer
Definition: Message.h:339

◆ toXML() [1/2]

std::string FIX::Message::toXML ( ) const

Get a XML representation of the message.

Definition at line 200 of file Message.cpp.

201 {
202  std::string str;
203  return toXML( str );
204 }
std::string toXML() const
Get a XML representation of the message.
Definition: Message.cpp:200

◆ toXML() [2/2]

std::string & FIX::Message::toXML ( std::string &  str) const

Get a XML representation without making a copy.

Definition at line 206 of file Message.cpp.

References getHeader(), getTrailer(), and toXMLFields().

207 {
208  std::stringstream stream;
209  stream << "<message>" << std::endl
210  << std::setw(2) << " " << "<header>" << std::endl
211  << toXMLFields(getHeader(), 4)
212  << std::setw(2) << " " << "</header>" << std::endl
213  << std::setw(2) << " " << "<body>" << std::endl
214  << toXMLFields(*this, 4)
215  << std::setw(2) << " " << "</body>" << std::endl
216  << std::setw(2) << " " << "<trailer>" << std::endl
217  << toXMLFields(getTrailer(), 4)
218  << std::setw(2) << " " << "</trailer>" << std::endl
219  << "</message>";
220 
221  return str = stream.str();
222 }
std::string toXMLFields(const FieldMap &fields, int space) const
Definition: Message.cpp:224
const Header & getHeader() const
Getter for the message header.
Definition: Message.h:192
const Trailer & getTrailer() const
Getter for the message trailer.
Definition: Message.h:196

◆ toXMLFields()

std::string FIX::Message::toXMLFields ( const FieldMap fields,
int  space 
) const
private

Definition at line 224 of file Message.cpp.

References FIX::FieldMap::begin(), FIX::FieldMap::end(), FIX::FieldMap::g_begin(), FIX::FieldMap::g_end(), and s_dataDictionary.

Referenced by toXML().

225 {
226  std::stringstream stream;
228  std::string name;
229  for(i = fields.begin(); i != fields.end(); ++i)
230  {
231  int field = i->first;
232  std::string value = i->second.getString();
233 
234  stream << std::setw(space) << " " << "<field ";
235  if(s_dataDictionary.get() && s_dataDictionary->getFieldName(field, name))
236  {
237  stream << "name=\"" << name << "\" ";
238  }
239  stream << "number=\"" << field << "\"";
240  if(s_dataDictionary.get()
241  && s_dataDictionary->getValueName(field, value, name))
242  {
243  stream << " enum=\"" << name << "\"";
244  }
245  stream << ">";
246  stream << "<![CDATA[" << value << "]]>";
247  stream << "</field>" << std::endl;
248  }
249 
251  for(j = fields.g_begin(); j != fields.g_end(); ++j)
252  {
253  std::vector<FieldMap*>::const_iterator k;
254  for(k = j->second.begin(); k != j->second.end(); ++k)
255  {
256  stream << std::setw(space) << " " << "<group>" << std::endl
257  << toXMLFields(*(*k), space+2)
258  << std::setw(space) << " " << "</group>" << std::endl;
259  }
260  }
261 
262  return stream.str();
263 }
Fields::const_iterator iterator
Definition: FieldMap.h:59
Groups::const_iterator g_iterator
Definition: FieldMap.h:61
std::string toXMLFields(const FieldMap &fields, int space) const
Definition: Message.cpp:224
static std::auto_ptr< DataDictionary > s_dataDictionary
Definition: Message.h:342

◆ validate()

void FIX::Message::validate ( )
private

Definition at line 489 of file Message.cpp.

References bodyLength(), FIX::FIELD::BodyLength, checkSum(), FIX::FIELD::CheckSum, FIX::Exception::detail, FIX::FieldNotFound::field, FIX::IncorrectDataFormat::field, FIELD_GET_REF, m_header, and m_trailer.

Referenced by Message(), and setString().

490 {
491  try
492  {
493  const BodyLength& aBodyLength = FIELD_GET_REF( m_header, BodyLength );
494 
495  const int expectedLength = (int)aBodyLength;
496  const int actualLength = bodyLength();
497 
498  if ( expectedLength != actualLength )
499  {
500  std::stringstream text;
501  text << "Expected BodyLength=" << actualLength
502  << ", Received BodyLength=" << expectedLength;
503  throw InvalidMessage(text.str());
504  }
505 
506  const CheckSum& aCheckSum = FIELD_GET_REF( m_trailer, CheckSum );
507 
508  const int expectedChecksum = (int)aCheckSum;
509  const int actualChecksum = checkSum();
510 
511  if ( expectedChecksum != actualChecksum )
512  {
513  std::stringstream text;
514  text << "Expected CheckSum=" << actualChecksum
515  << ", Received CheckSum=" << expectedChecksum;
516  throw InvalidMessage(text.str());
517  }
518  }
519  catch ( FieldNotFound& e )
520  {
521  const std::string fieldName = ( e.field == FIX::FIELD::BodyLength ) ? "BodyLength" : "CheckSum";
522  throw InvalidMessage( fieldName + std::string(" is missing") );
523  }
524  catch ( IncorrectDataFormat& e )
525  {
526  const std::string fieldName = ( e.field == FIX::FIELD::BodyLength ) ? "BodyLength" : "CheckSum";
527  throw InvalidMessage( fieldName + std::string(" has wrong format: ") + e.detail );
528  }
529 }
int checkSum(int checkSumField=FIELD::CheckSum) const
Definition: Message.h:213
int bodyLength(int beginStringField=FIELD::BeginString, int bodyLengthField=FIELD::BodyLength, int checkSumField=FIELD::CheckSum) const
Definition: Message.h:205
Header m_header
Definition: Message.h:338
const int BodyLength
#define FIELD_GET_REF(MAP, FLD)
Definition: FieldMap.h:238
const int CheckSum
Trailer m_trailer
Definition: Message.h:339

Friends And Related Function Documentation

◆ DataDictionary

friend class DataDictionary
friend

Definition at line 69 of file Message.h.

Referenced by InitializeXML().

◆ Session

friend class Session
friend

Definition at line 70 of file Message.h.

Member Data Documentation

◆ m_field

int FIX::Message::m_field
protected

Definition at line 341 of file Message.h.

Referenced by Message(), and setString().

◆ m_header

Header FIX::Message::m_header
mutableprotected

Definition at line 338 of file Message.h.

Referenced by Message(), reverseRoute(), setString(), setStringHeader(), toString(), and validate().

◆ m_trailer

Trailer FIX::Message::m_trailer
mutableprotected

Definition at line 339 of file Message.h.

Referenced by Message(), setString(), toString(), and validate().

◆ m_validStructure

bool FIX::Message::m_validStructure
protected

Definition at line 340 of file Message.h.

Referenced by Message(), and setString().

◆ s_dataDictionary

std::auto_ptr< DataDictionary > FIX::Message::s_dataDictionary
staticprotected

Definition at line 342 of file Message.h.

Referenced by InitializeXML(), and toXMLFields().


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

Generated on Thu Sep 5 2019 11:07:58 for QuickFIX by doxygen 1.8.13 written by Dimitri van Heesch, © 1997-2001