Public Member Functions | Static Public Member Functions | Private Types | Private Member Functions | Private Attributes | List of all members
FIX::DataDictionary Class Reference

Represents a data dictionary for a version of FIX. More...

#include <DataDictionary.h>

Collaboration diagram for FIX::DataDictionary:
Collaboration graph
[legend]

Public Member Functions

 DataDictionary ()
 
 DataDictionary (const DataDictionary &copy)
 
 DataDictionary (std::istream &stream) throw ( ConfigError )
 
 DataDictionary (const std::string &url) throw ( ConfigError )
 
virtual ~DataDictionary ()
 
void readFromURL (const std::string &url) throw ( ConfigError )
 
void readFromDocument (DOMDocumentPtr pDoc) throw ( ConfigError )
 
void readFromStream (std::istream &stream) throw ( ConfigError )
 
message_order const & getOrderedFields () const
 
void setVersion (const std::string &beginString)
 
std::string getVersion () const
 
void addField (int field)
 
void addFieldName (int field, const std::string &name)
 
bool getFieldName (int field, std::string &name) const
 
bool getFieldTag (const std::string &name, int &field) const
 
void addValueName (int field, const std::string &value, const std::string &name)
 
bool getValueName (int field, const std::string &value, std::string &name) const
 
bool isField (int field) const
 
void addMsgType (const std::string &msgType)
 
bool isMsgType (const std::string &msgType) const
 
void addMsgField (const std::string &msgType, int field)
 
bool isMsgField (const std::string &msgType, int field) const
 
void addHeaderField (int field, bool required)
 
bool isHeaderField (int field) const
 
void addTrailerField (int field, bool required)
 
bool isTrailerField (int field) const
 
void addFieldType (int field, FIX::TYPE::Type type)
 
bool getFieldType (int field, FIX::TYPE::Type &type) const
 
void addRequiredField (const std::string &msgType, int field)
 
bool isRequiredField (const std::string &msgType, int field) const
 
void addFieldValue (int field, const std::string &value)
 
bool hasFieldValue (int field) const
 
bool isFieldValue (int field, const std::string &value) const
 
void addGroup (const std::string &msg, int field, int delim, const DataDictionary &dataDictionary)
 
bool isGroup (const std::string &msg, int field) const
 
bool getGroup (const std::string &msg, int field, int &delim, const DataDictionary *&pDataDictionary) const
 
bool isDataField (int field) const
 
bool isMultipleValueField (int field) const
 
void checkFieldsOutOfOrder (bool value)
 
void checkFieldsHaveValues (bool value)
 
void checkUserDefinedFields (bool value)
 
void validate (const Message &message) const throw ( FIX::Exception )
 
void validate (const Message &message, bool bodyOnly) const throw ( FIX::Exception )
 
DataDictionaryoperator= (const DataDictionary &rhs)
 

Static Public Member Functions

static void validate (const Message &message, const DataDictionary *const pSessionDD, const DataDictionary *const pAppID) throw ( FIX::Exception )
 Validate a message. More...
 

Private Types

typedef std::set< int > MsgFields
 
typedef std::map< std::string,
MsgFields
MsgTypeToField
 
typedef std::set< std::string > MsgTypes
 
typedef std::set< int > Fields
 
typedef std::map< int, bool > NonBodyFields
 
typedef std::vector< int > OrderedFields
 
typedef message_order OrderedFieldsArray
 
typedef std::map< int, TYPE::TypeFieldTypes
 
typedef std::set< std::string > Values
 
typedef std::map< int, ValuesFieldToValue
 
typedef std::map< int,
std::string > 
FieldToName
 
typedef std::map< std::string,
int > 
NameToField
 
typedef std::map< std::pair
< int, std::string >
, std::string > 
ValueToName
 
typedef std::map< std::string,
std::pair< int, DataDictionary * > > 
FieldPresenceMap
 
typedef std::map< int,
FieldPresenceMap
FieldToGroup
 

Private Member Functions

void iterate (const FieldMap &map, const MsgType &msgType) const
 Iterate through fields while applying checks. More...
 
void checkMsgType (const MsgType &msgType) const
 Check if message type is defined in spec. More...
 
bool shouldCheckTag (const FieldBase &field) const
 If we need to check for the tag in the dictionary. More...
 
void checkValidTagNumber (const FieldBase &field) const throw ( InvalidTagNumber )
 Check if field tag number is defined in spec. More...
 
void checkValidFormat (const FieldBase &field) const throw ( IncorrectDataFormat )
 
void checkValue (const FieldBase &field) const throw ( IncorrectTagValue )
 
void checkHasValue (const FieldBase &field) const throw ( NoTagValue )
 Check if a field has a value. More...
 
void checkIsInMessage (const FieldBase &field, const MsgType &msgType) const throw ( TagNotDefinedForMessage )
 Check if a field is in this message type. More...
 
void checkGroupCount (const FieldBase &field, const FieldMap &fieldMap, const MsgType &msgType) const throw ( RepeatingGroupCountMismatch )
 Check if group count matches number of groups in. More...
 
void checkHasRequired (const FieldMap &header, const FieldMap &body, const FieldMap &trailer, const MsgType &msgType) const throw ( RequiredTagMissing )
 Check if a message has all required fields. More...
 
void readMSXMLDOM (const std::string &)
 Read XML file using MSXML. More...
 
void readMSXML (const std::string &)
 
void readLibXml (const std::string &)
 Read XML file using libXML. More...
 
int lookupXMLFieldNumber (DOMDocument *, DOMNode *) const
 
int lookupXMLFieldNumber (DOMDocument *, const std::string &name) const
 
int addXMLComponentFields (DOMDocument *, DOMNode *, const std::string &msgtype, DataDictionary &, bool)
 
void addXMLGroup (DOMDocument *, DOMNode *, const std::string &msgtype, DataDictionary &, bool)
 
TYPE::Type XMLTypeToType (const std::string &xmlType) const
 

Private Attributes

bool m_hasVersion
 
bool m_checkFieldsOutOfOrder
 
bool m_checkFieldsHaveValues
 
bool m_checkUserDefinedFields
 
BeginString m_beginString
 
MsgTypeToField m_messageFields
 
MsgTypeToField m_requiredFields
 
MsgTypes m_messages
 
Fields m_fields
 
OrderedFields m_orderedFields
 
OrderedFieldsArray m_orderedFieldsArray
 
NonBodyFields m_headerFields
 
NonBodyFields m_trailerFields
 
FieldTypes m_fieldTypes
 
FieldToValue m_fieldValues
 
FieldToName m_fieldNames
 
NameToField m_names
 
ValueToName m_valueNames
 
FieldToGroup m_groups
 
MsgFields m_dataFields
 

Detailed Description

Represents a data dictionary for a version of FIX.

Generally loaded from an XML document. The DataDictionary is also responsible for validation beyond the basic structure of a message.

Definition at line 49 of file DataDictionary.h.

Member Typedef Documentation

typedef std::map< std::string, std::pair < int, DataDictionary* > > FIX::DataDictionary::FieldPresenceMap
private

Definition at line 69 of file DataDictionary.h.

typedef std::set< int > FIX::DataDictionary::Fields
private

Definition at line 54 of file DataDictionary.h.

typedef std::map< int, FieldPresenceMap > FIX::DataDictionary::FieldToGroup
private

Definition at line 70 of file DataDictionary.h.

typedef std::map< int, std::string > FIX::DataDictionary::FieldToName
private

Definition at line 61 of file DataDictionary.h.

typedef std::map< int, Values > FIX::DataDictionary::FieldToValue
private

Definition at line 60 of file DataDictionary.h.

typedef std::map< int, TYPE::Type > FIX::DataDictionary::FieldTypes
private

Definition at line 58 of file DataDictionary.h.

typedef std::set< int > FIX::DataDictionary::MsgFields
private

Definition at line 51 of file DataDictionary.h.

typedef std::set< std::string > FIX::DataDictionary::MsgTypes
private

Definition at line 53 of file DataDictionary.h.

typedef std::map< std::string, MsgFields > FIX::DataDictionary::MsgTypeToField
private

Definition at line 52 of file DataDictionary.h.

typedef std::map< std::string, int > FIX::DataDictionary::NameToField
private

Definition at line 62 of file DataDictionary.h.

typedef std::map< int, bool > FIX::DataDictionary::NonBodyFields
private

Definition at line 55 of file DataDictionary.h.

typedef std::vector< int > FIX::DataDictionary::OrderedFields
private

Definition at line 56 of file DataDictionary.h.

Definition at line 57 of file DataDictionary.h.

typedef std::set< std::string > FIX::DataDictionary::Values
private

Definition at line 59 of file DataDictionary.h.

typedef std::map< std::pair < int, std::string > , std::string > FIX::DataDictionary::ValueToName
private

