1 /* 2 * Copyright 2024, Andrew Lindesay <apl@lindesay.co.nz>. 3 * All rights reserved. Distributed under the terms of the MIT License. 4 */ 5 6 7 #include "UserRatingInfo.h" 8 9 UserRatingInfo()10UserRatingInfo::UserRatingInfo() 11 : 12 fUserRatings(), 13 fSummary(), 14 fUserRatingsPopulated(false) 15 { 16 } 17 18 UserRatingInfo(const UserRatingInfo & other)19UserRatingInfo::UserRatingInfo(const UserRatingInfo& other) 20 : 21 fSummary(other.Summary()), 22 fUserRatingsPopulated(other.UserRatingsPopulated()) 23 { 24 for (int32 i = CountUserRatings() - 1; i >= 0; i--) 25 AddUserRating(other.UserRatingAtIndex(i)); 26 } 27 28 29 void Clear()30UserRatingInfo::Clear() 31 { 32 fSummary.Unset(); 33 ClearUserRatings(); 34 } 35 36 37 void SetSummary(UserRatingSummaryRef value)38UserRatingInfo::SetSummary(UserRatingSummaryRef value) 39 { 40 fSummary = value; 41 } 42 43 44 void SetUserRatingsPopulated()45UserRatingInfo::SetUserRatingsPopulated() 46 { 47 fUserRatingsPopulated = true; 48 } 49 50 51 bool UserRatingsPopulated() const52UserRatingInfo::UserRatingsPopulated() const 53 { 54 return fUserRatingsPopulated; 55 } 56 57 58 void ClearUserRatings()59UserRatingInfo::ClearUserRatings() 60 { 61 fUserRatings.clear(); 62 fUserRatingsPopulated = false; 63 } 64 65 66 int32 CountUserRatings() const67UserRatingInfo::CountUserRatings() const 68 { 69 return fUserRatings.size(); 70 } 71 72 73 UserRatingRef UserRatingAtIndex(int32 index) const74UserRatingInfo::UserRatingAtIndex(int32 index) const 75 { 76 return fUserRatings[index]; 77 } 78 79 80 void AddUserRating(const UserRatingRef & rating)81UserRatingInfo::AddUserRating(const UserRatingRef& rating) 82 { 83 fUserRatings.push_back(rating); 84 } 85 86 87 UserRatingInfo& operator =(const UserRatingInfo & other)88UserRatingInfo::operator=(const UserRatingInfo& other) 89 { 90 fSummary = other.Summary(); 91 92 fUserRatings.clear(); 93 94 fUserRatingsPopulated = other.UserRatingsPopulated(); 95 96 for (int32 i = CountUserRatings() - 1; i >= 0; i--) 97 AddUserRating(other.UserRatingAtIndex(i)); 98 99 return *this; 100 } 101 102 103 bool operator ==(const UserRatingInfo & other) const104UserRatingInfo::operator==(const UserRatingInfo& other) const 105 { 106 if (Summary() != other.Summary()) 107 return false; 108 109 if (UserRatingsPopulated() != other.UserRatingsPopulated()) 110 return false; 111 112 if (CountUserRatings() != other.CountUserRatings()) 113 return false; 114 115 for (int32 i = CountUserRatings() - 1; i >= 0; i--) { 116 if (other.UserRatingAtIndex(i) != UserRatingAtIndex(i)) 117 return false; 118 } 119 120 return true; 121 } 122 123 124 bool operator !=(const UserRatingInfo & other) const125UserRatingInfo::operator!=(const UserRatingInfo& other) const 126 { 127 return !(*this == other); 128 } 129