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

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 (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.
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) 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.
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.
const HeadergetHeader () const
 Getter for the message header.
HeadergetHeader ()
 Mutable getter for the message header.
const TrailergetTrailer () const
 Getter for the message trailer.
TrailergetTrailer ()
 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

Header m_header
Trailer 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

Static Private Member Functions

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

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


Member Enumeration Documentation

enum FIX::Message::field_type [private]
Enumerator:
header 
body 
trailer 

Definition at line 72 of file Message.h.


Constructor & Destructor Documentation

Definition at line 35 of file Message.cpp.

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

Construct a message from a string.

Definition at line 38 of file Message.cpp.

: m_validStructure( true )
{
  setString( string, validate );
}
FIX::Message::Message ( const std::string &  string,
const FIX::DataDictionary dataDictionary,
bool  validate = true 
) throw ( InvalidMessage )

Construct a message from a string using a data dictionary.

Definition at line 45 of file Message.cpp.

: m_validStructure( true )
{
  setString( string, validate, &dataDictionary, &dataDictionary );
}
FIX::Message::Message ( const std::string &  string,
const FIX::DataDictionary sessionDataDictionary,
const FIX::DataDictionary applicationDataDictionary,
bool  validate = true 
) throw ( InvalidMessage )

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

Definition at line 54 of file Message.cpp.

: m_validStructure( true )
{
  setStringHeader( string );
  if( isAdmin() )
    setString( string, validate, &sessionDataDictionary, &sessionDataDictionary );
  else
    setString( string, validate, &sessionDataDictionary, &applicationDataDictionary );
}
FIX::Message::Message ( const Message copy) [inline]

Definition at line 91 of file Message.h.

References m_field, m_header, m_trailer, and m_validStructure.

  : FieldMap( copy )
  {
    m_header = copy.m_header;
    m_trailer = copy.m_trailer;
    m_validStructure = copy.m_validStructure;
    m_field = copy.m_field;
  }
FIX::Message::Message ( const BeginString &  beginString,
const MsgType &  msgType 
) [inline, protected]

Definition at line 127 of file Message.h.

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

  : m_validStructure( true )
  {
    m_header.setField( beginString );
    m_header.setField( msgType );
  }

Member Function Documentation

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

Definition at line 103 of file Message.h.

References FIX::Group::field().

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

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

Referenced by toString(), and validate().

  { return m_header.calculateLength(beginStringField, bodyLengthField, checkSumField)
           + calculateLength(beginStringField, bodyLengthField, checkSumField)
           + m_trailer.calculateLength(beginStringField, bodyLengthField, checkSumField);
  }
int FIX::Message::checkSum ( int  checkSumField = FIELD::CheckSum) const [inline]

Definition at line 213 of file Message.h.

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

Referenced by toString(), and validate().

  { return ( m_header.calculateTotal(checkSumField)
             + calculateTotal(checkSumField)
             + m_trailer.calculateTotal(checkSumField) ) % 256;
  }
void FIX::Message::clear ( ) [inline]

Clear all fields from the map.

Reimplemented from FIX::FieldMap.

Definition at line 242 of file Message.h.

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

Referenced by setStringHeader().

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

Definition at line 531 of file Message.cpp.

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

Referenced by setGroup(), and setStringHeader().

{
  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;
  IntConvertor::convert( tagStart, equalSign, field );

  std::string::const_iterator const valueStart = equalSign + 1;

  std::string::const_iterator soh = std::find( valueStart, strEnd, '\001' );
  if ( soh == strEnd )
    throw InvalidMessage("SOH not found at end of field");

  if ( IsDataField( field, pSessionDD, pAppDD ) )
  {
    // 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;

    if ( pGroup && pGroup->isSetField( lenField ) )
    {
      const std::string& fieldLength = pGroup->getField( lenField );
      soh = valueStart + atol( fieldLength.c_str() );
    }
    else if ( isSetField( lenField ) )
    {
      const std::string& fieldLength = getField( lenField );
      soh = valueStart + atol( fieldLength.c_str() );
    }
  }

  std::string::const_iterator const tagEnd = soh + 1;
  pos = std::distance( string.begin(), tagEnd );

  return FieldBase (
    field,
    valueStart,
    soh,
    tagStart, 
    tagEnd );
}
Group& FIX::Message::getGroup ( unsigned  num,
FIX::Group group 
) const throw ( FieldNotFound ) [inline]

Definition at line 109 of file Message.h.

References FIX::FieldMap::clear().

  { group.clear();
    return static_cast < Group& >
      ( FieldMap::getGroup( num, group.field(), group ) );
  }
const Header& FIX::Message::getHeader ( ) const [inline]

Mutable getter for the message header.

Definition at line 194 of file Message.h.

References m_header.

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

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