Definition at line 63 of file DataDictionary.h.

Constructor & Destructor Documentation

FIX::DataDictionary::DataDictionary ( )

Definition at line 47 of file DataDictionary.cpp.

Referenced by addGroup().

FIX::DataDictionary::DataDictionary ( const DataDictionary copy)

Definition at line 69 of file DataDictionary.cpp.

70 {
71  *this = copy;
72 }
FIX::DataDictionary::DataDictionary ( std::istream &  stream)
throw (ConfigError
)

Definition at line 52 of file DataDictionary.cpp.

54 : m_hasVersion( false ), m_checkFieldsOutOfOrder( true ),
56 {
57  readFromStream( stream );
58 }
void readFromStream(std::istream &stream)
FIX::DataDictionary::DataDictionary ( const std::string &  url)
throw (ConfigError
)

Definition at line 60 of file DataDictionary.cpp.

62 : m_hasVersion( false ), m_checkFieldsOutOfOrder( true ),
65 {
66  readFromURL( url );
67 }
void readFromURL(const std::string &url)
OrderedFieldsArray m_orderedFieldsArray
FIX::DataDictionary::~DataDictionary ( )
virtual

Definition at line 74 of file DataDictionary.cpp.

References m_groups.

75 {
76  FieldToGroup::iterator i;
77  for ( i = m_groups.begin(); i != m_groups.end(); ++i )
78  {
79  const FieldPresenceMap& presenceMap = i->second;
80 
81  FieldPresenceMap::const_iterator iter = presenceMap.begin();
82  for ( ; iter != presenceMap.end(); ++iter )
83  delete iter->second.second;
84 }
85 }
FieldToGroup m_groups
std::map< std::string, std::pair< int, DataDictionary * > > FieldPresenceMap

Member Function Documentation

void FIX::DataDictionary::addField ( int  field)
inline

Definition at line 96 of file DataDictionary.h.

References m_fields, and m_orderedFields.

Referenced by addXMLComponentFields(), and addXMLGroup().

97  {
98  m_fields.insert( field );
99  m_orderedFields.push_back( field );
100  }
OrderedFields m_orderedFields
void FIX::DataDictionary::addFieldName ( int  field,
const std::string &  name 
)
inline

Definition at line 102 of file DataDictionary.h.

References m_fieldNames, and m_names.

103  {
104  if( m_names.insert( std::make_pair(name, field) ).second == false )
105  throw ConfigError( "Field named " + name + " defined multiple times" );
106  m_fieldNames[field] = name;
107  }
FieldToName m_fieldNames
void FIX::DataDictionary::addFieldType ( int  field,
FIX::TYPE::Type  type 
)
inline

Definition at line 185 of file DataDictionary.h.

References FIX::TYPE::Data, m_dataFields, and m_fieldTypes.

186  {
187  m_fieldTypes[ field ] = type;
188 
189  if( type == FIX::TYPE::Data )
190  m_dataFields.insert( field );
191  }
void FIX::DataDictionary::addFieldValue ( int  field,
const std::string &  value 
)
inline

Definition at line 213 of file DataDictionary.h.

References m_fieldValues.

214  {
215  m_fieldValues[ field ].insert( value );
216  }
FieldToValue m_fieldValues
void FIX::DataDictionary::addGroup ( const std::string &  msg,
int  field,
int  delim,
const DataDictionary dataDictionary 
)
inline

Definition at line 247 of file DataDictionary.h.

References DataDictionary(), getVersion(), m_groups, and setVersion().

Referenced by addXMLGroup(), and operator=().

249  {
250  DataDictionary * pDD = new DataDictionary( dataDictionary );
251  pDD->setVersion( getVersion() );
252 
253  FieldPresenceMap& presenceMap = m_groups[ field ];
254  presenceMap[ msg ] = std::make_pair( delim, pDD );
255  }
std::string getVersion() const
FieldToGroup m_groups
std::map< std::string, std::pair< int, DataDictionary * > > FieldPresenceMap
void FIX::DataDictionary::addHeaderField ( int  field,
bool  required 
)
inline

Definition at line 165 of file DataDictionary.h.

References m_headerFields.

166  {
167  m_headerFields[ field ] = required;
168  }
NonBodyFields m_headerFields
void FIX::DataDictionary::addMsgField ( const std::string &  msgType,
int  field 
)
inline

Definition at line 153 of file DataDictionary.h.

References m_messageFields.

Referenced by addXMLComponentFields().

154  {
155  m_messageFields[ msgType ].insert( field );
156  }
MsgTypeToField m_messageFields
void FIX::DataDictionary::addMsgType ( const std::string &  msgType)
inline

Definition at line 143 of file DataDictionary.h.

References m_messages.

144  {
145  m_messages.insert( msgType );
146  }
void FIX::DataDictionary::addRequiredField ( const std::string &  msgType,
int  field 
)
inline

Definition at line 201 of file DataDictionary.h.

References m_requiredFields.

Referenced by addXMLComponentFields(), and addXMLGroup().

202  {
203  m_requiredFields[ msgType ].insert( field );
204  }
MsgTypeToField m_requiredFields
void FIX::DataDictionary::addTrailerField ( int  field,
bool  required 
)
inline

Definition at line 175 of file DataDictionary.h.

References m_trailerFields.

176  {
177  m_trailerFields[ field ] = required;
178  }
NonBodyFields m_trailerFields
void FIX::DataDictionary::addValueName ( int  field,
const std::string &  value,
const std::string &  name 
)
inline

Definition at line 125 of file DataDictionary.h.

References m_valueNames.

126  {
127  m_valueNames[std::make_pair(field, value)] = name;
128  }
ValueToName m_valueNames
int FIX::DataDictionary::addXMLComponentFields ( DOMDocument pDoc,
DOMNode pNode,
const std::string &  msgtype,
DataDictionary DD,
bool  componentRequired 
)
private

Definition at line 480 of file DataDictionary.cpp.

References addField(), addMsgField(), addRequiredField(), addXMLGroup(), FIX::DOMNode::getAttributes(), FIX::DOMDocument::getNode(), lookupXMLFieldNumber(), and RESET_AUTO_PTR.

Referenced by addXMLGroup().

484 {
485  int firstField = 0;
486 
487  DOMAttributesPtr attrs = pNode->getAttributes();
488  std::string name;
489  if(!attrs->get("name", name))
490  throw ConfigError("No name given to component");
491 
492  DOMNodePtr pComponentNode =
493  pDoc->getNode("/fix/components/component[@name='" + name + "']");
494  if(pComponentNode.get() == 0)
495  throw ConfigError("Component not found");
496 
497  DOMNodePtr pComponentFieldNode = pComponentNode->getFirstChildNode();
498  while(pComponentFieldNode.get())
499  {
500  if(pComponentFieldNode->getName() == "field"
501  || pComponentFieldNode->getName() == "group")
502  {
503  DOMAttributesPtr attrs = pComponentFieldNode->getAttributes();
504  std::string name;
505  if(!attrs->get("name", name))
506  throw ConfigError("No name given to field");
507  int field = lookupXMLFieldNumber(pDoc, name);
508  if( firstField == 0 ) firstField = field;
509 
510  std::string required;
511  if(attrs->get("required", required)
512  && (required == "Y" || required =="y")
513  && componentRequired)
514  {
515  addRequiredField(msgtype, field);
516  }
517 
518  DD.addField(field);
519  DD.addMsgField(msgtype, field);
520  }
521  if(pComponentFieldNode->getName() == "component")
522  {
523  DOMAttributesPtr attrs = pComponentFieldNode->getAttributes();
524  std::string required;
525  attrs->get("required", required);
526  bool isRequired = (required == "Y" || required == "y");
527  addXMLComponentFields(pDoc, pComponentFieldNode.get(),
528  msgtype, DD, isRequired);
529  }
530  if(pComponentFieldNode->getName() == "group")
531  {
532  DOMAttributesPtr attrs = pComponentFieldNode->getAttributes();
533  std::string required;
534  attrs->get("required", required);
535  bool isRequired = (required == "Y" || required == "y");
536  addXMLGroup(pDoc, pComponentFieldNode.get(), msgtype, DD, isRequired);
537  }
538  RESET_AUTO_PTR(pComponentFieldNode,
539  pComponentFieldNode->getNextSiblingNode());
540  }
541  return firstField;
542 }
std::auto_ptr< DOMAttributes > DOMAttributesPtr
Definition: DOMDocument.h:43
void addXMLGroup(DOMDocument *, DOMNode *, const std::string &msgtype, DataDictionary &, bool)
#define RESET_AUTO_PTR(OLD, NEW)
int addXMLComponentFields(DOMDocument *, DOMNode *, const std::string &msgtype, DataDictionary &, bool)
std::auto_ptr< DOMNode > DOMNodePtr
Definition: DOMDocument.h:57
int lookupXMLFieldNumber(DOMDocument *, DOMNode *) const
void addRequiredField(const std::string &msgType, int field)
void FIX::DataDictionary::addXMLGroup ( DOMDocument pDoc,
DOMNode pNode,
const std::string &  msgtype,
DataDictionary DD,
bool  groupRequired 
)
private

