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 message_order &hdrOrder, const message_order &trlOrder, const message_order &order)
 Construct message with a specified order of fields. More...
 
 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_order &hdrOrder, const message_order &trlOrder, const message_order &order, 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 message_order &hdrOrder, const message_order &trlOrder, const message_order &order, 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)
 
 ~Message ()
 
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 &tag) 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 tag, 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 tag) const throw ( FieldNotFound )
 Get a field without a field class. More...
 
const FieldBasegetFieldRef (int tag) const throw ( FieldNotFound )
 Get direct access to a field through a reference. More...
 
const FieldBase *const getFieldPtr (int tag) 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 tag) const
 Check to see if a field is set by referencing its number. More...
 
void removeField (int tag)
 Remove a field. If field is not present, this is a no-op. More...
 
void addGroup (int tag, const FieldMap &group, bool setCount=true)
 Add a group. More...
 
void addGroupPtr (int tag, FieldMap *group, bool setCount=true)
 Acquire ownership of Group object. More...
 
void replaceGroup (int num, int tag, const FieldMap &group)
 Replace a specific instance of a group. More...
 
FieldMapgetGroup (int num, int tag, FieldMap &group) const throw ( FieldNotFound )
 Get a specific instance of a group. More...
 
FieldMapgetGroupRef (int num, int tag) const throw ( FieldNotFound )
 Get direct access to a field through a reference. More...
 
FieldMapgetGroupPtr (int num, int tag) const throw ( FieldNotFound )
 Get direct access to a field through a pointer. More...
 
void removeGroup (int num, int tag)
 Remove a specific instance of a group. More...
 
void removeGroup (int tag)
 Remove all instances of a group. More...
 
bool hasGroup (int tag) const
 Check to see any instance of a group exists. More...
 
bool hasGroup (int num, int tag) const
 Check to see if a specific instance of a group exists. More...
 
size_t groupCount (int tag) 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 ()
 
iterator end ()
 
const_iterator begin () const
 
const_iterator end () const
 
g_iterator g_begin ()
 
g_iterator g_end ()
 
g_const_iterator g_begin () const
 
g_const_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 isHeaderField (int field, const DataDictionary *pD)
 
static bool isTrailerField (int field)
 
static bool isTrailerField (const FieldBase &field, const DataDictionary *pD=0)
 
static bool isTrailerField (int field, const DataDictionary *pD)
 

Protected Member Functions

 Message (const BeginString &beginString, const MsgType &msgType)
 
- Protected Member Functions inherited from FIX::FieldMap
 FieldMap (const message_order &order, int size)
 
void addField (const FieldBase &field)
 
const FieldBasereverse_find (int tag) const
 
void appendField (const FieldBase &field)
 
void sortFields ()
 

Protected Attributes

Header m_header
 
Trailer m_trailer
 
bool m_validStructure
 
int m_tag
 

Static Protected Attributes

static SmartPtr< 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) const
 
void validate () const
 
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::vector< FieldBase, ALLOCATOR< FieldBase > > Fields
 
typedef std::map< int, std::vector< FieldMap * >, std::less< int >, ALLOCATOR< std::pair< const int, std::vector< FieldMap * > > > > Groups
 
typedef Fields::iterator iterator
 
typedef Fields::const_iterator const_iterator
 
typedef Groups::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 134 of file Message.h.

Member Enumeration Documentation

◆ field_type

Enumerator
header 
body 
trailer 

Definition at line 139 of file Message.h.

Constructor & Destructor Documentation

◆ Message() [1/9]

FIX::Message::Message ( )

Definition at line 60 of file Message.cpp.

66 : m_validStructure( true )

◆ Message() [2/9]

FIX::Message::Message ( const message_order hdrOrder,
const message_order trlOrder,
const message_order order 
)

Construct message with a specified order of fields.

Definition at line 67 of file Message.cpp.

