| 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 | * - Sergey Vasilevskiy |
| 35 | * - Doug Johnson |
| 36 | */ |
| 37 | |
| 38 | /* |
| 39 | * Contains class definition to generate Address table. |
| 40 | * Address table contains addresses for exchanges, companies, and customers. |
| 41 | */ |
| 42 | #ifndef ADDRESS_TABLE_H |
| 43 | #define ADDRESS_TABLE_H |
| 44 | |
| 45 | #include "EGenTables_common.h" |
| 46 | |
| 47 | #include "input/DataFileManager.h" |
| 48 | |
| 49 | namespace TPCE { |
| 50 | |
| 51 | class CAddressTable : public TableTemplate<ADDRESS_ROW> { |
| 52 | private: |
| 53 | CDateTime m_date_time; |
| 54 | const CCompanyFile &m_companies; |
| 55 | const StreetNameDataFile_t &m_Street; |
| 56 | const StreetSuffixDataFile_t &m_StreetSuffix; |
| 57 | const ZipCodeDataFile_t &m_ZipCode; |
| 58 | TIdent m_iStartFromCustomer; |
| 59 | TIdent m_iCustomerCount; // total # of customers for whom to generate addresses |
| 60 | bool m_bCustomerAddressesOnly; // whether generating only customer addresses |
| 61 | bool m_bCustomerAddress; // whether the currently generated row is for a |
| 62 | // customer |
| 63 | TIdent m_iCompanyCount; // total # of companies for which to generate addresses |
| 64 | UINT m_iExchangeCount; // total # of exchanges for which to generate |
| 65 | // addresses |
| 66 | TIdent m_iTotalAddressCount; // total # of address rows to generate |
| 67 | bool m_bCacheEnabled; |
| 68 | int m_iCacheSize; |
| 69 | TIdent m_iCacheOffset; |
| 70 | int *m_CacheZipCode; |
| 71 | const int INVALID_CACHE_ENTRY; |
| 72 | |
| 73 | /* |
| 74 | * Generate AD_LINE_1 and store it in the record structure. |
| 75 | * Does not increment the number of rows generated. |
| 76 | * |
| 77 | * PARAMETERS: |
| 78 | * none. |
| 79 | * |
| 80 | * RETURNS: |
| 81 | * none. |
| 82 | */ |
| 83 | void GenerateAD_LINE_1(); |
| 84 | /* |
| 85 | * Generate AD_LINE_2 and store it in the record structure. |
| 86 | * Does not increment the number of rows generated. |
| 87 | * |
| 88 | * PARAMETERS: |
| 89 | * none. |
| 90 | * |
| 91 | * RETURNS: |
| 92 | * none. |
| 93 | */ |
| 94 | void GenerateAD_LINE_2(); |
| 95 | /* |
| 96 | * For a given address id returns the same Threshold used to |
| 97 | * select the town, division, zip, and country. |
| 98 | * Needed to return a specific division/country for a given address id |
| 99 | * (for customer tax rates). |
| 100 | * |
| 101 | * PARAMETERS: |
| 102 | * IN ADID - address id |
| 103 | * |
| 104 | * RETURNS: |
| 105 | * none. |
| 106 | */ |
| 107 | int GetTownDivisionZipCodeThreshold(TIdent ADID); |
| 108 | /* |
| 109 | * Return the country code code for a given zip code. |
| 110 | * |
| 111 | * PARAMETERS: |
| 112 | * IN szZipCode - string with a US or Canada zip code |
| 113 | * |
| 114 | * RETURNS: |
| 115 | * country code. |
| 116 | */ |
| 117 | UINT GetCountryCode(const char *pZipCode); |
| 118 | /* |
| 119 | * Generate zip code and country for the current address id |
| 120 | * and store them in the record structure. |
| 121 | * Does not increment the number of rows generated. |
| 122 | * |
| 123 | * PARAMETERS: |
| 124 | * none. |
| 125 | * |
| 126 | * RETURNS: |
| 127 | * none. |
| 128 | */ |
| 129 | void GenerateAD_ZC_CODE_CTRY(); |
| 130 | |
| 131 | public: |
| 132 | /* |
| 133 | * Constructor for the ADDRESS table class. |
| 134 | * |
| 135 | * PARAMETERS: |
| 136 | * IN dfm - input flat files loaded in memory |
| 137 | * IN iCustomerCount - number of customers to generate |
| 138 | * IN iStartFromCustomer - ordinal position of the first |
| 139 | * customer in the sequence (Note: 1-based) for whom to generate the |
| 140 | * addresses. Used if generating customer addresses only. IN |
| 141 | * bCustomerAddressesOnly - if true, generate only customer addresses if |
| 142 | * false, generate exchange, company, and customer addresses (always start |
| 143 | * from the first customer in this case) RETURNS: not applicable. |
| 144 | */ |
| 145 | CAddressTable(const DataFileManager &dfm, TIdent iCustomerCount, TIdent iStartFromCustomer, |
| 146 | bool bCustomerAddressesOnly = false, bool bCacheEnabled = false); |
| 147 | |
| 148 | /* |
| 149 | * Destructor for the ADDRESS table class. |
| 150 | * |
| 151 | * PARAMETERS: |
| 152 | * none. |
| 153 | * |
| 154 | * RETURNS: |
| 155 | * not applicable. |
| 156 | */ |
| 157 | ~CAddressTable(); |
| 158 | |
| 159 | /* |
| 160 | * Reset the state for the next load unit. |
| 161 | * |
| 162 | * PARAMETERS: |
| 163 | * none. |
| 164 | * |
| 165 | * RETURNS: |
| 166 | * none. |
| 167 | */ |
| 168 | void InitNextLoadUnit(); |
| 169 | |
| 170 | /* |
| 171 | * Generates the next A_ID value. |
| 172 | * It is stored in the internal record structure and also returned. |
| 173 | * The number of rows generated is incremented. This is why |
| 174 | * this function cannot be called more than once for a record. |
| 175 | * |
| 176 | * PARAMETERS: |
| 177 | * none. |
| 178 | * |
| 179 | * RETURNS: |
| 180 | * next address id. |
| 181 | */ |
| 182 | TIdent GenerateNextAD_ID(); |
| 183 | |
| 184 | /* |
| 185 | * Returns the address id of the customer specified by the customer id. |
| 186 | * |
| 187 | * PARAMETERS: |
| 188 | * IN C_ID - customer id (1-based) |
| 189 | * |
| 190 | * RETURNS: |
| 191 | * address id. |
| 192 | */ |
| 193 | TIdent GetAD_IDForCustomer(TIdent C_ID); // return address id for the customer id |
| 194 | |
| 195 | /* |
| 196 | * Return a certain division/country code (from the input file) for a |
| 197 | * given address id. Used in the loader to properly calculate tax on a |
| 198 | * trade. |
| 199 | * |
| 200 | * PARAMETERS: |
| 201 | * IN AD_ID - address id |
| 202 | * OUT iDivCode - division (state/province) code |
| 203 | * OUT iCtryCode - country (USA/CANADA) code |
| 204 | * |
| 205 | * RETURNS: |
| 206 | * none. |
| 207 | */ |
| 208 | void GetDivisionAndCountryCodesForAddress(TIdent AD_ID, UINT &iDivCode, UINT &iCtryCode); |
| 209 | |
| 210 | /* |
| 211 | * Return division and country codes for current address. |
| 212 | * Used in generating customer taxrates. |
| 213 | * |
| 214 | * PARAMETERS: |
| 215 | * OUT iDivCode - division (state/province) code |
| 216 | * OUT iCtryCode - country (USA/CANADA) code |
| 217 | * |
| 218 | * RETURNS: |
| 219 | * none. |
| 220 | */ |
| 221 | void GetDivisionAndCountryCodes(UINT &iDivCode, UINT &iCtryCode) { |
| 222 | GetDivisionAndCountryCodesForAddress(m_row.AD_ID, iDivCode, iCtryCode); |
| 223 | } |
| 224 | |
| 225 | /* |
| 226 | * Generate all column values for the next row |
| 227 | * and store them in the record structure. |
| 228 | * Increment the number of rows generated. |
| 229 | * |
| 230 | * PARAMETERS: |
| 231 | * none. |
| 232 | * |
| 233 | * RETURNS: |
| 234 | * TRUE, if there are more records in the ADDRESS table; FALSE |
| 235 | * othewise. |
| 236 | */ |
| 237 | bool GenerateNextRecord(); // generates the next table row |
| 238 | }; |
| 239 | |
| 240 | } // namespace TPCE |
| 241 | |
| 242 | #endif // ADDRESS_TABLE_H |
| 243 | |