Index  Source Files  Annotated Class List  Alphabetical Class List  Class Hierarchy  Graphical Class Hierarchy   
 

/home/orenmnero/autobuild/quickfix/src/C++/FieldMap.cpp

Go to the documentation of this file.
00001 /****************************************************************************
00002 ** Copyright (c) quickfixengine.org  All rights reserved.
00003 **
00004 ** This file is part of the QuickFIX FIX Engine
00005 **
00006 ** This file may be distributed under the terms of the quickfixengine.org
00007 ** license as defined by quickfixengine.org and appearing in the file
00008 ** LICENSE included in the packaging of this file.
00009 **
00010 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00011 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00012 **
00013 ** See http://www.quickfixengine.org/LICENSE for licensing information.
00014 **
00015 ** Contact ask@quickfixengine.org if any conditions of this licensing are
00016 ** not clear to you.
00017 **
00018 ****************************************************************************/
00019 
00020 #ifdef _MSC_VER
00021 #include "stdafx.h"
00022 #else
00023 #include "config.h"
00024 #endif
00025 #include "CallStack.h"
00026 
00027 #include "FieldMap.h"
00028 #include <algorithm>
00029 #include <iterator>
00030 
00031 namespace FIX
00032 {
00033 FieldMap::~FieldMap()
00034 { QF_STACK_IGNORE_BEGIN
00035   clear();
00036   QF_STACK_IGNORE_END
00037 }
00038 
00039 FieldMap& FieldMap::operator=( const FieldMap& rhs )
00040 { QF_STACK_PUSH(FieldMap::operator=)
00041 
00042   clear();
00043 
00044   std::copy( rhs.m_fields.begin (), rhs.m_fields.end(),
00045              std::inserter(m_fields, m_fields.begin()) );
00046 
00047   Groups::const_iterator i;
00048   for ( i = rhs.m_groups.begin(); i != rhs.m_groups.end(); ++i )
00049   {
00050     std::vector < FieldMap* > ::const_iterator j;
00051     for ( j = i->second.begin(); j != i->second.end(); ++j )
00052       addGroup( i->first, **j );
00053   }
00054 
00055   return *this;
00056 
00057   QF_STACK_POP
00058 }
00059 
00060 void FieldMap::addGroup( int field, const FieldMap& group, bool setCount )
00061 { QF_STACK_PUSH(FieldMap::addGroup)
00062 
00063   FieldMap * pGroup = new FieldMap( group.m_fields.key_comp() );
00064   *pGroup = group;
00065   m_groups[ field ].push_back( pGroup );
00066   Groups::iterator i = m_groups.find( field );
00067   if( setCount )
00068     setField( IntField( field, i->second.size() ) );
00069 
00070   QF_STACK_POP
00071 }
00072 
00073 void FieldMap::replaceGroup( int num, int field, FieldMap& group )
00074 { QF_STACK_PUSH(FieldMap::replaceGroup)
00075 
00076   Groups::const_iterator i = m_groups.find( field );
00077   if ( i == m_groups.end() ) return;
00078   if ( num <= 0 ) return;
00079   if ( i->second.size() < ( unsigned ) num ) return;
00080   *( *( i->second.begin() + ( num - 1 ) ) ) = group;
00081 
00082   QF_STACK_POP
00083 }
00084 
00085 FieldMap& FieldMap::getGroup( int num, int field, FieldMap& group ) const
00086 throw( FieldNotFound )
00087 { QF_STACK_PUSH(FieldMap::getGroup)
00088 
00089   Groups::const_iterator i = m_groups.find( field );
00090   if ( i == m_groups.end() ) throw FieldNotFound( field );
00091   if ( num <= 0 ) throw FieldNotFound( field );
00092   if ( i->second.size() < ( unsigned ) num ) throw FieldNotFound( field );
00093   group = *( *( i->second.begin() + ( num - 1 ) ) );
00094   return group;
00095 
00096   QF_STACK_POP
00097 }
00098 
00099 void FieldMap::removeGroup( int num, int field )
00100 {
00101   Groups::iterator i = m_groups.find( field );
00102   if ( i == m_groups.end() ) return;
00103   if ( num <= 0 ) return;
00104   std::vector< FieldMap* >& vector = i->second;
00105   if ( vector.size() < ( unsigned ) num ) return;
00106 
00107   std::deque< FieldMap* > queue;
00108   while( vector.size() > (unsigned)num )
00109   {
00110     queue.push_back( vector.back() );
00111     vector.pop_back();
00112   }
00113   delete vector.back();
00114   vector.pop_back();
00115   while( queue.size() )
00116   {
00117     vector.push_back( queue.front() );
00118     queue.pop_front();
00119   }
00120 
00121   if( vector.size() == 0 )
00122   {
00123     m_groups.erase( field );
00124   }
00125   else
00126   {
00127     IntField groupCount( field, vector.size() );
00128     setField( groupCount, true );
00129   }
00130 }
00131 
00132 void FieldMap::removeGroup( int field )
00133 { QF_STACK_PUSH(FieldMap::removeGroup)
00134   removeGroup( groupCount(field), field );
00135   QF_STACK_POP
00136 }
00137 
00138 void FieldMap::removeField( int field )
00139 { QF_STACK_PUSH(FieldMap::removeField)
00140 
00141   Fields::iterator i = m_fields.find( field );
00142   if ( i != m_fields.end() )
00143     m_fields.erase( i );
00144 
00145   QF_STACK_POP
00146 }
00147 
00148 bool FieldMap::hasGroup( int num, int field ) const
00149 { QF_STACK_PUSH(FieldMap::hasGroup)
00150 
00151   return groupCount(field) >= num;
00152 
00153   QF_STACK_POP
00154 }
00155 
00156 bool FieldMap::hasGroup( int field ) const
00157 { QF_STACK_PUSH(FieldMap::hasGroup)
00158 
00159   Groups::const_iterator i = m_groups.find( field );
00160   return i != m_groups.end();
00161 
00162   QF_STACK_POP
00163 }
00164 
00165 int FieldMap::groupCount( int field ) const
00166 { QF_STACK_PUSH(FieldMap::groupCount)
00167 
00168   Groups::const_iterator i = m_groups.find( field );
00169   if( i == m_groups.end() )
00170     return 0;
00171   return i->second.size();
00172 
00173   QF_STACK_POP
00174 }
00175 
00176 void FieldMap::clear()
00177 { QF_STACK_PUSH(FieldMap::clear)
00178 
00179   m_fields.clear();
00180 
00181   Groups::iterator i;
00182   for ( i = m_groups.begin(); i != m_groups.end(); ++i )
00183   {
00184     std::vector < FieldMap* > ::iterator j;
00185     for ( j = i->second.begin(); j != i->second.end(); ++j )
00186       delete *j;
00187   }
00188   m_groups.clear();
00189 
00190   QF_STACK_POP
00191 }
00192 
00193 bool FieldMap::isEmpty()
00194 { QF_STACK_PUSH(FieldMap::isEmpty)
00195   return m_fields.size() == 0;
00196   QF_STACK_POP
00197 }
00198 
00199 std::string& FieldMap::calculateString( std::string& result, bool clear ) const
00200 { QF_STACK_PUSH(FieldMap::calculateString)
00201 
00202 #if defined(_MSC_VER) && _MSC_VER < 1300
00203   if( clear ) result = "";
00204 #else
00205   if( clear ) result.clear();
00206 #endif
00207 
00208   Fields::const_iterator i;
00209   for ( i = m_fields.begin(); i != m_fields.end(); ++i )
00210   {
00211     result += i->second.getValue();
00212 
00213     // add groups if they exist
00214     if( !m_groups.size() ) continue;
00215     Groups::const_iterator j = m_groups.find( i->first );
00216     if ( j == m_groups.end() ) continue;
00217     std::vector < FieldMap* > ::const_iterator k;
00218     for ( k = j->second.begin(); k != j->second.end(); ++k )
00219       ( *k ) ->calculateString( result, false );
00220   }
00221   return result;
00222 
00223   QF_STACK_POP
00224 }
00225 
00226 int FieldMap::calculateLength( int beginStringField,
00227                                int bodyLengthField,
00228                                int checkSumField ) const
00229 {
00230   int result = 0;
00231   Fields::const_iterator i;
00232   for ( i = m_fields.begin(); i != m_fields.end(); ++i )
00233   {
00234     if ( i->first != beginStringField
00235          && i->first != bodyLengthField
00236          && i->first != checkSumField )
00237     { result += i->second.getLength(); }
00238   }
00239 
00240   Groups::const_iterator j;
00241   for ( j = m_groups.begin(); j != m_groups.end(); ++j )
00242   {
00243     std::vector < FieldMap* > ::const_iterator k;
00244     for ( k = j->second.begin(); k != j->second.end(); ++k )
00245       result += ( *k ) ->calculateLength();
00246   }
00247   return result;
00248 }
00249 
00250 int FieldMap::calculateTotal( int checkSumField ) const
00251 { QF_STACK_PUSH(FieldMap::calculateTotal)
00252 
00253   int result = 0;
00254   Fields::const_iterator i;
00255   for ( i = m_fields.begin(); i != m_fields.end(); ++i )
00256   {
00257     if ( i->first != checkSumField )
00258       result += i->second.getTotal();
00259   }
00260 
00261   Groups::const_iterator j;
00262   for ( j = m_groups.begin(); j != m_groups.end(); ++j )
00263   {
00264     std::vector < FieldMap* > ::const_iterator k;
00265     for ( k = j->second.begin(); k != j->second.end(); ++k )
00266       result += ( *k ) ->calculateTotal();
00267   }
00268   return result;
00269 
00270   QF_STACK_POP
00271 }
00272 }

Generated on Mon Jul 24 19:36:27 2006 for QuickFIX by doxygen 1.3.6-20040222 written by Dimitri van Heesch, © 1997-2001