1#ifndef STREAM_SPLITTER_H
2#define STREAM_SPLITTER_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 <deque>
42#include <string>
43
44#include "ITextSplitter.h"
45
46namespace TPCE {
47
48//
49// Description:
50// A class to split a text stream into a series of records made up
51// of fields.
52//
53// Exception Safety:
54// The Basic guarantee is provided.
55//
56// Copy Behavior:
57// Copying is disallowed.
58//
59
60class StreamSplitter : public ITextSplitter {
61private:
62 char recordDelim;
63 char fieldDelim;
64 std::istream &stream;
65
66 // Copying a StreamSplitter doesn't make sense so disallow it.
67 StreamSplitter(const StreamSplitter &);
68 StreamSplitter &operator=(const StreamSplitter &);
69
70public:
71 static const char DEFAULT_RECORD_DELIMITER = '\n';
72 static const char DEFAULT_FIELD_DELIMITER = '\t';
73
74 explicit StreamSplitter(std::istream &textStream, char recordDelimiter = DEFAULT_RECORD_DELIMITER,
75 char fieldDelimiter = DEFAULT_FIELD_DELIMITER);
76 //~StreamSplitter() - default destructor is ok.
77
78 // ITextSplitter implementation
79 bool eof() const;
80 std::deque<std::string> getNextRecord();
81};
82
83} // namespace TPCE
84#endif // STREAM_SPLITTER_H
85