libjmmcg  release_579_6_g8cffd
A C++ library containing an eclectic mix of useful, advanced components.
ref_data_impl.hpp
Go to the documentation of this file.
1 /******************************************************************************
2 ** Copyright © 2016 by J.M.McGuiness, isimud@hussar.me.uk
3 **
4 ** This library is free software; you can redistribute it and/or
5 ** modify it under the terms of the GNU Lesser General Public
6 ** License as published by the Free Software Foundation; either
7 ** version 2.1 of the License, or (at your option) any later version.
8 **
9 ** This library is distributed in the hope that it will be useful,
10 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
11 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 ** Lesser General Public License for more details.
13 **
14 ** You should have received a copy of the GNU Lesser General Public
15 ** License along with this library; if not, write to the Free Software
16 ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 */
18 
19 namespace isimud { namespace ISIMUD_VER_NAMESPACE { namespace exchanges { namespace MIT { namespace common {
20 
21 constexpr inline
22 ref_data::security_id_key::security_id_key(element_type const &isin) noexcept(true)
23 : isin_(isin) {
24 }
25 
26 inline
27 ref_data::security_id_key::security_id_key(ref_data::MF_Record const &mfr) noexcept(true)
28 : isin_(mfr.isin) {
29 }
30 
31 inline bool
32 ref_data::security_id_key::operator==(security_id_key const &sik) const noexcept(true) {
33  return isin_==sik.isin_;
34 }
35 
36 inline bool
37 ref_data::security_id_key::operator<(security_id_key const &sik) const noexcept(true) {
38  return isin_<sik.isin_;
39 }
40 
41 inline std::string
42 ref_data::security_id_key::to_string() const noexcept(false) {
43  std::ostringstream os;
44  os
45  <<"ISIN="<<isin_.to_string();
46  return os.str();
47 }
48 
49 inline ref_data::hash_security_id_key::element_type
50 ref_data::hash_security_id_key::operator()(security_id_key const sik) const noexcept {
51  return sik.isin_.hash();
52 }
53 
54 inline
55 ref_data::ref_data(std::istream &is) noexcept(false) {
56  libjmmcg::line_iterator line_it(is), eof;
57  while (line_it!=eof) {
58  libjmmcg::csv_iterator semicolon_it(*line_it, ';');
59  std::string sid=*semicolon_it;
60  assert(!sid.empty());
61  std::string isin=*std::next(semicolon_it, isin_field);
62  assert(!isin.empty());
63  const MF_Record mfr{
64  boost::lexical_cast<common::SecurityID_t>(sid),
65  boost::lexical_cast<security_id_key::element_type>(isin),
66  };
67  lookup_instrument_id_.emplace(security_id_key(mfr), mfr.instrument);
68  lookup_isin_.emplace(mfr.instrument, security_id_key(mfr));
69  ++line_it;
70  }
71 }
72 
73 inline std::string
74 ref_data::to_string() const noexcept(false) {
75  std::ostringstream os;
76  os
77  <<"lookup_instrument_id: size="<<lookup_instrument_id_.size()<<", ";
78  for (auto const &i : lookup_isin_) {
79  os
80  <<"security_id_key="<<i.first
81  <<", ISIN="<<i.second;
82  }
83  os
84  <<"lookup_isin: size="<<lookup_isin_.size()<<", ";
85  for (auto const &i : lookup_isin_) {
86  os
87  <<"ISIN="<<i.first
88  <<", security_id_key="<<i.second;
89  }
90  return os.str();
91 }
92 
93 inline std::ostream &
94 operator<<(std::ostream &os, ref_data::security_id_key const &sik) noexcept(false) {
95  os<<sik.to_string();
96  return os;
97 }
98 
99 inline std::ostream &
100 operator<<(std::ostream &os, ref_data const &rd) noexcept(false) {
101  os<<rd.to_string();
102  return os;
103 }
104 
105 } } } } }