Mercurial > minori
annotate 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 |
| rev | line source |
|---|---|
| 9 | 1 #ifndef __core__date_h |
| 2 #define __core__date_h | |
| 85 | 3 |
|
187
9613d72b097e
*: multiple performance improvements
Paper <mrpapersonic@gmail.com>
parents:
174
diff
changeset
|
4 #include "json/json_fwd.hpp" |
|
9613d72b097e
*: multiple performance improvements
Paper <mrpapersonic@gmail.com>
parents:
174
diff
changeset
|
5 |
|
9613d72b097e
*: multiple performance improvements
Paper <mrpapersonic@gmail.com>
parents:
174
diff
changeset
|
6 class QDate; |
| 85 | 7 |
| 9 | 8 class Date { |
| 9 public: | |
| 10 Date(); | |
| 51 | 11 Date(unsigned int y); |
| 12 Date(unsigned int y, unsigned int m, unsigned int d); | |
| 13 Date(const QDate& date); | |
|
174
f88eda79c60a
anime/db: add some more json functionality, still doesn't compile :/
Paper <mrpapersonic@gmail.com>
parents:
85
diff
changeset
|
14 Date(const nlohmann::json& json); |
|
47
d8eb763e6661
information.cpp: add widgets to the list tab, and add an
Paper <mrpapersonic@gmail.com>
parents:
9
diff
changeset
|
15 bool IsValid() const; |
| 51 | 16 void SetYear(unsigned int y); |
| 17 void SetMonth(unsigned int m); | |
| 18 void SetDay(unsigned int d); | |
| 9 | 19 void VoidYear(); |
| 20 void VoidMonth(); | |
| 21 void VoidDay(); | |
| 51 | 22 unsigned int GetYear() const; |
| 23 unsigned int GetMonth() const; | |
| 24 unsigned int GetDay() const; | |
| 9 | 25 QDate GetAsQDate() const; |
| 26 nlohmann::json GetAsAniListJson() const; | |
| 27 bool operator<(const Date& other) const; | |
| 28 bool operator>(const Date& other) const; | |
| 29 bool operator<=(const Date& other) const; | |
| 30 bool operator>=(const Date& other) const; | |
| 31 | |
| 32 private: | |
|
174
f88eda79c60a
anime/db: add some more json functionality, still doesn't compile :/
Paper <mrpapersonic@gmail.com>
parents:
85
diff
changeset
|
33 /* this implementation sucks and we should really use a struct instead */ |
|
187
9613d72b097e
*: multiple performance improvements
Paper <mrpapersonic@gmail.com>
parents:
174
diff
changeset
|
34 template<typename T> |
|
9613d72b097e
*: multiple performance improvements
Paper <mrpapersonic@gmail.com>
parents:
174
diff
changeset
|
35 struct OptionalNumber { |
|
9613d72b097e
*: multiple performance improvements
Paper <mrpapersonic@gmail.com>
parents:
174
diff
changeset
|
36 public: |
|
9613d72b097e
*: multiple performance improvements
Paper <mrpapersonic@gmail.com>
parents:
174
diff
changeset
|
37 T Get() const { return enabled ? num : 0; } |
|
9613d72b097e
*: multiple performance improvements
Paper <mrpapersonic@gmail.com>
parents:
174
diff
changeset
|
38 bool Enabled() const { return enabled; } |
|
9613d72b097e
*: multiple performance improvements
Paper <mrpapersonic@gmail.com>
parents:
174
diff
changeset
|
39 void Set(T n) { num = n; enabled = true; } |
|
9613d72b097e
*: multiple performance improvements
Paper <mrpapersonic@gmail.com>
parents:
174
diff
changeset
|
40 void Void() { num = 0; enabled = false; } |
|
9613d72b097e
*: multiple performance improvements
Paper <mrpapersonic@gmail.com>
parents:
174
diff
changeset
|
41 |
|
9613d72b097e
*: multiple performance improvements
Paper <mrpapersonic@gmail.com>
parents:
174
diff
changeset
|
42 protected: |
|
9613d72b097e
*: multiple performance improvements
Paper <mrpapersonic@gmail.com>
parents:
174
diff
changeset
|
43 T num = 0; |
|
9613d72b097e
*: multiple performance improvements
Paper <mrpapersonic@gmail.com>
parents:
174
diff
changeset
|
44 bool enabled = false; |
|
9613d72b097e
*: multiple performance improvements
Paper <mrpapersonic@gmail.com>
parents:
174
diff
changeset
|
45 }; |
|
9613d72b097e
*: multiple performance improvements
Paper <mrpapersonic@gmail.com>
parents:
174
diff
changeset
|
46 |
|
9613d72b097e
*: multiple performance improvements
Paper <mrpapersonic@gmail.com>
parents:
174
diff
changeset
|
47 OptionalNumber<unsigned int> year; |
|
9613d72b097e
*: multiple performance improvements
Paper <mrpapersonic@gmail.com>
parents:
174
diff
changeset
|
48 OptionalNumber<unsigned int> month; |
|
9613d72b097e
*: multiple performance improvements
Paper <mrpapersonic@gmail.com>
parents:
174
diff
changeset
|
49 OptionalNumber<unsigned int> day; |
| 9 | 50 }; |
| 85 | 51 |
| 9 | 52 #endif // __core__date_h |
