FIX::Message Class Reference

Base class for all FIX messages. More...

`#include <Message.h>`

Inheritance diagram for FIX::Message:
[legend]
Collaboration diagram for FIX::Message:
[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)
Group & | getGroup (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 Header & | getHeader () const
| Getter for the message header. More...
Header & | getHeader ()
| Mutable getter for the message header. More...
const Trailer & | getTrailer () const
| Getter for the message trailer. More...
Trailer & | getTrailer ()
| 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 ()
FieldMap & | operator= (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...
FieldBase & | getField (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 FieldBase & | getFieldRef (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...
FieldMap & | getGroup (int num, int tag, FieldMap &group) const throw ( FieldNotFound )
| Get a specific instance of a group. More...
FieldMap & | getGroupRef (int num, int tag) const throw ( FieldNotFound )
| Get direct access to a field through a reference. More...
FieldMap * | getGroupPtr (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 FieldBase & | reverse_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< DataDictionary > | s_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

enum FIX::Message::field_type

private

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.

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

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

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

{
setString( string, validate, &sessionDataDictionary, &applicationDataDictionary );
}
Message::Message( const message_order &hdrOrder,
const message_order &trlOrder,
const message_order& order,
const std::string& string,
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.

: FieldMap(order), m_header(hdrOrder),
m_trailer(trlOrder), m_validStructure( true )
{
setString( string, validate, &dataDictionary, &dataDictionary );
}
Message::Message( const message_order &hdrOrder,
const message_order &trlOrder,
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.

: FieldMap(order), m_header(hdrOrder),
m_trailer(trlOrder), m_validStructure( true )
{
setStringHeader( string );
if( isAdmin() )
setString( string, validate, &sessionDataDictionary, &sessionDataDictionary );
else
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.

: m_validStructure(true)
, m_tag( 0 )
{
m_header.setField(beginString);
m_header.setField(msgType);
}
Message::Message(const Message& copy)
: FieldMap(copy)
, m_header(copy.m_header)
, m_trailer(copy.m_trailer)
, m_validStructure(copy.m_validStructure)
, m_tag(copy.m_tag)
#ifdef HAVE_EMX
, 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.

{
try
{
s_dataDictionary.reset(new DataDictionary(url));
return true;
}
catch( ConfigError& )
{ return false; }
}
void Message::reverseRoute( const Header& header )

References DataDictionary, and s_dataDictionary.

## ~Message()

FIX::Message::~Message | ( |  | ) |

Definition at line 152 of file Message.cpp.

{

## Message() [9/9]

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

protected

Definition at line 131 of file Message.cpp.

{
}
Message::~Message()
{
}

## Member Function Documentation

## addGroup()

void FIX::Message::addGroup | ( | const FIX::Group & | group | ) |

inline

Definition at line 178 of file Message.h.

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

{

## checkSum()

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

inline

Definition at line 283 of file Message.h.

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

## clear()

void FIX::Message::clear | ( |  | ) |

inline

Definition at line 308 of file Message.h.

{
if( value == BeginString_FIX40 )
return ApplVerID(ApplVerID_FIX40);
if( value == BeginString_FIX41 )
return ApplVerID(ApplVerID_FIX41);
if( value == BeginString_FIX42 )
return ApplVerID(ApplVerID_FIX42);
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.

{
// Assume length field is 1 less.
int lenField = field - 1;
// Special case for Signature which violates above assumption.
if ( field == FIELD::Signature ) lenField = FIELD::SignatureLength;
// identify part of the message that should contain length field
const FieldMap * location = pGroup;
if ( !location )
{
if ( isHeaderField( lenField, pSessionDD ) )
location = &m_header;
else if ( isTrailerField( lenField, pSessionDD ) )
location = &m_trailer;
else
location = this;
}
try
{
const FieldBase& fieldLength = location->reverse_find( lenField );
soh = valueStart + IntConvertor::convert( fieldLength.getString() );
}
catch( FieldNotFound& )
{
throw InvalidMessage( std::string( "Data length field " ) + IntConvertor::convert( lenField ) + std::string( " was not found for data field " ) + IntConvertor::convert( field ) );
}
catch( FieldConvertError& e )
{
throw InvalidMessage( std::string( "Unable to determine SOH for data field " ) + IntConvertor::convert( field ) + std::string( ": " ) + e.what() );
}
}
std::string::const_iterator const tagEnd = soh + 1;
#if defined(__SUNPRO_CC)
std::distance( string.begin(), tagEnd, pos );
#else
pos = std::distance( string.begin(), tagEnd );
#endif
return FieldBase (
field,
valueStart,
soh,
tagStart,
tagEnd );
}
}

## getGroup()

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

inline

Definition at line 184 of file Message.h.

:

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

{
try
{
const BodyLength& aBodyLength = FIELD_GET_REF( m_header, BodyLength );
const int expectedLength = (int)aBodyLength;
const int actualLength = bodyLength();

## getTrailer() [1/2]

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

inline

Mutable getter for the message trailer.

Definition at line 268 of file Message.h.

{

## getTrailer() [2/2]

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

inline

Getter for the message trailer.

Definition at line 266 of file Message.h.

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

{

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

{
if( beginString.getValue().size() )
m_header.setField( beginString );

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

## isAdmin()

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

inline

Definition at line 289 of file Message.h.

{ return m_header.isEmpty() && FieldMap::isEmpty() && m_trailer.isEmpty(); }
void clear()
{
m_tag = 0;
m_validStructure = true;
m_header.clear();

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

## isAdminMsgType()

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

inline static

Definition at line 317 of file Message.h.

{

## isApp()

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

inline

Definition at line 297 of file Message.h.

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

## IsDataField()

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

inline static private

Definition at line 396 of file Message.h.

:
mutable Header m_header;
mutable Trailer m_trailer;
bool m_validStructure;
int m_tag;
#ifdef HAVE_EMX
std::string m_subMsgType;
#endif
static SmartPtr<DataDictionary> s_dataDictionary;
};
inline std::ostream& operator <<

## isEmpty()

bool FIX::Message::isEmpty | ( |  | ) |

inline

Definition at line 305 of file Message.h.

{

## isHeaderField() [1/3]

bool FIX::Message::isHeaderField | ( | const FieldBase & | field,
|  | const DataDictionary * | pD = `0`
| ) |  |

static

Definition at line 553 of file Message.cpp.

{
case FIELD::SignatureLength:
case FIELD::Signature:
case FIELD::CheckSum:
return true;

## isHeaderField() [2/3]

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

static

Definition at line 514 of file Message.cpp.

:
case FIELD::OnBehalfOfLocationID:
case FIELD::DeliverToSubID:
case FIELD::DeliverToLocationID:
case FIELD::PossDupFlag:
case FIELD::PossResend:
case FIELD::SendingTime:
case FIELD::OrigSendingTime:
case FIELD::XmlDataLen:
case FIELD::XmlData:
case FIELD::MessageEncoding:
case FIELD::LastMsgSeqNumProcessed:
case FIELD::OnBehalfOfSendingTime:
case FIELD::ApplVerID:
case FIELD::CstmApplVerID:
case FIELD::NoHops:
return true;
default:
return false;
};
}
bool Message::isHeaderField( const FieldBase& field,
const DataDictionary* pD )
{
return isHeaderField( field.getTag(), pD );
}
bool Message::isHeaderField( int field,
const DataDictionary * pD )
{
if ( isHeaderField( field ) ) return true;
if ( pD ) return pD->isHeaderField( field );
return false;
}
bool Message::isTrailerField( int field )
{

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.

{

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

{
if ( isTrailerField( field ) ) return true;
if ( pD ) return pD->isTrailerField( field );
return false;
}
SessionID Message::getSessionID( const std::string& qualifier ) const
throw( FieldNotFound )
{

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.

{

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

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

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.

{
if( header.getFieldIfSet( onBehalfOfLocationID ) )
{
if( onBehalfOfLocationID.getValue().size() )
m_header.setField( DeliverToLocationID( onBehalfOfLocationID ) );
}
if( header.getFieldIfSet( deliverToLocationID ) )
{
if( deliverToLocationID.getValue().size() )
m_header.setField( OnBehalfOfLocationID( deliverToLocationID ) );
}
}
}
if( header.getFieldIfSet( senderCompID ) )
{
if( senderCompID.getValue().size() )
m_header.setField( TargetCompID( senderCompID ) );
}
if( header.getFieldIfSet( targetCompID ) )
{
if( targetCompID.getValue().size() )
m_header.setField( SenderCompID( targetCompID ) );
}
// optional routing tags
OnBehalfOfCompID onBehalfOfCompID;
OnBehalfOfSubID onBehalfOfSubID;
DeliverToCompID deliverToCompID;
DeliverToSubID deliverToSubID;
m_header.removeField( onBehalfOfCompID.getTag() );
m_header.removeField( onBehalfOfSubID.getTag() );
m_header.removeField( deliverToCompID.getTag() );
m_header.removeField( deliverToSubID.getTag() );
if( header.getFieldIfSet( onBehalfOfCompID ) )
{
if( onBehalfOfCompID.getValue().size() )
m_header.setField( DeliverToCompID( onBehalfOfCompID ) );
}
if( header.getFieldIfSet( onBehalfOfSubID ) )
{
if( onBehalfOfSubID.getValue().size() )
m_header.setField( DeliverToSubID( onBehalfOfSubID ) );
}
if( header.getFieldIfSet( deliverToCompID ) )
{
if( deliverToCompID.getValue().size() )
m_header.setField( OnBehalfOfCompID( deliverToCompID ) );
}
if( header.getFieldIfSet( deliverToSubID ) )
{
if( deliverToSubID.getValue().size() )
m_header.setField( OnBehalfOfSubID( deliverToSubID ) );
}
}
std::string Message::toString( int beginStringField,
int bodyLengthField,
int checkSumField ) const
{
std::string str;
toString( str, beginStringField, bodyLengthField, checkSumField );
return str;
}
std::string& Message::toString( std::string& str,
int beginStringField,
int bodyLengthField,
int checkSumField ) const
{
int length = bodyLength( beginStringField, bodyLengthField, checkSumField );
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.

{
if ( pGroup.get() )
{
map.addGroupPtr( group, pGroup.release(), false );
}
pGroup.reset( new Group( field.getTag(), delim, pDD->getOrderedFields() ) );
}
else if ( !pDD->isField( field.getTag() ) )
{
if ( pGroup.get() )
{
map.addGroupPtr( group, pGroup.release(), false );
}
pos = oldPos;
return ;
}
if ( !pGroup.get() ) return ;
pGroup->addField( field );
setGroup( msg, field, string, pos, *pGroup, *pDD );
}
}
bool Message::setStringHeader( const std::string& string )
{
clear();
std::string::size_type pos = 0;
int count = 0;
while ( pos < string.size() )
{
FieldBase field = extractField( string, pos );
if ( count < 3 && headerOrder[ count++ ] != field.getTag() )
return false;
if ( isHeaderField( field ) )
m_header.appendField( field );
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.

{
std::stringstream text;
text << "Expected BodyLength=" << actualLength
<< ", Received BodyLength=" << expectedLength;
throw InvalidMessage(text.str());
}

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

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

{
if ( type != header )
{
if(m_tag == 0) m_tag = field.getTag();
m_validStructure = false;
}
if ( field.getTag() == FIELD::MsgType )
{
msg.setString( field.getString() );
if ( isAdminMsgType( msg ) )
{
pApplicationDataDictionary = pSessionDataDictionary;
#ifdef HAVE_EMX
m_subMsgType.assign(msg);
}
else
{
std::string::size_type equalSign = string.find("\0019426=", pos);
if (equalSign == std::string::npos)
throw InvalidMessage("EMX message type (9426) not found");
equalSign += 6;
std::string::size_type soh = string.find_first_of('\001', equalSign);
if (soh == std::string::npos)
throw InvalidMessage("EMX message type (9426) soh char not found");
m_subMsgType.assign(string.substr(equalSign, soh - equalSign ));
#endif
}
}
m_header.appendField( field );
if ( pSessionDataDictionary )
setGroup( "_header_", field, string, pos, getHeader(), *pSessionDataDictionary );
}
else if ( isTrailerField( field, pSessionDataDictionary ) )
{
type = trailer;
m_trailer.appendField( field );
if ( pSessionDataDictionary )
setGroup( "_trailer_", field, string, pos, getTrailer(), *pSessionDataDictionary );
}
else
{
if ( type == trailer )
{
if(m_tag == 0) m_tag = field.getTag();
m_validStructure = false;
}
type = body;
appendField( field );
if ( pApplicationDataDictionary )
#ifdef HAVE_EMX
setGroup(m_subMsgType, field, string, pos, *this, *pApplicationDataDictionary);
#else
setGroup( msg, field, string, pos, *this, *pApplicationDataDictionary );
#endif
}
}
// sort fields
m_header.sortFields();
sortFields();
m_trailer.sortFields();
if ( doValidation )
validate();
}
void Message::setGroup( const std::string& msg, const FieldBase& field,
const std::string& string,
std::string::size_type& pos, FieldMap& map,
const DataDictionary& dataDictionary )
{
int group = field.getTag();
int delim;
const DataDictionary* pDD = 0;
if ( !dataDictionary.getGroup( msg, group, delim, pDD ) ) return ;
SmartPtr<Group> pGroup;
while ( pos < string.size() )
{
std::string::size_type oldPos = pos;
FieldBase field = extractField( string, pos, &dataDictionary, &dataDictionary, pGroup.get() );

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

{
switch ( field )
{
case FIELD::BeginString:
case FIELD::BodyLength:
case FIELD::MsgType:
case FIELD::SenderCompID:
case FIELD::TargetCompID:
case FIELD::OnBehalfOfCompID:
case FIELD::DeliverToCompID:
case FIELD::SecureDataLen:
case FIELD::MsgSeqNum:
case FIELD::SenderSubID:
case FIELD::SenderLocationID:
case FIELD::TargetSubID:

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

## toApplVerID()

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

inline static

Definition at line 324 of file Message.h.

{
if( applVerID == ApplVerID_FIX40 )
return BeginString(BeginString_FIX40);
else if( applVerID == ApplVerID_FIX41 )
return BeginString(BeginString_FIX41);
else if( applVerID == ApplVerID_FIX42 )
return BeginString(BeginString_FIX42);
else if( applVerID == ApplVerID_FIX43 )
return BeginString(BeginString_FIX43);
else if( applVerID == ApplVerID_FIX44 )
return BeginString(BeginString_FIX44);
else if( applVerID == ApplVerID_FIX50 )
return BeginString(BeginString_FIX50);
else if( applVerID == ApplVerID_FIX50SP1 )
return BeginString(BeginString_FIX50);

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

## toBeginString()

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

inline static

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.

{
std::string str;
toXML( str );
return str;
}
std::string& Message::toXML( std::string& str ) const
{
std::stringstream stream;
stream << "<message>" << std::endl
<< std::setw(2) << " " << "<header>" << std::endl
<< toXMLFields(getHeader(), 4)
<< std::setw(2) << " " << "</header>" << std::endl
<< std::setw(2) << " " << "<body>" << std::endl
<< 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.

{
std::stringstream stream;
FieldMap::const_iterator i;
std::string name;
for(i = fields.begin(); i != fields.end(); ++i)
{
int field = i->getTag();
std::string value = i->getString();
stream << std::setw(space) << " " << "<field ";
if(s_dataDictionary.get() && s_dataDictionary->getFieldName(field, name))
{
stream << "name=\"" << name << "\" ";
}
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.

{
stream << " enum=\"" << name << "\"";
}
stream << ">";
stream << "<![CDATA[" << value << "]]>";
stream << "</field>" << std::endl;
}
FieldMap::g_const_iterator j;
for(j = fields.g_begin(); j != fields.g_end(); ++j)
{
std::vector<FieldMap*>::const_iterator k;
for(k = j->second.begin(); k != j->second.end(); ++k)
{
stream << std::setw(space) << " " << "<group>" << std::endl
<< toXMLFields(*(*k), space+2)
<< std::setw(space) << " " << "</group>" << std::endl;
}
}
return stream.str();
}
void Message::setString( const std::string& string,
bool doValidation,
const DataDictionary* pSessionDataDictionary,
const DataDictionary* pApplicationDataDictionary )
throw( InvalidMessage )
{
clear();
std::string::size_type pos = 0;
int count = 0;
FIX::MsgType msg;
field_type type = header;
while ( pos < string.size() )

## validate()

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

private

Definition at line 614 of file Message.cpp.

{
std::stringstream text;
text << "Expected CheckSum=" << actualChecksum
<< ", Received CheckSum=" << expectedChecksum;
throw InvalidMessage(text.str());
}
}
catch ( FieldNotFound& e )
{
const std::string fieldName = ( e.field == FIX::FIELD::BodyLength ) ? "BodyLength" : "CheckSum";
throw InvalidMessage( fieldName + std::string(" is missing") );
}
catch ( IncorrectDataFormat& e )
{
const std::string fieldName = ( e.field == FIX::FIELD::BodyLength ) ? "BodyLength" : "CheckSum";
throw InvalidMessage( fieldName + std::string(" has wrong format: ") + e.detail );
}
}
FIX::FieldBase Message::extractField( const std::string& string, std::string::size_type& pos,
const DataDictionary* pSessionDD /*= 0*/, const DataDictionary* pAppDD /*= 0*/,
const Group* pGroup /*= 0*/ ) const
{
std::string::const_iterator const tagStart = string.begin() + pos;
std::string::const_iterator const strEnd = string.end();
std::string::const_iterator const equalSign = std::find( tagStart, strEnd, '=' );
if( equalSign == strEnd )
throw InvalidMessage("Equal sign not found in field");
int field = 0;
if( !IntConvertor::convert( tagStart, equalSign, field ) )
throw InvalidMessage( std::string("Field tag is invalid: ") + std::string( tagStart, equalSign ));
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

mutable protected

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

mutable protected

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

static protected

Definition at line 421 of file Message.h.

Referenced by Message(), and toXML().

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

- Message.h
- Message.cpp

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