root/isimud/exchanges/common/isin_impl.hpp

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

INCLUDED FROM


DEFINITIONS

This source file includes following definitions.
  1. to_string
  2. hash

   1 /******************************************************************************
   2 ** $Header: svn+ssh://jmmcg@svn.code.sf.net/p/libjmmcg/code/trunk/libjmmcg/isimud/exchanges/common/isin_impl.hpp 2177 2017-10-11 21:29:22Z jmmcg $
   3 **
   4 ** Copyright (c) 2016 by J.M.McGuiness, isimud@hussar.me.uk
   5 **
   6 ** This library is free software; you can redistribute it and/or
   7 ** modify it under the terms of the GNU Lesser General Public
   8 ** License as published by the Free Software Foundation; either
   9 ** version 2.1 of the License, or (at your option) any later version.
  10 **
  11 ** This library is distributed in the hope that it will be useful,
  12 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  13 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14 ** Lesser General Public License for more details.
  15 **
  16 ** You should have received a copy of the GNU Lesser General Public
  17 ** License along with this library; if not, write to the Free Software
  18 ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  19 */
  20 
  21 namespace isimud { namespace exchanges { namespace common {
  22 
  23 inline
  24 ISIN_t::ISIN_t() noexcept(true) {
  25 }
  26 
  27 inline
  28 ISIN_t::ISIN_t(block_t const &b) noexcept(true) {
  29         jmmcg::memcpy_opt(b, value.block);
  30 }
  31 
  32 template<std::size_t Sz>
  33 inline
  34 ISIN_t::ISIN_t(block_t::value_type const (&b)[Sz]) noexcept(true) {
  35         BOOST_MPL_ASSERT_RELATION(sizeof(block_t), ==, Sz-1);
  36         jmmcg::memcpy_opt(reinterpret_cast<block_t const &>(b), value.block);
  37 }
  38 
  39 inline bool
  40 ISIN_t::operator==(ISIN_t const &i) const noexcept(true) {
  41         return value.block==i.value.block;
  42 }
  43 
  44 inline std::string
  45 ISIN_t::to_string() const noexcept(false) {
  46         return std::string{value.block.begin(), value.block.end()};
  47 }
  48 
  49 inline uint64_t
  50 ISIN_t::hash() const noexcept(true) {
  51         const union {
  52                 ISIN_t isin;
  53                 uint64_t conv[(sizeof(ISIN_t)+sizeof(uint64_t)-1)/sizeof(uint64_t)];
  54         } c={
  55                 *this
  56         };
  57         return c.conv[0]^c.conv[1];
  58 }
  59 
  60 inline std::ostream &
  61 operator<<(std::ostream &os, ISIN_t const &i) noexcept(false) {
  62         os<<i.value.block;
  63         return os;
  64 }
  65 
  66 inline std::istream &
  67 operator>>(std::istream &is, ISIN_t &i) noexcept(false) {
  68         std::string tmp;
  69         is>>tmp;
  70         assert(tmp.size()<=sizeof(ISIN_t));
  71         jmmcg::memcpy_opt(reinterpret_cast<ISIN_t::block_t const &>(*tmp.data()), i.value.block);
  72         return is;
  73 }
  74 
  75 } } }

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