Public Types | Public Member Functions | Private Attributes
FIX::FieldMap Class Reference

Stores and organizes a collection of Fields. More...

#include <FieldMap.h>

Inheritance diagram for FIX::FieldMap:
Inheritance graph
[legend]

List of all members.

Public Types

typedef std::multimap< int,
FieldBase, message_order,
ALLOCATOR< std::pair< const
int, FieldBase > > > 
Fields
typedef std::map< int,
std::vector< FieldMap * >
, std::less< int >, ALLOCATOR
< std::pair< const int,
std::vector< FieldMap * > > > > 
Groups
typedef Fields::const_iterator iterator
typedef iterator const_iterator
typedef Groups::const_iterator g_iterator
typedef Groups::const_iterator g_const_iterator

Public Member Functions

 FieldMap (const message_order &order=message_order(message_order::normal))
 FieldMap (const int order[])
 FieldMap (const FieldMap &copy)
virtual ~FieldMap ()
FieldMapoperator= (const FieldMap &rhs)
void setField (const FieldBase &field, bool overwrite=true) throw ( RepeatedTag )
 Set a field without type checking.
void setField (int field, const std::string &value) throw ( RepeatedTag, NoTagValue )
 Set a field without a field class.
bool getFieldIfSet (FieldBase &field) const
 Get a field if set.
FieldBasegetField (FieldBase &field) const throw ( FieldNotFound )
 Get a field without type checking.
const std::string & getField (int field) const throw ( FieldNotFound )
 Get a field without a field class.
const FieldBasegetFieldRef (int field) const throw ( FieldNotFound )
 Get direct access to a field through a reference.
const FieldBase *const getFieldPtr (int field) const throw ( FieldNotFound )
 Get direct access to a field through a pointer.
bool isSetField (const FieldBase &field) const
 Check to see if a field is set.
bool isSetField (int field) const
 Check to see if a field is set by referencing its number.
void removeField (int field)
 Remove a field. If field is not present, this is a no-op.
void addGroup (int field, const FieldMap &group, bool setCount=true)
 Add a group.
void addGroupPtr (int field, FieldMap *group, bool setCount=true)
 Acquire ownership of Group object.
void replaceGroup (int num, int field, const FieldMap &group)
 Replace a specific instance of a group.
FieldMapgetGroup (int num, int field, FieldMap &group) const throw ( FieldNotFound )
 Get a specific instance of a group.
FieldMapgetGroupRef (int num, int field) const throw ( FieldNotFound )
 Get direct access to a field through a reference.
FieldMapgetGroupPtr (int num, int field) const throw ( FieldNotFound )
 Get direct access to a field through a pointer.
void removeGroup (int num, int field)
 Remove a specific instance of a group.
void removeGroup (int field)
 Remove all instances of a group.
bool hasGroup (int field) const
 Check to see any instance of a group exists.
bool hasGroup (int num, int field) const
 Check to see if a specific instance of a group exists.
int groupCount (int field) const
 Count the number of instance of a group.
void clear ()
 Clear all fields from the map.
bool isEmpty ()
 Check if map contains any fields.
int totalFields () const
std::string & calculateString (std::string &) const
int calculateLength (int beginStringField=FIELD::BeginString, int bodyLengthField=FIELD::BodyLength, int checkSumField=FIELD::CheckSum) const
int calculateTotal (int checkSumField=FIELD::CheckSum) const
iterator begin () const
iterator end () const
g_iterator g_begin () const
g_iterator g_end () const

Private Attributes

Fields m_fields
Groups m_groups

Detailed Description

Stores and organizes a collection of Fields.

This is the basis for a message, header, and trailer. This collection class uses a sorter to keep the fields in a particular order.

Definition at line 46 of file FieldMap.h.


Member Typedef Documentation

Definition at line 60 of file FieldMap.h.

typedef std::multimap< int, FieldBase, message_order, ALLOCATOR<std::pair<const int,FieldBase> > > FIX::FieldMap::Fields

Definition at line 54 of file FieldMap.h.

typedef Groups::const_iterator FIX::FieldMap::g_const_iterator

Definition at line 62 of file FieldMap.h.

typedef Groups::const_iterator FIX::FieldMap::g_iterator

Definition at line 61 of file FieldMap.h.

typedef std::map< int, std::vector < FieldMap* >, std::less<int>, ALLOCATOR<std::pair<const int, std::vector< FieldMap* > > > > FIX::FieldMap::Groups

Definition at line 56 of file FieldMap.h.

typedef Fields::const_iterator FIX::FieldMap::iterator

Definition at line 59 of file FieldMap.h.


