This source file includes following definitions.
- data
1 #ifndef libjmmcg_isimud_exchanges_common_isin_hpp
2 #define libjmmcg_isimud_exchanges_common_isin_hpp
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 #include "iso_3166_country_codes.hpp"
25
26 #include "core/memops.hpp"
27
28 #include <boost/mpl/assert.hpp>
29
30 #include <iostream>
31 #include <string>
32
33 namespace isimud { namespace exchanges { namespace common {
34
35
36 class ISIN_t {
37 public:
38 using Country_Code_t=isimud::exchanges::common::ctry_codes::alpha_2::country_t;
39 BOOST_MPL_ASSERT_RELATION(sizeof(Country_Code_t), ==, 2);
40 using NSIN_t=std::array<char, 9>;
41 using CUSIP_t=NSIN_t;
42 BOOST_MPL_ASSERT_RELATION(sizeof(CUSIP_t), ==, 9);
43
44 union SEDOL_t {
45 NSIN_t nsin;
46 struct padded_SEDOL {
47 using element_type=std::array<NSIN_t::value_type, 7>;
48
49 const NSIN_t::value_type prefix[sizeof(NSIN_t)-sizeof(element_type)]={'0', '0'};
50 element_type value;
51 } __attribute__((packed)) padded_sedol;
52 } __attribute__((packed));
53 BOOST_MPL_ASSERT_RELATION(sizeof(SEDOL_t), ==, 9);
54
55 private:
56
57 struct details_t {
58 Country_Code_t country;
59 union {
60 NSIN_t nsin;
61 CUSIP_t cusip;
62 SEDOL_t sedol;
63 } __attribute__((packed));
64 char check_digit;
65 } __attribute__((packed));
66 BOOST_MPL_ASSERT_RELATION(sizeof(details_t), ==, 12);
67
68 public:
69 using block_t=std::array<char, sizeof(details_t)>;
70 BOOST_MPL_ASSERT_RELATION(sizeof(block_t), ==, 12);
71
72 ISIN_t() noexcept(true);
73 explicit ISIN_t(block_t const &b) noexcept(true);
74 template<std::size_t Sz>
75 explicit ISIN_t(block_t::value_type const (&b)[Sz]) noexcept(true);
76
77 bool operator==(ISIN_t const &i) const noexcept(true);
78
79 block_t const &data() const noexcept(true) {
80 return value.block;
81 }
82
83 std::string to_string() const noexcept(false);
84
85 uint64_t hash() const noexcept(true);
86
87 friend std::ostream &operator<<(std::ostream &os, ISIN_t const &i) noexcept(false);
88 friend std::istream &operator>>(std::istream &is, ISIN_t &i) noexcept(false);
89
90 private:
91 union converter_t {
92 block_t block;
93 details_t components;
94
95 converter_t() noexcept(true) {}
96 } value;
97 BOOST_MPL_ASSERT_RELATION(sizeof(converter_t), ==, 12);
98 };
99
100 BOOST_MPL_ASSERT_RELATION(sizeof(ISIN_t), ==, 12);
101
102 } } }
103
104 #include "isin_impl.hpp"
105
106 #endif