-
Notifications
You must be signed in to change notification settings - Fork 0
/
select.hpp
42 lines (35 loc) · 1.27 KB
/
select.hpp
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
#ifndef __SELECT_HPP__
#define __SELECT_HPP__
#include <cstring>
#include "spreadsheet.hpp"
class Select
{
public:
virtual ~Select() = default;
// Return true if the specified row should be selected.
virtual bool select(const Spreadsheet* sheet, int row) const = 0;
};
// A common type of criterion for selection is to perform a comparison based on
// the contents of one column. This class contains contains the logic needed
// for dealing with columns. Note that this class is also an abstract base
// class, derived from Select. It introduces a new select function (taking just
// a string) and implements the original interface in terms of this. Derived
// classes need only implement the new select function. You may choose to
// derive from Select or Select_Column at your convenience.
class Select_Column: public Select
{
protected:
int column;
public:
Select_Column(const Spreadsheet* sheet, const std::string& name)
{
column = sheet->get_column_by_name(name);
}
virtual bool select(const Spreadsheet* sheet, int row) const
{
return select(sheet->cell_data(row, column));
}
// Derived classes can instead implement this simpler interface.
virtual bool select(const std::string& s) const = 0;
};
#endif //__SELECT_HPP__