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

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

#include <FieldMap.h>

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

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. More...
 
void setField (int field, const std::string &value) throw ( RepeatedTag, NoTagValue )
 Set a field without a field class. More...
 
bool getFieldIfSet (FieldBase &field) const
 Get a field if set. More...
 
FieldBasegetField (FieldBase &field) const throw ( FieldNotFound )
 Get a field without type checking. More...
 
const std::string & getField (int field) const throw ( FieldNotFound )
 Get a field without a field class. More...
 
const FieldBasegetFieldRef (int field) const throw ( FieldNotFound )
 Get direct access to a field through a reference. More...
 
const FieldBase *const getFieldPtr (int field) const throw ( FieldNotFound )
 Get direct access to a field through a pointer. More...
 
bool isSetField (const FieldBase &field) const
 Check to see if a field is set. More...
 
bool isSetField (int field) const
 Check to see if a field is set by referencing its number. More...
 
void removeField (int field)
 Remove a field. If field is not present, this is a no-op. More...
 
void addGroup (int field, const FieldMap &group, bool setCount=true)
 Add a group. More...
 
void addGroupPtr (int field, FieldMap *group, bool setCount=true)
 Acquire ownership of Group object. More...
 
void replaceGroup (int num, int field, const FieldMap &group)
 Replace a specific instance of a group. More...
 
FieldMapgetGroup (int num, int field, FieldMap &group) const throw ( FieldNotFound )
 Get a specific instance of a group. More...
 
FieldMapgetGroupRef (int num, int field) const throw ( FieldNotFound )
 Get direct access to a field through a reference. More...
 
FieldMapgetGroupPtr (int num, int field) const throw ( FieldNotFound )
 Get direct access to a field through a pointer. More...
 
void removeGroup (int num, int field)
 Remove a specific instance of a group. More...
 
void removeGroup (int field)
 Remove all instances of a group. More...
 
bool hasGroup (int field) const
 Check to see any instance of a group exists. More...
 
bool hasGroup (int num, int field) const
 Check to see if a specific instance of a group exists. More...
 
int groupCount (int field) const
 Count the number of instance of a group. More...
 
void clear ()
 Clear all fields from the map. More...
 
bool isEmpty ()
 Check if map contains any fields. More...
 
int totalFields () const
 
std::string & calculateString (std::string &, bool clear=true) 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

FIX::FieldMap::FieldMap ( const message_order order = message_ordermessage_order::normal ))
inline

Definition at line 64 of file FieldMap.h.

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

66  : m_fields( order ) {}
Fields m_fields
Definition: FieldMap.h:220
FIX::FieldMap::FieldMap ( const int  order[])
inline

Definition at line 68 of file FieldMap.h.

69  : m_fields( message_order(order) ) {}
Fields m_fields
Definition: FieldMap.h:220
FIX::FieldMap::FieldMap ( const FieldMap copy)
inline

Definition at line 71 of file FieldMap.h.

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

Definition at line 33 of file FieldMap.cpp.

References clear().

34 {
35  clear();
36 }
void clear()
Clear all fields from the map.
Definition: FieldMap.cpp:143

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().

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

59 {
60  FieldMap * pGroup = new FieldMap( group );
61 
62  addGroupPtr( field, pGroup, setCount );
63 }
void addGroupPtr(int field, FieldMap *group, bool setCount=true)
Acquire ownership of Group object.
Definition: FieldMap.cpp:65
FieldMap(const message_order &order=message_order(message_order::normal))
Definition: FieldMap.h:64
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().

66 {
67  if( group == 0 )
68  return;
69 
70  std::vector< FieldMap* >& vec = m_groups[ field ];
71  vec.push_back( group );
72 
73  if( setCount )
74  setField( IntField( field, vec.size() ) );
75 }
Groups m_groups
Definition: FieldMap.h:221
void setField(const FieldBase &field, bool overwrite=true)
Set a field without type checking.
Definition: FieldMap.h:79
iterator FIX::FieldMap::begin ( ) const
inline

Definition at line 214 of file FieldMap.h.

References m_fields.

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

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

Definition at line 203 of file FieldMap.cpp.

References m_fields, and m_groups.

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

206 {
207  int result = 0;
208  Fields::const_iterator i;
209  for ( i = m_fields.begin(); i != m_fields.end(); ++i )
210  {
211  if ( i->first != beginStringField
212  && i->first != bodyLengthField
213  && i->first != checkSumField )
214  { result += i->second.getLength(); }
215  }
216 
217  Groups::const_iterator j;
218  for ( j = m_groups.begin(); j != m_groups.end(); ++j )
219  {
220  std::vector < FieldMap* > ::const_iterator k;
221  for ( k = j->second.begin(); k != j->second.end(); ++k )
222  result += ( *k ) ->calculateLength();
223  }
224  return result;
225 }
Fields m_fields
Definition: FieldMap.h:220
Groups m_groups
Definition: FieldMap.h:221
iterator const_iterator
Definition: FieldMap.h:60
std::string & FIX::FieldMap::calculateString ( std::string &  result,
bool  clear = true 
) const

Definition at line 176 of file FieldMap.cpp.

