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

# MessageSorters.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 "MessageSorters.h"
    00028
    00029 namespace FIX
    00030 {
    00031 message_order::message_order( int first, ... )
    00032 : m_mode( group ), m_delim( 0 ), m_groupOrder( 0 ), m_largest( 0 )
    00033 {
    00034   int field = first;
    00035   int size = 0;
    00036
    00037   va_list arguments;
    00038   va_start( arguments, first );
    00039   while( field != 0 )
    00040   {
    00041     size++;
    00042     field = va_arg( arguments, int );
    00043   }
    00044
    00045   va_start( arguments, first );
    00046   int* order = new int[size];
    00047   order[0] = first;
    00048   for ( int i = 1; i < size; ++i )
    00049     order[ i ] = va_arg( arguments, int );
    00050   setOrder(size, order);
    00051   delete [] order;
    00052
    00053   va_end( arguments );
    00054 }
    00055
    00056 message_order::message_order( const int order[] )
    00057 : m_mode( group ), m_delim( 0 ), m_groupOrder( 0 ), m_largest( 0 )
    00058 {
    00059   int size = 0;
    00060   while( order[size] != 0 ) { ++size; }
    00061   setOrder(size, order);
    00062 }
    00063
    00064 message_order& message_order::operator=( const message_order& rhs )
    00065 { QF_STACK_PUSH(message_order::operator=)
    00066
    00067   m_mode = rhs.m_mode;
    00068   m_delim = rhs.m_delim;
    00069   m_largest = rhs.m_largest;
    00070   if ( rhs.m_groupOrder )
    00071   {
    00072     if ( m_groupOrder ) delete [] m_groupOrder;
    00073     m_groupOrder = new int[ m_largest + 1 ];
    00074     memcpy( m_groupOrder, rhs.m_groupOrder,
    00075             ( m_largest + 1 ) * sizeof( int ) );
    00076   }
    00077   return *this;
    00078
    00079   QF_STACK_POP
    00080 }
    00081
    00082 void message_order::setOrder( int size, const int order[] )
    00083 { QF_STACK_PUSH(message_order::operator=)
    00084
    00085   if(size < 1) return;
    00086   m_largest = m_delim = order[0];
    00087
    00088   int* fields = new int[ size + 1 ];
    00089   fields[ 1 ] = m_delim;
    00090   // collect all fields and find the largest field number
    00091   int i;
    00092   for ( i = 2; i <= size; ++i )
    00093   {
    00094     int field = order[i-1];
    00095     m_largest = m_largest > field ? m_largest : field;
    00096     fields[ i ] = field;
    00097   }
    00098
    00099   // populate array with field number as key and position as value
    00100   m_groupOrder = new int[ m_largest + 1 ];
    00101   memset( m_groupOrder, 0, ( m_largest + 1 ) * sizeof( int ) );
    00102   for ( i = 1; i <= size; ++i )
    00103     m_groupOrder[ fields[ i ] ] = i;
    00104   delete [] fields;
    00105
    00106   QF_STACK_POP
    00107 }
    00108 }