Mercurial > minori
comparison include/core/date.h @ 196:f0ff06a45c42
date: use std::optional for values
| author | Paper <mrpapersonic@gmail.com> |
|---|---|
| date | Thu, 07 Dec 2023 16:28:11 -0500 |
| parents | 9613d72b097e |
| children | c4ca035c565d |
comparison
equal
deleted
inserted
replaced
| 195:975a3f0965e2 | 196:f0ff06a45c42 |
|---|---|
| 1 #ifndef __core__date_h | 1 #ifndef __core__date_h |
| 2 #define __core__date_h | 2 #define __core__date_h |
| 3 | 3 |
| 4 #include "json/json_fwd.hpp" | 4 #include "json/json_fwd.hpp" |
| 5 | |
| 6 #include <optional> | |
| 5 | 7 |
| 6 class QDate; | 8 class QDate; |
| 7 | 9 |
| 8 class Date { | 10 class Date { |
| 9 public: | 11 public: |
| 28 bool operator>(const Date& other) const; | 30 bool operator>(const Date& other) const; |
| 29 bool operator<=(const Date& other) const; | 31 bool operator<=(const Date& other) const; |
| 30 bool operator>=(const Date& other) const; | 32 bool operator>=(const Date& other) const; |
| 31 | 33 |
| 32 private: | 34 private: |
| 33 /* this implementation sucks and we should really use a struct instead */ | 35 std::optional<unsigned int> year; |
| 34 template<typename T> | 36 std::optional<unsigned int> month; |
| 35 struct OptionalNumber { | 37 std::optional<unsigned int> day; |
| 36 public: | |
| 37 T Get() const { return enabled ? num : 0; } | |
| 38 bool Enabled() const { return enabled; } | |
| 39 void Set(T n) { num = n; enabled = true; } | |
| 40 void Void() { num = 0; enabled = false; } | |
| 41 | |
| 42 protected: | |
| 43 T num = 0; | |
| 44 bool enabled = false; | |
| 45 }; | |
| 46 | |
| 47 OptionalNumber<unsigned int> year; | |
| 48 OptionalNumber<unsigned int> month; | |
| 49 OptionalNumber<unsigned int> day; | |
| 50 }; | 38 }; |
| 51 | 39 |
| 52 #endif // __core__date_h | 40 #endif // __core__date_h |