Constructor & Destructor Documentation

Definition at line 64 of file FieldMap.h.

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

  : m_fields( order ) {}
FIX::FieldMap::FieldMap ( const int  order[]) [inline]

Definition at line 68 of file FieldMap.h.

  : m_fields( message_order(order) ) {}
FIX::FieldMap::FieldMap ( const FieldMap copy) [inline]

Definition at line 71 of file FieldMap.h.

  { *this = copy; }
FIX::FieldMap::~FieldMap ( ) [virtual]

Definition at line 33 of file FieldMap.cpp.

References clear().

{
  clear();
}

Member Function Documentation

void FIX::FieldMap::addGroup ( int  field,
const FieldMap group,
bool  setCount = true 
)

Add a group.

Definition at line 58 of file FieldMap.cpp.

References addGroupPtr(), and FieldMap().

{
  FieldMap * pGroup = new FieldMap( group );

  addGroupPtr( field, pGroup, setCount );
}
void FIX::FieldMap::addGroupPtr ( int  field,
FieldMap group,
bool  setCount = true 
)

Acquire ownership of Group object.

Definition at line 65 of file FieldMap.cpp.

References m_groups, and setField().

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

{
    if( group == 0 )
        return;

    std::vector< FieldMap* >& vec = m_groups[ field ];
    vec.push_back( group );

    if( setCount )
        setField( IntField( field, vec.size() ) );
}
iterator FIX::FieldMap::begin ( ) const [inline]

Definition at line 214 of file FieldMap.h.

References m_fields.

Referenced by FIX::Message::extractField(), FIX::DataDictionary::iterate(), and FIX::Message::toXMLFields().

{ return m_fields.begin(); }
int FIX::FieldMap::calculateLength ( int  beginStringField = FIELD::BeginString,
int  bodyLengthField = FIELD::BodyLength,
int  checkSumField = FIELD::CheckSum 
) const

Definition at line 194 of file FieldMap.cpp.

References m_fields, and m_groups.

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

{
  int result = 0;
  Fields::const_iterator i;
  for ( i = m_fields.begin(); i != m_fields.end(); ++i )
  {
    if ( i->first != beginStringField
         && i->first != bodyLengthField
         && i->first != checkSumField )
    { result += i->second.getLength(); }
  }

  Groups::const_iterator j;
  for ( j = m_groups.begin(); j != m_groups.end(); ++j )
  {
    std::vector < FieldMap* > ::const_iterator k;
    for ( k = j->second.begin(); k != j->second.end(); ++k )
      result += ( *k ) ->calculateLength();
  }
  return result;
}
std::string & FIX::FieldMap::calculateString ( std::string &  result) const

Definition at line 176 of file FieldMap.cpp.

References m_fields, and m_groups.

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

{  
  Fields::const_iterator i;
  for ( i = m_fields.begin(); i != m_fields.end(); ++i )
  {
    result += i->second.getFixString();

    // add groups if they exist
    if( !m_groups.size() ) continue;
    Groups::const_iterator j = m_groups.find( i->first );
    if ( j == m_groups.end() ) continue;
    std::vector < FieldMap* > ::const_iterator k;
    for ( k = j->second.begin(); k != j->second.end(); ++k )
      ( *k ) ->calculateString( result );
  }
  return result;
}
int FIX::FieldMap::calculateTotal ( int  checkSumField = FIELD::CheckSum) const

Definition at line 218 of file FieldMap.cpp.

References m_fields, and m_groups.

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

{
  int result = 0;
  Fields::const_iterator i;
  for ( i = m_fields.begin(); i != m_fields.end(); ++i )
  {
    if ( i->first != checkSumField )
      result += i->second.getTotal();
  }

  Groups::const_iterator j;
  for ( j = m_groups.begin(); j != m_groups.end(); ++j )
  {
    std::vector < FieldMap* > ::const_iterator k;
    for ( k = j->second.begin(); k != j->second.end(); ++k )
      result += ( *k ) ->calculateTotal();
  }
  return result;
}

Clear all fields from the map.

Reimplemented in FIX::Message.

Definition at line 143 of file FieldMap.cpp.

References m_fields, and m_groups.

Referenced by FIX::Message::clear(), FIX::Message::getGroup(), operator=(), and ~FieldMap().

{
  m_fields.clear();

  Groups::iterator i;
  for ( i = m_groups.begin(); i != m_groups.end(); ++i )
  {
    std::vector < FieldMap* > ::iterator j;
    for ( j = i->second.begin(); j != i->second.end(); ++j )
      delete *j;
  }
  m_groups.clear();
}
iterator FIX::FieldMap::end ( ) const [inline]

