1/*
2 * Legal Notice
3 *
4 * This document and associated source code (the "Work") is a part of a
5 * benchmark specification maintained by the TPC.
6 *
7 * The TPC reserves all right, title, and interest to the Work as provided
8 * under U.S. and international laws, including without limitation all patent
9 * and trademark rights therein.
10 *
11 * No Warranty
12 *
13 * 1.1 TO THE MAXIMUM EXTENT PERMITTED BY APPLICABLE LAW, THE INFORMATION
14 * CONTAINED HEREIN IS PROVIDED "AS IS" AND WITH ALL FAULTS, AND THE
15 * AUTHORS AND DEVELOPERS OF THE WORK HEREBY DISCLAIM ALL OTHER
16 * WARRANTIES AND CONDITIONS, EITHER EXPRESS, IMPLIED OR STATUTORY,
17 * INCLUDING, BUT NOT LIMITED TO, ANY (IF ANY) IMPLIED WARRANTIES,
18 * DUTIES OR CONDITIONS OF MERCHANTABILITY, OF FITNESS FOR A PARTICULAR
19 * PURPOSE, OF ACCURACY OR COMPLETENESS OF RESPONSES, OF RESULTS, OF
20 * WORKMANLIKE EFFORT, OF LACK OF VIRUSES, AND OF LACK OF NEGLIGENCE.
21 * ALSO, THERE IS NO WARRANTY OR CONDITION OF TITLE, QUIET ENJOYMENT,
22 * QUIET POSSESSION, CORRESPONDENCE TO DESCRIPTION OR NON-INFRINGEMENT
23 * WITH REGARD TO THE WORK.
24 * 1.2 IN NO EVENT WILL ANY AUTHOR OR DEVELOPER OF THE WORK BE LIABLE TO
25 * ANY OTHER PARTY FOR ANY DAMAGES, INCLUDING BUT NOT LIMITED TO THE
26 * COST OF PROCURING SUBSTITUTE GOODS OR SERVICES, LOST PROFITS, LOSS
27 * OF USE, LOSS OF DATA, OR ANY INCIDENTAL, CONSEQUENTIAL, DIRECT,
28 * INDIRECT, OR SPECIAL DAMAGES WHETHER UNDER CONTRACT, TORT, WARRANTY,
29 * OR OTHERWISE, ARISING IN ANY WAY OUT OF THIS OR ANY OTHER AGREEMENT
30 * RELATING TO THE WORK, WHETHER OR NOT SUCH AUTHOR OR DEVELOPER HAD
31 * ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES.
32 *
33 * Contributors
34 * - Doug Johnson
35 */
36
37#include "input/ExchangeDataFileRecord.h"
38
39#include <iomanip>
40#include <sstream>
41#include <stdexcept>
42#include <cstdlib> // for atoi, atof
43// #include <string> // C++11 for stoi, stod
44
45#include "input/Utilities.h"
46
47using namespace TPCE;
48
49ExchangeDataFileRecord::ExchangeDataFileRecord(const std::deque<std::string> &fields) {
50 if (fieldCount != fields.size()) {
51 throw std::runtime_error("Incorrect field count.");
52 }
53
54 DFRStringInit(fields[0], ex_id, ex_idCStr, maxEx_idLen);
55
56 DFRStringInit(fields[1], ex_name, ex_nameCStr, maxEx_nameLen);
57
58 ex_open = std::atoi(fields[2].c_str());
59 // ex_open = std::stoi(fields[2]); // C++11
60 ex_close = std::atoi(fields[3].c_str());
61 // ex_close = std::stoi(fields[3]); // C++11
62
63 DFRStringInit(fields[4], ex_desc, ex_descCStr, maxEx_descLen);
64
65 ex_ad_id = std::atoi(fields[5].c_str());
66 // ex_ad_id = std::stoi(fields[5]); // C++11
67}
68
69const std::string &ExchangeDataFileRecord::EX_ID() const {
70 return ex_id;
71}
72
73const char *ExchangeDataFileRecord::EX_ID_CSTR() const {
74 return ex_idCStr;
75}
76
77const std::string &ExchangeDataFileRecord::EX_NAME() const {
78 return ex_name;
79}
80
81const char *ExchangeDataFileRecord::EX_NAME_CSTR() const {
82 return ex_nameCStr;
83}
84
85int ExchangeDataFileRecord::EX_OPEN() const {
86 return ex_open;
87}
88
89int ExchangeDataFileRecord::EX_CLOSE() const {
90 return ex_close;
91}
92
93const std::string &ExchangeDataFileRecord::EX_DESC() const {
94 return ex_desc;
95}
96
97const char *ExchangeDataFileRecord::EX_DESC_CSTR() const {
98 return ex_descCStr;
99}
100
101TIdent ExchangeDataFileRecord::EX_AD_ID() const {
102 return ex_ad_id;
103}
104
105std::string ExchangeDataFileRecord::ToString(char fieldSeparator) const {
106 // Facilitate encapsulation by using public interface to fields.
107 std::ostringstream msg;
108 msg << EX_ID() << fieldSeparator << EX_NAME() << fieldSeparator << std::setfill('0') << std::setw(4) << EX_OPEN()
109 << fieldSeparator << std::setfill('0') << std::setw(4) << EX_CLOSE() << fieldSeparator << EX_DESC()
110 << fieldSeparator << EX_AD_ID();
111 return msg.str();
112}
113