Definition at line 544 of file DataDictionary.cpp.

References addField(), addGroup(), addRequiredField(), addXMLComponentFields(), FIX::DOMNode::getAttributes(), FIX::DOMNode::getFirstChildNode(), lookupXMLFieldNumber(), and RESET_AUTO_PTR.

Referenced by addXMLComponentFields().

547 {
548  DOMAttributesPtr attrs = pNode->getAttributes();
549  std::string name;
550  if(!attrs->get("name", name))
551  throw ConfigError("No name given to group");
552  int group = lookupXMLFieldNumber( pDoc, name );
553  int delim = 0;
554  int field = 0;
555  DataDictionary groupDD;
556  DOMNodePtr node = pNode->getFirstChildNode();
557  while(node.get())
558  {
559  if( node->getName() == "field" )
560  {
561  field = lookupXMLFieldNumber( pDoc, node.get() );
562  groupDD.addField( field );
563 
564  DOMAttributesPtr attrs = node->getAttributes();
565  std::string required;
566  if( attrs->get("required", required)
567  && ( required == "Y" || required =="y" )
568  && groupRequired )
569  {
570  groupDD.addRequiredField(msgtype, field);
571  }
572  }
573  else if( node->getName() == "component" )
574  {
575  field = addXMLComponentFields( pDoc, node.get(), msgtype, groupDD, false );
576  }
577  else if( node->getName() == "group" )
578  {
579  field = lookupXMLFieldNumber( pDoc, node.get() );
580  groupDD.addField( field );
581  DOMAttributesPtr attrs = node->getAttributes();
582  std::string required;
583  if( attrs->get("required", required )
584  && ( required == "Y" || required =="y" )
585  && groupRequired)
586  {
587  groupDD.addRequiredField(msgtype, field);
588  }
589  bool isRequired = false;
590  if( attrs->get("required", required) )
591  isRequired = (required == "Y" || required == "y");
592  addXMLGroup( pDoc, node.get(), msgtype, groupDD, isRequired );
593  }
594  if( delim == 0 ) delim = field;
595  RESET_AUTO_PTR(node, node->getNextSiblingNode());
596  }
597 
598  if( delim ) DD.addGroup( msgtype, group, delim, groupDD );
599 }
std::auto_ptr< DOMAttributes > DOMAttributesPtr
Definition: DOMDocument.h:43
void addXMLGroup(DOMDocument *, DOMNode *, const std::string &msgtype, DataDictionary &, bool)
#define RESET_AUTO_PTR(OLD, NEW)
int addXMLComponentFields(DOMDocument *, DOMNode *, const std::string &msgtype, DataDictionary &, bool)
std::auto_ptr< DOMNode > DOMNodePtr
Definition: DOMDocument.h:57
int lookupXMLFieldNumber(DOMDocument *, DOMNode *) const
void FIX::DataDictionary::checkFieldsHaveValues ( bool  value)
inline

Definition at line 302 of file DataDictionary.h.

References m_checkFieldsHaveValues.

Referenced by FIX::SessionFactory::createDataDictionary().

303  { m_checkFieldsHaveValues = value; }
void FIX::DataDictionary::checkFieldsOutOfOrder ( bool  value)
inline

Definition at line 300 of file DataDictionary.h.

References m_checkFieldsOutOfOrder.

Referenced by FIX::SessionFactory::createDataDictionary().

301  { m_checkFieldsOutOfOrder = value; }
void FIX::DataDictionary::checkGroupCount ( const FieldBase field,
const FieldMap fieldMap,
const MsgType &  msgType 
) const
throw (RepeatingGroupCountMismatch
)
inlineprivate

Check if group count matches number of groups in.

Definition at line 452 of file DataDictionary.h.

References FIX::IntConvertor::convert(), FIX::FieldBase::getField(), FIX::FieldBase::getString(), FIX::FieldMap::groupCount(), and isGroup().

Referenced by iterate().

454  {
455  int fieldNum = field.getField();
456  if( isGroup(msgType, fieldNum) )
457  {
458  if( fieldMap.groupCount(fieldNum)
459  != IntConvertor::convert(field.getString()) )
460  throw RepeatingGroupCountMismatch(fieldNum);
461  }
462  }
static std::string convert(signed_int value)
bool isGroup(const std::string &msg, int field) const
void FIX::DataDictionary::checkHasRequired ( const FieldMap header,
const FieldMap body,
const FieldMap trailer,
const MsgType &  msgType 
) const
throw (RequiredTagMissing
)
inlineprivate

Check if a message has all required fields.

Definition at line 466 of file DataDictionary.h.

References checkHasRequired(), FIX::FieldMap::g_begin(), FIX::FieldMap::g_end(), getGroup(), FIX::FieldMap::isSetField(), m_headerFields, m_requiredFields, and m_trailerFields.

Referenced by checkHasRequired().

469  {
470  NonBodyFields::const_iterator iNBF;
471  for( iNBF = m_headerFields.begin(); iNBF != m_headerFields.end(); ++iNBF )
472  {
473  if( iNBF->second == true && !header.isSetField(iNBF->first) )
474  throw RequiredTagMissing( iNBF->first );
475  }
476 
477  for( iNBF = m_trailerFields.begin(); iNBF != m_trailerFields.end(); ++iNBF )
478  {
479  if( iNBF->second == true && !trailer.isSetField(iNBF->first) )
480  throw RequiredTagMissing( iNBF->first );
481  }
482 
483  MsgTypeToField::const_iterator iM
484  = m_requiredFields.find( msgType.getString() );
485  if ( iM == m_requiredFields.end() ) return ;
486 
487  const MsgFields& fields = iM->second;
488  MsgFields::const_iterator iF;
489  for( iF = fields.begin(); iF != fields.end(); ++iF )
490  {
491  if( !body.isSetField(*iF) )
492  throw RequiredTagMissing( *iF );
493  }
494 
495  FieldMap::g_iterator groups;
496  for( groups = body.g_begin(); groups != body.g_end(); ++groups )
497  {
498  int delim;
499  const DataDictionary* DD = 0;
500  int field = groups->first;
501  if( getGroup( msgType.getValue(), field, delim, DD ) )
502  {
503  std::vector<FieldMap*>::const_iterator group;
504  for( group = groups->second.begin(); group != groups->second.end(); ++group )
505  DD->checkHasRequired( **group, **group, **group, msgType );
506  }
507  }
508  }
MsgTypeToField m_requiredFields
Groups::const_iterator g_iterator
Definition: FieldMap.h:61
NonBodyFields m_headerFields
bool getGroup(const std::string &msg, int field, int &delim, const DataDictionary *&pDataDictionary) const
std::set< int > MsgFields
NonBodyFields m_trailerFields
void FIX::DataDictionary::checkHasValue ( const FieldBase field) const
throw (NoTagValue
)
inlineprivate

Check if a field has a value.

Definition at line 434 of file DataDictionary.h.

References m_checkFieldsHaveValues.

Referenced by iterate().

436  {
437  if ( m_checkFieldsHaveValues && !field.getString().length() )
438  throw NoTagValue( field.getField() );
439  }
void FIX::DataDictionary::checkIsInMessage ( const FieldBase field,
const MsgType &  msgType 
) const
throw (TagNotDefinedForMessage
)
inlineprivate

Check if a field is in this message type.

Definition at line 443 of file DataDictionary.h.

References FIX::FieldBase::getField(), and isMsgField().

Referenced by iterate().

445  {
446  if ( !isMsgField( msgType, field.getField() ) )
447  throw TagNotDefinedForMessage( field.getField() );
448  }
bool isMsgField(const std::string &msgType, int field) const
void FIX::DataDictionary::checkMsgType ( const MsgType &  msgType) const
inlineprivate

Check if message type is defined in spec.

Definition at line 324 of file DataDictionary.h.

References isMsgType().

325  {
326  if ( !isMsgType( msgType.getValue() ) )
327  throw InvalidMessageType();
328  }
bool isMsgType(const std::string &msgType) const
void FIX::DataDictionary::checkUserDefinedFields ( bool  value)
inline

Definition at line 304 of file DataDictionary.h.

References m_checkUserDefinedFields.

Referenced by FIX::SessionFactory::createDataDictionary().

305  { m_checkUserDefinedFields = value; }
void FIX::DataDictionary::checkValidFormat ( const FieldBase field) const
throw (IncorrectDataFormat
)
inlineprivate

Definition at line 347 of file DataDictionary.h.

