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 
35 namespace FIX
36 {
38 struct header_order
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 
70 struct trailer_order
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 
82 struct group_order
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 
105 typedef std::less < int > normal_order;
106 
113 struct message_order
114 {
115 public:
116  enum cmp_mode { header, trailer, normal, group };
117 
118  message_order( cmp_mode mode = normal )
119  : m_mode( mode ), m_delim( 0 ), m_largest( 0 ) {}
120  message_order( int first, ... );
121  message_order( const int order[] );
122  message_order( const message_order& copy )
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 
140  message_order& operator=( const message_order& rhs );
141 
142  operator bool() const
143  { return !m_groupOrder.empty(); }
144 
145 private:
146  void setOrder( int size, const int order[] );
147 
149  int m_delim;
151  int m_largest;
152 };
153 }
154 
155 #endif //FIX_MESSAGESORTERS_H
156 
FIX::message_order::m_groupOrder
shared_array< int > m_groupOrder
Definition: MessageSorters.h:167
FIX::shared_array< int >
FIX::header_order::getOrderedPosition
static int getOrderedPosition(const int field)
Definition: MessageSorters.h:91
FIX::message_order::group
@ group
Definition: MessageSorters.h:133
FIX::message_order::setOrder
void setOrder(int size, const int order[])
Definition: MessageSorters.cpp:106
FIX::message_order::trailer
@ trailer
Definition: MessageSorters.h:133
FIX::trailer_order::compare
static bool compare(const int x, const int y)
Definition: MessageSorters.h:89
FIX::header_order::compare
static bool compare(const int x, const int y)
Definition: MessageSorters.h:74
FIX::message_order::message_order
message_order(cmp_mode mode=normal)
Definition: MessageSorters.h:135
FIX::message_order::operator=
message_order & operator=(const message_order &rhs)
Definition: MessageSorters.cpp:96
SharedArray.h
FieldNumbers.h
FIX::message_order::m_delim
int m_delim
Definition: MessageSorters.h:166
FIX::message_order::m_mode
cmp_mode m_mode
Definition: MessageSorters.h:165
FIX
Definition: Acceptor.cpp:34
FIX::normal_order
std::less< int > normal_order
Definition: MessageSorters.h:122
FIX::message_order::operator()
bool operator()(const int x, const int y) const
Definition: MessageSorters.h:142
FIX::shared_array::empty
bool empty() const
Definition: SharedArray.h:228
FIX::message_order::normal
@ normal
Definition: MessageSorters.h:133
FIX::message_order::m_largest
int m_largest
Definition: MessageSorters.h:168
FIX::message_order
Sorts fields in header, normal, or trailer order.
Definition: MessageSorters.h:130
FIX::group_order::compare
static bool compare(const int x, const int y, int *order, int largest)
Definition: MessageSorters.h:101
FIX::message_order::cmp_mode
cmp_mode
Definition: MessageSorters.h:133
FIX::message_order::header
@ header
Definition: MessageSorters.h:133

Generated on Wed Apr 29 2020 19:41:30 for QuickFIX by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2001