{
  BeginString beginString;
  SenderCompID senderCompID;
  TargetCompID targetCompID;

  getHeader().getField( beginString );
  getHeader().getField( senderCompID );
  getHeader().getField( targetCompID );

  return SessionID( beginString, senderCompID, targetCompID, qualifier );
}
const Trailer& FIX::Message::getTrailer ( ) const [inline]

Getter for the message trailer.

Definition at line 196 of file Message.h.

References m_trailer.

Referenced by toXML().

{ return m_trailer; }

Mutable getter for the message trailer.

Definition at line 198 of file Message.h.

References m_trailer.

{ return m_trailer; }
bool FIX::Message::hasGroup ( const FIX::Group group) const [inline]

Definition at line 120 of file Message.h.

References FIX::Group::field().

Referenced by hasGroup().

  { return FieldMap::hasGroup( group.field() ); }
bool FIX::Message::hasGroup ( unsigned  num,
const FIX::Group group 
) const [inline]

Definition at line 122 of file Message.h.

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

  { return FieldMap::hasGroup( num, group.field() ); }
bool FIX::Message::hasValidStructure ( int &  field) const [inline]

Definition at line 200 of file Message.h.

References m_field, and m_validStructure.

  { field = m_field;
    return m_validStructure;
  }
bool FIX::Message::InitializeXML ( const std::string &  string) [static]

Set global data dictionary for encoding messages into XML.

Definition at line 68 of file Message.cpp.

References DataDictionary, and s_dataDictionary.

{
  try
  {
    std::auto_ptr<DataDictionary> p =
      std::auto_ptr<DataDictionary>(new DataDictionary(url));
    s_dataDictionary = p;
    return true;
  }
  catch( ConfigError& )
  { return false; }
}
bool FIX::Message::isAdmin ( ) const [inline]

Definition at line 219 of file Message.h.

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

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

  { 
    if( m_header.isSetField(FIELD::MsgType) )
    {
      const MsgType& msgType = FIELD_GET_REF( m_header, MsgType );
      return isAdminMsgType( msgType );
    }
    return false;
  }
static bool FIX::Message::isAdminMsgType ( const MsgType &  msgType) [inline, static]

Definition at line 250 of file Message.h.

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

  { if ( msgType.getValue().length() != 1 ) return false;
    return strchr
           ( "0A12345",
             msgType.getValue().c_str() [ 0 ] ) != 0;
  }
bool FIX::Message::isApp ( ) const [inline]

Definition at line 229 of file Message.h.

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

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

  { 
    if( m_header.isSetField(FIELD::MsgType) )
    {
      const MsgType& msgType = FIELD_GET_REF( m_header, MsgType );
      return !isAdminMsgType( msgType );
    }
    return false;
  }
static bool FIX::Message::IsDataField ( int  field,
const DataDictionary pSessionDD,
const DataDictionary pAppDD 
) [inline, static, private]

Definition at line 320 of file Message.h.

Referenced by extractField().

  {
    if( (pSessionDD && pSessionDD->isDataField( field )) ||
        (pAppDD && pAppDD != pSessionDD && pAppDD->isDataField( field )) )
    {
      return true;
    }

    return false;
  }
bool FIX::Message::isEmpty ( ) [inline]

Check if map contains any fields.

Reimplemented from FIX::FieldMap.

Definition at line 239 of file Message.h.

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

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

Definition at line 400 of file Message.cpp.

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

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

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

Definition at line 439 of file Message.cpp.

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

{
  if ( isHeaderField( field.getField() ) ) return true;
  if ( pD ) return pD->isHeaderField( field.getField() );
  return false;
}
bool FIX::Message::isTrailerField ( int  field) [static]

Definition at line 447 of file Message.cpp.

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

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

{
  switch ( field )
  {
    case FIELD::SignatureLength:
    case FIELD::Signature:
    case FIELD::CheckSum:
    return true;
    default:
    return false;
  };
}
bool FIX::Message::isTrailerField ( const FieldBase field,
const DataDictionary pD = 0 
) [static]

Definition at line 460 of file Message.cpp.

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

{
  if ( isTrailerField( field.getField() ) ) return true;
  if ( pD ) return pD->isTrailerField( field.getField() );
  return false;
}
void FIX::Message::removeGroup ( unsigned  num,
const FIX::Group group 
) [inline]

Definition at line 115 of file Message.h.

References FIX::Group::field().

Referenced by removeGroup().

  { FieldMap::removeGroup( num, group.field() ); }
void FIX::Message::removeGroup ( const FIX::Group group) [inline]

Definition at line 117 of file Message.h.

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

  { FieldMap::removeGroup( group.field() ); }
void FIX::Message::replaceGroup ( unsigned  num,
const FIX::Group group 
) [inline]

Definition at line 106 of file Message.h.

