MessageSorters.h
Go to the documentation of this file.
1/* -*- C++ -*- */
2
3/****************************************************************************
4** Copyright (c) 2001-2014
5**
6** This file is part of the QuickFIX FIX Engine
7**
8** This file may be distributed under the terms of the quickfixengine.org
9** license as defined by quickfixengine.org and appearing in the file
10** LICENSE included in the packaging of this file.
11**
12** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
13** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
14**
15** See http://www.quickfixengine.org/LICENSE for licensing information.
16**
17** Contact ask@quickfixengine.org if any conditions of this licensing are
18** not clear to you.
19**
20****************************************************************************/
21
22#ifndef FIX_MESSAGESORTERS_H
23#define FIX_MESSAGESORTERS_H
24
25#ifdef _MSC_VER
26#pragma warning( disable : 4503 4355 4786 4290 )
27#endif
28
29#include "FieldNumbers.h"
30#include "SharedArray.h"
31#include <stdarg.h>
32#include <functional>
33#include <map>
34
35namespace FIX
36{
39{
40 static bool compare( const int x, const int y )
41 {
42 int orderedX = getOrderedPosition( x );
43 int orderedY = getOrderedPosition( y );
44
45 if ( orderedX && orderedY )
46 return orderedX < orderedY;
47 else
48 if ( orderedX )
49 return true;
50 else
51 if ( orderedY )
52 return false;
53 else
54 return x < y;
55 }
56
57 static int getOrderedPosition( const int field )
58 {
59 switch ( field )
60 {
61 case FIELD::BeginString: return 1;
62 case FIELD::BodyLength: return 2;
63 case FIELD::MsgType: return 3;
64 default: return 0;
65 };
66 }
67};
68
71{
72 static bool compare( const int x, const int y )
73 {
74 if ( x == FIELD::CheckSum ) return false;
75 else
76 if ( y == FIELD::CheckSum ) return true;
77 else return x < y;
78 }
79};
80
83{
84 static bool compare( const int x, const int y, int* order, int largest )
85 {
86 if ( x <= largest && y <= largest )
87 {
88 int iX = order[ x ];
89 int iY = order[ y ];
90 if ( iX == 0 && iY == 0 )
91 return x < y;
92 else if ( iX == 0 )
93 return false;
94 else if ( iY == 0 )
95 return true;
96 else
97 return iX < iY;
98 }
99 else if ( x <= largest ) return true;
100 else if ( y <= largest ) return false;
101 else return x < y;
102 }
103};
104
105typedef std::less < int > normal_order;
106
114{
115public:
117
119 : m_mode( mode ), m_delim( 0 ), m_largest( 0 ) {}
120 message_order( int first, ... );
121 message_order( const int order[] );
123 { *this = copy; }
124
125 bool operator() ( const int x, const int y ) const
126 {
127 switch ( m_mode )
128 {
129 case header:
130 return header_order::compare( x, y );
131 case trailer:
132 return trailer_order::compare( x, y );
133 case group:
135 case normal: default:
136 return x < y;
137 }
138 }
139
141
142 operator bool() const
143 { return !m_groupOrder.empty(); }
144
145private:
146 void setOrder( int size, const int order[] );
147
152};
153}
154
155#endif //FIX_MESSAGESORTERS_H
156
Shared array with atomic reference count.
bool empty() const
std::less< int > normal_order
Sorts fields in correct group order.
static bool compare(const int x, const int y, int *order, int largest)
Sorts fields in correct header order.
static bool compare(const int x, const int y)
static int getOrderedPosition(const int field)
Sorts fields in header, normal, or trailer order.
message_order & operator=(const message_order &rhs)
message_order(const message_order &copy)
shared_array< int > m_groupOrder
message_order(cmp_mode mode=normal)
bool operator()(const int x, const int y) const
void setOrder(int size, const int order[])
Sorts fields in correct trailer order.
static bool compare(const int x, const int y)

Generated on Sat Feb 3 2024 04:23:15 for QuickFIX by doxygen 1.9.8 written by Dimitri van Heesch, © 1997-2001