comparison src/core/anime.cc @ 264:9a04802848c0

*: improve multiple things e.g. making some strings.cc functions modify strings in-place, improving m4_ax_have_qt.m4 code, making anime_db.cc rely on std::optional rather than std::shared_ptr (which was stupid anyway)
author Paper <paper@paper.us.eu.org>
date Thu, 11 Apr 2024 10:15:57 -0400
parents 862d0d8619f6
children ff0b2052b234
comparison
equal deleted inserted replaced
263:96416310ea14 264:9a04802848c0
13 13
14 namespace Anime { 14 namespace Anime {
15 15
16 /* User list data */ 16 /* User list data */
17 bool Anime::IsInUserList() const { 17 bool Anime::IsInUserList() const {
18 if (list_info_.get()) 18 if (list_info_.has_value())
19 return true; 19 return true;
20 return false; 20 return false;
21 } 21 }
22 22
23 void Anime::AddToUserList() { 23 void Anime::AddToUserList() {
24 list_info_.reset(new ListInformation); 24 ListInformation list = {0};
25 list_info_.emplace(list);
25 } 26 }
26 27
27 void Anime::RemoveFromUserList() { 28 void Anime::RemoveFromUserList() {
28 list_info_.reset(); 29 list_info_.reset();
29 } 30 }
30 31
31 ListStatus Anime::GetUserStatus() const { 32 ListStatus Anime::GetUserStatus() const {
32 assert(list_info_.get()); 33 assert(list_info_.has_value());
33 return list_info_->status; 34 return list_info_->status;
34 } 35 }
35 36
36 int Anime::GetUserProgress() const { 37 int Anime::GetUserProgress() const {
37 assert(list_info_.get()); 38 assert(list_info_.has_value());
38 return list_info_->progress; 39 return list_info_->progress;
39 } 40 }
40 41
41 int Anime::GetUserScore() const { 42 int Anime::GetUserScore() const {
42 assert(list_info_.get()); 43 assert(list_info_.has_value());
43 return list_info_->score; 44 return list_info_->score;
44 } 45 }
45 46
46 std::string Anime::GetUserPresentableScore() const { 47 std::string Anime::GetUserPresentableScore() const {
47 assert(list_info_.get()); 48 assert(list_info_.has_value());
48 const int score = list_info_->score; 49 const int score = list_info_->score;
49 if (score == 0) 50 if (score == 0)
50 return ""; 51 return "";
51 52
52 switch (session.config.anime_list.score_format) { 53 switch (session.config.anime_list.score_format) {
75 case ScoreFormat::POINT_100: return Strings::ToUtf8String(score); 76 case ScoreFormat::POINT_100: return Strings::ToUtf8String(score);
76 } 77 }
77 } 78 }
78 79
79 Date Anime::GetUserDateStarted() const { 80 Date Anime::GetUserDateStarted() const {
80 assert(list_info_.get()); 81 assert(list_info_.has_value());
81 return list_info_->started; 82 return list_info_->started;
82 } 83 }
83 84
84 Date Anime::GetUserDateCompleted() const { 85 Date Anime::GetUserDateCompleted() const {
85 assert(list_info_.get()); 86 assert(list_info_.has_value());
86 return list_info_->completed; 87 return list_info_->completed;
87 } 88 }
88 89
89 bool Anime::GetUserIsPrivate() const { 90 bool Anime::GetUserIsPrivate() const {
90 assert(list_info_.get()); 91 assert(list_info_.has_value());
91 return list_info_->is_private; 92 return list_info_->is_private;
92 } 93 }
93 94
94 unsigned int Anime::GetUserRewatchedTimes() const { 95 unsigned int Anime::GetUserRewatchedTimes() const {
95 assert(list_info_.get()); 96 assert(list_info_.has_value());
96 return list_info_->rewatched_times; 97 return list_info_->rewatched_times;
97 } 98 }
98 99
99 bool Anime::GetUserIsRewatching() const { 100 bool Anime::GetUserIsRewatching() const {
100 assert(list_info_.get()); 101 assert(list_info_.has_value());
101 return list_info_->rewatching; 102 return list_info_->rewatching;
102 } 103 }
103 104
104 uint64_t Anime::GetUserTimeUpdated() const { 105 uint64_t Anime::GetUserTimeUpdated() const {
105 assert(list_info_.get()); 106 assert(list_info_.has_value());
106 return list_info_->updated; 107 return list_info_->updated;
107 } 108 }
108 109
109 std::string Anime::GetUserNotes() const { 110 std::string Anime::GetUserNotes() const {
110 assert(list_info_.get()); 111 assert(list_info_.has_value());
111 return list_info_->notes; 112 return list_info_->notes;
112 } 113 }
113 114
114 void Anime::SetUserStatus(ListStatus status) { 115 void Anime::SetUserStatus(ListStatus status) {
115 assert(list_info_.get()); 116 assert(list_info_.has_value());
116 list_info_->status = status; 117 list_info_->status = status;
117 } 118 }
118 119
119 void Anime::SetUserScore(int score) { 120 void Anime::SetUserScore(int score) {
120 assert(list_info_.get()); 121 assert(list_info_.has_value());
121 list_info_->score = score; 122 list_info_->score = score;
122 } 123 }
123 124
124 void Anime::SetUserProgress(int progress) { 125 void Anime::SetUserProgress(int progress) {
125 assert(list_info_.get()); 126 assert(list_info_.has_value());
126 list_info_->progress = progress; 127 list_info_->progress = progress;
127 } 128 }
128 129
129 void Anime::SetUserDateStarted(Date const& started) { 130 void Anime::SetUserDateStarted(Date const& started) {
130 assert(list_info_.get()); 131 assert(list_info_.has_value());
131 list_info_->started = started; 132 list_info_->started = started;
132 } 133 }
133 134
134 void Anime::SetUserDateCompleted(Date const& completed) { 135 void Anime::SetUserDateCompleted(Date const& completed) {
135 assert(list_info_.get()); 136 assert(list_info_.has_value());
136 list_info_->completed = completed; 137 list_info_->completed = completed;
137 } 138 }
138 139
139 void Anime::SetUserIsPrivate(bool is_private) { 140 void Anime::SetUserIsPrivate(bool is_private) {
140 assert(list_info_.get()); 141 assert(list_info_.has_value());
141 list_info_->is_private = is_private; 142 list_info_->is_private = is_private;
142 } 143 }
143 144
144 void Anime::SetUserRewatchedTimes(int rewatched) { 145 void Anime::SetUserRewatchedTimes(int rewatched) {
145 assert(list_info_.get()); 146 assert(list_info_.has_value());
146 list_info_->rewatched_times = rewatched; 147 list_info_->rewatched_times = rewatched;
147 } 148 }
148 149
149 void Anime::SetUserIsRewatching(bool rewatching) { 150 void Anime::SetUserIsRewatching(bool rewatching) {
150 assert(list_info_.get()); 151 assert(list_info_.has_value());
151 list_info_->rewatching = rewatching; 152 list_info_->rewatching = rewatching;
152 } 153 }
153 154
154 void Anime::SetUserTimeUpdated(uint64_t updated) { 155 void Anime::SetUserTimeUpdated(uint64_t updated) {
155 assert(list_info_.get()); 156 assert(list_info_.has_value());
156 list_info_->updated = updated; 157 list_info_->updated = updated;
157 } 158 }
158 159
159 void Anime::SetUserNotes(std::string const& notes) { 160 void Anime::SetUserNotes(std::string const& notes) {
160 assert(list_info_.get()); 161 assert(list_info_.has_value());
161 list_info_->notes = notes; 162 list_info_->notes = notes;
162 } 163 }
163 164
164 /* Series data */ 165 /* Series data */
165 int Anime::GetId() const { 166 int Anime::GetId() const {