-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathScan.cpp
More file actions
68 lines (58 loc) · 1.23 KB
/
Scan.cpp
File metadata and controls
68 lines (58 loc) · 1.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#include "Scan.h"
#include <iostream>
#include <fstream>
#include <sstream>
ScanPlan::ScanPlan(char const *const name, RowCount const count)
: Plan(name), _count(count), _file("database.txt")
{
TRACE(true);
} // ScanPlan::ScanPlan
ScanPlan::~ScanPlan()
{
TRACE(true);
} // ScanPlan::~ScanPlan
Iterator *ScanPlan::init() const
{
TRACE(true);
return new ScanIterator(this);
} // ScanPlan::init
ScanIterator::ScanIterator(ScanPlan const *const plan) : _plan(plan), _count(0)
{
TRACE(true);
} // ScanIterator::ScanIterator
ScanIterator::~ScanIterator()
{
TRACE(true);
traceprintf("produced %lu of %lu rows\n",
(unsigned long)(_count),
(unsigned long)(_plan->_count));
} // ScanIterator::~ScanIterator
bool ScanIterator::next(Row &row)
{
TRACE(true);
if (_count >= _plan->_count)
return false;
if (_plan->_file.is_open())
{
if (getline(_plan->_file, _plan->_currentLine))
{
string str = _plan->_currentLine;
stringstream ss(str);
int num;
while (ss >> num)
{
row.record.push_back(num);
}
}
++_count;
return true;
// Successfully read a line
}
++_count;
return true;
} // ScanIterator::next
void ScanIterator::free(Row &row)
{
row.record = vector<int>();
TRACE(true);
} // ScanIterator::free