MessageSorters.h
Go to the documentation of this file.
/* -*- C++ -*- */
/****************************************************************************
** Copyright (c) 2001-2014
**
** This file is part of the QuickFIX FIX Engine
**
** This file may be distributed under the terms of the quickfixengine.org
** license as defined by quickfixengine.org and appearing in the file
** LICENSE included in the packaging of this file.
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
** See http://www.quickfixengine.org/LICENSE for licensing information.
**
** Contact ask@quickfixengine.org if any conditions of this licensing are
** not clear to you.
**
****************************************************************************/
#ifndef FIX_MESSAGESORTERS_H
#define FIX_MESSAGESORTERS_H
#ifdef _MSC_VER
#pragma warning( disable : 4503 4355 4786 4290 )
#endif
#include "FieldNumbers.h"
#include "SharedArray.h"
#include <stdarg.h>
#include <functional>
#include <map>
namespace FIX
{
struct header_order
{
static bool compare( const int x, const int y )
{
int orderedX = getOrderedPosition( x );
int orderedY = getOrderedPosition( y );
if ( orderedX && orderedY )
return orderedX < orderedY;
else
if ( orderedX )
return true;
else
if ( orderedY )
return false;
else
return x < y;
}
static int getOrderedPosition( const int field )
{
switch ( field )
{
case FIELD::BeginString: return 1;
case FIELD::BodyLength: return 2;
case FIELD::MsgType: return 3;
default: return 0;
};
}
};
struct trailer_order
{
static bool compare( const int x, const int y )
{
if ( x == FIELD::CheckSum ) return false;
else
if ( y == FIELD::CheckSum ) return true;
else return x < y;
}
};
struct group_order
{
static bool compare( const int x, const int y, int* order, int largest )
{
if ( x <= largest && y <= largest )
{
int iX = order[ x ];
int iY = order[ y ];
if ( iX == 0 && iY == 0 )
return x < y;
else if ( iX == 0 )
return false;
else if ( iY == 0 )
return true;
else
return iX < iY;
}
else if ( x <= largest ) return true;
else if ( y <= largest ) return false;
else return x < y;
}
};
typedef std::less < int > normal_order;
struct message_order
{
public:
enum cmp_mode { header, trailer, normal, group };
message_order( cmp_mode mode = normal )
: m_mode( mode ), m_delim( 0 ), m_largest( 0 ) {}
message_order( int first, ... );
message_order( const int order[] );
message_order( const message_order& copy )
{ *this = copy; }
bool operator() ( const int x, const int y ) const
{
switch ( m_mode )
{
case header:
return header_order::compare( x, y );
case trailer:
return trailer_order::compare( x, y );
case group:
return group_order::compare( x, y, m_groupOrder, m_largest );
case normal: default:
return x < y;
}
}
message_order& operator=( const message_order& rhs );
operator bool() const
{ return !m_groupOrder.empty(); }
private:
void setOrder( int size, const int order[] );
cmp_mode m_mode;
int m_delim;
shared_array<int> m_groupOrder;
int m_largest;
};
}
#endif //FIX_MESSAGESORTERS_H
FieldNumbers.h
SharedArray.h
FIX::shared_array
Shared array with atomic reference count.
Definition SharedArray.h:158
FIX::shared_array::empty
bool empty() const
Definition SharedArray.h:194
FIX
Definition Acceptor.cpp:35
FIX::normal_order
std::less< int > normal_order
Definition MessageSorters.h:105
FIX::group_order
Sorts fields in correct group order.
Definition MessageSorters.h:83
FIX::group_order::compare
static bool compare(const int x, const int y, int *order, int largest)
Definition MessageSorters.h:84
FIX::header_order
Sorts fields in correct header order.
Definition MessageSorters.h:39
FIX::header_order::compare
static bool compare(const int x, const int y)
Definition MessageSorters.h:40
FIX::header_order::getOrderedPosition
static int getOrderedPosition(const int field)
Definition MessageSorters.h:57
FIX::message_order
Sorts fields in header, normal, or trailer order.
Definition MessageSorters.h:114
FIX::message_order::operator=
message_order & operator=(const message_order &rhs)
Definition MessageSorters.cpp:79
FIX::message_order::m_delim
int m_delim
Definition MessageSorters.h:149
FIX::message_order::message_order
message_order(const message_order &copy)
Definition MessageSorters.h:122
FIX::message_order::m_groupOrder
shared_array< int > m_groupOrder
Definition MessageSorters.h:150
FIX::message_order::message_order
message_order(cmp_mode mode=normal)
Definition MessageSorters.h:118
FIX::message_order::operator()
bool operator()(const int x, const int y) const
Definition MessageSorters.h:125
FIX::message_order::cmp_mode
cmp_mode
Definition MessageSorters.h:116
FIX::message_order::normal
@ normal
Definition MessageSorters.h:116
FIX::message_order::header
@ header
Definition MessageSorters.h:116
FIX::message_order::group
@ group
Definition MessageSorters.h:116
FIX::message_order::trailer
@ trailer
Definition MessageSorters.h:116
FIX::message_order::m_largest
int m_largest
Definition MessageSorters.h:151
FIX::message_order::setOrder
void setOrder(int size, const int order[])
Definition MessageSorters.cpp:89
FIX::message_order::m_mode
cmp_mode m_mode
Definition MessageSorters.h:148
FIX::trailer_order
Sorts fields in correct trailer order.
Definition MessageSorters.h:71
FIX::trailer_order::compare
static bool compare(const int x, const int y)
Definition MessageSorters.h:72