References FIX::TYPE::Amt, FIX::TYPE::Boolean, FIX::TYPE::Char, FIX::EmptyConvertor::convert(), FIX::IntConvertor::convert(), FIX::DoubleConvertor::convert(), FIX::CharConvertor::convert(), FIX::BoolConvertor::convert(), FIX::UtcTimeStampConvertor::convert(), FIX::UtcTimeOnlyConvertor::convert(), FIX::UtcDateConvertor::convert(), FIX::TYPE::Country, FIX::TYPE::Currency, FIX::TYPE::Data, FIX::TYPE::DayOfMonth, FIX::TYPE::Exchange, FIX::TYPE::Float, getFieldType(), FIX::TYPE::Int, FIX::TYPE::Language, FIX::TYPE::Length, FIX::TYPE::LocalMktDate, FIX::TYPE::MonthYear, FIX::TYPE::MultipleCharValue, FIX::TYPE::MultipleStringValue, FIX::TYPE::MultipleValueString, FIX::TYPE::NumInGroup, FIX::TYPE::Percentage, FIX::TYPE::Price, FIX::TYPE::PriceOffset, FIX::TYPE::Qty, FIX::TYPE::SeqNum, FIX::TYPE::String, FIX::TYPE::TzTimeOnly, FIX::TYPE::TzTimeStamp, FIX::TYPE::Unknown, FIX::TYPE::UtcDate, FIX::TYPE::UtcTimeOnly, FIX::TYPE::UtcTimeStamp, and FIX::TYPE::XmlData.

Referenced by iterate().

349  {
350  try
351  {
352  TYPE::Type type = TYPE::Unknown;
353  getFieldType( field.getField(), type );
354  switch ( type )
355  {
356  case TYPE::String:
357  STRING_CONVERTOR::convert( field.getString() ); break;
358  case TYPE::Char:
359  CHAR_CONVERTOR::convert( field.getString() ); break;
360  case TYPE::Price:
361  PRICE_CONVERTOR::convert( field.getString() ); break;
362  case TYPE::Int:
363  INT_CONVERTOR::convert( field.getString() ); break;
364  case TYPE::Amt:
365  AMT_CONVERTOR::convert( field.getString() ); break;
366  case TYPE::Qty:
367  QTY_CONVERTOR::convert( field.getString() ); break;
368  case TYPE::Currency:
369  CURRENCY_CONVERTOR::convert( field.getString() ); break;
371  MULTIPLEVALUESTRING_CONVERTOR::convert( field.getString() ); break;
373  MULTIPLESTRINGVALUE_CONVERTOR::convert( field.getString() ); break;
375  MULTIPLECHARVALUE_CONVERTOR::convert( field.getString() ); break;
376  case TYPE::Exchange:
377  EXCHANGE_CONVERTOR::convert( field.getString() ); break;
378  case TYPE::UtcTimeStamp:
379  UTCTIMESTAMP_CONVERTOR::convert( field.getString() ); break;
380  case TYPE::Boolean:
381  BOOLEAN_CONVERTOR::convert( field.getString() ); break;
382  case TYPE::LocalMktDate:
383  LOCALMKTDATE_CONVERTOR::convert( field.getString() ); break;
384  case TYPE::Data:
385  DATA_CONVERTOR::convert( field.getString() ); break;
386  case TYPE::Float:
387  FLOAT_CONVERTOR::convert( field.getString() ); break;
388  case TYPE::PriceOffset:
389  PRICEOFFSET_CONVERTOR::convert( field.getString() ); break;
390  case TYPE::MonthYear:
391  MONTHYEAR_CONVERTOR::convert( field.getString() ); break;
392  case TYPE::DayOfMonth:
393  DAYOFMONTH_CONVERTOR::convert( field.getString() ); break;
394  case TYPE::UtcDate:
395  UTCDATE_CONVERTOR::convert( field.getString() ); break;
396  case TYPE::UtcTimeOnly:
397  UTCTIMEONLY_CONVERTOR::convert( field.getString() ); break;
398  case TYPE::NumInGroup:
399  NUMINGROUP_CONVERTOR::convert( field.getString() ); break;
400  case TYPE::Percentage:
401  PERCENTAGE_CONVERTOR::convert( field.getString() ); break;
402  case TYPE::SeqNum:
403  SEQNUM_CONVERTOR::convert( field.getString() ); break;
404  case TYPE::Length:
405  LENGTH_CONVERTOR::convert( field.getString() ); break;
406  case TYPE::Country:
407  COUNTRY_CONVERTOR::convert( field.getString() ); break;
408  case TYPE::TzTimeOnly:
409  TZTIMEONLY_CONVERTOR::convert( field.getString() ); break;
410  case TYPE::TzTimeStamp:
411  TZTIMESTAMP_CONVERTOR::convert( field.getString() ); break;
412  case TYPE::XmlData:
413  XMLDATA_CONVERTOR::convert( field.getString() ); break;
414  case TYPE::Language:
415  LANGUAGE_CONVERTOR::convert( field.getString() ); break;
416  case TYPE::Unknown: break;
417  }
418  }
419  catch ( FieldConvertError& )
420  { throw IncorrectDataFormat( field.getField(), field.getString() ); }
421  }
static std::string convert(const UtcTimeOnly &value, bool showMilliseconds=false)
static std::string convert(char value)
static std::string convert(const UtcTimeStamp &value, bool showMilliseconds=false)
static std::string convert(signed_int value)
static std::string convert(double value, int padding=0)
bool getFieldType(int field, FIX::TYPE::Type &type) const
static std::string convert(const UtcDate &value)
static std::string convert(bool value)
static const std::string & convert(const std::string &value)
void FIX::DataDictionary::checkValidTagNumber ( const FieldBase field) const
throw (InvalidTagNumber
)
inlineprivate

Check if field tag number is defined in spec.

Definition at line 340 of file DataDictionary.h.

References m_fields.

Referenced by iterate().

342  {
343  if( m_fields.find( field.getField() ) == m_fields.end() )
344  throw InvalidTagNumber( field.getField() );
345  }
void FIX::DataDictionary::checkValue ( const FieldBase field) const
throw (IncorrectTagValue
)
inlineprivate

Definition at line 423 of file DataDictionary.h.

References hasFieldValue(), and isFieldValue().

Referenced by iterate().

425  {
426  if ( !hasFieldValue( field.getField() ) ) return ;
427 
428  const std::string& value = field.getString();
429  if ( !isFieldValue( field.getField(), value ) )
430  throw IncorrectTagValue( field.getField() );
431  }
bool isFieldValue(int field, const std::string &value) const
bool hasFieldValue(int field) const
bool FIX::DataDictionary::getFieldName ( int  field,
std::string &  name 
) const
inline

Definition at line 109 of file DataDictionary.h.

References m_fieldNames.

110  {
111  FieldToName::const_iterator i = m_fieldNames.find( field );
112  if(i == m_fieldNames.end()) return false;
113  name = i->second;
114  return true;
115  }
FieldToName m_fieldNames
bool FIX::DataDictionary::getFieldTag ( const std::string &  name,
int &  field 
) const
inline

Definition at line 117 of file DataDictionary.h.

References m_names.

118  {
119  NameToField::const_iterator i = m_names.find( name );
120  if(i == m_names.end()) return false;
121  field = i->second;
122  return true;
123  }
bool FIX::DataDictionary::getFieldType ( int  field,
FIX::TYPE::Type type 
) const
inline

Definition at line 193 of file DataDictionary.h.

References m_fieldTypes.

Referenced by checkValidFormat().

194  {
195  FieldTypes::const_iterator i = m_fieldTypes.find( field );
196  if ( i == m_fieldTypes.end() ) return false;
197  type = i->second;
198  return true;
199  }
bool FIX::DataDictionary::getGroup ( const std::string &  msg,
int  field,
int &  delim,
const DataDictionary *&  pDataDictionary 
) const
inline

Definition at line 268 of file DataDictionary.h.

References m_groups.

Referenced by checkHasRequired(), and FIX::Message::setGroup().

270  {
271  FieldToGroup::const_iterator i = m_groups.find( field );
272  if ( i == m_groups.end() ) return false;
273 
274  const FieldPresenceMap& presenceMap = i->second;
275 
276  FieldPresenceMap::const_iterator iter = presenceMap.find( msg );
277  if( iter == presenceMap.end() ) return false;
278 
279  std::pair < int, DataDictionary* > pair = iter->second;
280  delim = pair.first;
281  pDataDictionary = pair.second;
282  return true;
283  }
FieldToGroup m_groups
std::map< std::string, std::pair< int, DataDictionary * > > FieldPresenceMap
message_order const & FIX::DataDictionary::getOrderedFields ( ) const

Definition at line 445 of file DataDictionary.cpp.

References m_orderedFields, and m_orderedFieldsArray.

Referenced by FIX::Message::setGroup().

