EHM DAL 0.2.3
Data abstraction layer for Eastside Hockey Manager
Loading...
Searching...
No Matches
year.h
1#pragma once
2
3// Application headers
4#include "include/data_types/data_type.h"
5
6// Qt headers
7class QString;
8#include <type_traits>
9
10namespace ehm_dal::data_types {
11template<class T>
12concept Short = std::is_same_v<qint16, T> || std::is_same_v<quint16, T>;
13
17template<Short T>
18class Year : public DataType<T>
19{
20public:
21 enum ENUM_FLAGS {
22 INVALID_YEAR = 1900,
23 MINIMUM_YEAR = 0,
24 MAXIMUM_YEAR = 2899 // This will prevent typos (e.g. 2900 instead of 1900)
25 };
26
27 Year(const T value = INVALID_YEAR);
28
29 // Compare data
34 bool compare(const QString &year) const;
35
36 // Get data
40 inline bool isInvalid() const { return !isValid(); }
44 inline bool isValid() const { return (this->value() > INVALID_YEAR); }
50 bool isWithinRange(const qint32 min, const qint32 max) const;
51
52 // Set data
58 void adjust(const qint32 adjustment_amount, const bool allow_pre_1901_years = false);
62 inline void reset() { this->setData(INVALID_YEAR, Qt::EditRole); }
67 void setIfLater(const Year &comparator);
72 void validate(const qint32 year);
73};
74} // namespace ehm_dal::data_types
The DataType class is a template class for all C++ integral and floating point data types.
Definition: data_type.h:18
T value() const
Returns the raw value which can otherwise be accessed via QVariant data(const qint32 role).
Definition: data_type.h:33
void setData(const QVariant &value, const qint32 role=Qt::EditRole)
Sets the role data for the item at to value.
Definition: data_type.h:167
The Year class represents a calendar year value. Only qint16 and quint16 are permissible.
Definition: year.h:19
bool isInvalid() const
Returns whether the year is invalid (i.e. <= 1900).
Definition: year.h:40
void adjust(const qint32 adjustment_amount, const bool allow_pre_1901_years=false)
Adjusts the year by adjustment amount.
void reset()
Resets the year to its default invalid value of ENUM_FLAGS::INVALID_YEAR.
Definition: year.h:62
bool isWithinRange(const qint32 min, const qint32 max) const
Returns whether the year is >= min and <= max
void validate(const qint32 year)
Sets the year to year if year is valid.
bool compare(const QString &year) const
Compares the current value with year.
bool isValid() const
Returns whether the year is valid (i.e. > 1900).
Definition: year.h:44
void setIfLater(const Year &comparator)
Sets the year to comparator if comparator is greater than the present value.
Definition: year.h:12
namespace ehm_dal::data_types
Definition: attribute.h:6