Index Source Files Annotated Class List Alphabetical Class List Class Hierarchy Graphical Class Hierarchy

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

List of all members.

## Public Member Functions

| Message ()
| Message (const std::string &string, bool validate=true) throw ( InvalidMessage )
| Construct a message from a string.
| Message (const std::string &string, const FIX::DataDictionary &dataDictionary, bool validate=true) throw ( InvalidMessage )
| Construct a message from a string using a data dictionary.
| 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.
| Message (const Message &copy)
void | addGroup (FIX::Group &group)
void | replaceGroup (unsigned num, FIX::Group &group)
Group & | getGroup (unsigned num, FIX::Group &group) const throw ( FieldNotFound )
void | removeGroup (unsigned num, FIX::Group &group)
void | removeGroup (FIX::Group &group)
bool | hasGroup (const FIX::Group &group) const
bool | hasGroup (unsigned num, 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.
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.
std::string | toXML () const
| Get a XML representation of the message.
std::string & | toXML (std::string &) const
| Get a XML representation without making a copy.
void | reverseRoute (const Header &)
| Add header informations depending on a source message.
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 out the string that is passed in.
void | setString (const std::string &string, bool validate)
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.
const Header & | getHeader () const
| Getter for the message header.
Header & | getHeader ()
| Mutable getter for the message header.
const Header & | getTrailer () const
| Getter for the message trailer.
Trailer & | getTrailer ()
| Mutable getter for the message trailer.
bool | hasValidStructure (int &field) const
int | bodyLength (int beginStringField=FIELD::BeginString, int bodyLengthField=FIELD::BodyLength, int checkSumField=FIELD::CheckSum) const
int | checkSum (int checkSumField=FIELD::CheckSum) const
bool | isAdmin () const
bool | isApp () const
bool | isEmpty ()
| Check if map contains any fields.
void | clear ()
| Clear all fields from the map.
SessionID | getSessionID (const std::string &qualifier="") const throw ( FieldNotFound )
| Returns the session ID of the intended recipient.
void | setSessionID (const SessionID &sessionID)
| Sets the session ID of the intended recipient.

## Static Public Member Functions

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

## Protected Member Functions

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

## Protected Attributes

FieldMap | m_header
FieldMap | m_trailer
bool | m_validStructure
int | m_field

## Static Protected Attributes

static std::auto_ptr < 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)
void | validate ()
std::string | toXMLFields (const FieldMap &fields, int space) const

## Friends

class | DataDictionary
class | Session

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

## Member Enumeration Documentation

enum FIX::Message::field_type`[private]`

Enumerator:

  header |
  body |
  trailer |

Definition at line 62 of file Message.h.

    00062 { header, body, trailer };

## Constructor & Destructor Documentation

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

Definition at line 36 of file Message.cpp.

    00037 : m_header( message_order( message_order::header ) ),
    00038   m_trailer( message_order( message_order::trailer ) ),
    00039   m_validStructure( true ) {}

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

Construct a message from a string.

Definition at line 41 of file Message.cpp.

    00043 : m_header( message_order( message_order::header ) ),
    00044   m_trailer( message_order( message_order::trailer ) ),
    00045   m_validStructure( true )
    00046 {
    00047   setString( string, validate );
    00048 }

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

    00054 : m_header( message_order( message_order::header ) ),
    00055   m_trailer( message_order( message_order::trailer ) ),
    00056   m_validStructure( true )
    00057 {
    00058   setString( string, validate, &dataDictionary, &dataDictionary );
    00059 }

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

    00066 : m_header( message_order( message_order::header ) ),
    00067   m_trailer( message_order( message_order::trailer ) ),
    00068   m_validStructure( true )
    00069 {
    00070   setStringHeader( string );
    00071   if( isAdmin() )
    00072     setString( string, validate, &sessionDataDictionary, &sessionDataDictionary );
    00073   else
    00074     setString( string, validate, &sessionDataDictionary, &applicationDataDictionary );
    00075 }

FIX::Message::Message | ( | const Message & | copy | ) | `[inline]`

Definition at line 81 of file Message.h.

References m_field, m_header, m_trailer, and m_validStructure.

    00082   : FieldMap( copy ),
    00083     m_header( message_order( message_order::header ) ),
    00084     m_trailer( message_order( message_order::trailer ) )
    00085   {
    00086     m_header = copy.m_header;
    00087     m_trailer = copy.m_trailer;
    00088     m_validStructure = copy.m_validStructure;
    00089     m_field = copy.m_field;
    00090   }

FIX::Message::Message | ( | const BeginString & | beginString,
|  | const MsgType & | msgType |
| ) |  |  | `[inline, protected]`

Definition at line 119 of file Message.h.

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

    00120   : m_header( message_order( message_order::header ) ),
    00121   m_trailer( message_order( message_order::trailer ) ),
    00122   m_validStructure( true )
    00123   {
    00124     m_header.setField( beginString );
    00125     m_header.setField( msgType );
    00126   }

