| 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/CommissionRateDataFileRecord.h" | 
|---|
| 38 |  | 
|---|
| 39 | #include <sstream> | 
|---|
| 40 | #include <stdexcept> | 
|---|
| 41 | #include <cstdlib> // for atoi, atof | 
|---|
| 42 | // #include <string> // C++11 for stoi, stod | 
|---|
| 43 |  | 
|---|
| 44 | #include "input/Utilities.h" | 
|---|
| 45 |  | 
|---|
| 46 | using namespace TPCE; | 
|---|
| 47 |  | 
|---|
| 48 | CommissionRateDataFileRecord::CommissionRateDataFileRecord(const std::deque<std::string> &fields) { | 
|---|
| 49 | if (fieldCount != fields.size()) { | 
|---|
| 50 | throw std::runtime_error( "Incorrect field count."); | 
|---|
| 51 | } | 
|---|
| 52 |  | 
|---|
| 53 | cr_c_tier = std::atoi(fields[0].c_str()); | 
|---|
| 54 | // cr_c_tier = std::stoi(fields[0]); // C++11 | 
|---|
| 55 |  | 
|---|
| 56 | DFRStringInit(fields[1], cr_tt_id, cr_tt_idCStr, maxCr_tt_idLen); | 
|---|
| 57 |  | 
|---|
| 58 | DFRStringInit(fields[2], cr_ex_id, cr_ex_idCStr, maxCr_ex_idLen); | 
|---|
| 59 |  | 
|---|
| 60 | cr_from_qty = std::atoi(fields[3].c_str()); | 
|---|
| 61 | // cr_from_qty = std::stoi(fields[3]); // C++11 | 
|---|
| 62 | cr_to_qty = std::atoi(fields[4].c_str()); | 
|---|
| 63 | // cr_to_qty = std::stoi(fields[4]); // C++11 | 
|---|
| 64 | cr_rate = std::atof(fields[5].c_str()); | 
|---|
| 65 | // cr_rate = std::stod(fields[5]); // C++11 | 
|---|
| 66 | } | 
|---|
| 67 |  | 
|---|
| 68 | int CommissionRateDataFileRecord::CR_C_TIER() const { | 
|---|
| 69 | return cr_c_tier; | 
|---|
| 70 | } | 
|---|
| 71 |  | 
|---|
| 72 | const std::string &CommissionRateDataFileRecord::CR_TT_ID() const { | 
|---|
| 73 | return cr_tt_id; | 
|---|
| 74 | } | 
|---|
| 75 |  | 
|---|
| 76 | const char *CommissionRateDataFileRecord::CR_TT_ID_CSTR() const { | 
|---|
| 77 | return cr_tt_idCStr; | 
|---|
| 78 | } | 
|---|
| 79 |  | 
|---|
| 80 | const std::string &CommissionRateDataFileRecord::CR_EX_ID() const { | 
|---|
| 81 | return cr_ex_id; | 
|---|
| 82 | } | 
|---|
| 83 |  | 
|---|
| 84 | const char *CommissionRateDataFileRecord::CR_EX_ID_CSTR() const { | 
|---|
| 85 | return cr_ex_idCStr; | 
|---|
| 86 | } | 
|---|
| 87 |  | 
|---|
| 88 | int CommissionRateDataFileRecord::CR_FROM_QTY() const { | 
|---|
| 89 | return cr_from_qty; | 
|---|
| 90 | } | 
|---|
| 91 |  | 
|---|
| 92 | int CommissionRateDataFileRecord::CR_TO_QTY() const { | 
|---|
| 93 | return cr_to_qty; | 
|---|
| 94 | } | 
|---|
| 95 |  | 
|---|
| 96 | double CommissionRateDataFileRecord::CR_RATE() const { | 
|---|
| 97 | return cr_rate; | 
|---|
| 98 | } | 
|---|
| 99 |  | 
|---|
| 100 | std::string CommissionRateDataFileRecord::ToString(char fieldSeparator) const { | 
|---|
| 101 | // Facilitate encapsulation by using public interface to fields. | 
|---|
| 102 | std::ostringstream msg; | 
|---|
| 103 | msg << CR_C_TIER() << fieldSeparator << CR_TT_ID() << fieldSeparator << CR_EX_ID() << fieldSeparator | 
|---|
| 104 | << CR_FROM_QTY() << fieldSeparator << CR_TO_QTY() << fieldSeparator << CR_RATE(); | 
|---|
| 105 | return msg.str(); | 
|---|
| 106 | } | 
|---|
| 107 |  | 
|---|