Definition at line 215 of file FieldMap.h.

References m_fields.

Referenced by FIX::DataDictionary::iterate(), and FIX::Message::toXMLFields().

{ return m_fields.end(); }
g_iterator FIX::FieldMap::g_begin ( ) const [inline]

Definition at line 216 of file FieldMap.h.

References m_groups.

Referenced by FIX::DataDictionary::checkHasRequired(), and FIX::Message::toXMLFields().

{ return m_groups.begin(); }
g_iterator FIX::FieldMap::g_end ( ) const [inline]

Definition at line 217 of file FieldMap.h.

References m_groups.

Referenced by FIX::DataDictionary::checkHasRequired(), and FIX::Message::toXMLFields().

{ return m_groups.end(); }
FieldBase& FIX::FieldMap::getField ( FieldBase field) const throw ( FieldNotFound ) [inline]
const std::string& FIX::FieldMap::getField ( int  field) const throw ( FieldNotFound ) [inline]

Get a field without a field class.

Definition at line 120 of file FieldMap.h.

References getFieldRef(), and FIX::FieldBase::getString().

  {
    return getFieldRef( field ).getString();
  }
bool FIX::FieldMap::getFieldIfSet ( FieldBase field) const [inline]

Get a field if set.

Definition at line 102 of file FieldMap.h.

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

Referenced by FIX::MessageCracker::crack(), FIX::Session::doPossDup(), FIX::Session::doTargetTooLow(), FIX::Session::generateReject(), FIX::Session::next(), FIX::Session::nextLogon(), FIX::Session::nextResendRequest(), FIX::Session::nextSequenceReset(), FIX::Message::reverseRoute(), and FIX::Session::sendRaw().

  {
    Fields::const_iterator iter = m_fields.find( field.getField() );
    if ( iter == m_fields.end() )
      return false;
    field = iter->second;
    return true;
  }
const FieldBase* const FIX::FieldMap::getFieldPtr ( int  field) const throw ( FieldNotFound ) [inline]

Get direct access to a field through a pointer.

Definition at line 137 of file FieldMap.h.

References getFieldRef().

  {
    return &getFieldRef( field );
  }
const FieldBase& FIX::FieldMap::getFieldRef ( int  field) const throw ( FieldNotFound ) [inline]

Get direct access to a field through a reference.

Definition at line 127 of file FieldMap.h.

References m_fields.

Referenced by getField(), and getFieldPtr().

  {
    Fields::const_iterator iter = m_fields.find( field );
    if ( iter == m_fields.end() )
      throw FieldNotFound( field );
    return iter->second;
  }
FieldMap& FIX::FieldMap::getGroup ( int  num,
int  field,
FieldMap group 
) const throw ( FieldNotFound ) [inline]

Get a specific instance of a group.

Definition at line 163 of file FieldMap.h.

References getGroupRef().

Referenced by FIX::Group::getGroup().

  {
    return group = getGroupRef( num, field );
  }
FieldMap* FIX::FieldMap::getGroupPtr ( int  num,
int  field 
) const throw ( FieldNotFound ) [inline]

Get direct access to a field through a pointer.

Definition at line 181 of file FieldMap.h.

References getGroupRef().

  {
    return &getGroupRef( num, field );
  }
FieldMap& FIX::FieldMap::getGroupRef ( int  num,
int  field 
) const throw ( FieldNotFound ) [inline]

Get direct access to a field through a reference.

Definition at line 170 of file FieldMap.h.

References m_groups.

Referenced by getGroup(), and getGroupPtr().

  {
    Groups::const_iterator i = m_groups.find( field );
    if( i == m_groups.end() ) throw FieldNotFound( field );
    if( num <= 0 ) throw FieldNotFound( field );
    if( i->second.size() < (unsigned)num ) throw FieldNotFound( field );
    return *( *(i->second.begin() + (num-1) ) );
  }
int FIX::FieldMap::groupCount ( int  field) const

Count the number of instance of a group.

Definition at line 135 of file FieldMap.cpp.

References m_groups.

Referenced by FIX::DataDictionary::checkGroupCount(), hasGroup(), and removeGroup().

{
  Groups::const_iterator i = m_groups.find( field );
  if( i == m_groups.end() )
    return 0;
  return i->second.size();
}
bool FIX::FieldMap::hasGroup ( int  field) const

Check to see any instance of a group exists.

Definition at line 129 of file FieldMap.cpp.

References m_groups.

{
  Groups::const_iterator i = m_groups.find( field );
  return i != m_groups.end();
}
bool FIX::FieldMap::hasGroup ( int  num,
int  field 
) const