## Member Function Documentation

void FIX::Message::addGroup | ( | FIX::Group & | group | ) | `[inline]`

Definition at line 95 of file Message.h.

References FIX::Group::field().

    00096   { FieldMap::addGroup( group.field(), group ); }

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

Definition at line 197 of file Message.h.

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

Referenced by toString(), and validate().

    00200   { return m_header.calculateLength(beginStringField, bodyLengthField, checkSumField)
    00201            + calculateLength(beginStringField, bodyLengthField, checkSumField)
    00202            + m_trailer.calculateLength(beginStringField, bodyLengthField, checkSumField);
    00203   }

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

Definition at line 205 of file Message.h.

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

Referenced by toString(), and validate().

    00206   { return ( m_header.calculateTotal(checkSumField)
    00207              + calculateTotal(checkSumField)
    00208              + m_trailer.calculateTotal(checkSumField) ) % 256;
    00209   }

void FIX::Message::clear | ( |  | ) | `[inline]`

Clear all fields from the map.

Reimplemented from FIX::FieldMap.

Definition at line 234 of file Message.h.

References FIX::FieldMap::clear(), m_field, m_header, and m_trailer.

Referenced by setStringHeader().

    00235   {
    00236     m_field = 0;
    00237     m_header.clear();
    00238     FieldMap::clear();
    00239     m_trailer.clear();
    00240   }

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` |
| ) |  |  | `[inline, private]`

Definition at line 311 of file Message.h.

References FIX::FieldMap::getField(), FIX::FieldMap::isSetField(), QF_STACK_POP, and QF_STACK_PUSH.

Referenced by setGroup(), and setStringHeader().

    00314   { QF_STACK_PUSH(extractField)
    00315
    00316     std::string::size_type equalSign
    00317       = string.find_first_of( '=', pos );
    00318     if( equalSign == std::string::npos )
    00319       throw InvalidMessage("Equal sign not found in field");
    00320
    00321     char* pEnd = 0;
    00322     int field = strtol( string.c_str() + pos, &pEnd, 0 );
    00323
    00324     std::string::size_type soh =
    00325       string.find_first_of( '\001', equalSign + 1 );
    00326     if ( soh == std::string::npos )
    00327       throw InvalidMessage("SOH not found at end of field");
    00328
    00329     if ( (pSessionDD && pSessionDD->isDataField(field)) || (pAppDD && pAppDD->isDataField(field)) )
    00330     {
    00331       std::string fieldLength;
    00332       // Assume length field is 1 less.
    00333       int lenField = field - 1;
    00334       // Special case for Signature which violates above assumption.
    00335       if ( field == 89 ) lenField = 93;
    00336
    00337       if ( pGroup && pGroup->isSetField( lenField ) )
    00338       {
    00339         fieldLength = pGroup->getField( lenField );
    00340         soh = equalSign + 1 + atol( fieldLength.c_str() );
    00341       }
    00342       else if ( isSetField( lenField ) )
    00343       {
    00344         fieldLength = getField( lenField );
    00345         soh = equalSign + 1 + atol( fieldLength.c_str() );
    00346       }
    00347     }
    00348
    00349     pos = soh + 1;
    00350     return FieldBase (
    00351       field,
    00352       string.substr( equalSign + 1, soh - ( equalSign + 1 ) ) );
    00353
    00354     QF_STACK_POP
    00355   }

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

Definition at line 101 of file Message.h.

References FIX::FieldMap::clear().

    00102   { group.clear();
    00103     return static_cast < Group& >
    00104       ( FieldMap::getGroup( num, group.field(), group ) );
    00105   }

Header& FIX::Message::getHeader | ( |  | ) | `[inline]`

Mutable getter for the message header.

Definition at line 186 of file Message.h.

References m_header.

    00186 { return m_header; }

const Header& FIX::Message::getHeader | ( |  | ) | const`[inline]`

Getter for the message header.

Definition at line 184 of file Message.h.

References m_header.

Referenced by FIX::MessageCracker::crack(), FIX::Session::doPossDup(), FIX::Session::doTargetTooHigh(), FIX::Session::doTargetTooLow(), FIX::Session::generateBusinessReject(), FIX::Session::generateHeartbeat(), FIX::Session::generateLogon(), FIX::Session::generateLogout(), FIX::Session::generateReject(), FIX::Session::generateResendRequest(), FIX::Session::generateSequenceReset(), FIX::Session::generateTestRequest(), FIX::Acceptor::getSession(), FIX::Session::lookupSession(), FIX::Session::next(), FIX::Session::nextLogon(), FIX::Session::nextQueued(), FIX::Session::nextResendRequest(), FIX::Session::populateRejectReason(), FIX::Session::resend(), FIX::Session::send(), FIX::Session::sendRaw(), FIX::Session::sendToTarget(), setSessionID(), toXML(), and FIX::Session::verify().

    00184 { return m_header; }

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

Returns the session ID of the intended recipient.

Definition at line 517 of file Message.cpp.

References FIX::FIELD::BeginString, QF_STACK_POP, QF_STACK_PUSH, FIX::FIELD::SenderCompID, and FIX::FIELD::TargetCompID.

    00519 { QF_STACK_PUSH(Message::getSessionID)
    00520
    00521   BeginString beginString;
    00522   SenderCompID senderCompID;
    00523   TargetCompID targetCompID;
    00524
    00525   getHeader().getField( beginString );
    00526   getHeader().getField( senderCompID );
    00527   getHeader().getField( targetCompID );
    00528
    00529   return SessionID( beginString, senderCompID, targetCompID, qualifier );
    00530
    00531   QF_STACK_POP
    00532 }

Trailer& FIX::Message::getTrailer | ( |  | ) | `[inline]`

Mutable getter for the message trailer.

Definition at line 190 of file Message.h.

References m_trailer.

    00190 { return m_trailer; }

const Header& FIX::Message::getTrailer | ( |  | ) | const`[inline]`

Getter for the message trailer.

Definition at line 188 of file Message.h.

References m_trailer.

Referenced by toXML().

    00188 { return m_trailer; }

bool FIX::Message::hasGroup | ( | unsigned | num,
|  | FIX::Group & | group |
| ) |  |  | const`[inline]`

Definition at line 114 of file Message.h.

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

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

bool FIX::Message::hasGroup | ( | const FIX::Group & | group | ) | const`[inline]`

Definition at line 112 of file Message.h.

References FIX::Group::field().

Referenced by hasGroup().

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

bool FIX::Message::hasValidStructure | ( | int & | field | ) | const`[inline]`

Definition at line 192 of file Message.h.

References m_field, and m_validStructure.

    00193   { field = m_field;
    00194     return m_validStructure;
    00195   }

bool FIX::Message::InitializeXML | ( | const std::string & | string | ) | `[static]`

Set global data dictionary for encoding messages into XML.

Definition at line 77 of file Message.cpp.

References DataDictionary, QF_STACK_POP, QF_STACK_PUSH, and s_dataDictionary.

    00078 { QF_STACK_PUSH(Message::InitializeXML)
    00079
    00080   try
    00081   {
    00082     std::auto_ptr<DataDictionary> p =
    00083       std::auto_ptr<DataDictionary>(new DataDictionary(url));
    00084     s_dataDictionary = p;
    00085     return true;
    00086   }
    00087   catch( ConfigError& )
    00088   { return false; }
    00089
    00090   QF_STACK_POP
    00091 }

bool FIX::Message::isAdmin | ( |  | ) | const`[inline]`

Definition at line 211 of file Message.h.

References FIELD_GET_REF, isAdminMsgType(), FIX::FieldMap::isSetField(), m_header, and FIX::FIELD::MsgType.

Referenced by FIX::MessageCracker::crack().

    00212   {
    00213     if( m_header.isSetField(FIELD::MsgType) )
    00214     {
    00215       const MsgType& msgType = FIELD_GET_REF( m_header, MsgType );
    00216       return isAdminMsgType( msgType );
    00217     }
    00218     return false;
    00219   }

static bool FIX::Message::isAdminMsgType | ( | const MsgType & | msgType | ) | `[inline, static]`

Definition at line 242 of file Message.h.

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

    00243   { if ( msgType.getValue().length() != 1 ) return false;
    00244     return strchr
    00245            ( "0A12345",
    00246              msgType.getValue().c_str() [ 0 ] ) != 0;
    00247   }

bool FIX::Message::isApp | ( |  | ) | const`[inline]`

Definition at line 221 of file Message.h.

References FIELD_GET_REF, isAdminMsgType(), FIX::FieldMap::isSetField(), m_header, and FIX::FIELD::MsgType.

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

    00222   {
    00223     if( m_header.isSetField(FIELD::MsgType) )
    00224     {
    00225       const MsgType& msgType = FIELD_GET_REF( m_header, MsgType );
    00226       return !isAdminMsgType( msgType );
    00227     }
    00228     return false;
    00229   }

bool FIX::Message::isEmpty | ( |  | ) | `[inline]`

Check if map contains any fields.

Reimplemented from FIX::FieldMap.

Definition at line 231 of file Message.h.

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

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

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

Definition at line 479 of file Message.cpp.

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

    00481 { QF_STACK_PUSH(Message::isHeaderField)
    00482
    00483   if ( isHeaderField( field.getField() ) ) return true;
    00484   if ( pD ) return pD->isHeaderField( field.getField() );
    00485   return false;
    00486
    00487   QF_STACK_POP
    00488 }

bool FIX::Message::isHeaderField | ( | int | field | ) | `[static]`

Definition at line 437 of file Message.cpp.

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

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

    00438 { QF_STACK_PUSH(Message::isHeaderField)
    00439
    00440   switch ( field )
    00441   {
    00442     case FIELD::BeginString:
    00443     case FIELD::BodyLength:
    00444     case FIELD::MsgType:
    00445     case FIELD::SenderCompID:
    00446     case FIELD::TargetCompID:
    00447     case FIELD::OnBehalfOfCompID:
    00448     case FIELD::DeliverToCompID:
    00449     case FIELD::SecureDataLen:
    00450     case FIELD::MsgSeqNum:
    00451     case FIELD::SenderSubID:
    00452     case FIELD::SenderLocationID:
    00453     case FIELD::TargetSubID:
    00454     case FIELD::TargetLocationID:
    00455     case FIELD::OnBehalfOfSubID:
    00456     case FIELD::OnBehalfOfLocationID:
    00457     case FIELD::DeliverToSubID:
    00458     case FIELD::DeliverToLocationID:
    00459     case FIELD::PossDupFlag:
    00460     case FIELD::PossResend:
    00461     case FIELD::SendingTime:
    00462     case FIELD::OrigSendingTime:
    00463     case FIELD::XmlDataLen:
    00464     case FIELD::XmlData:
    00465     case FIELD::MessageEncoding:
    00466     case FIELD::LastMsgSeqNumProcessed:
    00467     case FIELD::OnBehalfOfSendingTime:
    00468     case FIELD::ApplVerID:
    00469     case FIELD::CstmApplVerID:
    00470     case FIELD::NoHops:
    00471     return true;
    00472     default:
    00473     return false;
    00474   };
    00475
    00476   QF_STACK_POP
    00477 }

bool FIX::Message::isTrailerField | ( | const FieldBase & | field,
|  | const DataDictionary * | pD = `0` |
| ) |  |  | `[static]`

Definition at line 506 of file Message.cpp.

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

    00508 { QF_STACK_PUSH(Message::isTrailerField)
    00509
    00510   if ( isTrailerField( field.getField() ) ) return true;
    00511   if ( pD ) return pD->isTrailerField( field.getField() );
    00512   return false;
    00513
    00514   QF_STACK_POP
    00515 }

bool FIX::Message::isTrailerField | ( | int | field | ) | `[static]`

Definition at line 490 of file Message.cpp.

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

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

    00491 { QF_STACK_PUSH(Message::isTrailerField)
    00492
    00493   switch ( field )
    00494   {
    00495     case FIELD::SignatureLength:
    00496     case FIELD::Signature:
    00497     case FIELD::CheckSum:
    00498     return true;
    00499     default:
    00500     return false;
    00501   };
    00502
    00503   QF_STACK_POP
    00504 }

void FIX::Message::removeGroup | ( | FIX::Group & | group | ) | `[inline]`

Definition at line 109 of file Message.h.

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

    00110   { FieldMap::removeGroup( group.field() ); }

void FIX::Message::removeGroup | ( | unsigned | num,
|  | FIX::Group & | group |
| ) |  |  | `[inline]`

Definition at line 107 of file Message.h.

References FIX::Group::field().

Referenced by removeGroup().

    00108   { FieldMap::removeGroup( num, group.field() ); }

void FIX::Message::replaceGroup | ( | unsigned | num,
|  | FIX::Group & | group |
| ) |  |  | `[inline]`

Definition at line 98 of file Message.h.

References FIX::Group::field().

    00099   { FieldMap::replaceGroup( num, group.field(), group ); }

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

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

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

    00094 { QF_STACK_PUSH(Message::reverseRoute)
    00095
    00096   // required routing tags
    00097   BeginString beginString;
    00098   SenderCompID senderCompID;
    00099   TargetCompID targetCompID;
    00100
    00101   m_header.removeField( beginString.getField() );
    00102   m_header.removeField( senderCompID.getField() );
    00103   m_header.removeField( targetCompID.getField() );
    00104
    00105   if( header.isSetField( beginString ) )
    00106   {
    00107     header.getField( beginString );
    00108     if( beginString.getValue().size() )
    00109       m_header.setField( beginString );
    00110
    00111     OnBehalfOfLocationID onBehalfOfLocationID;
    00112     DeliverToLocationID deliverToLocationID;
    00113
    00114     m_header.removeField( onBehalfOfLocationID.getField() );
    00115     m_header.removeField( deliverToLocationID.getField() );
    00116
    00117     if( beginString >= BeginString_FIX41 )
    00118     {
    00119       if( header.isSetField( onBehalfOfLocationID ) )
    00120       {
    00121         header.getField( onBehalfOfLocationID );
    00122         if( onBehalfOfLocationID.getValue().size() )
    00123           m_header.setField( DeliverToLocationID( onBehalfOfLocationID ) );
    00124       }
    00125
    00126       if( header.isSetField( deliverToLocationID ) )
    00127       {
    00128         header.getField( deliverToLocationID );
    00129         if( deliverToLocationID.getValue().size() )
    00130           m_header.setField( OnBehalfOfLocationID( deliverToLocationID ) );
    00131       }
    00132     }
    00133   }
    00134
    00135   if( header.isSetField( senderCompID ) )
    00136   {
    00137     header.getField( senderCompID );
    00138     if( senderCompID.getValue().size() )
    00139       m_header.setField( TargetCompID( senderCompID ) );
    00140   }
    00141
    00142   if( header.isSetField( targetCompID ) )
    00143   {
    00144     header.getField( targetCompID );
    00145     if( targetCompID.getValue().size() )
    00146       m_header.setField( SenderCompID( targetCompID ) );
    00147   }
    00148
    00149   // optional routing tags
    00150   OnBehalfOfCompID onBehalfOfCompID;
    00151   OnBehalfOfSubID onBehalfOfSubID;
    00152   DeliverToCompID deliverToCompID;
    00153   DeliverToSubID deliverToSubID;
    00154
    00155   m_header.removeField( onBehalfOfCompID.getField() );
    00156   m_header.removeField( onBehalfOfSubID.getField() );
    00157   m_header.removeField( deliverToCompID.getField() );
    00158   m_header.removeField( deliverToSubID.getField() );
    00159
    00160   if( header.isSetField( onBehalfOfCompID ) )
    00161   {
    00162     header.getField( onBehalfOfCompID );
    00163     if( onBehalfOfCompID.getValue().size() )
    00164       m_header.setField( DeliverToCompID( onBehalfOfCompID ) );
    00165   }
    00166
    00167   if( header.isSetField( onBehalfOfSubID ) )
    00168   {
    00169     header.getField( onBehalfOfSubID );
    00170     if( onBehalfOfSubID.getValue().size() )
    00171       m_header.setField( DeliverToSubID( onBehalfOfSubID ) );
    00172   }
    00173
    00174   if( header.isSetField( deliverToCompID ) )
    00175   {
    00176     header.getField( deliverToCompID );
    00177     if( deliverToCompID.getValue().size() )
    00178       m_header.setField( OnBehalfOfCompID( deliverToCompID ) );
    00179   }
    00180
    00181   if( header.isSetField( deliverToSubID ) )
    00182   {
    00183     header.getField( deliverToSubID );
    00184     if( deliverToSubID.getValue().size() )
    00185       m_header.setField( OnBehalfOfSubID( deliverToSubID ) );
    00186   }
    00187
    00188   QF_STACK_POP
    00189 }

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

References FIX::FieldMap::addGroup(), extractField(), FIX::FieldBase::getField(), FIX::DataDictionary::getGroup(), FIX::DataDictionary::getOrderedFields(), FIX::DataDictionary::isField(), QF_STACK_POP, QF_STACK_PUSH, and FIX::FieldMap::setField().

    00373 { QF_STACK_PUSH(Message::setGroup)
    00374
    00375   int group = field.getField();
    00376   int delim;
    00377   const DataDictionary* pDD = 0;
    00378   if ( !dataDictionary.getGroup( msg, group, delim, pDD ) ) return ;
    00379   Group* pGroup = 0;
    00380
    00381   while ( pos < string.size() )
    00382   {
    00383     std::string::size_type oldPos = pos;
    00384     FieldBase field = extractField( string, pos, &dataDictionary, &dataDictionary, pGroup );
    00385     if ( (field.getField() == delim)
    00386         || (pGroup == 0 && pDD->isField(field.getField())) )
    00387     {
    00388       if ( pGroup )
    00389       {
    00390         map.addGroup( group, *pGroup, false );
    00391         delete pGroup; pGroup = 0;
    00392       }
    00393       pGroup = new Group( field.getField(), delim, pDD->getOrderedFields()  );
    00394     }
    00395     else if ( !pDD->isField( field.getField() ) )
    00396     {
    00397       if ( pGroup )
    00398       {
    00399         map.addGroup( group, *pGroup, false );
    00400         delete pGroup; pGroup = 0;
    00401       }
    00402       pos = oldPos;
    00403       return ;
    00404     }
    00405
    00406     if ( !pGroup ) return ;
    00407     pGroup->setField( field, false );
    00408     setGroup( msg, field, string, pos, *pGroup, *pDD );
    00409   }
    00410
    00411   QF_STACK_POP
    00412 }

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

Sets the session ID of the intended recipient.

Definition at line 534 of file Message.cpp.

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

    00535 { QF_STACK_PUSH(Message::setSessionID)
    00536
    00537   getHeader().setField( sessionID.getBeginString() );
    00538   getHeader().setField( sessionID.getSenderCompID() );
    00539   getHeader().setField( sessionID.getTargetCompID() );
    00540
    00541   QF_STACK_POP
    00542 }

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

Definition at line 295 of file Message.cpp.

References FIX::FIELD::BeginString, FIX::FIELD::BodyLength, FIX::FieldBase::getField(), FIX::FieldBase::getString(), FIX::headerOrder, FIX::FIELD::MsgType, QF_STACK_POP, QF_STACK_PUSH, and setString().

    00300 { QF_STACK_PUSH(Message::setString)
    00301
    00302   clear();
    00303
    00304   std::string::size_type pos = 0;
    00305   int count = 0;
    00306   std::string msg;
    00307
    00308   static int const headerOrder[] =
    00309   {
    00310     FIELD::BeginString,
    00311     FIELD::BodyLength,
    00312     FIELD::MsgType
    00313   };
    00314
    00315   field_type type = header;
    00316
    00317   while ( pos < string.size() )
    00318   {
    00319     FieldBase field = extractField( string, pos, pSessionDataDictionary, pApplicationDataDictionary );
    00320     if ( count < 3 && headerOrder[ count++ ] != field.getField() )
    00321       if ( doValidation ) throw InvalidMessage("Header fields out of order");
    00322
    00323     if ( isHeaderField( field, pSessionDataDictionary ) )
    00324     {
    00325       if ( type != header )
    00326       {
    00327         if(m_field == 0) m_field = field.getField();
    00328         m_validStructure = false;
    00329       }
    00330
    00331       if ( field.getField() == FIELD::MsgType )
    00332         msg = field.getString();
    00333
    00334       m_header.setField( field, false );
    00335
    00336       if ( pSessionDataDictionary )
    00337         setGroup( "_header_", field, string, pos, getHeader(), *pSessionDataDictionary );
    00338     }
    00339     else if ( isTrailerField( field, pSessionDataDictionary ) )
    00340     {
    00341       type = trailer;
    00342       m_trailer.setField( field, false );
    00343
    00344       if ( pSessionDataDictionary )
    00345         setGroup( "_trailer_", field, string, pos, getTrailer(), *pSessionDataDictionary );
    00346     }
    00347     else
    00348     {
    00349       if ( type == trailer )
    00350       {
    00351         if(m_field == 0) m_field = field.getField();
    00352         m_validStructure = false;
    00353       }
    00354
    00355       type = body;
    00356       setField( field, false );
    00357
    00358       if ( pApplicationDataDictionary )
    00359         setGroup( msg, field, string, pos, *this, *pApplicationDataDictionary );
    00360     }
    00361   }
    00362
    00363   if ( doValidation )
    00364     validate();
    00365
    00366   QF_STACK_POP
    00367 }

void FIX::Message::setString | ( | const std::string & | string,
|  | bool | validate,
|  | const FIX::DataDictionary * | pDataDictionary |
| ) |  |  | throw ( InvalidMessage )`[inline]`

Definition at line 160 of file Message.h.

References setString(), and validate().

Referenced by setString().

    00164   { setString(string, validate, pDataDictionary, pDataDictionary); }

void FIX::Message::setString | ( | const std::string & | string,
|  | bool | validate |
| ) |  |  | `[inline]`

Definition at line 158 of file Message.h.

References setString().

Referenced by setString().

    00159   { setString(string, validate, 0); }

void FIX::Message::setString | ( | const std::string & | string | ) | `[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 156 of file Message.h.

References setString().

Referenced by setString().

    00157   { setString(string, true); }

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

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

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

    00415 { QF_STACK_PUSH(Message::setStringHeader)
    00416
    00417   clear();
    00418
    00419   std::string::size_type pos = 0;
    00420   int count = 0;
    00421
    00422   while ( pos < string.size() )
    00423   {
    00424     FieldBase field = extractField( string, pos );
    00425     if ( count < 3 && headerOrder[ count++ ] != field.getField() )
    00426       return false;
    00427
    00428     if ( isHeaderField( field ) )
    00429       m_header.setField( field, false );
    00430     else break;
    00431   }
    00432   return true;
    00433
    00434   QF_STACK_POP
    00435 }

static ApplVerID FIX::Message::toApplVerID | ( | const BeginString & | value | ) | `[inline, static]`

Definition at line 249 of file Message.h.

References FIX::FIELD::ApplVerID, FIX::ApplVerID_FIX40, FIX::ApplVerID_FIX41, FIX::ApplVerID_FIX42, FIX::ApplVerID_FIX43, FIX::ApplVerID_FIX44, FIX::ApplVerID_FIX50, FIX::ApplVerID_FIX50SP1, FIX::ApplVerID_FIX50SP2, FIX::BeginString_FIX40, FIX::BeginString_FIX41, FIX::BeginString_FIX42, FIX::BeginString_FIX43, FIX::BeginString_FIX44, FIX::BeginString_FIX50, QF_STACK_POP, QF_STACK_PUSH, and FIX::SessionFactory::toApplVerID().

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

    00250   { QF_STACK_PUSH(SessionFactory::toApplVerID)
    00251
    00252     if( value == BeginString_FIX40 )
    00253       return ApplVerID(ApplVerID_FIX40);
    00254     if( value == BeginString_FIX41 )
    00255       return ApplVerID(ApplVerID_FIX41);
    00256     if( value == BeginString_FIX42 )
    00257       return ApplVerID(ApplVerID_FIX42);
    00258     if( value == BeginString_FIX43 )
    00259       return ApplVerID(ApplVerID_FIX43);
    00260     if( value == BeginString_FIX44 )
    00261       return ApplVerID(ApplVerID_FIX44);
    00262     if( value == BeginString_FIX50 )
    00263       return ApplVerID(ApplVerID_FIX50);
    00264     if( value == "FIX.5.0SP1" )
    00265       return ApplVerID(ApplVerID_FIX50SP1);
    00266     if( value == "FIX.5.0SP2" )
    00267       return ApplVerID(ApplVerID_FIX50SP2);
    00268     return ApplVerID(ApplVerID(value));
    00269
    00270     QF_STACK_POP
    00271   }

static BeginString FIX::Message::toBeginString | ( | const ApplVerID & | applVerID | ) | `[inline, static]`

Definition at line 273 of file Message.h.

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

Referenced by FIX::MessageCracker::crack().

    00274   {
    00275     if( applVerID == ApplVerID_FIX40 )
    00276       return BeginString(BeginString_FIX40);
    00277     else if( applVerID == ApplVerID_FIX41 )
    00278       return BeginString(BeginString_FIX41);
    00279     else if( applVerID == ApplVerID_FIX42 )
    00280       return BeginString(BeginString_FIX42);
    00281     else if( applVerID == ApplVerID_FIX43 )
    00282       return BeginString(BeginString_FIX43);
    00283     else if( applVerID == ApplVerID_FIX44 )
    00284       return BeginString(BeginString_FIX44);
    00285     else if( applVerID == ApplVerID_FIX50 )
    00286       return BeginString(BeginString_FIX50);
    00287     else if( applVerID == ApplVerID_FIX50SP1 )
    00288       return BeginString(BeginString_FIX50);
    00289     else if( applVerID == ApplVerID_FIX50SP2 )
    00290       return BeginString(BeginString_FIX50);
    00291     else
    00292       return BeginString("");
    00293   }

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

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

    00206 { QF_STACK_PUSH(Message::toString)
    00207
    00208   int length = bodyLength( beginStringField, bodyLengthField, checkSumField );
    00209   m_header.setField( IntField(bodyLengthField, length) );
    00210   m_trailer.setField( CheckSumField(checkSumField, checkSum(checkSumField)) );
    00211
    00212   m_header.calculateString( str, true );
    00213   FieldMap::calculateString( str, false );
    00214   m_trailer.calculateString( str, false );
    00215
    00216   return str;
    00217
    00218   QF_STACK_POP
    00219 }

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

References QF_STACK_POP, and QF_STACK_PUSH.

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

    00194 { QF_STACK_PUSH(Message::toString)
    00195
    00196   std::string str;
    00197   return toString( str, beginStringField, bodyLengthField, checkSumField );
    00198
    00199   QF_STACK_POP
    00200 }

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

Get a XML representation without making a copy.

Definition at line 230 of file Message.cpp.

References getHeader(), getTrailer(), QF_STACK_POP, QF_STACK_PUSH, toXML(), and toXMLFields().

    00231 { QF_STACK_PUSH(Message::toXML)
    00232
    00233   std::stringstream stream;
    00234   stream << "<message>"                         << std::endl
    00235          << std::setw(2) << " " << "<header>"   << std::endl
    00236          << toXMLFields(getHeader(), 4)
    00237          << std::setw(2) << " " << "</header>"  << std::endl
    00238          << std::setw(2) << " " << "<body>"     << std::endl
    00239          << toXMLFields(*this, 4)
    00240          << std::setw(2) << " " << "</body>"    << std::endl
    00241          << std::setw(2) << " " << "<trailer>"  << std::endl
    00242          << toXMLFields(getTrailer(), 4)
    00243          << std::setw(2) << " " << "</trailer>" << std::endl
    00244          << "</message>";
    00245
    00246   return str = stream.str();
    00247
    00248   QF_STACK_POP
    00249 }

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

Get a XML representation of the message.

Definition at line 221 of file Message.cpp.

References QF_STACK_POP, and QF_STACK_PUSH.

Referenced by toXML().

    00222 { QF_STACK_PUSH(Message::toXML)
    00223
    00224   std::string str;
    00225   return toXML( str );
    00226
    00227   QF_STACK_POP
    00228 }

std::string FIX::Message::toXMLFields | ( | const FieldMap & | fields,
|  | int | space |
| ) |  |  | const`[private]`

Definition at line 251 of file Message.cpp.

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

Referenced by toXML().

    00252 { QF_STACK_PUSH(Message::toXMLFields)
    00253
    00254   std::stringstream stream;
    00255   FieldMap::iterator i;
    00256   std::string name;
    00257   for(i = fields.begin(); i != fields.end(); ++i)
    00258   {
    00259     int field = i->first;
    00260     std::string value = i->second.getString();
    00261
    00262     stream << std::setw(space) << " " << "<field ";
    00263     if(s_dataDictionary.get() && s_dataDictionary->getFieldName(field, name))
    00264     {
    00265       stream << "name=\"" << name << "\" ";
    00266     }
    00267     stream << "number=\"" << field << "\"";
    00268     if(s_dataDictionary.get()
    00269        && s_dataDictionary->getValueName(field, value, name))
    00270     {
    00271       stream << " enum=\"" << name << "\"";
    00272     }
    00273     stream << ">";
    00274     stream << "<![CDATA[" << value << "]]>";
    00275     stream << "</field>" << std::endl;
    00276   }
    00277
    00278   FieldMap::g_iterator j;
    00279   for(j = fields.g_begin(); j != fields.g_end(); ++j)
    00280   {
    00281     std::vector<FieldMap*>::const_iterator k;
    00282     for(k = j->second.begin(); k != j->second.end(); ++k)
    00283     {
    00284       stream << std::setw(space) << " " << "<group>" << std::endl
    00285              << toXMLFields(*(*k), space+2)
    00286              << std::setw(space) << " " << "</group>" << std::endl;
    00287     }
    00288   }
    00289
    00290   return stream.str();
    00291
    00292   QF_STACK_POP
    00293 }

void FIX::Message::validate | ( |  | ) | `[private]`

Definition at line 544 of file Message.cpp.

References bodyLength(), FIX::FIELD::BodyLength, checkSum(), FIX::FIELD::CheckSum, FIELD_GET_REF, m_header, m_trailer, QF_STACK_POP, and QF_STACK_PUSH.

Referenced by setString().

    00545 { QF_STACK_PUSH(Message::validate)
    00546
    00547   try
    00548   {
    00549     const BodyLength& aBodyLength = FIELD_GET_REF( m_header, BodyLength );
    00550
    00551     if ( aBodyLength != bodyLength() )
    00552     {
    00553       std::stringstream text;
    00554       text << "Expected BodyLength=" << bodyLength()
    00555            << ", Recieved BodyLength=" << (int)aBodyLength;
    00556       throw InvalidMessage(text.str());
    00557     }
    00558
    00559     const CheckSum& aCheckSum = FIELD_GET_REF( m_trailer, CheckSum );
    00560
    00561     if ( aCheckSum != checkSum() )
    00562     {
    00563       std::stringstream text;
    00564       text << "Expected CheckSum=" << checkSum()
    00565            << ", Recieved CheckSum=" << (int)aCheckSum;
    00566       throw InvalidMessage(text.str());
    00567     }
    00568   }
    00569   catch ( FieldNotFound& )
    00570   {
    00571     throw InvalidMessage("BodyLength or CheckSum missing");
    00572   }
    00573   catch ( IncorrectDataFormat& )
    00574   {
    00575     throw InvalidMessage("BodyLength or Checksum has wrong format");
    00576   }
    00577
    00578   QF_STACK_POP
    00579 }

## Friends And Related Function Documentation

friend class DataDictionary`[friend]`

Definition at line 59 of file Message.h.

Referenced by InitializeXML().

friend class Session`[friend]`

Definition at line 60 of file Message.h.

## Member Data Documentation

int FIX::Message::m_field`[protected]`

Definition at line 364 of file Message.h.

Referenced by clear(), hasValidStructure(), and Message().

FieldMap FIX::Message::m_header`[mutable, protected]`

Definition at line 361 of file Message.h.

Referenced by bodyLength(), checkSum(), clear(), getHeader(), isAdmin(), isApp(), isEmpty(), Message(), reverseRoute(), setStringHeader(), toString(), and validate().

FieldMap FIX::Message::m_trailer`[mutable, protected]`

Definition at line 362 of file Message.h.

Referenced by bodyLength(), checkSum(), clear(), getTrailer(), isEmpty(), Message(), toString(), and validate().

bool FIX::Message::m_validStructure`[protected]`

Definition at line 363 of file Message.h.

Referenced by hasValidStructure(), and Message().

std::auto_ptr< DataDictionary > FIX::Message::s_dataDictionary`[static, protected]`

Definition at line 365 of file Message.h.

Referenced by InitializeXML(), and toXMLFields().

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

- /home/omiller/Development/autobuild/quickfix/src/C++/Message.h
- /home/omiller/Development/autobuild/quickfix/src/C++/Message.cpp