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

# MessageSorters.h

Go to the documentation of this file.

    00001 /* -*- C++ -*- */
    00002
    00003 /****************************************************************************
    00004 ** Copyright (c) quickfixengine.org  All rights reserved.
    00005 **
    00006 ** This file is part of the QuickFIX FIX Engine
    00007 **
    00008 ** This file may be distributed under the terms of the quickfixengine.org
    00009 ** license as defined by quickfixengine.org and appearing in the file
    00010 ** LICENSE included in the packaging of this file.
    00011 **
    00012 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
    00013 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
    00014 **
    00015 ** See http://www.quickfixengine.org/LICENSE for licensing information.
    00016 **
    00017 ** Contact ask@quickfixengine.org if any conditions of this licensing are
    00018 ** not clear to you.
    00019 **
    00020 ****************************************************************************/
    00021
    00022 #ifndef FIX_MESSAGESORTERS_H
    00023 #define FIX_MESSAGESORTERS_H
    00024
    00025 #ifdef _MSC_VER
    00026 #pragma warning( disable : 4503 4355 4786 4290 )
    00027 #endif
    00028
    00029 #include "FieldNumbers.h"
    00030 #include <stdarg.h>
    00031 #include <functional>
    00032 #include <map>
    00033
    00034 namespace FIX
    00035 {
    00037 struct header_order
    00038 {
    00039   static bool compare( const int& x, const int& y )
    00040   {
    00041     int orderedX = getOrderedPosition( x );
    00042     int orderedY = getOrderedPosition( y );
    00043
    00044     if ( orderedX && orderedY )
    00045       return orderedX < orderedY;
    00046     else
    00047       if ( orderedX )
    00048         return true;
    00049       else
    00050         if ( orderedY )
    00051           return false;
    00052         else
    00053           return x < y;
    00054   }
    00055
    00056   static int getOrderedPosition( const int& field )
    00057   {
    00058     switch ( field )
    00059     {
    00060       case FIELD::BeginString: return 1;
    00061       case FIELD::BodyLength: return 2;
    00062       case FIELD::MsgType: return 3;
    00063       default: return 0;
    00064     };
    00065   }
    00066 };
    00067
    00069 struct trailer_order
    00070 {
    00071   static bool compare( const int x, const int y )
    00072   {
    00073     if ( x == FIELD::CheckSum ) return false;
    00074     else
    00075       if ( y == FIELD::CheckSum ) return true;
    00076       else return x < y;
    00077   }
    00078 };
    00079
    00081 struct group_order
    00082 {
    00083   static bool compare( const int x, const int y, int* order, int largest )
    00084   {
    00085     if ( x <= largest && y <= largest )
    00086     {
    00087       int iX = order[ x ];
    00088       int iY = order[ y ];
    00089       if ( iX == 0 && iY == 0 )
    00090         return x < y;
    00091       else if ( iX == 0 )
    00092         return false;
    00093       else if ( iY == 0 )
    00094         return true;
    00095       else
    00096         return iX < iY;
    00097     }
    00098     else if ( x <= largest ) return true;
    00099     else if ( y <= largest ) return false;
    00100     else return x < y;
    00101   }
    00102 };
    00103
    00104 typedef std::less < int > normal_order;
    00105
    00112 struct message_order
    00113 {
    00114 public:
    00115   enum cmp_mode { header, trailer, normal, group };
    00116
    00117   message_order( cmp_mode mode = normal ) : m_mode( mode ), m_groupOrder( 0 ) {}
    00118   message_order( int first, ... );
    00119   message_order( const int order[] );
    00120   message_order( const message_order& copy ) : m_groupOrder( 0 )
    00121   { *this = copy; }
    00122
    00123   virtual ~message_order()
    00124   {
    00125     if ( m_groupOrder )
    00126       delete [] m_groupOrder;
    00127   }
    00128
    00129   bool operator() ( const int& x, const int& y ) const
    00130   {
    00131     switch ( m_mode )
    00132     {
    00133       case header:
    00134       return header_order::compare( x, y );
    00135       case trailer:
    00136       return trailer_order::compare( x, y );
    00137       case group:
    00138       return group_order::compare( x, y, m_groupOrder, m_largest );
    00139       case normal: default:
    00140       return x < y;
    00141     }
    00142   }
    00143
    00144   message_order& operator=( const message_order& rhs );
    00145
    00146 private:
    00147   void setOrder( int size, const int order[] );
    00148
    00149   cmp_mode m_mode;
    00150   int m_delim;
    00151   int* m_groupOrder;
    00152   int m_largest;
    00153 };
    00154 }
    00155
    00156 #endif //FIX_MESSAGESORTERS_H
    00157