1 | #ifndef DATA_FILE_MANAGER_H |
2 | #define DATA_FILE_MANAGER_H |
3 | |
4 | /* |
5 | * Legal Notice |
6 | * |
7 | * This document and associated source code (the "Work") is a part of a |
8 | * benchmark specification maintained by the TPC. |
9 | * |
10 | * The TPC reserves all right, title, and interest to the Work as provided |
11 | * under U.S. and international laws, including without limitation all patent |
12 | * and trademark rights therein. |
13 | * |
14 | * No Warranty |
15 | * |
16 | * 1.1 TO THE MAXIMUM EXTENT PERMITTED BY APPLICABLE LAW, THE INFORMATION |
17 | * CONTAINED HEREIN IS PROVIDED "AS IS" AND WITH ALL FAULTS, AND THE |
18 | * AUTHORS AND DEVELOPERS OF THE WORK HEREBY DISCLAIM ALL OTHER |
19 | * WARRANTIES AND CONDITIONS, EITHER EXPRESS, IMPLIED OR STATUTORY, |
20 | * INCLUDING, BUT NOT LIMITED TO, ANY (IF ANY) IMPLIED WARRANTIES, |
21 | * DUTIES OR CONDITIONS OF MERCHANTABILITY, OF FITNESS FOR A PARTICULAR |
22 | * PURPOSE, OF ACCURACY OR COMPLETENESS OF RESPONSES, OF RESULTS, OF |
23 | * WORKMANLIKE EFFORT, OF LACK OF VIRUSES, AND OF LACK OF NEGLIGENCE. |
24 | * ALSO, THERE IS NO WARRANTY OR CONDITION OF TITLE, QUIET ENJOYMENT, |
25 | * QUIET POSSESSION, CORRESPONDENCE TO DESCRIPTION OR NON-INFRINGEMENT |
26 | * WITH REGARD TO THE WORK. |
27 | * 1.2 IN NO EVENT WILL ANY AUTHOR OR DEVELOPER OF THE WORK BE LIABLE TO |
28 | * ANY OTHER PARTY FOR ANY DAMAGES, INCLUDING BUT NOT LIMITED TO THE |
29 | * COST OF PROCURING SUBSTITUTE GOODS OR SERVICES, LOST PROFITS, LOSS |
30 | * OF USE, LOSS OF DATA, OR ANY INCIDENTAL, CONSEQUENTIAL, DIRECT, |
31 | * INDIRECT, OR SPECIAL DAMAGES WHETHER UNDER CONTRACT, TORT, WARRANTY, |
32 | * OR OTHERWISE, ARISING IN ANY WAY OUT OF THIS OR ANY OTHER AGREEMENT |
33 | * RELATING TO THE WORK, WHETHER OR NOT SUCH AUTHOR OR DEVELOPER HAD |
34 | * ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. |
35 | * |
36 | * Contributors |
37 | * - Doug Johnson |
38 | */ |
39 | |
40 | #include <istream> |
41 | #include <string> |
42 | |
43 | #include "DataFileTypes.h" |
44 | #include "StreamSplitter.h" |
45 | |
46 | #include "utilities/EGenStandardTypes.h" |
47 | #include "CompanyCompetitorFile.h" |
48 | #include "CompanyFile.h" |
49 | #include "SecurityFile.h" |
50 | #include "TaxRateFile.h" |
51 | #include "utilities/MiscConsts.h" |
52 | |
53 | namespace TPCE { |
54 | // |
55 | // Description: |
56 | // A class for managing all data files. There are several important |
57 | // characteristics of this class. |
58 | // |
59 | // - Thread Saftey. This class is currently not thread safe. The onus is on |
60 | // the client to make sure this class is used safely in a multi-threaded |
61 | // environment. |
62 | // |
63 | // - Load Type. This class supports both immediate and lazy loading of the data |
64 | // files. The type of load can be specified at object creation time. |
65 | // |
66 | // - Const-ness. Because of the lazy-load, const-correctness is a bit funky. In |
67 | // general, logical constness is what is honored. Public interfaces that clearly |
68 | // alter things are not considered const but lazy loading of a file on file |
69 | // access is considered const even though that lazy load may trigger an |
70 | // exception (e.g. if the file doesn't exist). |
71 | // |
72 | // Exception Safety: |
73 | // The Basic guarantee is provided. |
74 | // |
75 | // Copy Behavior: |
76 | // Copying is disallowed. |
77 | // |
78 | class DataFileManager { |
79 | private: |
80 | // Disallow copying. |
81 | DataFileManager(const DataFileManager &); |
82 | DataFileManager &operator=(const DataFileManager &); |
83 | |
84 | // Customer counts needed for scaling file abstractions. |
85 | TIdent configuredCustomers; |
86 | TIdent activeCustomers; |
87 | |
88 | // Data Files (mutable to support const-appearing lazy load) |
89 | mutable AreaCodeDataFile_t *areaCodeDataFile; |
90 | mutable ChargeDataFile_t *chargeDataFile; |
91 | mutable CommissionRateDataFile_t *commissionRateDataFile; |
92 | mutable CompanyCompetitorDataFile_t *companyCompetitorDataFile; |
93 | mutable CompanyDataFile_t *companyDataFile; |
94 | mutable CompanySPRateDataFile_t *companySPRateDataFile; |
95 | mutable ExchangeDataFile_t *exchangeDataFile; |
96 | mutable FemaleFirstNameDataFile_t *femaleFirstNameDataFile; |
97 | mutable IndustryDataFile_t *industryDataFile; |
98 | mutable LastNameDataFile_t *lastNameDataFile; |
99 | mutable MaleFirstNameDataFile_t *maleFirstNameDataFile; |
100 | mutable NewsDataFile_t *newsDataFile; |
101 | mutable NonTaxableAccountNameDataFile_t *nonTaxableAccountNameDataFile; |
102 | mutable SectorDataFile_t *sectorDataFile; |
103 | mutable SecurityDataFile_t *securityDataFile; |
104 | mutable StatusTypeDataFile_t *statusTypeDataFile; |
105 | mutable StreetNameDataFile_t *streetNameDataFile; |
106 | mutable StreetSuffixDataFile_t *streetSuffixDataFile; |
107 | mutable TaxableAccountNameDataFile_t *taxableAccountNameDataFile; |
108 | mutable TaxRateCountryDataFile_t *taxRateCountryDataFile; |
109 | mutable TaxRateDivisionDataFile_t *taxRateDivisionDataFile; |
110 | mutable TradeTypeDataFile_t *tradeTypeDataFile; |
111 | mutable ZipCodeDataFile_t *zipCodeDataFile; |
112 | |
113 | // Scaling Data File Abstractions (mutable to support const-appearing lazy |
114 | // load) |
115 | mutable CCompanyCompetitorFile *companyCompetitorFile; |
116 | mutable CCompanyFile *companyFile; |
117 | mutable CSecurityFile *securityFile; |
118 | mutable CTaxRateFile *taxRateFile; |
119 | |
120 | // Template for loading any file. |
121 | // Logically const for lazy load. |
122 | // If the file has already been loaded then no action is taken. |
123 | template <class SourceFileT, class SplitterT, class DataFileT> |
124 | void loadFile(SourceFileT sourceFile, DataFileT **dataFile) const { |
125 | // Only load if it hasn't already been loaded. |
126 | if (!(*dataFile)) { |
127 | SplitterT splitter(sourceFile); |
128 | *dataFile = new DataFileT(splitter); |
129 | } |
130 | } |
131 | |
132 | // Helper method for lazy loading (hence logically const) by file type. |
133 | void loadFile(DataFileType fileType) const; |
134 | |
135 | // Centralized clean up of any allocated resources. |
136 | void CleanUp(); |
137 | |
138 | public: |
139 | // Constructor - default to lazy load from the current directory |
140 | // for the default number of customers. |
141 | explicit DataFileManager(TIdent configuredCustomerCount = iDefaultCustomerCount, |
142 | TIdent activeCustomerCount = iDefaultCustomerCount); |
143 | |
144 | ~DataFileManager(); |
145 | |
146 | // Load a file using an istream. |
147 | void loadFile(std::istream &file, DataFileType fileType); |
148 | |
149 | // Load a file using a file type. |
150 | void loadFile(DataFileType fileType); |
151 | |
152 | // Accessors for files. |
153 | const AreaCodeDataFile_t &AreaCodeDataFile() const; |
154 | const ChargeDataFile_t &ChargeDataFile() const; |
155 | const CommissionRateDataFile_t &CommissionRateDataFile() const; |
156 | const CompanyCompetitorDataFile_t &CompanyCompetitorDataFile() const; |
157 | const CompanyDataFile_t &CompanyDataFile() const; |
158 | const CompanySPRateDataFile_t &CompanySPRateDataFile() const; |
159 | const ExchangeDataFile_t &ExchangeDataFile() const; |
160 | const FemaleFirstNameDataFile_t &FemaleFirstNameDataFile() const; |
161 | const IndustryDataFile_t &IndustryDataFile() const; |
162 | const LastNameDataFile_t &LastNameDataFile() const; |
163 | const MaleFirstNameDataFile_t &MaleFirstNameDataFile() const; |
164 | const NewsDataFile_t &NewsDataFile() const; |
165 | const NonTaxableAccountNameDataFile_t &NonTaxableAccountNameDataFile() const; |
166 | const SectorDataFile_t &SectorDataFile() const; |
167 | const SecurityDataFile_t &SecurityDataFile() const; |
168 | const StatusTypeDataFile_t &StatusTypeDataFile() const; |
169 | const StreetNameDataFile_t &StreetNameDataFile() const; |
170 | const StreetSuffixDataFile_t &StreetSuffixDataFile() const; |
171 | const TaxableAccountNameDataFile_t &TaxableAccountNameDataFile() const; |
172 | const TaxRateCountryDataFile_t &TaxRateCountryDataFile() const; |
173 | const TaxRateDivisionDataFile_t &TaxRateDivisionDataFile() const; |
174 | const TradeTypeDataFile_t &TradeTypeDataFile() const; |
175 | const ZipCodeDataFile_t &ZipCodeDataFile() const; |
176 | |
177 | // Data file abstractions. |
178 | const CCompanyCompetitorFile &CompanyCompetitorFile() const; |
179 | const CCompanyFile &CompanyFile() const; |
180 | const CSecurityFile &SecurityFile() const; |
181 | const CTaxRateFile &TaxRateFile() const; |
182 | }; |
183 | |
184 | } // namespace TPCE |
185 | #endif // DATA_FILE_MANAGER_H |
186 | |