References FIX::Group::field().

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

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

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

{
  // required routing tags
  BeginString beginString;
  SenderCompID senderCompID;
  TargetCompID targetCompID;

  m_header.removeField( beginString.getField() );
  m_header.removeField( senderCompID.getField() );
  m_header.removeField( targetCompID.getField() );

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

    OnBehalfOfLocationID onBehalfOfLocationID;
    DeliverToLocationID deliverToLocationID;

    m_header.removeField( onBehalfOfLocationID.getField() );
    m_header.removeField( deliverToLocationID.getField() );

    if( beginString >= BeginString_FIX41 )
    {
      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.getField() );
  m_header.removeField( onBehalfOfSubID.getField() );
  m_header.removeField( deliverToCompID.getField() );
  m_header.removeField( deliverToSubID.getField() );

  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 ) );
  }
}
void FIX::Message::setGroup ( const std::string &  msg,
const FieldBase field,
const std::string &  string,
std::string::size_type &  pos,
FieldMap map,
const DataDictionary dataDictionary 
)

Definition at line 336 of file Message.cpp.

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

{
  int group = field.getField();
  int delim;
  const DataDictionary* pDD = 0;
  if ( !dataDictionary.getGroup( msg, group, delim, pDD ) ) return ;
  std::auto_ptr<Group> pGroup;

  while ( pos < string.size() )
  {
    std::string::size_type oldPos = pos;
    FieldBase field = extractField( string, pos, &dataDictionary, &dataDictionary, pGroup.get() );
       
    // Start a new group because...
    if (// found delimiter
    (field.getField() == delim) ||
    // no delimiter, but field belongs to group OR field already processed
    (pDD->isField( field.getField() ) && (pGroup.get() == 0 || pGroup->isSetField( field.getField() )) ))
    {
      if ( pGroup.get() )
      {
        map.addGroupPtr( group, pGroup.release(), false );
      }
      pGroup.reset( new Group( field.getField(), delim, pDD->getOrderedFields() ) );
    }
    else if ( !pDD->isField( field.getField() ) )
    {
      if ( pGroup.get() )
      {
        map.addGroupPtr( group, pGroup.release(), false );
      }
      pos = oldPos;
      return ;
    }

    if ( !pGroup.get() ) return ;
    pGroup->setField( field, false );
    setGroup( msg, field, string, pos, *pGroup, *pDD );
  }
}
void FIX::Message::setSessionID ( const SessionID sessionID)

Sets the session ID of the intended recipient.

Definition at line 482 of file Message.cpp.

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

{
  getHeader().setField( sessionID.getBeginString() );
  getHeader().setField( sessionID.getSenderCompID() );
  getHeader().setField( sessionID.getTargetCompID() );
}
void FIX::Message::setString ( const std::string &  string) throw ( InvalidMessage ) [inline]

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

It will return true on success and false on failure.

Definition at line 162 of file Message.h.

References setString().

Referenced by setString().

  { setString(string, true); }
void FIX::Message::setString ( const std::string &  string,
bool  validate 
) throw ( InvalidMessage ) [inline]

Definition at line 165 of file Message.h.

References setString(), and validate().

Referenced by setString().

  { setString(string, validate, 0); }
void FIX::Message::setString ( const std::string &  string,
bool  validate,
const FIX::DataDictionary pDataDictionary 
) throw ( InvalidMessage ) [inline]

Definition at line 168 of file Message.h.

References setString(), and validate().

Referenced by setString().

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

Definition at line 265 of file Message.cpp.

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

{
  clear();

  std::string::size_type pos = 0;
  int count = 0;
  std::string msg;

  static int const headerOrder[] =
  {
    FIELD::BeginString,
    FIELD::BodyLength,
    FIELD::MsgType
  };

  field_type type = header;

  while ( pos < string.size() )
  {
    FieldBase field = extractField( string, pos, pSessionDataDictionary, pApplicationDataDictionary );
    if ( count < 3 && headerOrder[ count++ ] != field.getField() )
      if ( doValidation ) throw InvalidMessage("Header fields out of order");

    if ( isHeaderField( field, pSessionDataDictionary ) )
    {
      if ( type != header )
      {
        if(m_field == 0) m_field = field.getField();
        m_validStructure = false;
      }

      if ( field.getField() == FIELD::MsgType )
        msg = field.getString();

      m_header.setField( field, false );

      if ( pSessionDataDictionary )
        setGroup( "_header_", field, string, pos, getHeader(), *pSessionDataDictionary );
    }
    else if ( isTrailerField( field, pSessionDataDictionary ) )
    {
      type = trailer;
      m_trailer.setField( field, false );

      if ( pSessionDataDictionary )
        setGroup( "_trailer_", field, string, pos, getTrailer(), *pSessionDataDictionary );
    }
    else
    {
      if ( type == trailer )
      {
        if(m_field == 0) m_field = field.getField();
        m_validStructure = false;
      }

      type = body;
      setField( field, false );

      if ( pApplicationDataDictionary )
        setGroup( msg, field, string, pos, *this, *pApplicationDataDictionary );
    }
  }

  if ( doValidation )
    validate();
}
bool FIX::Message::setStringHeader ( const std::string &  string)

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

