libjmmcg  release_579_6_g8cffd
A C++ library containing an eclectic mix of useful, advanced components.
types.hpp
Go to the documentation of this file.
1 #ifndef ISIMUD_EXCHANGES_FIX_common_types_hpp
2 #define ISIMUD_EXCHANGES_FIX_common_types_hpp
3 
4 /******************************************************************************
5 ** Copyright © 2015 by J.M.McGuiness, isimud@hussar.me.uk
6 **
7 ** This library is free software; you can redistribute it and/or
8 ** modify it under the terms of the GNU Lesser General Public
9 ** License as published by the Free Software Foundation; either
10 ** version 2.1 of the License, or (at your option) any later version.
11 **
12 ** This library is distributed in the hope that it will be useful,
13 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
14 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 ** Lesser General Public License for more details.
16 **
17 ** You should have received a copy of the GNU Lesser General Public
18 ** License along with this library; if not, write to the Free Software
19 ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 */
21 
22 #include "core/enum_as_char_array.hpp"
23 #include "core/int128_compatibility.hpp"
24 
25 #include <array>
26 #include <iterator>
27 #include <iostream>
28 #include <limits>
29 
30 namespace isimud { namespace ISIMUD_VER_NAMESPACE { namespace exchanges { namespace FIX { namespace common {
31 
32 using element_type=char;
33 enum : std::size_t {
34  max_size_of_fix_message=sizeof(libjmmcg::uint128_t)*32 ///< The largest size of FIX message that the library can accommodate including all components, e.g. type, size & checksum fields. Note that this must be in units of 512 bits, due to the use of AVX2 operations, if available.
35 };
36 /// An underlying data-buffer into which the fix message may be created.
37 /**
38  Ideally this should be suitably aligned, e.g. 64-it aligned. For optimal performance it would actually be the underlying memory of the network card or IP stack.
39 */
40 using underlying_fix_data_buffer=std::array<element_type, max_size_of_fix_message>;
41 using pointer=element_type *;
42 using const_pointer=element_type const *;
43 /// The type of the internal data-buffer.
44 /**
45  FIX messages are basically an array of chars. so we need a type that is compatible with this char-array that is received from a socket.
46 */
47 using data_block_t=pointer;
48 
49 using SecurityID_t=std::array<char, 20>;
50 using ClientOrderID_t=std::array<char, 20>;
51 using Reason_t=std::array<char, 20>;
52 using Password_t=std::array<char, 25>;
53 using UserName_t=std::array<char, 25>;
54 using Price_str_t=std::array<char, 25>;
55 
56 constexpr const char Separator='\001';
57 constexpr const unsigned short CheckSumLength=3;
58 
59 /// The checksum type used by FIX.
60 using checksum_t=std::array<char, CheckSumLength+1>;
61 
62 using field_str_const_range_t=std::pair<const_pointer, const_pointer>;
63 using field_str_range_t=std::pair<pointer, pointer>;
64 
65 constexpr const std::uint64_t implied_decimal_places=1;
66 
67 /// When creating a FIX message it will always have this many chars. All this variable-sized stuff is a crock.
68 #define JMMCG_FIX_MSG_BODY_LENGTH_NULL "000"
69 
70 #define JMMCG_FIX_MSG_BODY_LENGTH_TAG "\0019="
71 #define JMMCG_FIX_MSG_TYPE_TAG "\00135="
72 
73 BOOST_MPL_ASSERT_RELATION((libjmmcg::enum_tags::mpl::to_array<FieldsFast, FieldsFast::BodyLength>::size), ==, sizeof(JMMCG_FIX_MSG_BODY_LENGTH_TAG)-1);
74 BOOST_MPL_ASSERT_RELATION((libjmmcg::enum_tags::mpl::to_array<FieldsFast, FieldsFast::MsgType>::size), >=, sizeof(JMMCG_FIX_MSG_TYPE_TAG)-1);
75 
76 } } } } }
77 
78 namespace std {
79 
80 inline std::ostream &
81 operator<<(std::ostream &os, isimud::ISIMUD_VER_NAMESPACE::exchanges::FIX::common::field_str_const_range_t const &v) {
82  std::copy(v.first, v.second, std::ostream_iterator<isimud::ISIMUD_VER_NAMESPACE::exchanges::FIX::common::element_type>(os));
83  return os;
84 }
85 
86 }
87 
88 #endif