-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcolumn.hpp
81 lines (60 loc) · 1.61 KB
/
column.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
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
69
70
71
72
73
74
75
76
77
78
79
80
81
/**
* \file cppsas7bdat/filter/column.hpp
*
* \brief Column filter description
*
* \author Olivia Quinet
*/
#ifndef _CPP_SAS7BDAT_FILTER_COLUMN_HPP_
#define _CPP_SAS7BDAT_FILTER_COLUMN_HPP_
#include <set>
#include <string>
#include <cppsas7bdat/column.hpp>
namespace cppsas7bdat {
namespace ColumnFilter {
struct AcceptAll {
bool accept([[maybe_unused]] const Column &_column) const noexcept {
return true;
}
};
struct Include {
using NAMES = std::set<std::string>;
NAMES included;
bool accept(const Column &_column) const noexcept {
return is_accepted(_column.name);
}
bool is_accepted(const std::string &_name) const noexcept {
return is_included(_name);
}
bool is_included(const std::string &_name) const noexcept {
return included.find(_name) != included.end();
}
};
struct Exclude {
using NAMES = std::set<std::string>;
NAMES excluded;
bool accept(const Column &_column) const noexcept {
return is_accepted(_column.name);
}
bool is_accepted(const std::string &_name) const noexcept {
return !is_excluded(_name);
}
bool is_excluded(const std::string &_name) const noexcept {
return excluded.find(_name) != excluded.end();
}
};
struct IncludeExclude : public Include, public Exclude {
bool accept(const Column &_column) const noexcept {
return is_accepted(_column.name);
}
bool is_accepted(const std::string &_name) const noexcept {
if (!included.empty())
return is_included(_name);
if (!excluded.empty())
return !is_excluded(_name);
return true;
}
};
} // namespace ColumnFilter
} // namespace cppsas7bdat
#endif