References m_fields, m_groups, and totalFields().

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

177 {
178 #if defined(_MSC_VER) && _MSC_VER < 1300
179  if( clear ) result = "";
180 #else
181  if( clear ) result.clear();
182 #endif
183 
184  if( !result.size() )
185  result.reserve( totalFields() * 32 );
186 
187  Fields::const_iterator i;
188  for ( i = m_fields.begin(); i != m_fields.end(); ++i )
189  {
190  result += i->second.getFixString();
191 
192  // add groups if they exist
193  if( !m_groups.size() ) continue;
194  Groups::const_iterator j = m_groups.find( i->first );
195  if ( j == m_groups.end() ) continue;
196  std::vector < FieldMap* > ::const_iterator k;
197  for ( k = j->second.begin(); k != j->second.end(); ++k )
198  ( *k ) ->calculateString( result, false );
199  }
200  return result;
201 }
int totalFields() const
Definition: FieldMap.cpp:162
Fields m_fields
Definition: FieldMap.h:220
Groups m_groups
Definition: FieldMap.h:221
iterator const_iterator
Definition: FieldMap.h:60
void clear()
Clear all fields from the map.
Definition: FieldMap.cpp:143
int FIX::FieldMap::calculateTotal ( int  checkSumField = FIELD::CheckSum) const

Definition at line 227 of file FieldMap.cpp.

References m_fields, and m_groups.

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

228 {
229  int result = 0;
230  Fields::const_iterator i;
231  for ( i = m_fields.begin(); i != m_fields.end(); ++i )
232  {
233  if ( i->first != checkSumField )
234  result += i->second.getTotal();
235  }
236 
237  Groups::const_iterator j;
238  for ( j = m_groups.begin(); j != m_groups.end(); ++j )
239  {
240  std::vector < FieldMap* > ::const_iterator k;
241  for ( k = j->second.begin(); k != j->second.end(); ++k )
242  result += ( *k ) ->calculateTotal();
243  }
244  return result;
245 }
Fields m_fields
Definition: FieldMap.h:220
Groups m_groups
Definition: FieldMap.h:221
iterator const_iterator
Definition: FieldMap.h:60
void FIX::FieldMap::clear ( )

Clear all fields from the map.

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().

144 {
145  m_fields.clear();
146 
147  Groups::iterator i;
148  for ( i = m_groups.begin(); i != m_groups.end(); ++i )
149  {
150  std::vector < FieldMap* > ::iterator j;
151  for ( j = i->second.begin(); j != i->second.end(); ++j )
152  delete *j;
153  }
154  m_groups.clear();
155 }
Fields::const_iterator iterator
Definition: FieldMap.h:59
Fields m_fields
Definition: FieldMap.h:220
Groups m_groups
Definition: FieldMap.h:221
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().

215 { return m_fields.end(); }
Fields m_fields
Definition: FieldMap.h:220
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().

216 { return m_groups.begin(); }
Groups m_groups
Definition: FieldMap.h:221
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().

217 { return m_groups.end(); }
Groups m_groups
Definition: FieldMap.h:221
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().

122  {
123  return getFieldRef( field ).getString();
124  }
const std::string & getString() const
Get the string representation of the fields value.
Definition: Field.h:73
const FieldBase & getFieldRef(int field) const
Get direct access to a field through a reference.
Definition: FieldMap.h:127
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().

103  {
104  Fields::const_iterator iter = m_fields.find( field.getField() );
105  if ( iter == m_fields.end() )
106  return false;
107  field = iter->second;
108  return true;
109  }
Fields m_fields
Definition: FieldMap.h:220
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().

139  {
140  return &getFieldRef( field );
141  }
const FieldBase & getFieldRef(int field) const
Get direct access to a field through a reference.
Definition: FieldMap.h:127
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().

129  {
130  Fields::const_iterator iter = m_fields.find( field );
131  if ( iter == m_fields.end() )
132  throw FieldNotFound( field );
133  return iter->second;
134  }
Fields m_fields
Definition: FieldMap.h:220
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(), and FIX::Message::getGroup().

165  {
166  return group = getGroupRef( num, field );
167  }
FieldMap & getGroupRef(int num, int field) const
Get direct access to a field through a reference.
Definition: FieldMap.h:170
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().

183  {
184  return &getGroupRef( num, field );
185  }
FieldMap & getGroupRef(int num, int field) const
Get direct access to a field through a reference.
Definition: FieldMap.h:170
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().

172  {
173  Groups::const_iterator i = m_groups.find( field );
174  if( i == m_groups.end() ) throw FieldNotFound( field );
175  if( num <= 0 ) throw FieldNotFound( field );
176  if( i->second.size() < (unsigned)num ) throw FieldNotFound( field );
177  return *( *(i->second.begin() + (num-1) ) );
178  }
Groups m_groups
Definition: FieldMap.h:221
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().

136 {
137  Groups::const_iterator i = m_groups.find( field );
138  if( i == m_groups.end() )
139  return 0;
140  return i->second.size();
141 }
Groups m_groups
Definition: FieldMap.h:221
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.

Referenced by FIX::Group::hasGroup(), and FIX::Message::hasGroup().

