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

Member Enumeration Documentation

◆ field_type

Enumerator
header 
body 
trailer 

Definition at line 137 of file Message.h.

Constructor & Destructor Documentation

◆ Message() [1/9]

FIX::Message::Message ( )

Definition at line 58 of file Message.cpp.

58 {
59  setString( string, validate );
60 }
61 
62 Message::Message( const std::string& string,
63  const DataDictionary& dataDictionary,

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

66 : m_validStructure( true )
67 , m_tag( 0 )

◆ Message() [3/9]

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

Construct a message from a string.

Definition at line 69 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 77 of file Message.cpp.

77 : m_validStructure( true )
78 , m_tag( 0 )
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,

◆ 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 87 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,

◆ 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 98 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 );

◆ 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 111 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)

◆ Message() [8/9]

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

Definition at line 137 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 }

◆ ~Message()

FIX::Message::~Message ( )

Definition at line 150 of file Message.cpp.

151 {
152  // required routing tags

◆ Message() [9/9]

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

Definition at line 129 of file Message.cpp.

131 {
132 
133 }
134 

Member Function Documentation

◆ addGroup()

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

Definition at line 176 of file Message.h.

176  { FieldMap::removeGroup( group.field() ); }
177 

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

◆ bodyLength()

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

Definition at line 273 of file Message.h.

273  {
274  MsgType msgType;
275  if( m_header.getFieldIfSet( msgType ) )
276  return isAdminMsgType( msgType );
277  return false;
278  }
279 

References FIX::FieldMap::getFieldIfSet(), isAdminMsgType(), and m_header.

◆ checkSum()

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

Definition at line 281 of file Message.h.

281  {
282  MsgType msgType;
283  if( m_header.getFieldIfSet( msgType ) )
284  return !isAdminMsgType( msgType );
285  return false;

References FIX::FieldMap::getFieldIfSet(), isAdminMsgType(), and m_header.

◆ clear()

void FIX::Message::clear ( )
inline

Definition at line 306 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 )

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

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

183  :
184  // Constructor for derived classes
185  Message( const BeginString& beginString, const MsgType& msgType );
186 

◆ getHeader() [1/2]

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

Mutable getter for the message header.

Definition at line 262 of file Message.h.

◆ getHeader() [2/2]

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

Getter for the message header.

Definition at line 260 of file Message.h.

261 { return m_header.calculateLength(beginStringField, bodyLengthField, checkSumField)

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

Referenced by getSessionID(), 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 591 of file Message.cpp.

591 {
592  getHeader().setField( sessionID.getBeginString() );
593  getHeader().setField( sessionID.getSenderCompID() );
594  getHeader().setField( sessionID.getTargetCompID() );
595 }
596 
597 void Message::validate() const
598 {
599  try
600  {
601  const BodyLength& aBodyLength = FIELD_GET_REF( m_header, BodyLength );
602 
603  const int expectedLength = (int)aBodyLength;

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

◆ getTrailer() [1/2]

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

Mutable 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.

◆ getTrailer() [2/2]

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

Getter for the message trailer.

Definition at line 264 of file Message.h.

◆ hasGroup() [1/2]

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

Definition at line 193 of file Message.h.

◆ hasGroup() [2/2]

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

Definition at line 195 of file Message.h.

◆ hasValidStructure()

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

Definition at line 268 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 154 of file Message.cpp.

162  {
163  if( beginString.getValue().size() )

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

◆ isAdmin()

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

Definition at line 287 of file Message.h.

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

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

◆ isAdminMsgType()

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

Definition at line 315 of file Message.h.

329  {

Referenced by bodyLength(), and checkSum().

◆ isApp()

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

Definition at line 295 of file Message.h.

301  { if ( msgType.getValue().length() != 1 ) return false;

◆ IsDataField()

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

Definition at line 394 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 };

◆ isEmpty()

bool FIX::Message::isEmpty ( )
inline

Definition at line 303 of file Message.h.

308  {

◆ isHeaderField() [1/3]

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

Definition at line 551 of file Message.cpp.

551 {
552  switch ( field )
553  {
554  case FIELD::SignatureLength:
555  case FIELD::Signature:

◆ isHeaderField() [2/3]

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

Definition at line 512 of file Message.cpp.

512  :
513  case FIELD::TargetLocationID:
514  case FIELD::OnBehalfOfSubID:
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 

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

◆ isHeaderField() [3/3]

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

Definition at line 557 of file Message.cpp.

558  :
559  return false;
560  };
561 }
562 
563 bool Message::isTrailerField( const FieldBase& field,

◆ isTrailerField() [1/3]

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

Definition at line 578 of file Message.cpp.

578 {
579  BeginString beginString;
580  SenderCompID senderCompID;
581  TargetCompID targetCompID;
582 

◆ isTrailerField() [2/3]

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

Definition at line 565 of file Message.cpp.

565 {
566  return isTrailerField( field.getTag(), pD );
567 }
568 
569 bool Message::isTrailerField( int field, const DataDictionary * pD )
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

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

◆ isTrailerField() [3/3]

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

Definition at line 584 of file Message.cpp.

◆ removeGroup() [1/2]

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

Definition at line 190 of file Message.h.

◆ removeGroup() [2/2]

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

Definition at line 188 of file Message.h.

◆ replaceGroup()

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

Definition at line 179 of file Message.h.

179  { return FieldMap::hasGroup( group.field() ); }
180  bool hasGroup( unsigned num, const FIX::Group& group ) const

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 165 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 {

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 446 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 ) )

◆ setSessionID()

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

Sets the session ID of the intended recipient.

Definition at line 605 of file Message.cpp.

607  {
608  std::stringstream text;
609  text << "Expected BodyLength=" << actualLength
610  << ", Received BodyLength=" << expectedLength;

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

◆ setString() [2/4]

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

Definition at line 233 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 236 of file Message.h.

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

352  {
353  FieldBase field = extractField( string, pos, pSessionDataDictionary, pApplicationDataDictionary );
354  if ( count < 3 && headerOrder[ count++ ] != field.getTag() )
355  if ( doValidation ) throw InvalidMessage("Header fields out of order");
356 
357  if ( isHeaderField( field, pSessionDataDictionary ) )
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;

References FIX::FieldBase::getString(), FIX::FieldBase::getTag(), and FIX::headerOrder.

◆ 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 490 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:

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

◆ toApplVerID()

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

Definition at line 322 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);

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

◆ toBeginString()

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

Definition at line 343 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 251 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 260 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

◆ toXML() [1/2]

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

Get a XML representation of the message.

Definition at line 285 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 292 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 << "\" ";

◆ toXMLFields()

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

Definition at line 310 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;

◆ validate()

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

Definition at line 612 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 ));

Friends And Related Function Documentation

◆ DataDictionary

friend class DataDictionary
friend

Definition at line 134 of file Message.h.

◆ Session

friend class Session
friend

Definition at line 135 of file Message.h.

Member Data Documentation

◆ m_header

Header FIX::Message::m_header
mutableprotected

◆ m_tag

int FIX::Message::m_tag
protected

Definition at line 415 of file Message.h.

◆ m_trailer

Trailer FIX::Message::m_trailer
mutableprotected

Definition at line 413 of file Message.h.

Referenced by isAdmin().

◆ m_validStructure

bool FIX::Message::m_validStructure
protected

Definition at line 414 of file Message.h.

◆ s_dataDictionary

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

Definition at line 419 of file Message.h.


The documentation for this class was generated from the following files:
FIX::BeginString_FIX41
const char BeginString_FIX41[]
Definition: Values.h:50
FIX::Message::header
Definition: Message.h:137
FIX::headerOrder
const int headerOrder[]
Definition: Message.cpp:49
FIX::FieldMap::calculateTotal
int calculateTotal(int checkSumField=FIELD::CheckSum) const
Definition: FieldMap.cpp:273
FIX::BeginString_FIX44
const char BeginString_FIX44[]
Definition: Values.h:47
FIX::FieldMap::hasGroup
bool hasGroup(int tag) const
Check to see any instance of a group exists.
Definition: FieldMap.cpp:183
FIX::BeginString_FIX40
const char BeginString_FIX40[]
Definition: Values.h:51
FIX::Message::DataDictionary
friend class DataDictionary
Definition: Message.h:134
FIX::BeginString_FIX42
const char BeginString_FIX42[]
Definition: Values.h:49
FIX::FieldMap::FieldMap
FieldMap(const message_order &order, int size)
Definition: FieldMap.cpp:49
FIX::FieldMap::isEmpty
bool isEmpty()
Check if map contains any fields.
Definition: FieldMap.cpp:211
FIX::Message::trailer
Definition: Message.h:137
FIX::Message::getTrailer
const Trailer & getTrailer() const
Getter for the message trailer.
Definition: Message.h:264
FIX::Message::m_validStructure
bool m_validStructure
Definition: Message.h:414
FIX::Group::field
int field() const
Definition: Group.h:87
FIX::Message::body
Definition: Message.h:137
FIX::Message::~Message
~Message()
Definition: Message.cpp:150
FIX::Message::hasGroup
bool hasGroup(const FIX::Group &group) const
Definition: Message.h:193
FIX::FieldMap::begin
iterator begin()
Definition: FieldMap.h:289
FIX::Message::Message
Message()
Definition: Message.cpp:58
FIX::Message::field_type
field_type
Definition: Message.h:137
FIX::Message::toXML
std::string toXML() const
Get a XML representation of the message.
Definition: Message.cpp:285
FIX::FieldMap::getFieldIfSet
bool getFieldIfSet(FieldBase &field) const
Get a field if set.
Definition: FieldMap.h:177
FIX::Message::getSessionID
SessionID getSessionID(const std::string &qualifier="") const
Returns the session ID of the intended recipient.
Definition: Message.cpp:591
FIX::BeginString_FIX50
const char BeginString_FIX50[]
Definition: Values.h:46
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:251
FIX::Message::clear
void clear()
Definition: Message.h:306
FIX::Message::m_trailer
Trailer m_trailer
Definition: Message.h:413
FIX::Message::isTrailerField
static bool isTrailerField(int field)
Definition: Message.cpp:565
FIX::Message::s_dataDictionary
static SmartPtr< DataDictionary > s_dataDictionary
Definition: Message.h:419
FIX::IntConvertor::convert
static std::string convert(signed_int value)
Definition: FieldConvertors.h:168
FIX::BeginString_FIX43
const char BeginString_FIX43[]
Definition: Values.h:48
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:490
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:654
FIX::Message::isAdmin
bool isAdmin() const
Definition: Message.h:287
FIX::Message::isAdminMsgType
static bool isAdminMsgType(const MsgType &msgType)
Definition: Message.h:315
FIX::FieldMap::appendField
void appendField(const FieldBase &field)
Definition: FieldMap.h:328
FIX::FieldMap::g_const_iterator
Groups::const_iterator g_const_iterator
Definition: FieldMap.h:133
FIX::TYPE::XmlData
Definition: FieldTypes.h:956
FIX::FieldMap::removeField
void removeField(int tag)
Remove a field. If field is not present, this is a no-op.
Definition: FieldMap.cpp:171
FIX::Message::m_header
Header m_header
Definition: Message.h:412
FIX::Message::toXMLFields
std::string toXMLFields(const FieldMap &fields, int space) const
Definition: Message.cpp:310
FIX::Message::m_tag
int m_tag
Definition: Message.h:415
FIX::Group
Base class for all FIX repeating groups.
Definition: Group.h:55
FIX::Message::isHeaderField
static bool isHeaderField(int field)
Definition: Message.cpp:512
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:230
FIX::FieldMap::setField
void setField(const FieldBase &field, bool overwrite=true)
Set a field without type checking.
Definition: FieldMap.h:147
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:446
FIX::FieldBase
Base representation of all Field classes.
Definition: Field.h:64
FIX::FieldMap::reverse_find
const FieldBase & reverse_find(int tag) const
Definition: FieldMap.h:317
FIX::FieldMap::removeGroup
void removeGroup(int num, int tag)
Remove a specific instance of a group.
Definition: FieldMap.cpp:126
FIX::FieldMap::sortFields
void sortFields()
Definition: FieldMap.h:334
FIELD_GET_REF
#define FIELD_GET_REF(MAP, FLD)
Definition: FieldMap.h:375
FIX::FieldMap::calculateLength
int calculateLength(int beginStringField=FIELD::BeginString, int bodyLengthField=FIELD::BodyLength, int checkSumField=FIELD::CheckSum) const
Definition: FieldMap.cpp:248
FIX::Message::validate
void validate() const
Definition: Message.cpp:612
FIX::Message::getHeader
const Header & getHeader() const
Getter for the message header.
Definition: Message.h:260
FIX::FieldMap::const_iterator
Fields::const_iterator const_iterator
Definition: FieldMap.h:131

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