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 | */ |
36 | |
37 | /* |
38 | * This template represents a general table class. |
39 | * The type specified is the type of the table row. |
40 | */ |
41 | #ifndef TABLE_TEMPLATE_H |
42 | #define TABLE_TEMPLATE_H |
43 | |
44 | #include <cstring> |
45 | |
46 | #include "utilities/EGenStandardTypes.h" |
47 | #include "utilities/Random.h" |
48 | #include "utilities/RNGSeeds.h" |
49 | |
50 | namespace TPCE { |
51 | |
52 | template <typename T> class TableTemplate { |
53 | protected: |
54 | T m_row; // private row for generation |
55 | TIdent m_iLastRowNumber; // sequential last row number |
56 | bool m_bMoreRecords; // true if more records can be generated, otherwise |
57 | // false |
58 | CRandom m_rnd; // random generator - present in all tables |
59 | public: |
60 | /* |
61 | * The Constructor - just initializes member variables. |
62 | * |
63 | * PARAMETERS: |
64 | * not applicable. |
65 | * |
66 | * RETURNS: |
67 | * not applicable. |
68 | */ |
69 | TableTemplate() |
70 | : m_iLastRowNumber(0), m_bMoreRecords(false) // assume |
71 | { |
72 | ClearRecord(); // zero the row |
73 | |
74 | m_rnd.SetSeed(RNGSeedTableDefault); |
75 | } |
76 | |
77 | /* |
78 | * Virtual destructor. Provided so that a sponsor-specific |
79 | * destructor can be called on destruction from the base-class pointer. |
80 | * |
81 | * PARAMETERS: |
82 | * none. |
83 | * |
84 | * RETURNS: |
85 | * not applicable. |
86 | */ |
87 | virtual ~TableTemplate(){}; |
88 | |
89 | /* |
90 | * Generate the next record (row). |
91 | * |
92 | * PARAMETERS: |
93 | * none. |
94 | * |
95 | * RETURNS: |
96 | * true - if more records are available in the table. |
97 | * false - if no more records can be generated. |
98 | */ |
99 | virtual bool GenerateNextRecord() = 0; // abstract class |
100 | |
101 | /* |
102 | * Return whether all records in this table have been generated. |
103 | * |
104 | * PARAMETERS: |
105 | * none. |
106 | * |
107 | * RETURNS: |
108 | * true - if more records are available in the table. |
109 | * false - if no more records can be generated. |
110 | */ |
111 | bool MoreRecords() { |
112 | return m_bMoreRecords; |
113 | } |
114 | |
115 | /* |
116 | * Return a reference to the data row. |
117 | * |
118 | * PARAMETERS: |
119 | * none. |
120 | * |
121 | * RETURNS: |
122 | * typed reference to internal row buffer. |
123 | */ |
124 | // T const * GetRow() { return &m_row; } |
125 | const T &GetRow() { |
126 | return m_row; |
127 | } |
128 | |
129 | /* |
130 | * Set the internal record buffer to zero. |
131 | * |
132 | * This routine allows bitwise comparison between two versions of a row, |
133 | * because it clears the unused bytes in string values |
134 | * (past the NULL terminators). |
135 | * |
136 | * Note: the record cannot contain any inter-record state information, |
137 | * or this information will be lost. |
138 | * |
139 | * PARAMETERS: |
140 | * none. |
141 | * |
142 | * RETURNS: |
143 | * none. |
144 | */ |
145 | void ClearRecord() { |
146 | memset(&m_row, 0, sizeof(m_row)); |
147 | } |
148 | }; |
149 | |
150 | } // namespace TPCE |
151 | |
152 | #endif // TABLE_TEMPLATE_H |
153 | |