446 {
448 
449  int * tmp = new int[m_orderedFields.size() + 1];
450  int * i = tmp;
451 
452  OrderedFields::const_iterator iter;
453  for( iter = m_orderedFields.begin(); iter != m_orderedFields.end(); *(i++) = *(iter++) ) {}
454  *i = 0;
455 
456  m_orderedFieldsArray = message_order(tmp);
457  delete [] tmp;
458 
459  return m_orderedFieldsArray;
460 }
OrderedFields m_orderedFields
OrderedFieldsArray m_orderedFieldsArray
bool FIX::DataDictionary::getValueName ( int  field,
const std::string &  value,
std::string &  name 
) const
inline

Definition at line 130 of file DataDictionary.h.

References m_valueNames.

131  {
132  ValueToName::const_iterator i = m_valueNames.find( std::make_pair(field, value) );
133  if(i == m_valueNames.end()) return false;
134  name = i->second;
135  return true;
136  }
ValueToName m_valueNames
std::string FIX::DataDictionary::getVersion ( ) const
inline

Definition at line 91 of file DataDictionary.h.

References m_beginString.

Referenced by addGroup().

92  {
93  return m_beginString.getString();
94  }
BeginString m_beginString
bool FIX::DataDictionary::hasFieldValue ( int  field) const
inline

Definition at line 218 of file DataDictionary.h.

References m_fieldValues.

Referenced by checkValue().

219  {
220  FieldToValue::const_iterator i = m_fieldValues.find( field );
221  return i != m_fieldValues.end();
222  }
FieldToValue m_fieldValues
bool FIX::DataDictionary::isDataField ( int  field) const
inline

Definition at line 285 of file DataDictionary.h.

References m_dataFields.

286  {
287  MsgFields::const_iterator iter = m_dataFields.find( field );
288  return iter != m_dataFields.end();
289  }
bool FIX::DataDictionary::isField ( int  field) const
inline

Definition at line 138 of file DataDictionary.h.

References m_fields.

Referenced by FIX::Message::setGroup().

139  {
140  return m_fields.find( field ) != m_fields.end();
141  }
bool FIX::DataDictionary::isFieldValue ( int  field,
const std::string &  value 
) const
inline

Definition at line 224 of file DataDictionary.h.

References isMultipleValueField(), and m_fieldValues.

Referenced by checkValue().

225  {
226  FieldToValue::const_iterator i = m_fieldValues.find( field );
227  if ( i == m_fieldValues.end() )
228  return false;
229  if( !isMultipleValueField( field ) )
230  return i->second.find( value ) != i->second.end();
231 
232  // MultipleValue
233  std::string::size_type startPos = 0;
234  std::string::size_type endPos = 0;
235  do
236  {
237  endPos = value.find_first_of(' ', startPos);
238  std::string singleValue =
239  value.substr( startPos, endPos - startPos );
240  if( i->second.find( singleValue ) == i->second.end() )
241  return false;
242  startPos = endPos + 1;
243  } while( endPos != std::string::npos );
244  return true;
245  }
FieldToValue m_fieldValues
bool isMultipleValueField(int field) const
bool FIX::DataDictionary::isGroup ( const std::string &  msg,
int  field 
) const
inline

Definition at line 257 of file DataDictionary.h.

References m_groups.

Referenced by checkGroupCount().

258  {
259  FieldToGroup::const_iterator i = m_groups.find( field );
260  if ( i == m_groups.end() ) return false;
261 
262  const FieldPresenceMap& presenceMap = i->second;
263 
264  FieldPresenceMap::const_iterator iter = presenceMap.find( msg );
265  return ( iter != presenceMap.end() );
266  }
FieldToGroup m_groups
std::map< std::string, std::pair< int, DataDictionary * > > FieldPresenceMap
bool FIX::DataDictionary::isHeaderField ( int  field) const
inline

Definition at line 170 of file DataDictionary.h.

References m_headerFields.

Referenced by FIX::Message::isHeaderField().

171  {
172  return m_headerFields.find( field ) != m_headerFields.end();
173  }
NonBodyFields m_headerFields
bool FIX::DataDictionary::isMsgField ( const std::string &  msgType,
int  field 
) const
inline

Definition at line 158 of file DataDictionary.h.

References m_messageFields.

Referenced by checkIsInMessage().

159  {
160  MsgTypeToField::const_iterator i = m_messageFields.find( msgType );
161  if ( i == m_messageFields.end() ) return false;
162  return i->second.find( field ) != i->second.end();
163  }
MsgTypeToField m_messageFields
bool FIX::DataDictionary::isMsgType ( const std::string &  msgType) const
inline

Definition at line 148 of file DataDictionary.h.

References m_messages.

Referenced by checkMsgType().

149  {
150  return m_messages.find( msgType ) != m_messages.end();
151  }
bool FIX::DataDictionary::isMultipleValueField ( int  field) const
inline

Definition at line 291 of file DataDictionary.h.

References m_fieldTypes, FIX::TYPE::MultipleCharValue, FIX::TYPE::MultipleStringValue, and FIX::TYPE::MultipleValueString.

Referenced by isFieldValue().

292  {
293  FieldTypes::const_iterator i = m_fieldTypes.find( field );
294  return i != m_fieldTypes.end()
295  && (i->second == TYPE::MultipleValueString
296  || i->second == TYPE::MultipleCharValue
297  || i->second == TYPE::MultipleStringValue );
298  }
bool FIX::DataDictionary::isRequiredField ( const std::string &  msgType,
int  field 
) const
inline

Definition at line 206 of file DataDictionary.h.

References m_requiredFields.

207  {
208  MsgTypeToField::const_iterator i = m_requiredFields.find( msgType );
209  if ( i == m_requiredFields.end() ) return false;
210  return i->second.find( field ) != i->second.end();
211  }
MsgTypeToField m_requiredFields
bool FIX::DataDictionary::isTrailerField ( int  field) const
inline

Definition at line 180 of file DataDictionary.h.

References m_trailerFields.

Referenced by FIX::Message::isTrailerField().

181  {
182  return m_trailerFields.find( field ) != m_trailerFields.end();
183  }
NonBodyFields m_trailerFields
void FIX::DataDictionary::iterate ( const FieldMap map,
const MsgType &  msgType 
) const
private

Iterate through fields while applying checks.

Definition at line 165 of file DataDictionary.cpp.

References FIX::FieldMap::begin(), checkGroupCount(), checkHasValue(), checkIsInMessage(), checkValidFormat(), checkValidTagNumber(), checkValue(), FIX::FieldMap::end(), FIX::FieldBase::getField(), FIX::Message::isHeaderField(), FIX::Message::isTrailerField(), m_beginString, m_hasVersion, and shouldCheckTag().

166 {
167  int lastField = 0;
168 
170  for ( i = map.begin(); i != map.end(); ++i )
171  {
172  const FieldBase& field = i->second;
173  if( i != map.begin() && (field.getField() == lastField) )
174  throw RepeatedTag( lastField );
175  checkHasValue( field );
176 
177  if ( m_hasVersion )
178  {
179  checkValidFormat( field );
180  checkValue( field );
181  }
182 
183  if ( m_beginString.getValue().length() && shouldCheckTag(field) )
184  {
185  checkValidTagNumber( field );
186  if ( !Message::isHeaderField( field, this )
187  && !Message::isTrailerField( field, this ) )
188  {
189  checkIsInMessage( field, msgType );
190  checkGroupCount( field, map, msgType );
191  }
192  }
193  lastField = field.getField();
194  }
195 }
void checkValidFormat(const FieldBase &field) const
Fields::const_iterator iterator
Definition: FieldMap.h:59
void checkIsInMessage(const FieldBase &field, const MsgType &msgType) const
Check if a field is in this message type.
void checkValue(const FieldBase &field) const
bool shouldCheckTag(const FieldBase &field) const
If we need to check for the tag in the dictionary.
BeginString m_beginString
void checkValidTagNumber(const FieldBase &field) const
Check if field tag number is defined in spec.
void checkGroupCount(const FieldBase &field, const FieldMap &fieldMap, const MsgType &msgType) const
Check if group count matches number of groups in.
void checkHasValue(const FieldBase &field) const
Check if a field has a value.
static bool isHeaderField(int field)
Definition: Message.cpp:391
static bool isTrailerField(int field)
Definition: Message.cpp:438
int FIX::DataDictionary::lookupXMLFieldNumber ( DOMDocument pDoc,
DOMNode pNode 
) const
private

Definition at line 462 of file DataDictionary.cpp.

References FIX::DOMNode::getAttributes().

Referenced by addXMLComponentFields(), and addXMLGroup().

