root/isimud/exchanges/MIT/common/ref_data_impl.hpp

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

INCLUDED FROM


DEFINITIONS

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

   1 /******************************************************************************
   2 ** $Header: svn+ssh://jmmcg@svn.code.sf.net/p/libjmmcg/code/trunk/libjmmcg/isimud/exchanges/MIT/common/ref_data_impl.hpp 2281 2018-04-28 09:39:05Z 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 MIT { namespace common {
  22 
  23 constexpr inline
  24 ref_data::security_id_key::security_id_key(element_type const &isin) noexcept(true)
  25 : isin_(isin) {
  26 }
  27 
  28 inline
  29 ref_data::security_id_key::security_id_key(ref_data::MF_Record const &mfr) noexcept(true)
  30 : isin_(mfr.isin) {
  31 }
  32 
  33 inline bool
  34 ref_data::security_id_key::operator==(security_id_key const &sik) const noexcept(true) {
  35         return isin_==sik.isin_;
  36 }
  37 
  38 inline std::string
  39 ref_data::security_id_key::to_string() const noexcept(false) {
  40         std::ostringstream os;
  41         os
  42                 <<"ISIN="<<isin_.to_string();
  43         return os.str();
  44 }
  45 
  46 inline ref_data::hash_security_id_key::element_type
  47 ref_data::hash_security_id_key::operator()(security_id_key const sik) const noexcept {
  48         return sik.isin_.hash();
  49 }
  50 
  51 inline
  52 ref_data::ref_data(std::istream &is) {
  53         std::string line;
  54         while (std::getline(is, line, '\n')) {
  55                 std::regex word_regex("(\"[^\"]+\")|[^;]+");
  56                 auto what=std::sregex_iterator(line.begin(), line.end(), word_regex);
  57                 auto wend=std::sregex_iterator();
  58                 std::smatch sid=*std::next(what, instrument_id_field);
  59                 std::smatch isin=*std::next(what, isin_field);
  60                 const MF_Record mfr{
  61                         boost::lexical_cast<common::SecurityID_t>(sid.str()),
  62                         boost::lexical_cast<security_id_key::element_type>(isin.str()),
  63                 };
  64                 lookup_instrument_id_.emplace(security_id_key(mfr), mfr.instrument);
  65                 lookup_isin_.emplace(mfr.instrument, security_id_key(mfr));
  66         }
  67 }
  68 
  69 inline std::string
  70 ref_data::to_string() const noexcept(false) {
  71         std::ostringstream os;
  72         os
  73                 <<"lookup_instrument_id: size="<<lookup_instrument_id_.size()<<", ";
  74         for (auto const &i : lookup_isin_) {
  75                 os
  76                         <<"security_id_key="<<i.first
  77                         <<", ISIN="<<i.second;
  78         }
  79         os
  80                 <<"lookup_isin: size="<<lookup_isin_.size()<<", ";
  81         for (auto const &i : lookup_isin_) {
  82                 os
  83                         <<"ISIN="<<i.first
  84                         <<", security_id_key="<<i.second;
  85         }
  86         return os.str();
  87 }
  88 
  89 inline std::ostream &
  90 operator<<(std::ostream &os, ref_data::security_id_key const &sik) noexcept(false) {
  91         os<<sik.to_string();
  92         return os;
  93 }
  94 
  95 inline std::ostream &
  96 operator<<(std::ostream &os, ref_data_t rd) noexcept(false) {
  97         os<<rd.to_string();
  98         return os;
  99 }
 100 
 101 } } } }

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