Check to see if a specific instance of a group exists.

Definition at line 124 of file FieldMap.cpp.

References groupCount().

{
  return groupCount(field) >= num;
}

Check if map contains any fields.

Reimplemented in FIX::Message.

Definition at line 157 of file FieldMap.cpp.

References m_fields.

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

{
  return m_fields.size() == 0;
}
bool FIX::FieldMap::isSetField ( const FieldBase field) const [inline]

Check to see if a field is set.

Definition at line 144 of file FieldMap.h.

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

Referenced by FIX::DataDictionary::checkHasRequired(), FIX::Message::extractField(), FIX::Message::isAdmin(), FIX::Message::isApp(), and isSetField().

  { return isSetField( field.getField() ); }
bool FIX::FieldMap::isSetField ( int  field) const [inline]

Check to see if a field is set by referencing its number.

Definition at line 147 of file FieldMap.h.

References m_fields.

  { return m_fields.find( field ) != m_fields.end(); }
FieldMap & FIX::FieldMap::operator= ( const FieldMap rhs)

Definition at line 38 of file FieldMap.cpp.

References clear(), FieldMap(), m_fields, and m_groups.

{
  clear();

  m_fields = rhs.m_fields;

  Groups::const_iterator i;
  for ( i = rhs.m_groups.begin(); i != rhs.m_groups.end(); ++i )
  {
    std::vector < FieldMap* > ::const_iterator j;
    for ( j = i->second.begin(); j != i->second.end(); ++j )
    {
        FieldMap * pGroup = new FieldMap( **j );
        m_groups[ i->first ].push_back( pGroup );
    }
  }

  return *this;
}
void FIX::FieldMap::removeField ( int  field)

Remove a field. If field is not present, this is a no-op.

Definition at line 117 of file FieldMap.cpp.

References m_fields.

Referenced by removeGroup(), FIX::Message::reverseRoute(), and FIX::Session::send().

{
  Fields::iterator i = m_fields.find( field );
  if ( i != m_fields.end() )
    m_fields.erase( i );
}
void FIX::FieldMap::removeGroup ( int  num,
int  field 
)

Remove a specific instance of a group.

Definition at line 86 of file FieldMap.cpp.

References groupCount(), m_groups, removeField(), and setField().

Referenced by removeGroup().

{
  Groups::iterator i = m_groups.find( field );
  if ( i == m_groups.end() ) return;
  if ( num <= 0 ) return;
  std::vector< FieldMap* >& vector = i->second;
  if ( vector.size() < ( unsigned ) num ) return;

  std::vector< FieldMap* >::iterator iter = vector.begin();
  std::advance( iter, ( num - 1 ) );

  delete (*iter);
  vector.erase( iter );

  if( vector.size() == 0 )
  {
    m_groups.erase( field );
    removeField( field );
  }
  else
  {
    IntField groupCount( field, vector.size() );
    setField( groupCount, true );
  }
}
void FIX::FieldMap::removeGroup ( int  field)

Remove all instances of a group.

Definition at line 112 of file FieldMap.cpp.

References groupCount(), and removeGroup().

{
  removeGroup( groupCount(field), field );
}
void FIX::FieldMap::replaceGroup ( int  num,
int  field,
const FieldMap group 
)

Replace a specific instance of a group.

Definition at line 77 of file FieldMap.cpp.

References m_groups.

{
  Groups::const_iterator i = m_groups.find( field );
  if ( i == m_groups.end() ) return;
  if ( num <= 0 ) return;
  if ( i->second.size() < ( unsigned ) num ) return;
  *( *( i->second.begin() + ( num - 1 ) ) ) = group;
}
void FIX::FieldMap::setField ( const FieldBase field,
bool  overwrite = true 
) throw ( RepeatedTag ) [inline]
void FIX::FieldMap::setField ( int  field,
const std::string &  value 
) throw ( RepeatedTag, NoTagValue ) [inline]

Set a field without a field class.

Definition at line 94 of file FieldMap.h.

References setField().

  {
    FieldBase fieldBase( field, value );
    setField( fieldBase );
  }

Definition at line 162 of file FieldMap.cpp.

References m_fields, and m_groups.

{
  int result = m_fields.size();
    
  Groups::const_iterator i;
  for ( i = m_groups.begin(); i != m_groups.end(); ++i )
  {
    std::vector < FieldMap* > ::const_iterator j;
    for ( j = i->second.begin(); j != i->second.end(); ++j )
      result += ( *j ) ->totalFields();
  }
  return result;
}

Member Data Documentation


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