463 {
464  DOMAttributesPtr attrs = pNode->getAttributes();
465  std::string name;
466  if(!attrs->get("name", name))
467  throw ConfigError("No name given to field");
468  return lookupXMLFieldNumber( pDoc, name );
469 }
std::auto_ptr< DOMAttributes > DOMAttributesPtr
Definition: DOMDocument.h:43
int lookupXMLFieldNumber(DOMDocument *, DOMNode *) const
int FIX::DataDictionary::lookupXMLFieldNumber ( DOMDocument pDoc,
const std::string &  name 
) const
private

Definition at line 472 of file DataDictionary.cpp.

473 {
474  NameToField::const_iterator i = m_names.find(name);
475  if( i == m_names.end() )
476  throw ConfigError("Field " + name + " not defined in fields section");
477  return i->second;
478 }
DataDictionary & FIX::DataDictionary::operator= ( const DataDictionary rhs)

Definition at line 87 of file DataDictionary.cpp.

References addGroup(), m_beginString, m_checkFieldsHaveValues, m_checkFieldsOutOfOrder, m_checkUserDefinedFields, m_dataFields, m_fieldNames, m_fields, m_fieldTypes, m_fieldValues, m_groups, m_hasVersion, m_headerFields, m_messageFields, m_messages, m_names, m_orderedFields, m_orderedFieldsArray, m_requiredFields, m_trailerFields, and m_valueNames.

88 {
89  m_hasVersion = rhs.m_hasVersion;
90  m_checkFieldsOutOfOrder = rhs.m_checkFieldsOutOfOrder;
91  m_checkFieldsHaveValues = rhs.m_checkFieldsHaveValues;
92  m_checkUserDefinedFields = rhs.m_checkUserDefinedFields;
93  m_beginString = rhs.m_beginString;
94  m_messageFields = rhs.m_messageFields;
95  m_requiredFields = rhs.m_requiredFields;
96  m_messages = rhs.m_messages;
97  m_fields = rhs.m_fields;
98  m_orderedFields = rhs.m_orderedFields;
99  m_orderedFieldsArray = rhs.m_orderedFieldsArray;
100  m_headerFields = rhs.m_headerFields;
101  m_trailerFields = rhs.m_trailerFields;
102  m_fieldTypes = rhs.m_fieldTypes;
103  m_fieldValues = rhs.m_fieldValues;
104  m_fieldNames = rhs.m_fieldNames;
105  m_names = rhs.m_names;
106  m_valueNames = rhs.m_valueNames;
107  m_dataFields = rhs.m_dataFields;
108 
109  FieldToGroup::const_iterator i = rhs.m_groups.begin();
110  for ( ; i != rhs.m_groups.end(); ++i )
111  {
112  const FieldPresenceMap& presenceMap = i->second;
113 
114  FieldPresenceMap::const_iterator iter = presenceMap.begin();
115  for ( ; iter != presenceMap.end(); ++iter )
116  {
117  addGroup( iter->first, i->first, iter->second.first, *iter->second.second );
118  }
119  }
120  return *this;
121 }
MsgTypeToField m_requiredFields
OrderedFields m_orderedFields
void addGroup(const std::string &msg, int field, int delim, const DataDictionary &dataDictionary)
NonBodyFields m_headerFields
FieldToName m_fieldNames
BeginString m_beginString
MsgTypeToField m_messageFields
FieldToValue m_fieldValues
ValueToName m_valueNames
std::map< std::string, std::pair< int, DataDictionary * > > FieldPresenceMap
NonBodyFields m_trailerFields
OrderedFieldsArray m_orderedFieldsArray
void FIX::DataDictionary::readFromDocument ( DOMDocumentPtr  pDoc)
throw (ConfigError
)

Definition at line 238 of file DataDictionary.cpp.

References RESET_AUTO_PTR.

240 {
241  // VERSION
242  DOMNodePtr pFixNode = pDoc->getNode("/fix");
243  if(!pFixNode.get())
244  throw ConfigError("Could not parse data dictionary file"
245  ", or no <fix> node found at root");
246  DOMAttributesPtr attrs = pFixNode->getAttributes();
247  std::string type = "FIX";
248  if(attrs->get("type", type))
249  {
250  if(type != "FIX" && type != "FIXT")
251  throw ConfigError("type attribute must be FIX or FIXT");
252  }
253  std::string major;
254  if(!attrs->get("major", major))
255  throw ConfigError("major attribute not found on <fix>");
256  std::string minor;
257  if(!attrs->get("minor", minor))
258  throw ConfigError("minor attribute not found on <fix>");
259  setVersion(type + "." + major + "." + minor);
260 
261  // FIELDS
262  DOMNodePtr pFieldsNode = pDoc->getNode("/fix/fields");
263  if(!pFieldsNode.get())
264  throw ConfigError("<fields> section not found in data dictionary");
265 
266  DOMNodePtr pFieldNode = pFieldsNode->getFirstChildNode();
267  if(!pFieldNode.get()) throw ConfigError("No fields defined");
268 
269  while(pFieldNode.get())
270  {
271  if(pFieldNode->getName() == "field")
272  {
273  DOMAttributesPtr attrs = pFieldNode->getAttributes();
274  std::string name;
275  if(!attrs->get("name", name))
276  throw ConfigError("<field> does not have a name attribute");
277  std::string number;
278  if(!attrs->get("number", number))
279  throw ConfigError("<field> " + name + " does not have a number attribute");
280  int num = atol(number.c_str());
281  std::string type;
282  if(!attrs->get("type", type))
283  throw ConfigError("<field> " + name + " does not have a type attribute");
284  addField(num);
285  addFieldType(num, XMLTypeToType(type));
286  addFieldName(num, name);
287 
288  DOMNodePtr pFieldValueNode = pFieldNode->getFirstChildNode();
289  while(pFieldValueNode.get())
290  {
291  if(pFieldValueNode->getName() == "value")
292  {
293  DOMAttributesPtr attrs = pFieldValueNode->getAttributes();
294  std::string enumeration;
295  if(!attrs->get("enum", enumeration))
296  throw ConfigError("<value> does not have enum attribute in field " + name);
297  addFieldValue(num, enumeration);
298  std::string description;
299  if(attrs->get("description", description))
300  addValueName(num, enumeration, description);
301  }
302  RESET_AUTO_PTR(pFieldValueNode, pFieldValueNode->getNextSiblingNode());
303  }
304  }
305  RESET_AUTO_PTR(pFieldNode, pFieldNode->getNextSiblingNode());
306  }
307 
308  // HEADER
309  if( type == "FIXT" || (type == "FIX" && major < "5") )
310  {
311  DOMNodePtr pHeaderNode = pDoc->getNode("/fix/header");
312  if(!pHeaderNode.get())
313  throw ConfigError("<header> section not found in data dictionary");
314 
315  DOMNodePtr pHeaderFieldNode = pHeaderNode->getFirstChildNode();
316  if(!pHeaderFieldNode.get()) throw ConfigError("No header fields defined");
317 
318  while(pHeaderFieldNode.get())
319  {
320  if(pHeaderFieldNode->getName() == "field" || pHeaderFieldNode->getName() == "group" )
321  {
322  DOMAttributesPtr attrs = pHeaderFieldNode->getAttributes();
323  std::string name;
324  if(!attrs->get("name", name))
325  throw ConfigError("<field> does not have a name attribute");
326  std::string required = "false";
327  attrs->get("required", required);
328  addHeaderField(lookupXMLFieldNumber(pDoc.get(), name), required == "true");
329  }
330  if(pHeaderFieldNode->getName() == "group")
331  {
332  DOMAttributesPtr attrs = pHeaderFieldNode->getAttributes();
333  std::string required;
334  attrs->get("required", required);
335  bool isRequired = (required == "Y" || required == "y");
336  addXMLGroup(pDoc.get(), pHeaderFieldNode.get(), "_header_", *this, isRequired);
337  }
338 
339  RESET_AUTO_PTR(pHeaderFieldNode, pHeaderFieldNode->getNextSiblingNode());
340  }
341  }
342 
343  // TRAILER
344  if( type == "FIXT" || (type == "FIX" && major < "5") )
345  {
346  DOMNodePtr pTrailerNode = pDoc->getNode("/fix/trailer");
347  if(!pTrailerNode.get())
348  throw ConfigError("<trailer> section not found in data dictionary");
349 
350  DOMNodePtr pTrailerFieldNode = pTrailerNode->getFirstChildNode();
351  if(!pTrailerFieldNode.get()) throw ConfigError("No trailer fields defined");
352 
353  while(pTrailerFieldNode.get())
354  {
355  if(pTrailerFieldNode->getName() == "field" || pTrailerFieldNode->getName() == "group" )
356  {
357  DOMAttributesPtr attrs = pTrailerFieldNode->getAttributes();
358  std::string name;
359  if(!attrs->get("name", name))
360  throw ConfigError("<field> does not have a name attribute");
361  std::string required = "false";
362  attrs->get("required", required);
363  addTrailerField(lookupXMLFieldNumber(pDoc.get(), name), required == "true");
364  }
365  if(pTrailerFieldNode->getName() == "group")
366  {
367  DOMAttributesPtr attrs = pTrailerFieldNode->getAttributes();
368  std::string required;
369  attrs->get("required", required);
370  bool isRequired = (required == "Y" || required == "y");
371  addXMLGroup(pDoc.get(), pTrailerFieldNode.get(), "_trailer_", *this, isRequired);
372  }
373 
374  RESET_AUTO_PTR(pTrailerFieldNode, pTrailerFieldNode->getNextSiblingNode());
375  }
376  }
377 
378  // MSGTYPE
379  DOMNodePtr pMessagesNode = pDoc->getNode("/fix/messages");
380  if(!pMessagesNode.get())
381  throw ConfigError("<messages> section not found in data dictionary");
382 
383  DOMNodePtr pMessageNode = pMessagesNode->getFirstChildNode();
384  if(!pMessageNode.get()) throw ConfigError("No messages defined");
385 
386  while(pMessageNode.get())
387  {
388  if(pMessageNode->getName() == "message")
389  {
390  DOMAttributesPtr attrs = pMessageNode->getAttributes();
391  std::string msgtype;
392  if(!attrs->get("msgtype", msgtype))
393  throw ConfigError("<field> does not have a name attribute");
394  addMsgType(msgtype);
395 
396  std::string name;
397  if(attrs->get("name", name))
398  addValueName( 35, msgtype, name );
399 
400  DOMNodePtr pMessageFieldNode = pMessageNode->getFirstChildNode();
401  while( pMessageFieldNode.get() )
402  {
403  if(pMessageFieldNode->getName() == "field"
404  || pMessageFieldNode->getName() == "group")
405  {
406  DOMAttributesPtr attrs = pMessageFieldNode->getAttributes();
407  std::string name;
408  if(!attrs->get("name", name))
409  throw ConfigError("<field> does not have a name attribute");
410  int num = lookupXMLFieldNumber(pDoc.get(), name);
411  addMsgField(msgtype, num);
412 
413  std::string required;
414  if(attrs->get("required", required)
415  && (required == "Y" || required == "y"))
416  {
417  addRequiredField(msgtype, num);
418  }
419  }
420  else if(pMessageFieldNode->getName() == "component")
421  {
422  DOMAttributesPtr attrs = pMessageFieldNode->getAttributes();
423  std::string required;
424  attrs->get("required", required);
425  bool isRequired = (required == "Y" || required == "y");
426  addXMLComponentFields(pDoc.get(), pMessageFieldNode.get(),
427  msgtype, *this, isRequired);
428  }
429  if(pMessageFieldNode->getName() == "group")
430  {
431  DOMAttributesPtr attrs = pMessageFieldNode->getAttributes();
432  std::string required;
433  attrs->get("required", required);
434  bool isRequired = (required == "Y" || required == "y");
435  addXMLGroup(pDoc.get(), pMessageFieldNode.get(), msgtype, *this, isRequired);
436  }
437  RESET_AUTO_PTR(pMessageFieldNode,
438  pMessageFieldNode->getNextSiblingNode());
439  }
440  }
441  RESET_AUTO_PTR(pMessageNode, pMessageNode->getNextSiblingNode());
442  }
443 }
TYPE::Type XMLTypeToType(const std::string &xmlType) const
std::auto_ptr< DOMAttributes > DOMAttributesPtr
Definition: DOMDocument.h:43
void addMsgField(const std::string &msgType, int field)
void addTrailerField(int field, bool required)
void addXMLGroup(DOMDocument *, DOMNode *, const std::string &msgtype, DataDictionary &, bool)
#define RESET_AUTO_PTR(OLD, NEW)
int addXMLComponentFields(DOMDocument *, DOMNode *, const std::string &msgtype, DataDictionary &, bool)
void addHeaderField(int field, bool required)
void addValueName(int field, const std::string &value, const std::string &name)
std::auto_ptr< DOMNode > DOMNodePtr
Definition: DOMDocument.h:57
int lookupXMLFieldNumber(DOMDocument *, DOMNode *) const
void addField(int field)
void addFieldName(int field, const std::string &name)
void setVersion(const std::string &beginString)
void addFieldValue(int field, const std::string &value)
void addMsgType(const std::string &msgType)
void addFieldType(int field, FIX::TYPE::Type type)
void addRequiredField(const std::string &msgType, int field)
void FIX::DataDictionary::readFromStream ( std::istream &  stream)
throw (ConfigError
)