68 {
69  setString( string, validate, &dataDictionary, &dataDictionary );

◆ Message() [3/9]

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

Construct a message from a string.

Definition at line 71 of file Message.cpp.

77 : m_validStructure( true )

◆ Message() [4/9]

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 79 of file Message.cpp.

79 {
80  setString( string, validate, &sessionDataDictionary, &applicationDataDictionary );
81 }
82 
83 Message::Message( const message_order &hdrOrder,
84  const message_order &trlOrder,
85  const message_order& order,
86  const std::string& string,
87  const DataDictionary& dataDictionary,

◆ Message() [5/9]

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 89 of file Message.cpp.

90 : FieldMap(order), m_header(hdrOrder),
91  m_trailer(trlOrder), m_validStructure( true )
92 {
93  setString( string, validate, &dataDictionary, &dataDictionary );
94 }
95 
96 Message::Message( const message_order &hdrOrder,
97  const message_order &trlOrder,
98  const message_order& order,

◆ Message() [6/9]

FIX::Message::Message ( const message_order hdrOrder,
const message_order trlOrder,
const message_order order,
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 100 of file Message.cpp.

104 : FieldMap(order), m_header(hdrOrder),
105  m_trailer(trlOrder), m_validStructure( true )
106 {
107  setStringHeader( string );
108  if( isAdmin() )
109  setString( string, validate, &sessionDataDictionary, &sessionDataDictionary );
110  else
111  setString( string, validate, &sessionDataDictionary, &applicationDataDictionary );

◆ Message() [7/9]

FIX::Message::Message ( const message_order hdrOrder,
const message_order trlOrder,
const message_order order,
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 113 of file Message.cpp.

115 : m_validStructure(true)
116 , m_tag( 0 )
117 {
118  m_header.setField(beginString);
119  m_header.setField(msgType);
120 }
121 
122 Message::Message(const Message& copy)
123 : FieldMap(copy)
124 , m_header(copy.m_header)
125 , m_trailer(copy.m_trailer)
127 , m_tag(copy.m_tag)
128 #ifdef HAVE_EMX
129 , m_subMsgType(copy.m_subMsgType)

References m_header, and FIX::FieldMap::setField().

◆ Message() [8/9]

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

Definition at line 139 of file Message.cpp.

140 {
141  try
142  {
143  s_dataDictionary.reset(new DataDictionary(url));
144  return true;
145  }
146  catch( ConfigError& )
147  { return false; }
148 }
149 
150 void Message::reverseRoute( const Header& header )

References DataDictionary, and s_dataDictionary.

◆ ~Message()

FIX::Message::~Message ( )

Definition at line 152 of file Message.cpp.

162  {

◆ Message() [9/9]

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

Definition at line 131 of file Message.cpp.

131 {
132 
133 }
134 
136 {
137 }

Member Function Documentation

◆ addGroup()

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

Definition at line 178 of file Message.h.

179  { return FieldMap::hasGroup( group.field() ); }

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

◆ bodyLength()

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

Definition at line 275 of file Message.h.

281  {

◆ checkSum()

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

Definition at line 283 of file Message.h.

289  { return m_header.isEmpty() && FieldMap::isEmpty() && m_trailer.isEmpty(); }

◆ clear()

void FIX::Message::clear ( )
inline

Definition at line 308 of file Message.h.

308  {
309  if( value == BeginString_FIX40 )
310  return ApplVerID(ApplVerID_FIX40);
311  if( value == BeginString_FIX41 )
312  return ApplVerID(ApplVerID_FIX41);
313  if( value == BeginString_FIX42 )
314  return ApplVerID(ApplVerID_FIX42);
315  if( value == BeginString_FIX43 )

References FIX::BeginString_FIX40, FIX::BeginString_FIX41, FIX::BeginString_FIX42, and FIX::BeginString_FIX43.

◆ 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 
) const
private

Definition at line 656 of file Message.cpp.

661  {
662  // Assume length field is 1 less.
663  int lenField = field - 1;
664  // Special case for Signature which violates above assumption.
665  if ( field == FIELD::Signature ) lenField = FIELD::SignatureLength;
666 
667  // identify part of the message that should contain length field
668  const FieldMap * location = pGroup;
669  if ( !location )
670  {
671  if ( isHeaderField( lenField, pSessionDD ) )
672  location = &m_header;
673  else if ( isTrailerField( lenField, pSessionDD ) )
674  location = &m_trailer;
675  else
676  location = this;
677  }
678 
679  try
680  {
681  const FieldBase& fieldLength = location->reverse_find( lenField );
682  soh = valueStart + IntConvertor::convert( fieldLength.getString() );
683  }
684  catch( FieldNotFound& )
685  {
686  throw InvalidMessage( std::string( "Data length field " ) + IntConvertor::convert( lenField ) + std::string( " was not found for data field " ) + IntConvertor::convert( field ) );
687  }
688  catch( FieldConvertError& e )
689  {
690  throw InvalidMessage( std::string( "Unable to determine SOH for data field " ) + IntConvertor::convert( field ) + std::string( ": " ) + e.what() );
691  }
692  }
693 
694  std::string::const_iterator const tagEnd = soh + 1;
695 #if defined(__SUNPRO_CC)
696  std::distance( string.begin(), tagEnd, pos );
697 #else
698  pos = std::distance( string.begin(), tagEnd );
699 #endif
700 
701  return FieldBase (
702  field,
703  valueStart,
704  soh,
705  tagStart,
706  tagEnd );
707 }
708 
709 }

◆ getGroup()

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

Definition at line 184 of file Message.h.

187  :

◆ getHeader() [1/2]

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

Mutable getter for the message header.

Definition at line 264 of file Message.h.

◆ getHeader() [2/2]

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

Getter for the message header.

Definition at line 262 of file Message.h.

Referenced by FIX::Session::generateHeartbeat(), and FIX::Session::lookupSession().

◆ getSessionID()

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

Returns the session ID of the intended recipient.

Definition at line 593 of file Message.cpp.

598 {
599  try
600  {
601  const BodyLength& aBodyLength = FIELD_GET_REF( m_header, BodyLength );
602 
603  const int expectedLength = (int)aBodyLength;
604  const int actualLength = bodyLength();
605 

◆ getTrailer() [1/2]

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

Mutable getter for the message trailer.

Definition at line 268 of file Message.h.

273 {

◆ getTrailer() [2/2]

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

Getter for the message trailer.

Definition at line 266 of file Message.h.

267 { return ( m_header.calculateTotal(checkSumField)

References FIX::FieldMap::calculateTotal(), and m_header.

◆ hasGroup() [1/2]

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

Definition at line 195 of file Message.h.

◆ hasGroup() [2/2]

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

Definition at line 197 of file Message.h.

◆ hasValidStructure()

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

Definition at line 270 of file Message.h.

273  {

◆ InitializeXML()

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

Set global data dictionary for encoding messages into XML.

Definition at line 156 of file Message.cpp.

162  {
163  if( beginString.getValue().size() )
164  m_header.setField( beginString );
165 

References m_header, and FIX::FieldMap::setField().

◆ isAdmin()

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

Definition at line 289 of file Message.h.

289  { return m_header.isEmpty() && FieldMap::isEmpty() && m_trailer.isEmpty(); }
290 
291  void clear()
292  {
293  m_tag = 0;
294  m_validStructure = true;
295  m_header.clear();

References FIX::FieldMap::isEmpty(), m_header, and m_trailer.

◆ isAdminMsgType()

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

Definition at line 317 of file Message.h.

329  {

◆ isApp()

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

Definition at line 297 of file Message.h.

301  { if ( msgType.getValue().length() != 1 ) return false;
302  return strchr
303  ( "0A12345",

◆ IsDataField()

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

Definition at line 396 of file Message.h.

396  :
397  mutable Header m_header;
398  mutable Trailer m_trailer;
399  bool m_validStructure;
400  int m_tag;
401 #ifdef HAVE_EMX
402  std::string m_subMsgType;
403 #endif
404  static SmartPtr<DataDictionary> s_dataDictionary;
405 };
408 inline std::ostream& operator <<

◆ isEmpty()

bool FIX::Message::isEmpty ( )
inline

Definition at line 305 of file Message.h.

308  {

◆ isHeaderField() [1/3]

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

Definition at line 553 of file Message.cpp.

553  {
554  case FIELD::SignatureLength:
555  case FIELD::Signature:
556  case FIELD::CheckSum:
557  return true;

◆ isHeaderField() [2/3]

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

Definition at line 514 of file Message.cpp.

514  :
515  case FIELD::OnBehalfOfLocationID:
516  case FIELD::DeliverToSubID:
517  case FIELD::DeliverToLocationID:
518  case FIELD::PossDupFlag:
519  case FIELD::PossResend:
520  case FIELD::SendingTime:
521  case FIELD::OrigSendingTime:
522  case FIELD::XmlDataLen:
523  case FIELD::XmlData:
524  case FIELD::MessageEncoding:
525  case FIELD::LastMsgSeqNumProcessed:
526  case FIELD::OnBehalfOfSendingTime:
527  case FIELD::ApplVerID:
528  case FIELD::CstmApplVerID:
529  case FIELD::NoHops:
530  return true;
531  default:
532  return false;
533  };
534 }
535 
536 bool Message::isHeaderField( const FieldBase& field,
537  const DataDictionary* pD )
538 {
539  return isHeaderField( field.getTag(), pD );
540 }
541 
542 bool Message::isHeaderField( int field,
543  const DataDictionary * pD )
544 {
545  if ( isHeaderField( field ) ) return true;
546  if ( pD ) return pD->isHeaderField( field );
547  return false;
548 }
549 
550 bool Message::isTrailerField( int field )
551 {

Referenced by FIX::DataDictionary::iterate().

◆ isHeaderField() [3/3]

bool FIX::Message::isHeaderField ( int  field,
const DataDictionary pD 
)
static

Definition at line 559 of file Message.cpp.

565 {

◆ isTrailerField() [1/3]

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

Definition at line 580 of file Message.cpp.

◆ isTrailerField() [2/3]

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

Definition at line 567 of file Message.cpp.

570 {
571  if ( isTrailerField( field ) ) return true;
572  if ( pD ) return pD->isTrailerField( field );
573  return false;
574 }
575 
576 SessionID Message::getSessionID( const std::string& qualifier ) const
577 throw( FieldNotFound )
578 {

Referenced by FIX::DataDictionary::iterate().

◆ isTrailerField() [3/3]

bool FIX::Message::isTrailerField ( int  field,
const DataDictionary pD 
)
static

Definition at line 586 of file Message.cpp.

591 {

◆ removeGroup() [1/2]

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

Definition at line 192 of file Message.h.

◆ removeGroup() [2/2]

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

Definition at line 190 of file Message.h.

◆ replaceGroup()

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

Definition at line 181 of file Message.h.

181  { return FieldMap::hasGroup( num, group.field() ); }
182 

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

◆ 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 167 of file Message.cpp.

173  {
174  if( header.getFieldIfSet( onBehalfOfLocationID ) )
175  {
176  if( onBehalfOfLocationID.getValue().size() )
177  m_header.setField( DeliverToLocationID( onBehalfOfLocationID ) );
178  }
179 
180  if( header.getFieldIfSet( deliverToLocationID ) )
181  {
182  if( deliverToLocationID.getValue().size() )
183  m_header.setField( OnBehalfOfLocationID( deliverToLocationID ) );
184  }
185  }
186  }
187 
188  if( header.getFieldIfSet( senderCompID ) )
189  {
190  if( senderCompID.getValue().size() )
191  m_header.setField( TargetCompID( senderCompID ) );
192  }
193 
194  if( header.getFieldIfSet( targetCompID ) )
195  {
196  if( targetCompID.getValue().size() )
197  m_header.setField( SenderCompID( targetCompID ) );
198  }
199 
200  // optional routing tags
201  OnBehalfOfCompID onBehalfOfCompID;
202  OnBehalfOfSubID onBehalfOfSubID;
203  DeliverToCompID deliverToCompID;
204  DeliverToSubID deliverToSubID;
205 
206  m_header.removeField( onBehalfOfCompID.getTag() );
207  m_header.removeField( onBehalfOfSubID.getTag() );
208  m_header.removeField( deliverToCompID.getTag() );
209  m_header.removeField( deliverToSubID.getTag() );
210 
211  if( header.getFieldIfSet( onBehalfOfCompID ) )
212  {
213  if( onBehalfOfCompID.getValue().size() )
214  m_header.setField( DeliverToCompID( onBehalfOfCompID ) );
215  }
216 
217  if( header.getFieldIfSet( onBehalfOfSubID ) )
218  {
219  if( onBehalfOfSubID.getValue().size() )
220  m_header.setField( DeliverToSubID( onBehalfOfSubID ) );
221  }
222 
223  if( header.getFieldIfSet( deliverToCompID ) )
224  {
225  if( deliverToCompID.getValue().size() )
226  m_header.setField( OnBehalfOfCompID( deliverToCompID ) );
227  }
228 
229  if( header.getFieldIfSet( deliverToSubID ) )
230  {
231  if( deliverToSubID.getValue().size() )
232  m_header.setField( OnBehalfOfSubID( deliverToSubID ) );
233  }
234 }
235 
236 std::string Message::toString( int beginStringField,
237  int bodyLengthField,
238  int checkSumField ) const
239 {
240  std::string str;
241  toString( str, beginStringField, bodyLengthField, checkSumField );
242  return str;
243 }
244 
245 std::string& Message::toString( std::string& str,
246  int beginStringField,
247  int bodyLengthField,
248  int checkSumField ) const
249 {
250  int length = bodyLength( beginStringField, bodyLengthField, checkSumField );
251  m_header.setField( IntField(bodyLengthField, length) );

References header, m_header, and FIX::FieldMap::setField().

◆ 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 448 of file Message.cpp.

452  {
453  if ( pGroup.get() )
454  {
455  map.addGroupPtr( group, pGroup.release(), false );
456  }
457  pGroup.reset( new Group( field.getTag(), delim, pDD->getOrderedFields() ) );
458  }
459  else if ( !pDD->isField( field.getTag() ) )
460  {
461  if ( pGroup.get() )
462  {
463  map.addGroupPtr( group, pGroup.release(), false );
464  }
465  pos = oldPos;
466  return ;
467  }
468 
469  if ( !pGroup.get() ) return ;
470  pGroup->addField( field );
471  setGroup( msg, field, string, pos, *pGroup, *pDD );
472  }
473 }
474 
475 bool Message::setStringHeader( const std::string& string )
476 {
477  clear();
478 
479  std::string::size_type pos = 0;
480  int count = 0;
481 
482  while ( pos < string.size() )
483  {
484  FieldBase field = extractField( string, pos );
485  if ( count < 3 && headerOrder[ count++ ] != field.getTag() )
486  return false;
487 
488  if ( isHeaderField( field ) )
489  m_header.appendField( field );
490  else break;

◆ setSessionID()

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

Sets the session ID of the intended recipient.

Definition at line 607 of file Message.cpp.

607  {
608  std::stringstream text;
609  text << "Expected BodyLength=" << actualLength
610  << ", Received BodyLength=" << expectedLength;
611  throw InvalidMessage(text.str());
612  }

◆ 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 232 of file Message.h.

◆ setString() [2/4]

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

Definition at line 235 of file Message.h.

◆ setString() [3/4]

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

Definition at line 238 of file Message.h.

245  { return m_header; }

◆ 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 353 of file Message.cpp.

358  {
359  if ( type != header )
360  {
361  if(m_tag == 0) m_tag = field.getTag();
362  m_validStructure = false;
363  }
364 
365  if ( field.getTag() == FIELD::MsgType )
366  {
367  msg.setString( field.getString() );
368  if ( isAdminMsgType( msg ) )
369  {
370  pApplicationDataDictionary = pSessionDataDictionary;
371 #ifdef HAVE_EMX
372  m_subMsgType.assign(msg);
373  }
374  else
375  {
376  std::string::size_type equalSign = string.find("\0019426=", pos);
377  if (equalSign == std::string::npos)
378  throw InvalidMessage("EMX message type (9426) not found");
379 
380  equalSign += 6;
381  std::string::size_type soh = string.find_first_of('\001', equalSign);
382  if (soh == std::string::npos)
383  throw InvalidMessage("EMX message type (9426) soh char not found");
384  m_subMsgType.assign(string.substr(equalSign, soh - equalSign ));
385 #endif
386  }
387  }
388 
389  m_header.appendField( field );
390 
391  if ( pSessionDataDictionary )
392  setGroup( "_header_", field, string, pos, getHeader(), *pSessionDataDictionary );
393  }
394  else if ( isTrailerField( field, pSessionDataDictionary ) )
395  {
396  type = trailer;
397  m_trailer.appendField( field );
398 
399  if ( pSessionDataDictionary )
400  setGroup( "_trailer_", field, string, pos, getTrailer(), *pSessionDataDictionary );
401  }
402  else
403  {
404  if ( type == trailer )
405  {
406  if(m_tag == 0) m_tag = field.getTag();
407  m_validStructure = false;
408  }
409 
410  type = body;
411  appendField( field );
412 
413  if ( pApplicationDataDictionary )
414 #ifdef HAVE_EMX
415  setGroup(m_subMsgType, field, string, pos, *this, *pApplicationDataDictionary);
416 #else
417  setGroup( msg, field, string, pos, *this, *pApplicationDataDictionary );
418 #endif
419  }
420  }
421 
422  // sort fields
424  sortFields();
426 
427  if ( doValidation )
428  validate();
429 }
430 
431 void Message::setGroup( const std::string& msg, const FieldBase& field,
432  const std::string& string,
433  std::string::size_type& pos, FieldMap& map,
434  const DataDictionary& dataDictionary )
435 {
436  int group = field.getTag();
437  int delim;
438  const DataDictionary* pDD = 0;
439  if ( !dataDictionary.getGroup( msg, group, delim, pDD ) ) return ;
440  SmartPtr<Group> pGroup;
441 
442  while ( pos < string.size() )
443  {
444  std::string::size_type oldPos = pos;
445  FieldBase field = extractField( string, pos, &dataDictionary, &dataDictionary, pGroup.get() );
446 

◆ 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 492 of file Message.cpp.

498 {
499  switch ( field )
500  {
501  case FIELD::BeginString:
502  case FIELD::BodyLength:
503  case FIELD::MsgType:
504  case FIELD::SenderCompID:
505  case FIELD::TargetCompID:
506  case FIELD::OnBehalfOfCompID:
507  case FIELD::DeliverToCompID:
508  case FIELD::SecureDataLen:
509  case FIELD::MsgSeqNum:
510  case FIELD::SenderSubID:
511  case FIELD::SenderLocationID:
512  case FIELD::TargetSubID:

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

◆ toApplVerID()

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

Definition at line 324 of file Message.h.

329  {
330  if( applVerID == ApplVerID_FIX40 )
331  return BeginString(BeginString_FIX40);
332  else if( applVerID == ApplVerID_FIX41 )
333  return BeginString(BeginString_FIX41);
334  else if( applVerID == ApplVerID_FIX42 )
335  return BeginString(BeginString_FIX42);
336  else if( applVerID == ApplVerID_FIX43 )
337  return BeginString(BeginString_FIX43);
338  else if( applVerID == ApplVerID_FIX44 )
339  return BeginString(BeginString_FIX44);
340  else if( applVerID == ApplVerID_FIX50 )
341  return BeginString(BeginString_FIX50);
342  else if( applVerID == ApplVerID_FIX50SP1 )
343  return BeginString(BeginString_FIX50);

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

◆ toBeginString()

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

Definition at line 345 of file Message.h.

◆ 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 253 of file Message.cpp.

◆ 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 262 of file Message.cpp.

271 {
272  std::string str;
273  toXML( str );
274  return str;
275 }
276 
277 std::string& Message::toXML( std::string& str ) const
278 {
279  std::stringstream stream;
280  stream << "<message>" << std::endl
281  << std::setw(2) << " " << "<header>" << std::endl
282  << toXMLFields(getHeader(), 4)
283  << std::setw(2) << " " << "</header>" << std::endl
284  << std::setw(2) << " " << "<body>" << std::endl
285  << toXMLFields(*this, 4)

◆ toXML() [1/2]

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

Get a XML representation of the message.

Definition at line 287 of file Message.cpp.

◆ toXML() [2/2]

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

Get a XML representation without making a copy.

Definition at line 294 of file Message.cpp.

296 {
297  std::stringstream stream;
299  std::string name;
300  for(i = fields.begin(); i != fields.end(); ++i)
301  {
302  int field = i->getTag();
303  std::string value = i->getString();
304 
305  stream << std::setw(space) << " " << "<field ";
306  if(s_dataDictionary.get() && s_dataDictionary->getFieldName(field, name))
307  {
308  stream << "name=\"" << name << "\" ";
309  }
310  stream << "number=\"" << field << "\"";

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

◆ toXMLFields()

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

Definition at line 312 of file Message.cpp.

313  {
314  stream << " enum=\"" << name << "\"";
315  }
316  stream << ">";
317  stream << "<![CDATA[" << value << "]]>";
318  stream << "</field>" << std::endl;
319  }
320 
322  for(j = fields.g_begin(); j != fields.g_end(); ++j)
323  {
324  std::vector<FieldMap*>::const_iterator k;
325  for(k = j->second.begin(); k != j->second.end(); ++k)
326  {
327  stream << std::setw(space) << " " << "<group>" << std::endl
328  << toXMLFields(*(*k), space+2)
329  << std::setw(space) << " " << "</group>" << std::endl;
330  }
331  }
332 
333  return stream.str();
334 }
335 
336 void Message::setString( const std::string& string,
337  bool doValidation,
338  const DataDictionary* pSessionDataDictionary,
339  const DataDictionary* pApplicationDataDictionary )
340 throw( InvalidMessage )
341 {
342  clear();
343 
344  std::string::size_type pos = 0;
345  int count = 0;
346 
347  FIX::MsgType msg;
348 
349  field_type type = header;
350 
351  while ( pos < string.size() )

◆ validate()

void FIX::Message::validate ( ) const
private

Definition at line 614 of file Message.cpp.

620  {
621  std::stringstream text;
622  text << "Expected CheckSum=" << actualChecksum
623  << ", Received CheckSum=" << expectedChecksum;
624  throw InvalidMessage(text.str());
625  }
626  }
627  catch ( FieldNotFound& e )
628  {
629  const std::string fieldName = ( e.field == FIX::FIELD::BodyLength ) ? "BodyLength" : "CheckSum";
630  throw InvalidMessage( fieldName + std::string(" is missing") );
631  }
632  catch ( IncorrectDataFormat& e )
633  {
634  const std::string fieldName = ( e.field == FIX::FIELD::BodyLength ) ? "BodyLength" : "CheckSum";
635  throw InvalidMessage( fieldName + std::string(" has wrong format: ") + e.detail );
636  }
637 }
638 
639 FIX::FieldBase Message::extractField( const std::string& string, std::string::size_type& pos,
640  const DataDictionary* pSessionDD /*= 0*/, const DataDictionary* pAppDD /*= 0*/,
641  const Group* pGroup /*= 0*/ ) const
642 {
643  std::string::const_iterator const tagStart = string.begin() + pos;
644  std::string::const_iterator const strEnd = string.end();
645 
646  std::string::const_iterator const equalSign = std::find( tagStart, strEnd, '=' );
647  if( equalSign == strEnd )
648  throw InvalidMessage("Equal sign not found in field");
649 
650  int field = 0;
651  if( !IntConvertor::convert( tagStart, equalSign, field ) )
652  throw InvalidMessage( std::string("Field tag is invalid: ") + std::string( tagStart, equalSign ));
653 
654  std::string::const_iterator const valueStart = equalSign + 1;

Friends And Related Function Documentation

◆ DataDictionary

friend class DataDictionary
friend

Definition at line 136 of file Message.h.

Referenced by Message().

◆ Session

friend class Session
friend

Definition at line 137 of file Message.h.

Member Data Documentation

◆ m_header

Header FIX::Message::m_header
mutableprotected

Definition at line 414 of file Message.h.

Referenced by getTrailer(), InitializeXML(), isAdmin(), Message(), and reverseRoute().

◆ m_tag

int FIX::Message::m_tag
protected

Definition at line 417 of file Message.h.

◆ m_trailer

Trailer FIX::Message::m_trailer
mutableprotected

Definition at line 415 of file Message.h.

Referenced by isAdmin().

◆ m_validStructure

bool FIX::Message::m_validStructure
protected

Definition at line 416 of file Message.h.

◆ s_dataDictionary

SmartPtr< DataDictionary > FIX::Message::s_dataDictionary
staticprotected

Definition at line 421 of file Message.h.

Referenced by Message(), and toXML().


The documentation for this class was generated from the following files:
FIX::BeginString_FIX41
const char BeginString_FIX41[]
Definition: Values.h:52
FIX::Message::header
@ header
Definition: Message.h:139
FIX::headerOrder
const int headerOrder[]
Definition: Message.cpp:51
FIX::FieldMap::calculateTotal
int calculateTotal(int checkSumField=FIELD::CheckSum) const
Definition: FieldMap.cpp:275
FIX::BeginString_FIX44
const char BeginString_FIX44[]
Definition: Values.h:49
FIX::FieldMap::hasGroup
bool hasGroup(int tag) const
Check to see any instance of a group exists.
Definition: FieldMap.cpp:185
FIX::BeginString_FIX40
const char BeginString_FIX40[]
Definition: Values.h:53
FIX::Message::DataDictionary
friend class DataDictionary
Definition: Message.h:136
FIX::FieldMap::clear
void clear()
Clear all fields from the map.
Definition: FieldMap.cpp:199
FIX::BeginString_FIX42
const char BeginString_FIX42[]
Definition: Values.h:51
FIX::FieldMap::FieldMap
FieldMap(const message_order &order, int size)
Definition: FieldMap.cpp:51
FIX::FieldMap::isEmpty
bool isEmpty()
Check if map contains any fields.
Definition: FieldMap.cpp:213
FIX::Message::trailer
@ trailer
Definition: Message.h:139
FIX::Message::getTrailer
const Trailer & getTrailer() const
Getter for the message trailer.
Definition: Message.h:266
FIX::Message::m_validStructure
bool m_validStructure
Definition: Message.h:416
FIX::Group::field
int field() const
Definition: Group.h:90
FIX::Message::body
@ body
Definition: Message.h:139
FIX::Message::~Message
~Message()
Definition: Message.cpp:152
FIX::FieldMap::begin
iterator begin()
Definition: FieldMap.h:292
FIX::Message::Message
Message()
Definition: Message.cpp:60
FIX::Message::field_type
field_type
Definition: Message.h:139
FIX::Message::toXML
std::string toXML() const
Get a XML representation of the message.
Definition: Message.cpp:287
FIX::Message::getSessionID
SessionID getSessionID(const std::string &qualifier="") const
Returns the session ID of the intended recipient.
Definition: Message.cpp:593
FIX::BeginString_FIX50
const char BeginString_FIX50[]
Definition: Values.h:48
FIX::Message::toString
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:253
FIX::Message::clear
void clear()
Definition: Message.h:308
FIX::Message::reverseRoute
void reverseRoute(const Header &)
Add header informations depending on a source message.
Definition: Message.cpp:167
FIX::Message::m_trailer
Trailer m_trailer
Definition: Message.h:415
FIX::Message::isTrailerField
static bool isTrailerField(int field)
Definition: Message.cpp:567
FIX::Message::s_dataDictionary
static SmartPtr< DataDictionary > s_dataDictionary
Definition: Message.h:421
FIX::IntConvertor::convert
static std::string convert(signed_int value)
Definition: FieldConvertors.h:170
FIX::BeginString_FIX43
const char BeginString_FIX43[]
Definition: Values.h:50
FIX::Message::setStringHeader
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:492
FIX::Message::extractField
FieldBase extractField(const std::string &string, std::string::size_type &pos, const DataDictionary *pSessionDD=0, const DataDictionary *pAppDD=0, const Group *pGroup=0) const
Definition: Message.cpp:656
FIX::Message::isAdmin
bool isAdmin() const
Definition: Message.h:289
FIX::Message::isAdminMsgType
static bool isAdminMsgType(const MsgType &msgType)
Definition: Message.h:317
FIX::FieldMap::appendField
void appendField(const FieldBase &field)
Definition: FieldMap.h:331
FIX::FieldMap::g_const_iterator
Groups::const_iterator g_const_iterator
Definition: FieldMap.h:136
FIX::TYPE::XmlData
@ XmlData
Definition: FieldTypes.h:958
FIX::FieldMap::removeField
void removeField(int tag)
Remove a field. If field is not present, this is a no-op.
Definition: FieldMap.cpp:173
FIX::Message::m_header
Header m_header
Definition: Message.h:414
FIX::Message::toXMLFields
std::string toXMLFields(const FieldMap &fields, int space) const
Definition: Message.cpp:312
FIX::Message::m_tag
int m_tag
Definition: Message.h:417
FIX::Message::isHeaderField
static bool isHeaderField(int field)
Definition: Message.cpp:514
FIX::Message::setString
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:232
FIX::FieldMap::setField
void setField(const FieldBase &field, bool overwrite=true)
Set a field without type checking.
Definition: FieldMap.h:150
FIX::Message::setGroup
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:448
FIX::FieldBase
Base representation of all Field classes.
Definition: Field.h:66
FIX::FieldMap::reverse_find
const FieldBase & reverse_find(int tag) const
Definition: FieldMap.h:320
FIX::FieldMap::sortFields
void sortFields()
Definition: FieldMap.h:337
FIELD_GET_REF
#define FIELD_GET_REF(MAP, FLD)
Definition: FieldMap.h:376
FIX::Message::validate
void validate() const
Definition: Message.cpp:614
FIX::Message::bodyLength
int bodyLength(int beginStringField=FIELD::BeginString, int bodyLengthField=FIELD::BodyLength, int checkSumField=FIELD::CheckSum) const
Definition: Message.h:275
FIX::Message::getHeader
const Header & getHeader() const
Getter for the message header.
Definition: Message.h:262
FIX::FieldMap::const_iterator
Fields::const_iterator const_iterator
Definition: FieldMap.h:134

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