![]() |
Stores and organizes a collection of Fields. More...
#include <FieldMap.h>
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 ©) | |
virtual | ~FieldMap () |
FieldMap & | operator= (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. | |
FieldBase & | getField (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 FieldBase & | getFieldRef (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 | replaceGroup (int num, int field, FieldMap &group) |
Replace a specific instanct of a group. | |
FieldMap & | getGroup (int num, int field, FieldMap &group) const throw ( FieldNotFound ) |
Get a specific instance of a group. | |
FieldMap & | getGroupRef (int num, int field) const throw ( FieldNotFound ) |
Get direct access to a field through a reference. | |
FieldMap * | getGroupPtr (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 &, 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 |
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 47 of file FieldMap.h.
Definition at line 61 of file FieldMap.h.
typedef std::multimap< int, FieldBase, message_order, ALLOCATOR<std::pair<const int,FieldBase> > > FIX::FieldMap::Fields |
Definition at line 55 of file FieldMap.h.
typedef Groups::const_iterator FIX::FieldMap::g_const_iterator |
Definition at line 63 of file FieldMap.h.
typedef Groups::const_iterator FIX::FieldMap::g_iterator |
Definition at line 62 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 57 of file FieldMap.h.
typedef Fields::const_iterator FIX::FieldMap::iterator |
Definition at line 60 of file FieldMap.h.
FIX::FieldMap::FieldMap | ( | const message_order & | order = message_order( message_order::normal ) |
) | [inline] |
FIX::FieldMap::FieldMap | ( | const int | order[] | ) | [inline] |
Definition at line 69 of file FieldMap.h.
00070 : m_fields( message_order(order) ) {}
FIX::FieldMap::FieldMap | ( | const FieldMap & | copy | ) | [inline] |
Definition at line 72 of file FieldMap.h.
FIX::FieldMap::~FieldMap | ( | ) | [virtual] |
Definition at line 33 of file FieldMap.cpp.
References clear(), QF_STACK_IGNORE_BEGIN, and QF_STACK_IGNORE_END.
00034 { QF_STACK_IGNORE_BEGIN 00035 clear(); 00036 QF_STACK_IGNORE_END 00037 }
void FIX::FieldMap::addGroup | ( | int | field, | |
const FieldMap & | group, | |||
bool | setCount = true | |||
) |
Add a group.
Definition at line 62 of file FieldMap.cpp.
References FieldMap(), m_fields, m_groups, QF_STACK_POP, QF_STACK_PUSH, and setField().
Referenced by operator=(), and FIX::Message::setGroup().
00063 { QF_STACK_PUSH(FieldMap::addGroup) 00064 00065 FieldMap * pGroup = new FieldMap( group.m_fields.key_comp() ); 00066 *pGroup = group; 00067 m_groups[ field ].push_back( pGroup ); 00068 Groups::iterator i = m_groups.find( field ); 00069 if( setCount ) 00070 setField( IntField( field, i->second.size() ) ); 00071 00072 QF_STACK_POP 00073 }
iterator FIX::FieldMap::begin | ( | ) | const [inline] |
Definition at line 205 of file FieldMap.h.
References m_fields.
Referenced by FIX::DataDictionary::iterate(), and FIX::Message::toXMLFields().
00205 { return m_fields.begin(); }
int FIX::FieldMap::calculateLength | ( | int | beginStringField = FIELD::BeginString , |
|
int | bodyLengthField = FIELD::BodyLength , |
|||
int | checkSumField = FIELD::CheckSum | |||
) | const |
Definition at line 231 of file FieldMap.cpp.
References m_fields, and m_groups.
Referenced by FIX::Message::bodyLength().
00234 { 00235 int result = 0; 00236 Fields::const_iterator i; 00237 for ( i = m_fields.begin(); i != m_fields.end(); ++i ) 00238 { 00239 if ( i->first != beginStringField 00240 && i->first != bodyLengthField 00241 && i->first != checkSumField ) 00242 { result += i->second.getLength(); } 00243 } 00244 00245 Groups::const_iterator j; 00246 for ( j = m_groups.begin(); j != m_groups.end(); ++j ) 00247 { 00248 std::vector < FieldMap* > ::const_iterator k; 00249 for ( k = j->second.begin(); k != j->second.end(); ++k ) 00250 result += ( *k ) ->calculateLength(); 00251 } 00252 return result; 00253 }
std::string & FIX::FieldMap::calculateString | ( | std::string & | result, | |
bool | clear = true | |||
) | const |
Definition at line 201 of file FieldMap.cpp.
References m_fields, m_groups, QF_STACK_POP, QF_STACK_PUSH, and totalFields().
Referenced by FIX::Message::toString().
00202 { QF_STACK_PUSH(FieldMap::calculateString) 00203 00204 #if defined(_MSC_VER) && _MSC_VER < 1300 00205 if( clear ) result = ""; 00206 #else 00207 if( clear ) result.clear(); 00208 #endif 00209 00210 if( !result.size() ) 00211 result.reserve( totalFields() * 32 ); 00212 00213 Fields::const_iterator i; 00214 for ( i = m_fields.begin(); i != m_fields.end(); ++i ) 00215 { 00216 result += i->second.getValue(); 00217 00218 // add groups if they exist 00219 if( !m_groups.size() ) continue; 00220 Groups::const_iterator j = m_groups.find( i->first ); 00221 if ( j == m_groups.end() ) continue; 00222 std::vector < FieldMap* > ::const_iterator k; 00223 for ( k = j->second.begin(); k != j->second.end(); ++k ) 00224 ( *k ) ->calculateString( result, false ); 00225 } 00226 return result; 00227 00228 QF_STACK_POP 00229 }
int FIX::FieldMap::calculateTotal | ( | int | checkSumField = FIELD::CheckSum |
) | const |
Definition at line 255 of file FieldMap.cpp.
References m_fields, m_groups, QF_STACK_POP, and QF_STACK_PUSH.
Referenced by FIX::Message::checkSum().
00256 { QF_STACK_PUSH(FieldMap::calculateTotal) 00257 00258 int result = 0; 00259 Fields::const_iterator i; 00260 for ( i = m_fields.begin(); i != m_fields.end(); ++i ) 00261 { 00262 if ( i->first != checkSumField ) 00263 result += i->second.getTotal(); 00264 } 00265 00266 Groups::const_iterator j; 00267 for ( j = m_groups.begin(); j != m_groups.end(); ++j ) 00268 { 00269 std::vector < FieldMap* > ::const_iterator k; 00270 for ( k = j->second.begin(); k != j->second.end(); ++k ) 00271 result += ( *k ) ->calculateTotal(); 00272 } 00273 return result; 00274 00275 QF_STACK_POP 00276 }
void FIX::FieldMap::clear | ( | ) |
Clear all fields from the map.
Reimplemented in FIX::Message.
Definition at line 164 of file FieldMap.cpp.
References m_fields, m_groups, QF_STACK_POP, and QF_STACK_PUSH.
Referenced by FIX::Message::clear(), FIX::Message::getGroup(), operator=(), and ~FieldMap().
00165 { QF_STACK_PUSH(FieldMap::clear) 00166 00167 m_fields.clear(); 00168 00169 Groups::iterator i; 00170 for ( i = m_groups.begin(); i != m_groups.end(); ++i ) 00171 { 00172 std::vector < FieldMap* > ::iterator j; 00173 for ( j = i->second.begin(); j != i->second.end(); ++j ) 00174 delete *j; 00175 } 00176 m_groups.clear(); 00177 00178 QF_STACK_POP 00179 }
iterator FIX::FieldMap::end | ( | ) | const [inline] |
Definition at line 206 of file FieldMap.h.
References m_fields.
Referenced by FIX::DataDictionary::iterate(), and FIX::Message::toXMLFields().
00206 { return m_fields.end(); }
g_iterator FIX::FieldMap::g_begin | ( | ) | const [inline] |
Definition at line 207 of file FieldMap.h.
References m_groups.
Referenced by FIX::DataDictionary::checkHasRequired(), and FIX::Message::toXMLFields().
00207 { return m_groups.begin(); }
g_iterator FIX::FieldMap::g_end | ( | ) | const [inline] |
Definition at line 208 of file FieldMap.h.
References m_groups.
Referenced by FIX::DataDictionary::checkHasRequired(), and FIX::Message::toXMLFields().
00208 { return m_groups.end(); }
const std::string& FIX::FieldMap::getField | ( | int | field | ) | const throw ( FieldNotFound ) [inline] |
Get a field without a field class.
Definition at line 114 of file FieldMap.h.
References getFieldRef(), and FIX::FieldBase::getString().
00116 { 00117 return getFieldRef( field ).getString(); 00118 }
FieldBase& FIX::FieldMap::getField | ( | FieldBase & | field | ) | const throw ( FieldNotFound ) [inline] |
Get a field without type checking.
Definition at line 103 of file FieldMap.h.
References m_fields.
Referenced by FIX::MessageCracker::crack(), FIX::Session::doPossDup(), FIX::Session::doTargetTooHigh(), FIX::Session::doTargetTooLow(), FIX::Message::extractField(), FIX::Session::generateBusinessReject(), FIX::Session::generateHeartbeat(), FIX::Session::generateLogon(), FIX::Session::generateReject(), FIX::Session::generateSequenceReset(), FIX::Acceptor::getSession(), FIX::Session::next(), FIX::Session::nextLogon(), FIX::Session::nextQueued(), FIX::Session::nextResendRequest(), FIX::Session::nextSequenceReset(), FIX::Session::populateRejectReason(), FIX::Session::resend(), FIX::Message::reverseRoute(), and FIX::Session::sendRaw().
const FieldBase* const FIX::FieldMap::getFieldPtr | ( | int | field | ) | const throw ( FieldNotFound ) [inline] |
Get direct access to a field through a pointer.
Definition at line 131 of file FieldMap.h.
References getFieldRef().
00133 { 00134 return &getFieldRef( field ); 00135 }
const FieldBase& FIX::FieldMap::getFieldRef | ( | int | field | ) | const throw ( FieldNotFound ) [inline] |
Get direct access to a field through a reference.
Definition at line 121 of file FieldMap.h.
References m_fields.
Referenced by getField(), and getFieldPtr().
FieldMap& FIX::FieldMap::getGroup | ( | int | num, | |
int | field, | |||
FieldMap & | group | |||
) | const throw ( FieldNotFound ) [inline] |
Get a specific instance of a group.
Definition at line 154 of file FieldMap.h.
References getGroupRef().
Referenced by FIX::Group::getGroup().
00156 { 00157 return group = getGroupRef( num, field ); 00158 }
FieldMap* FIX::FieldMap::getGroupPtr | ( | int | num, | |
int | field | |||
) | const throw ( FieldNotFound ) [inline] |
Get direct access to a field through a pointer.
Definition at line 172 of file FieldMap.h.
References getGroupRef().
00174 { 00175 return &getGroupRef( num, field ); 00176 }
FieldMap& FIX::FieldMap::getGroupRef | ( | int | num, | |
int | field | |||
) | const throw ( FieldNotFound ) [inline] |
Get direct access to a field through a reference.
Definition at line 161 of file FieldMap.h.
References m_groups.
Referenced by getGroup(), and getGroupPtr().
00163 { 00164 Groups::const_iterator i = m_groups.find( field ); 00165 if( i == m_groups.end() ) throw FieldNotFound( field ); 00166 if( num <= 0 ) throw FieldNotFound( field ); 00167 if( i->second.size() < (unsigned)num ) throw FieldNotFound( field ); 00168 return *( *(i->second.begin() + (num-1) ) ); 00169 }
int FIX::FieldMap::groupCount | ( | int | field | ) | const |
Count the number of instance of a group.
Definition at line 153 of file FieldMap.cpp.
References m_groups, QF_STACK_POP, and QF_STACK_PUSH.
Referenced by FIX::DataDictionary::checkGroupCount(), hasGroup(), and removeGroup().
00154 { QF_STACK_PUSH(FieldMap::groupCount) 00155 00156 Groups::const_iterator i = m_groups.find( field ); 00157 if( i == m_groups.end() ) 00158 return 0; 00159 return i->second.size(); 00160 00161 QF_STACK_POP 00162 }
bool FIX::FieldMap::hasGroup | ( | int | num, | |
int | field | |||
) | const |
Check to see if a specific instance of a group exists.
Definition at line 136 of file FieldMap.cpp.
References groupCount(), hasGroup(), QF_STACK_POP, and QF_STACK_PUSH.
00137 { QF_STACK_PUSH(FieldMap::hasGroup) 00138 00139 return groupCount(field) >= num; 00140 00141 QF_STACK_POP 00142 }
bool FIX::FieldMap::hasGroup | ( | int | field | ) | const |
Check to see any instance of a group exists.
Definition at line 144 of file FieldMap.cpp.
References m_groups, QF_STACK_POP, and QF_STACK_PUSH.
Referenced by hasGroup().
00145 { QF_STACK_PUSH(FieldMap::hasGroup) 00146 00147 Groups::const_iterator i = m_groups.find( field ); 00148 return i != m_groups.end(); 00149 00150 QF_STACK_POP 00151 }
bool FIX::FieldMap::isEmpty | ( | ) |
Check if map contains any fields.
Reimplemented in FIX::Message.
Definition at line 181 of file FieldMap.cpp.
References m_fields, QF_STACK_POP, and QF_STACK_PUSH.
Referenced by FIX::Message::isEmpty().
00182 { QF_STACK_PUSH(FieldMap::isEmpty) 00183 return m_fields.size() == 0; 00184 QF_STACK_POP 00185 }
bool FIX::FieldMap::isSetField | ( | int | field | ) | const [inline] |
Check to see if a field is set by referencing its number.
Definition at line 141 of file FieldMap.h.
References m_fields.
bool FIX::FieldMap::isSetField | ( | const FieldBase & | field | ) | const [inline] |
Check to see if a field is set.
Definition at line 138 of file FieldMap.h.
References FIX::FieldBase::getField(), and m_fields.
Referenced by FIX::DataDictionary::checkHasRequired(), FIX::MessageCracker::crack(), FIX::Session::doPossDup(), FIX::Session::doTargetTooLow(), FIX::Message::extractField(), FIX::Session::generateReject(), FIX::Message::isAdmin(), FIX::Message::isApp(), FIX::Session::next(), FIX::Session::nextLogon(), FIX::Session::nextResendRequest(), FIX::Session::nextSequenceReset(), FIX::Message::reverseRoute(), and FIX::Session::sendRaw().
Definition at line 39 of file FieldMap.cpp.
References addGroup(), clear(), m_fields, m_groups, QF_STACK_POP, and QF_STACK_PUSH.
00040 { QF_STACK_PUSH(FieldMap::operator=) 00041 00042 m_fields = rhs.m_fields; 00043 00044 clear(); 00045 00046 std::copy( rhs.m_fields.begin (), rhs.m_fields.end(), 00047 std::inserter(m_fields, m_fields.begin()) ); 00048 00049 Groups::const_iterator i; 00050 for ( i = rhs.m_groups.begin(); i != rhs.m_groups.end(); ++i ) 00051 { 00052 std::vector < FieldMap* > ::const_iterator j; 00053 for ( j = i->second.begin(); j != i->second.end(); ++j ) 00054 addGroup( i->first, **j ); 00055 } 00056 00057 return *this; 00058 00059 QF_STACK_POP 00060 }
void FIX::FieldMap::removeField | ( | int | field | ) |
Remove a field. If field is not present, this is a no-op.
Definition at line 126 of file FieldMap.cpp.
References m_fields, QF_STACK_POP, and QF_STACK_PUSH.
Referenced by FIX::Message::reverseRoute(), and FIX::Session::send().
00127 { QF_STACK_PUSH(FieldMap::removeField) 00128 00129 Fields::iterator i = m_fields.find( field ); 00130 if ( i != m_fields.end() ) 00131 m_fields.erase( i ); 00132 00133 QF_STACK_POP 00134 }
void FIX::FieldMap::removeGroup | ( | int | field | ) |
Remove all instances of a group.
Definition at line 120 of file FieldMap.cpp.
References groupCount(), QF_STACK_POP, QF_STACK_PUSH, and removeGroup().
00121 { QF_STACK_PUSH(FieldMap::removeGroup) 00122 removeGroup( groupCount(field), field ); 00123 QF_STACK_POP 00124 }
void FIX::FieldMap::removeGroup | ( | int | num, | |
int | field | |||
) |
Remove a specific instance of a group.
Definition at line 87 of file FieldMap.cpp.
References groupCount(), m_groups, and setField().
Referenced by removeGroup().
00088 { 00089 Groups::iterator i = m_groups.find( field ); 00090 if ( i == m_groups.end() ) return; 00091 if ( num <= 0 ) return; 00092 std::vector< FieldMap* >& vector = i->second; 00093 if ( vector.size() < ( unsigned ) num ) return; 00094 00095 std::deque< FieldMap* > queue; 00096 while( vector.size() > (unsigned)num ) 00097 { 00098 queue.push_back( vector.back() ); 00099 vector.pop_back(); 00100 } 00101 delete vector.back(); 00102 vector.pop_back(); 00103 while( queue.size() ) 00104 { 00105 vector.push_back( queue.front() ); 00106 queue.pop_front(); 00107 } 00108 00109 if( vector.size() == 0 ) 00110 { 00111 m_groups.erase( field ); 00112 } 00113 else 00114 { 00115 IntField groupCount( field, vector.size() ); 00116 setField( groupCount, true ); 00117 } 00118 }
void FIX::FieldMap::replaceGroup | ( | int | num, | |
int | field, | |||
FieldMap & | group | |||
) |
Replace a specific instanct of a group.
Definition at line 75 of file FieldMap.cpp.
References m_groups, QF_STACK_POP, and QF_STACK_PUSH.
00076 { QF_STACK_PUSH(FieldMap::replaceGroup) 00077 00078 Groups::const_iterator i = m_groups.find( field ); 00079 if ( i == m_groups.end() ) return; 00080 if ( num <= 0 ) return; 00081 if ( i->second.size() < ( unsigned ) num ) return; 00082 *( *( i->second.begin() + ( num - 1 ) ) ) = group; 00083 00084 QF_STACK_POP 00085 }
void FIX::FieldMap::setField | ( | int | field, | |
const std::string & | value | |||
) | throw ( RepeatedTag, NoTagValue ) [inline] |
Set a field without a field class.
Definition at line 95 of file FieldMap.h.
References setField().
00097 { 00098 FieldBase fieldBase( field, value ); 00099 setField( fieldBase ); 00100 }
void FIX::FieldMap::setField | ( | const FieldBase & | field, | |
bool | overwrite = true | |||
) | throw ( RepeatedTag ) [inline] |
Set a field without type checking.
Definition at line 80 of file FieldMap.h.
References FIX::FieldBase::getField(), and m_fields.
Referenced by addGroup(), FIX::Session::fill(), FIX::Session::generateBusinessReject(), FIX::Session::generateHeartbeat(), FIX::Session::generateLogon(), FIX::Session::generateLogout(), FIX::Session::generateReject(), FIX::Session::generateResendRequest(), FIX::Session::generateSequenceReset(), FIX::Session::generateTestRequest(), FIX::Session::insertOrigSendingTime(), FIX::Session::insertSendingTime(), FIX::Message::Message(), FIX::Session::populateRejectReason(), removeGroup(), FIX::Session::resend(), FIX::Message::reverseRoute(), FIX::Session::sendRaw(), FIX::Session::sendToTarget(), setField(), FIX::Message::setGroup(), FIX::Message::setSessionID(), FIX::Message::setStringHeader(), and FIX::Message::toString().
00082 { 00083 Fields::iterator i = m_fields.find( field.getField() ); 00084 if( i == m_fields.end() ) 00085 m_fields.insert( Fields::value_type( field.getField(), field ) ); 00086 else 00087 { 00088 if( overwrite ) 00089 i->second = field; 00090 else 00091 m_fields.insert( Fields::value_type( field.getField(), field ) ); 00092 } 00093 }
int FIX::FieldMap::totalFields | ( | ) | const |
Definition at line 187 of file FieldMap.cpp.
References m_fields, and m_groups.
Referenced by calculateString().
00188 { 00189 int result = m_fields.size(); 00190 00191 Groups::const_iterator i; 00192 for ( i = m_groups.begin(); i != m_groups.end(); ++i ) 00193 { 00194 std::vector < FieldMap* > ::const_iterator j; 00195 for ( j = i->second.begin(); j != i->second.end(); ++j ) 00196 result += ( *j ) ->totalFields(); 00197 } 00198 return result; 00199 }
Fields FIX::FieldMap::m_fields [private] |
Definition at line 211 of file FieldMap.h.
Referenced by addGroup(), begin(), calculateLength(), calculateString(), calculateTotal(), clear(), end(), getField(), getFieldRef(), isEmpty(), isSetField(), operator=(), removeField(), setField(), and totalFields().
Groups FIX::FieldMap::m_groups [private] |
Definition at line 212 of file FieldMap.h.
Referenced by addGroup(), calculateLength(), calculateString(), calculateTotal(), clear(), g_begin(), g_end(), getGroupRef(), groupCount(), hasGroup(), operator=(), removeGroup(), replaceGroup(), and totalFields().