Definition at line 221 of file DataDictionary.cpp.

223 {
224 #ifdef HAVE_LIBXML
225  DOMDocumentPtr pDoc = DOMDocumentPtr(new LIBXML_DOMDocument());
226 #elif _MSC_VER
227  DOMDocumentPtr pDoc = DOMDocumentPtr(new MSXML_DOMDocument());
228 #else
229  DOMDocumentPtr pDoc = DOMDocumentPtr(new LIBXML_DOMDocument());
230 #endif
231 
232  if(!pDoc->load(stream))
233  throw ConfigError("Could not parse data dictionary stream");
234 
235  readFromDocument( pDoc );
236 }
void readFromDocument(DOMDocumentPtr pDoc)
std::auto_ptr< DOMDocument > DOMDocumentPtr
Definition: DOMDocument.h:71
void FIX::DataDictionary::readFromURL ( const std::string &  url)
throw (ConfigError
)

Definition at line 197 of file DataDictionary.cpp.

199 {
200 #ifdef HAVE_LIBXML
201  DOMDocumentPtr pDoc = DOMDocumentPtr(new LIBXML_DOMDocument());
202 #elif _MSC_VER
203  DOMDocumentPtr pDoc = DOMDocumentPtr(new MSXML_DOMDocument());
204 #else
205  DOMDocumentPtr pDoc = DOMDocumentPtr(new LIBXML_DOMDocument());
206 #endif
207 
208  if(!pDoc->load(url))
209  throw ConfigError(url + ": Could not parse data dictionary file");
210 
211  try
212  {
213  readFromDocument( pDoc );
214  }
215  catch( ConfigError& e )
216  {
217  throw ConfigError( url + ": " + e.what() );
218  }
219 }
void readFromDocument(DOMDocumentPtr pDoc)
std::auto_ptr< DOMDocument > DOMDocumentPtr
Definition: DOMDocument.h:71
void FIX::DataDictionary::readLibXml ( const std::string &  )
private

Read XML file using libXML.

void FIX::DataDictionary::readMSXML ( const std::string &  )
private
void FIX::DataDictionary::readMSXMLDOM ( const std::string &  )
private

Read XML file using MSXML.

void FIX::DataDictionary::setVersion ( const std::string &  beginString)
inline

Definition at line 86 of file DataDictionary.h.

References m_beginString, and m_hasVersion.

Referenced by addGroup().

87  {
88  m_beginString = beginString;
89  m_hasVersion = true;
90  }
BeginString m_beginString
bool FIX::DataDictionary::shouldCheckTag ( const FieldBase field) const
inlineprivate

If we need to check for the tag in the dictionary.

Definition at line 331 of file DataDictionary.h.

References FIX::FieldBase::getField(), m_checkUserDefinedFields, and FIX::FIELD::UserMin.

Referenced by iterate().

332  {
333  if( !m_checkUserDefinedFields && field.getField() >= FIELD::UserMin )
334  return false;
335  else
336  return true;
337  }
const int UserMin
Definition: FieldNumbers.h:40
void FIX::DataDictionary::validate ( const Message message,
const DataDictionary *const  pSessionDD,
const DataDictionary *const  pAppID 
)
throw (FIX::Exception
)
static

Validate a message.

Definition at line 123 of file DataDictionary.cpp.

References FIX::FIELD::BeginString, FIELD_GET_REF, and FIX::FIELD::MsgType.

Referenced by FIX::Session::next(), and validate().

127 {
128  const Header& header = message.getHeader();
129  const BeginString& beginString = FIELD_GET_REF( header, BeginString );
130  const MsgType& msgType = FIELD_GET_REF( header, MsgType );
131  if ( pSessionDD != 0 && pSessionDD->m_hasVersion )
132  {
133  if( pSessionDD->getVersion() != beginString )
134  {
135  throw UnsupportedVersion();
136  }
137  }
138 
139  int field = 0;
140  if( (pSessionDD !=0 && pSessionDD->m_checkFieldsOutOfOrder) ||
141  (pAppDD != 0 && pAppDD->m_checkFieldsOutOfOrder) )
142  {
143  if ( !message.hasValidStructure(field) )
144  throw TagOutOfOrder(field);
145  }
146 
147  if ( pAppDD != 0 && pAppDD->m_hasVersion )
148  {
149  pAppDD->checkMsgType( msgType );
150  pAppDD->checkHasRequired( message.getHeader(), message, message.getTrailer(), msgType );
151  }
152 
153  if( pSessionDD != 0 )
154  {
155  pSessionDD->iterate( message.getHeader(), msgType );
156  pSessionDD->iterate( message.getTrailer(), msgType );
157  }
158 
159  if( pAppDD != 0 )
160  {
161  pAppDD->iterate( message, msgType );
162  }
163 }
const int BeginString
#define FIELD_GET_REF(MAP, FLD)
Definition: FieldMap.h:236
const int MsgType
void FIX::DataDictionary::validate ( const Message message) const
throw (FIX::Exception
)
inline