Definition at line 380 of file Message.cpp.

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

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

{
  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.getField() )
      return false;

    if ( isHeaderField( field ) )
      m_header.setField( field, false );
    else break;
  }
  return true;
}
static ApplVerID FIX::Message::toApplVerID ( const BeginString &  value) [inline, static]
static BeginString FIX::Message::toBeginString ( const ApplVerID &  applVerID) [inline, static]
std::string FIX::Message::toString ( int  beginStringField = FIELD::BeginString,
int  bodyLengthField = FIELD::BodyLength,
int  checkSumField = FIELD::CheckSum 
) const

Get a string representation of the message.

Definition at line 167 of file Message.cpp.

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

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

Get a string representation without making a copy.

Definition at line 175 of file Message.cpp.

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

{
  int length = bodyLength( beginStringField, bodyLengthField, checkSumField );
  m_header.setField( IntField(bodyLengthField, length) );
  m_trailer.setField( CheckSumField(checkSumField, checkSum(checkSumField)) );

#if defined(_MSC_VER) && _MSC_VER < 1300
  str = "";
#else
  str.clear();
#endif

  /*small speculation about the space needed for FIX string*/
  str.reserve( length + 64 );

  m_header.calculateString( str );
  FieldMap::calculateString( str );
  m_trailer.calculateString( str );

  return str;
}
std::string FIX::Message::toXML ( ) const

Get a XML representation of the message.

Definition at line 200 of file Message.cpp.

{
  std::string str;
  return toXML( str );
}
std::string & FIX::Message::toXML ( std::string &  str) const

Get a XML representation without making a copy.

Definition at line 206 of file Message.cpp.

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

{
  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)
         << std::setw(2) << " " << "</body>"    << std::endl
         << std::setw(2) << " " << "<trailer>"  << std::endl
         << toXMLFields(getTrailer(), 4)
         << std::setw(2) << " " << "</trailer>" << std::endl
         << "</message>";

  return str = stream.str();
}
std::string FIX::Message::toXMLFields ( const FieldMap fields,
int  space 
) const [private]

Definition at line 224 of file Message.cpp.

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

Referenced by toXML().

{
  std::stringstream stream;
  FieldMap::iterator i;
  std::string name;
  for(i = fields.begin(); i != fields.end(); ++i)
  {
    int field = i->first;
    std::string value = i->second.getString();

    stream << std::setw(space) << " " << "<field ";
    if(s_dataDictionary.get() && s_dataDictionary->getFieldName(field, name))
    {
      stream << "name=\"" << name << "\" ";
    }
    stream << "number=\"" << field << "\"";
    if(s_dataDictionary.get()
       && s_dataDictionary->getValueName(field, value, name))
    {
      stream << " enum=\"" << name << "\"";
    }
    stream << ">";
    stream << "<![CDATA[" << value << "]]>";
    stream << "</field>" << std::endl;
  }

  FieldMap::g_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 FIX::Message::validate ( ) [private]

Definition at line 489 of file Message.cpp.

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

Referenced by setString().

{
  try
  {
    const BodyLength& aBodyLength = FIELD_GET_REF( m_header, BodyLength );

    const int expectedLength = (int)aBodyLength;
    const int actualLength = bodyLength();

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

    const CheckSum& aCheckSum = FIELD_GET_REF( m_trailer, CheckSum );

    const int expectedChecksum = (int)aCheckSum;
    const int actualChecksum = checkSum();

    if ( expectedChecksum != actualChecksum )
    {
      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 );
  }
}

Friends And Related Function Documentation

friend class DataDictionary [friend]

Definition at line 69 of file Message.h.

Referenced by InitializeXML().

friend class Session [friend]

Definition at line 70 of file Message.h.


Member Data Documentation

int FIX::Message::m_field [protected]

Definition at line 341 of file Message.h.

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

Header FIX::Message::m_header [mutable, protected]
Trailer FIX::Message::m_trailer [mutable, protected]

Definition at line 339 of file Message.h.

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

Definition at line 340 of file Message.h.

Referenced by hasValidStructure(), and Message().

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

Definition at line 342 of file Message.h.

Referenced by InitializeXML(), and toXMLFields().


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

Generated on Mon Jun 23 2014 23:49:39 for QuickFIX by doxygen 1.7.6.1 written by Dimitri van Heesch, © 1997-2001