9
+ − 1 /*
+ − 2 * anime.cpp: defining of custom anime-related
+ − 3 * datatypes & variables
+ − 4 */
+ − 5 #include "core/anime.h"
+ − 6 #include "core/date.h"
+ − 7 #include "core/session.h"
+ − 8 #include <algorithm>
+ − 9 #include <chrono>
+ − 10 #include <cmath>
+ − 11 #include <string>
+ − 12 #include <vector>
+ − 13
+ − 14 namespace Anime {
+ − 15
+ − 16 /* User list data */
+ − 17 bool Anime::IsInUserList() const {
+ − 18 if (list_info_.get())
+ − 19 return true;
+ − 20 return false;
+ − 21 }
+ − 22
+ − 23 void Anime::AddToUserList() {
+ − 24 list_info_.reset(new ListInformation);
+ − 25 }
+ − 26
+ − 27 void Anime::RemoveFromUserList() {
+ − 28 list_info_.reset();
+ − 29 }
+ − 30
+ − 31 ListStatus Anime::GetUserStatus() const {
+ − 32 assert(list_info_.get());
+ − 33 return list_info_->status;
+ − 34 }
+ − 35
+ − 36 int Anime::GetUserProgress() const {
+ − 37 assert(list_info_.get());
+ − 38 return list_info_->progress;
+ − 39 }
+ − 40
+ − 41 int Anime::GetUserScore() const {
+ − 42 assert(list_info_.get());
+ − 43 return list_info_->score;
+ − 44 }
+ − 45
+ − 46 Date Anime::GetUserDateStarted() const {
+ − 47 assert(list_info_.get());
+ − 48 return list_info_->started;
+ − 49 }
+ − 50
+ − 51 Date Anime::GetUserDateCompleted() const {
+ − 52 assert(list_info_.get());
+ − 53 return list_info_->completed;
+ − 54 }
+ − 55
+ − 56 bool Anime::GetUserIsPrivate() const {
+ − 57 assert(list_info_.get());
+ − 58 return list_info_->is_private;
+ − 59 }
+ − 60
+ − 61 unsigned int Anime::GetUserRewatchedTimes() const {
+ − 62 assert(list_info_.get());
+ − 63 return list_info_->rewatched_times;
+ − 64 }
+ − 65
+ − 66 bool Anime::GetUserIsRewatching() const {
+ − 67 assert(list_info_.get());
+ − 68 return list_info_->rewatching;
+ − 69 }
+ − 70
+ − 71 uint64_t Anime::GetUserTimeUpdated() const {
+ − 72 assert(list_info_.get());
+ − 73 return list_info_->updated;
+ − 74 }
+ − 75
+ − 76 std::string Anime::GetUserNotes() const {
+ − 77 assert(list_info_.get());
+ − 78 return list_info_->notes;
+ − 79 }
+ − 80
+ − 81 void Anime::SetUserStatus(ListStatus status) {
+ − 82 assert(list_info_.get());
+ − 83 list_info_->status = status;
+ − 84 }
+ − 85
10
+ − 86 void Anime::SetUserScore(int score) {
+ − 87 assert(list_info_.get());
+ − 88 list_info_->score = score;
+ − 89 }
+ − 90
9
+ − 91 void Anime::SetUserProgress(int progress) {
+ − 92 assert(list_info_.get());
+ − 93 list_info_->progress = progress;
+ − 94 }
+ − 95
+ − 96 void Anime::SetUserDateStarted(Date const& started) {
+ − 97 assert(list_info_.get());
+ − 98 list_info_->started = started;
+ − 99 }
+ − 100
+ − 101 void Anime::SetUserDateCompleted(Date const& completed) {
+ − 102 assert(list_info_.get());
+ − 103 list_info_->completed = completed;
+ − 104 }
+ − 105
+ − 106 void Anime::SetUserIsPrivate(bool is_private) {
+ − 107 assert(list_info_.get());
+ − 108 list_info_->is_private = is_private;
+ − 109 }
+ − 110
+ − 111 void Anime::SetUserRewatchedTimes(int rewatched) {
+ − 112 assert(list_info_.get());
+ − 113 list_info_->rewatched_times = rewatched;
+ − 114 }
+ − 115
+ − 116 void Anime::SetUserIsRewatching(bool rewatching) {
+ − 117 assert(list_info_.get());
+ − 118 list_info_->rewatching = rewatching;
+ − 119 }
+ − 120
+ − 121 void Anime::SetUserTimeUpdated(uint64_t updated) {
+ − 122 assert(list_info_.get());
+ − 123 list_info_->updated = updated;
+ − 124 }
+ − 125
+ − 126 void Anime::SetUserNotes(std::string const& notes) {
+ − 127 assert(list_info_.get());
+ − 128 list_info_->notes = notes;
+ − 129 }
+ − 130
+ − 131 /* Series data */
+ − 132 int Anime::GetId() const {
+ − 133 return info_.id;
+ − 134 }
+ − 135
+ − 136 std::string Anime::GetRomajiTitle() const {
+ − 137 return info_.title.romaji;
+ − 138 }
+ − 139
+ − 140 std::string Anime::GetEnglishTitle() const {
+ − 141 return info_.title.english;
+ − 142 }
+ − 143
+ − 144 std::string Anime::GetNativeTitle() const {
+ − 145 return info_.title.native;
+ − 146 }
+ − 147
+ − 148 std::vector<std::string> Anime::GetTitleSynonyms() const {
+ − 149 std::vector<std::string> result;
+ − 150 #define IN_VECTOR(v, k) (std::count(v.begin(), v.end(), k))
36
+ − 151 #define ADD_TO_SYNONYMS(v, k) \
+ − 152 if (!k.empty() && !IN_VECTOR(v, k) && k != GetUserPreferredTitle()) \
9
+ − 153 v.push_back(k)
+ − 154 ADD_TO_SYNONYMS(result, info_.title.english);
+ − 155 ADD_TO_SYNONYMS(result, info_.title.romaji);
+ − 156 ADD_TO_SYNONYMS(result, info_.title.native);
+ − 157 for (auto& synonym : info_.synonyms) {
+ − 158 ADD_TO_SYNONYMS(result, synonym);
+ − 159 }
+ − 160 #undef ADD_TO_SYNONYMS
+ − 161 #undef IN_VECTOR
+ − 162 return result;
+ − 163 }
+ − 164
+ − 165 int Anime::GetEpisodes() const {
+ − 166 return info_.episodes;
+ − 167 }
+ − 168
+ − 169 SeriesStatus Anime::GetAiringStatus() const {
+ − 170 return info_.status;
+ − 171 }
+ − 172
+ − 173 Date Anime::GetAirDate() const {
+ − 174 return info_.air_date;
+ − 175 }
+ − 176
+ − 177 std::vector<std::string> Anime::GetGenres() const {
+ − 178 return info_.genres;
+ − 179 }
+ − 180
+ − 181 std::vector<std::string> Anime::GetProducers() const {
+ − 182 return info_.producers;
+ − 183 }
+ − 184
+ − 185 SeriesFormat Anime::GetFormat() const {
+ − 186 return info_.format;
+ − 187 }
+ − 188
+ − 189 SeriesSeason Anime::GetSeason() const {
+ − 190 return info_.season;
+ − 191 }
+ − 192
+ − 193 int Anime::GetAudienceScore() const {
+ − 194 return info_.audience_score;
+ − 195 }
+ − 196
+ − 197 std::string Anime::GetSynopsis() const {
+ − 198 return info_.synopsis;
+ − 199 }
+ − 200
+ − 201 int Anime::GetDuration() const {
+ − 202 return info_.duration;
+ − 203 }
+ − 204
+ − 205 void Anime::SetId(int id) {
+ − 206 info_.id = id;
+ − 207 }
+ − 208
+ − 209 void Anime::SetRomajiTitle(std::string const& title) {
+ − 210 info_.title.romaji = title;
+ − 211 }
+ − 212
+ − 213 void Anime::SetEnglishTitle(std::string const& title) {
+ − 214 info_.title.english = title;
+ − 215 }
+ − 216
+ − 217 void Anime::SetNativeTitle(std::string const& title) {
+ − 218 info_.title.native = title;
+ − 219 }
+ − 220
+ − 221 void Anime::SetTitleSynonyms(std::vector<std::string> const& synonyms) {
+ − 222 info_.synonyms = synonyms;
+ − 223 }
+ − 224
+ − 225 void Anime::AddTitleSynonym(std::string const& synonym) {
+ − 226 info_.synonyms.push_back(synonym);
+ − 227 }
+ − 228
+ − 229 void Anime::SetEpisodes(int episodes) {
+ − 230 info_.episodes = episodes;
+ − 231 }
+ − 232
+ − 233 void Anime::SetAiringStatus(SeriesStatus status) {
+ − 234 info_.status = status;
+ − 235 }
+ − 236
+ − 237 void Anime::SetAirDate(Date const& date) {
+ − 238 info_.air_date = date;
+ − 239 }
+ − 240
+ − 241 void Anime::SetGenres(std::vector<std::string> const& genres) {
+ − 242 info_.genres = genres;
+ − 243 }
+ − 244
+ − 245 void Anime::SetProducers(std::vector<std::string> const& producers) {
+ − 246 info_.producers = producers;
+ − 247 }
+ − 248
+ − 249 void Anime::SetFormat(SeriesFormat format) {
+ − 250 info_.format = format;
+ − 251 }
+ − 252
+ − 253 void Anime::SetSeason(SeriesSeason season) {
+ − 254 info_.season = season;
+ − 255 }
+ − 256
+ − 257 void Anime::SetAudienceScore(int audience_score) {
+ − 258 info_.audience_score = audience_score;
+ − 259 }
+ − 260
+ − 261 void Anime::SetSynopsis(std::string synopsis) {
+ − 262 info_.synopsis = synopsis;
+ − 263 }
+ − 264
+ − 265 void Anime::SetDuration(int duration) {
+ − 266 info_.duration = duration;
+ − 267 }
+ − 268
+ − 269 std::string Anime::GetUserPreferredTitle() const {
+ − 270 switch (session.config.anime_list.language) {
+ − 271 case TitleLanguage::NATIVE: return (GetNativeTitle().empty()) ? GetRomajiTitle() : GetNativeTitle();
+ − 272 case TitleLanguage::ENGLISH: return (GetEnglishTitle().empty()) ? GetRomajiTitle() : GetEnglishTitle();
+ − 273 default: break;
+ − 274 }
+ − 275 return GetRomajiTitle();
+ − 276 }
+ − 277
+ − 278 } // namespace Anime