Mercurial > minori
comparison include/core/date.h @ 187:9613d72b097e
*: multiple performance improvements
like marking `static const` when it makes sense...
date: change old stupid heap-based method to a structure which should
make copying the thing actually make a copy.
also many performance-based changes, like removing the std::tie
dependency and forward-declaring nlohmann json
*: replace every instance of QString::fromUtf8 to Strings::ToQString.
the main difference is that our function will always convert exactly
what is in the string, while some other times it would only convert
up to the nearest NUL byte
author | Paper <mrpapersonic@gmail.com> |
---|---|
date | Wed, 06 Dec 2023 13:43:54 -0500 |
parents | f88eda79c60a |
children | f0ff06a45c42 |
comparison
equal
deleted
inserted
replaced
186:6ef31dbb90ca | 187:9613d72b097e |
---|---|
1 #ifndef __core__date_h | 1 #ifndef __core__date_h |
2 #define __core__date_h | 2 #define __core__date_h |
3 | 3 |
4 #include "core/json.h" | 4 #include "json/json_fwd.hpp" |
5 #include <QDate> | 5 |
6 #include <cstdint> | 6 class QDate; |
7 | 7 |
8 class Date { | 8 class Date { |
9 public: | 9 public: |
10 Date(); | 10 Date(); |
11 Date(unsigned int y); | 11 Date(unsigned int y); |
29 bool operator<=(const Date& other) const; | 29 bool operator<=(const Date& other) const; |
30 bool operator>=(const Date& other) const; | 30 bool operator>=(const Date& other) const; |
31 | 31 |
32 private: | 32 private: |
33 /* this implementation sucks and we should really use a struct instead */ | 33 /* this implementation sucks and we should really use a struct instead */ |
34 std::shared_ptr<unsigned int> year; | 34 template<typename T> |
35 std::shared_ptr<unsigned int> month; | 35 struct OptionalNumber { |
36 std::shared_ptr<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; | |
37 }; | 50 }; |
38 | 51 |
39 #endif // __core__date_h | 52 #endif // __core__date_h |