Definition at line 312 of file DataDictionary.h.

References validate().

313  { validate( message, false ); }
static void validate(const Message &message, const DataDictionary *const pSessionDD, const DataDictionary *const pAppID)
Validate a message.
void FIX::DataDictionary::validate ( const Message message,
bool  bodyOnly 
) const
throw (FIX::Exception
)
inline

Definition at line 314 of file DataDictionary.h.

References validate().

315  { validate( message, bodyOnly ? (DataDictionary*)0 : this, this ); }
static void validate(const Message &message, const DataDictionary *const pSessionDD, const DataDictionary *const pAppID)
Validate a message.
TYPE::Type FIX::DataDictionary::XMLTypeToType ( const std::string &  xmlType) const
private

Definition at line 601 of file DataDictionary.cpp.

References FIX::TYPE::Amt, FIX::TYPE::Boolean, FIX::TYPE::Char, FIX::TYPE::Country, FIX::TYPE::Currency, FIX::TYPE::Data, FIX::TYPE::DayOfMonth, FIX::TYPE::Exchange, FIX::TYPE::Float, FIX::TYPE::Int, FIX::TYPE::Length, FIX::TYPE::LocalMktDate, m_beginString, FIX::TYPE::MonthYear, FIX::TYPE::MultipleCharValue, FIX::TYPE::MultipleStringValue, FIX::TYPE::MultipleValueString, FIX::TYPE::NumInGroup, FIX::TYPE::Percentage, FIX::TYPE::Price, FIX::TYPE::PriceOffset, FIX::TYPE::Qty, FIX::TYPE::SeqNum, FIX::TYPE::String, FIX::TYPE::Unknown, FIX::TYPE::UtcDate, FIX::TYPE::UtcDateOnly, FIX::TYPE::UtcTimeOnly, and FIX::TYPE::UtcTimeStamp.

602 {
603  if ( m_beginString < "FIX.4.2" && type == "CHAR" )
604  return TYPE::String;
605 
606  if ( type == "STRING" ) return TYPE::String;
607  if ( type == "CHAR" ) return TYPE::Char;
608  if ( type == "PRICE" ) return TYPE::Price;
609  if ( type == "INT" ) return TYPE::Int;
610  if ( type == "AMT" ) return TYPE::Amt;
611  if ( type == "QTY" ) return TYPE::Qty;
612  if ( type == "CURRENCY" ) return TYPE::Currency;
613  if ( type == "MULTIPLEVALUESTRING" ) return TYPE::MultipleValueString;
614  if ( type == "MULTIPLESTRINGVALUE" ) return TYPE::MultipleStringValue;
615  if ( type == "MULTIPLECHARVALUE" ) return TYPE::MultipleCharValue;
616  if ( type == "EXCHANGE" ) return TYPE::Exchange;
617  if ( type == "UTCTIMESTAMP" ) return TYPE::UtcTimeStamp;
618  if ( type == "BOOLEAN" ) return TYPE::Boolean;
619  if ( type == "LOCALMKTDATE" ) return TYPE::LocalMktDate;
620  if ( type == "DATA" ) return TYPE::Data;
621  if ( type == "FLOAT" ) return TYPE::Float;
622  if ( type == "PRICEOFFSET" ) return TYPE::PriceOffset;
623  if ( type == "MONTHYEAR" ) return TYPE::MonthYear;
624  if ( type == "DAYOFMONTH" ) return TYPE::DayOfMonth;
625  if ( type == "UTCDATE" ) return TYPE::UtcDate;
626  if ( type == "UTCDATEONLY" ) return TYPE::UtcDateOnly;
627  if ( type == "UTCTIMEONLY" ) return TYPE::UtcTimeOnly;
628  if ( type == "NUMINGROUP" ) return TYPE::NumInGroup;
629  if ( type == "PERCENTAGE" ) return TYPE::Percentage;
630  if ( type == "SEQNUM" ) return TYPE::SeqNum;
631  if ( type == "LENGTH" ) return TYPE::Length;
632  if ( type == "COUNTRY" ) return TYPE::Country;
633  if ( type == "TIME" ) return TYPE::UtcTimeStamp;
634  return TYPE::Unknown;
635 }
BeginString m_beginString

Member Data Documentation

BeginString FIX::DataDictionary::m_beginString
private

Definition at line 526 of file DataDictionary.h.

Referenced by getVersion(), iterate(), operator=(), setVersion(), and XMLTypeToType().

bool FIX::DataDictionary::m_checkFieldsHaveValues
private

Definition at line 524 of file DataDictionary.h.

Referenced by checkFieldsHaveValues(), checkHasValue(), and operator=().

bool FIX::DataDictionary::m_checkFieldsOutOfOrder
private

Definition at line 523 of file DataDictionary.h.

Referenced by checkFieldsOutOfOrder(), and operator=().

bool FIX::DataDictionary::m_checkUserDefinedFields
private

Definition at line 525 of file DataDictionary.h.

Referenced by checkUserDefinedFields(), operator=(), and shouldCheckTag().

MsgFields FIX::DataDictionary::m_dataFields
private

Definition at line 541 of file DataDictionary.h.

Referenced by addFieldType(), isDataField(), and operator=().

FieldToName FIX::DataDictionary::m_fieldNames
private

Definition at line 537 of file DataDictionary.h.

Referenced by addFieldName(), getFieldName(), and operator=().

Fields FIX::DataDictionary::m_fields
private

Definition at line 530 of file DataDictionary.h.

Referenced by addField(), checkValidTagNumber(), isField(), and operator=().

FieldTypes FIX::DataDictionary::m_fieldTypes
private

Definition at line 535 of file DataDictionary.h.

Referenced by addFieldType(), getFieldType(), isMultipleValueField(), and operator=().

FieldToValue FIX::DataDictionary::m_fieldValues
private

Definition at line 536 of file DataDictionary.h.

Referenced by addFieldValue(), hasFieldValue(), isFieldValue(), and operator=().

FieldToGroup FIX::DataDictionary::m_groups
private

Definition at line 540 of file DataDictionary.h.

Referenced by addGroup(), getGroup(), isGroup(), operator=(), and ~DataDictionary().

bool FIX::DataDictionary::m_hasVersion
private

Definition at line 522 of file DataDictionary.h.

Referenced by iterate(), operator=(), and setVersion().

NonBodyFields FIX::DataDictionary::m_headerFields
private

Definition at line 533 of file DataDictionary.h.

Referenced by addHeaderField(), checkHasRequired(), isHeaderField(), and operator=().

MsgTypeToField FIX::DataDictionary::m_messageFields
private

Definition at line 527 of file DataDictionary.h.

Referenced by addMsgField(), isMsgField(), and operator=().

MsgTypes FIX::DataDictionary::m_messages
private

Definition at line 529 of file DataDictionary.h.

Referenced by addMsgType(), isMsgType(), and operator=().

NameToField FIX::DataDictionary::m_names
private

Definition at line 538 of file DataDictionary.h.

Referenced by addFieldName(), getFieldTag(), and operator=().

OrderedFields FIX::DataDictionary::m_orderedFields
private

Definition at line 531 of file DataDictionary.h.

Referenced by addField(), getOrderedFields(), and operator=().

OrderedFieldsArray FIX::DataDictionary::m_orderedFieldsArray
mutableprivate

Definition at line 532 of file DataDictionary.h.

Referenced by getOrderedFields(), and operator=().

MsgTypeToField FIX::DataDictionary::m_requiredFields
private

Definition at line 528 of file DataDictionary.h.

Referenced by addRequiredField(), checkHasRequired(), isRequiredField(), and operator=().

NonBodyFields FIX::DataDictionary::m_trailerFields
private

Definition at line 534 of file DataDictionary.h.

Referenced by addTrailerField(), checkHasRequired(), isTrailerField(), and operator=().

ValueToName FIX::DataDictionary::m_valueNames
private

Definition at line 539 of file DataDictionary.h.

Referenced by addValueName(), getValueName(), and operator=().


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

Generated on Sat Mar 29 2014 15:13:33 for QuickFIX by doxygen 1.8.5 written by Dimitri van Heesch, © 1997-2001