diff options
Diffstat (limited to 'lib/order.h')
| -rw-r--r-- | lib/order.h | 69 |
1 files changed, 69 insertions, 0 deletions
| diff --git a/lib/order.h b/lib/order.h new file mode 100644 index 0000000..d2f0f92 --- /dev/null +++ b/lib/order.h | |||
| @@ -0,0 +1,69 @@ | |||
| 1 | #ifndef ORDER_H_0EC669D5 | ||
| 2 | #define ORDER_H_0EC669D5 | ||
| 3 | |||
| 4 | #include <stdexcept> | ||
| 5 | #include "field.h" | ||
| 6 | |||
| 7 | namespace verbly { | ||
| 8 | |||
| 9 | class order { | ||
| 10 | public: | ||
| 11 | enum class type { | ||
| 12 | random, | ||
| 13 | field | ||
| 14 | }; | ||
| 15 | |||
| 16 | // Type | ||
| 17 | |||
| 18 | type getType() const | ||
| 19 | { | ||
| 20 | return type_; | ||
| 21 | } | ||
| 22 | |||
| 23 | // Random | ||
| 24 | |||
| 25 | order() : type_(type::random) | ||
| 26 | { | ||
| 27 | } | ||
| 28 | |||
| 29 | // Field | ||
| 30 | |||
| 31 | order( | ||
| 32 | field arg, | ||
| 33 | bool asc = true) : | ||
| 34 | type_(type::field), | ||
| 35 | sortField_(std::move(arg)), | ||
| 36 | ascending_(asc) | ||
| 37 | { | ||
| 38 | } | ||
| 39 | |||
| 40 | field getSortField() const | ||
| 41 | { | ||
| 42 | if (type_ != type::field) | ||
| 43 | { | ||
| 44 | throw std::domain_error("Invalid access to non-field order"); | ||
| 45 | } | ||
| 46 | |||
| 47 | return sortField_; | ||
| 48 | } | ||
| 49 | |||
| 50 | bool isAscending() const | ||
| 51 | { | ||
| 52 | if (type_ != type::field) | ||
| 53 | { | ||
| 54 | throw std::domain_error("Invalid access to non-field order"); | ||
| 55 | } | ||
| 56 | |||
| 57 | return ascending_; | ||
| 58 | } | ||
| 59 | |||
| 60 | private: | ||
| 61 | type type_; | ||
| 62 | field sortField_; | ||
| 63 | bool ascending_; | ||
| 64 | |||
| 65 | }; | ||
| 66 | |||
| 67 | }; | ||
| 68 | |||
| 69 | #endif /* end of include guard: ORDER_H_0EC669D5 */ | ||
