| 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 | * Description: Implementation of the Security input file that scales |
| 40 | * with the database size. |
| 41 | ******************************************************************************/ |
| 42 | |
| 43 | #ifndef SECURITY_FILE_H |
| 44 | #define SECURITY_FILE_H |
| 45 | |
| 46 | #include <map> |
| 47 | #include <cassert> |
| 48 | |
| 49 | #include "utilities/EGenStandardTypes.h" |
| 50 | #include "DataFileTypes.h" |
| 51 | #include "main/ExchangeIDs.h" |
| 52 | |
| 53 | namespace TPCE { |
| 54 | |
| 55 | class CSecurityFile { |
| 56 | SecurityDataFile_t const *m_dataFile; |
| 57 | |
| 58 | // Total number of securities in the database. |
| 59 | // Depends on the total number of customers. |
| 60 | // |
| 61 | TIdent m_iConfiguredSecurityCount; |
| 62 | TIdent m_iActiveSecurityCount; |
| 63 | |
| 64 | // Number of base companies (=rows in Company.txt input file). |
| 65 | // |
| 66 | UINT m_iBaseCompanyCount; |
| 67 | |
| 68 | // Used to map a symbol to it's id value. To support logical const-ness |
| 69 | // these are mutable since they don't change the "real" contents of the |
| 70 | // Security File. |
| 71 | mutable bool m_SymbolToIdMapIsLoaded; |
| 72 | mutable std::map<std::string, TIdent> m_SymbolToIdMap; |
| 73 | mutable std::map<char, int> m_LowerCaseLetterToIntMap; |
| 74 | char m_SUFFIX_SEPARATOR; |
| 75 | |
| 76 | void CreateSuffix(TIdent Multiplier, char *pBuf, size_t BufSize) const; |
| 77 | INT64 ParseSuffix(const char *pSymbol) const; |
| 78 | |
| 79 | public: |
| 80 | // Constructor. |
| 81 | // |
| 82 | CSecurityFile(const SecurityDataFile_t &dataFile, TIdent iConfiguredCustomerCount, TIdent iActiveCustomerCount, |
| 83 | UINT baseCompanyCount); |
| 84 | |
| 85 | // Calculate total security count for the specified number of customers. |
| 86 | // Sort of a static method. Used in parallel generation of securities |
| 87 | // related tables. |
| 88 | // |
| 89 | TIdent CalculateSecurityCount(TIdent iCustomerCount) const; |
| 90 | |
| 91 | // Calculate the first security id (0-based) for the specified customer id |
| 92 | // |
| 93 | TIdent CalculateStartFromSecurity(TIdent iStartFromCustomer) const; |
| 94 | |
| 95 | // Create security symbol with mod/div magic. |
| 96 | // |
| 97 | // This function is needed to scale unique security |
| 98 | // symbols with the database size. |
| 99 | // |
| 100 | void CreateSymbol(TIdent iIndex, // row number |
| 101 | char *szOutput, // output buffer |
| 102 | size_t iOutputLen // size of the output buffer (including null) |
| 103 | ) const; |
| 104 | |
| 105 | // Return company id for the specified row of the SECURITY table. |
| 106 | // Index can exceed the size of the Security flat file. |
| 107 | // |
| 108 | TIdent GetCompanyId(TIdent iIndex) const; |
| 109 | |
| 110 | TIdent GetCompanyIndex(TIdent Index) const; |
| 111 | |
| 112 | // Return the number of securities in the database for |
| 113 | // a certain number of customers. |
| 114 | // |
| 115 | TIdent GetSize() const; |
| 116 | |
| 117 | // Return the number of securities in the database for |
| 118 | // the configured number of customers. |
| 119 | // |
| 120 | TIdent GetConfiguredSecurityCount() const; |
| 121 | |
| 122 | // Return the number of securities in the database for |
| 123 | // the active number of customers. |
| 124 | // |
| 125 | TIdent GetActiveSecurityCount() const; |
| 126 | |
| 127 | // Overload GetRecord to wrap around indices that |
| 128 | // are larger than the flat file |
| 129 | // |
| 130 | const SecurityDataFileRecord &GetRecord(TIdent index) const; |
| 131 | |
| 132 | // Load the symbol-to-id map |
| 133 | // Logical const-ness - the maps and the is-loaded flag may change but the |
| 134 | // "real" Security File data is unchanged. |
| 135 | bool LoadSymbolToIdMap(void) const; |
| 136 | |
| 137 | TIdent GetId(char *pSymbol) const; |
| 138 | |
| 139 | TIdent GetIndex(char *pSymbol) const; |
| 140 | |
| 141 | eExchangeID GetExchangeIndex(TIdent index) const; |
| 142 | }; |
| 143 | |
| 144 | } // namespace TPCE |
| 145 | |
| 146 | #endif // SECURITY_FILE_H |
| 147 | |