130 {
131  Groups::const_iterator i = m_groups.find( field );
132  return i != m_groups.end();
133 }
Groups m_groups
Definition: FieldMap.h:221
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().

125 {
126  return groupCount(field) >= num;
127 }
int groupCount(int field) const
Count the number of instance of a group.
Definition: FieldMap.cpp:135
bool FIX::FieldMap::isEmpty ( )

Check if map contains any fields.

Definition at line 157 of file FieldMap.cpp.

References m_fields.

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

158 {
159  return m_fields.size() == 0;
160 }
Fields m_fields
Definition: FieldMap.h:220
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().

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

145  { return isSetField( field.getField() ); }
bool isSetField(const FieldBase &field) const
Check to see if a field is set.
Definition: FieldMap.h:144
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.

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

Definition at line 38 of file FieldMap.cpp.

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

39 {
40  clear();
41 
42  m_fields = rhs.m_fields;
43 
44  Groups::const_iterator i;
45  for ( i = rhs.m_groups.begin(); i != rhs.m_groups.end(); ++i )
46  {
47  std::vector < FieldMap* > ::const_iterator j;
48  for ( j = i->second.begin(); j != i->second.end(); ++j )
49  {
50  FieldMap * pGroup = new FieldMap( **j );
51  m_groups[ i->first ].push_back( pGroup );
52  }
53  }
54 
55  return *this;
56 }
Fields m_fields
Definition: FieldMap.h:220
Groups m_groups
Definition: FieldMap.h:221
iterator const_iterator
Definition: FieldMap.h:60
FieldMap(const message_order &order=message_order(message_order::normal))
Definition: FieldMap.h:64
void clear()
Clear all fields from the map.
Definition: FieldMap.cpp:143
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().

118 {
119  Fields::iterator i = m_fields.find( field );
120  if ( i != m_fields.end() )
121  m_fields.erase( i );
122 }
Fields m_fields
Definition: FieldMap.h:220
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 FIX::Group::removeGroup(), FIX::Message::removeGroup(), and removeGroup().

87 {
88  Groups::iterator i = m_groups.find( field );
89  if ( i == m_groups.end() ) return;
90  if ( num <= 0 ) return;
91  std::vector< FieldMap* >& vector = i->second;
92  if ( vector.size() < ( unsigned ) num ) return;
93 
94  std::vector< FieldMap* >::iterator iter = vector.begin();
95  std::advance( iter, ( num - 1 ) );
96 
97  delete (*iter);
98  vector.erase( iter );
99 
100  if( vector.size() == 0 )
101  {
102  m_groups.erase( field );
103  removeField( field );
104  }
105  else
106  {
107  IntField groupCount( field, vector.size() );
108  setField( groupCount, true );
109  }
110 }
int groupCount(int field) const
Count the number of instance of a group.
Definition: FieldMap.cpp:135
Groups m_groups
Definition: FieldMap.h:221
void setField(const FieldBase &field, bool overwrite=true)
Set a field without type checking.
Definition: FieldMap.h:79
void removeField(int field)
Remove a field. If field is not present, this is a no-op.
Definition: FieldMap.cpp:117
void FIX::FieldMap::removeGroup ( int  field)

Remove all instances of a group.

Definition at line 112 of file FieldMap.cpp.

References groupCount(), and removeGroup().

113 {
114  removeGroup( groupCount(field), field );
115 }
int groupCount(int field) const
Count the number of instance of a group.
Definition: FieldMap.cpp:135
void removeGroup(int num, int field)
Remove a specific instance of a group.
Definition: FieldMap.cpp:86
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.

Referenced by FIX::Group::replaceGroup(), and FIX::Message::replaceGroup().

78 {
79  Groups::const_iterator i = m_groups.find( field );
80  if ( i == m_groups.end() ) return;
81  if ( num <= 0 ) return;
82  if ( i->second.size() < ( unsigned ) num ) return;
83  *( *( i->second.begin() + ( num - 1 ) ) ) = group;
84 }
Groups m_groups
Definition: FieldMap.h:221
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().

96  {
97  FieldBase fieldBase( field, value );
98  setField( fieldBase );
99  }
void setField(const FieldBase &field, bool overwrite=true)
Set a field without type checking.
Definition: FieldMap.h:79
int FIX::FieldMap::totalFields ( ) const

Definition at line 162 of file FieldMap.cpp.

References m_fields, and m_groups.

Referenced by calculateString().

163 {
164  int result = m_fields.size();
165 
166  Groups::const_iterator i;
167  for ( i = m_groups.begin(); i != m_groups.end(); ++i )
168  {
169  std::vector < FieldMap* > ::const_iterator j;
170  for ( j = i->second.begin(); j != i->second.end(); ++j )
171  result += ( *j ) ->totalFields();
172  }
173  return result;
174 }
Fields m_fields
Definition: FieldMap.h:220
Groups m_groups
Definition: FieldMap.h:221
iterator const_iterator
Definition: FieldMap.h:60

Member Data Documentation

Fields FIX::FieldMap::m_fields
private
Groups FIX::FieldMap::m_groups
private

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

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