root/isimud/exchanges/common/isin.hpp

/* [<][>][^][v][top][bottom][index][help] */

INCLUDED FROM


DEFINITIONS

This source file includes following definitions.
  1. data

   1 #ifndef libjmmcg_isimud_exchanges_common_isin_hpp
   2 #define libjmmcg_isimud_exchanges_common_isin_hpp
   3 
   4 /******************************************************************************
   5 ** $Header: svn+ssh://jmmcg@svn.code.sf.net/p/libjmmcg/code/trunk/libjmmcg/isimud/exchanges/common/isin.hpp 2177 2017-10-11 21:29:22Z jmmcg $
   6 **
   7 ** Copyright (c) 2016 by J.M.McGuiness, isimud@hussar.me.uk
   8 **
   9 ** This library is free software; you can redistribute it and/or
  10 ** modify it under the terms of the GNU Lesser General Public
  11 ** License as published by the Free Software Foundation; either
  12 ** version 2.1 of the License, or (at your option) any later version.
  13 **
  14 ** This library is distributed in the hope that it will be useful,
  15 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  16 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17 ** Lesser General Public License for more details.
  18 **
  19 ** You should have received a copy of the GNU Lesser General Public
  20 ** License along with this library; if not, write to the Free Software
  21 ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  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 /// The <a href="http://www.isin.org/isin/">ISIN code</a> for an instrument.
  36 class ISIN_t {
  37 public:
  38         using Country_Code_t=isimud::exchanges::common::ctry_codes::alpha_2::country_t; ///< The <a href="https://www.iso.org/obp/ui/#search">ISO 3166 Country-Code</a>, Alpha-2 format.
  39         BOOST_MPL_ASSERT_RELATION(sizeof(Country_Code_t), ==, 2);
  40         using NSIN_t=std::array<char, 9>;       ///< Must be printable characters.
  41         using CUSIP_t=NSIN_t;   ///< When appropriate this may be the CUSIP.
  42         BOOST_MPL_ASSERT_RELATION(sizeof(CUSIP_t), ==, 9);
  43         /// When appropriate the last 7 characters may be the SEDOL.
  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         /// Get at the internal components.
  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;       ///< The 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;  ///< Deal with the ISIN as a flat data-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

/* [<][>][^][v][top][bottom][index][help] */