forked from Mooophy/Cpp-Primer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathqueryresult.cpp
41 lines (38 loc) · 839 Bytes
/
queryresult.cpp
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
#include "queryresult.h"
#include <iostream>
using std::ostream;
ostream&
print(ostream &os, const QueryResult &qr)
{
os <<"The result of your query "<< qr.sought <<" is: \n";
for (const auto &index: *qr.lines)
os << "\t(line " << index + 1 << ")"
<< *(qr.file->begin() + index) << "\n";
return os;
}
/*
Head is the first line of the range.
Trail is the last line of the range.
*/
ostream&
print(ostream& os, const QueryResult &qr, size_t head, size_t trail)
{
if (head > trail)
{
os << "illegal range!\n";
return os;
}
else
{
os << "The result of your query " << qr.sought << " is: \n";
for (const auto &index : *qr.lines)
{
if (index + 1 >= head&&index + 1 <= trail)
{
os << "\t(line " << index + 1 << ")"
<< *(qr.file->begin() + index) << "\n";
}
}
return os;
}
}