diff --git a/ugc/serdes.hpp b/ugc/serdes.hpp index 79c0698cec..f799403dcf 100644 --- a/ugc/serdes.hpp +++ b/ugc/serdes.hpp @@ -49,7 +49,7 @@ public: template void operator()(vector const & vs) { - SerVarUint(vs.size()); + SerVarUint(static_cast(vs.size())); for (auto const & v : vs) (*this)(v); } @@ -84,12 +84,12 @@ public: (*this)(text.m_text); } - void operator()(Review::Sentiment sentiment) + void operator()(Sentiment sentiment) { switch (sentiment) { - case Review::Sentiment::Negative: return (*this)(static_cast(0)); - case Review::Sentiment::Positive: return (*this)(static_cast(1)); + case Sentiment::Negative: return (*this)(static_cast(0)); + case Sentiment::Positive: return (*this)(static_cast(1)); } } @@ -160,7 +160,7 @@ public: template void operator()(vector & vs) { - auto const size = DesVarUint(); + auto const size = DesVarUint(); vs.resize(size); for (auto & v : vs) (*this)(v); @@ -190,14 +190,14 @@ public: (*this)(text.m_text); } - void operator()(Review::Sentiment & sentiment) + void operator()(Sentiment & sentiment) { uint8_t s = 0; (*this)(s); switch (s) { - case 0: sentiment = Review::Sentiment::Negative; break; - case 1: sentiment = Review::Sentiment::Positive; break; + case 0: sentiment = Sentiment::Negative; break; + case 1: sentiment = Sentiment::Positive; break; default: CHECK(false, ("Can't parse sentiment from:", static_cast(s))); break; } } diff --git a/ugc/types.hpp b/ugc/types.hpp index 145038e758..1fffe74d07 100644 --- a/ugc/types.hpp +++ b/ugc/types.hpp @@ -16,6 +16,22 @@ namespace ugc { using TranslationKey = std::string; +using Time = std::chrono::time_point; + +enum class Sentiment +{ + Positive, + Negative +}; + +inline std::string DebugPrint(Sentiment const & sentiment) +{ + switch (sentiment) + { + case Sentiment::Positive: return "Positive"; + case Sentiment::Negative: return "Negative"; + } +} struct RatingRecord { @@ -54,7 +70,7 @@ struct Rating friend std::string DebugPrint(Rating const & rating) { std::ostringstream os; - os << "Rating [ ratings:" << DebugPrint(rating.m_ratings) << ", aggValue:" << rating.m_aggValue + os << "Rating [ ratings:" << ::DebugPrint(rating.m_ratings) << ", aggValue:" << rating.m_aggValue << " ]"; return os.str(); } @@ -123,13 +139,6 @@ struct Text struct Review { using ReviewId = uint32_t; - using Time = std::chrono::time_point; - - enum class Sentiment - { - Positive, - Negative - }; Review() = default; Review(ReviewId id, Text const & text, Author const & author, float const rating, @@ -156,15 +165,6 @@ struct Review m_time = Time(hours); } - friend std::string DebugPrint(Sentiment const sentiment) - { - switch (sentiment) - { - case Sentiment::Positive: return "Positive"; - case Sentiment::Negative: return "Negative"; - } - } - friend std::string DebugPrint(Review const & review) { std::ostringstream os; @@ -231,8 +231,8 @@ struct UGC std::ostringstream os; os << "UGC [ "; os << "rating:" << DebugPrint(ugc.m_rating) << ", "; - os << "reviews:" << DebugPrint(ugc.m_reviews) << ", "; - os << "attributes:" << DebugPrint(ugc.m_attributes) << " ]"; + os << "reviews:" << ::DebugPrint(ugc.m_reviews) << ", "; + os << "attributes:" << ::DebugPrint(ugc.m_attributes) << " ]"; return os.str(); } @@ -243,26 +243,21 @@ struct UGC struct ReviewFeedback { - ReviewFeedback(bool const evaluation, - std::chrono::time_point const time) - : m_evaluation(evaluation), m_time(time) + ReviewFeedback(Sentiment const sentiment, Time const & time) + : m_sentiment(sentiment), m_time(time) { } - bool m_evaluation; - std::chrono::time_point m_time; + Sentiment m_sentiment; + Time m_time; }; struct ReviewAbuse { - ReviewAbuse(std::string const & reason, - std::chrono::time_point const & time) - : m_reason(reason), m_time(time) - { - } + ReviewAbuse(std::string const & reason, Time const & time) : m_reason(reason), m_time(time) {} std::string m_reason; - std::chrono::time_point m_time; + Time m_time; }; struct UGCUpdate diff --git a/ugc/ugc.pro b/ugc/ugc.pro index c90196970c..3bcf6703e4 100644 --- a/ugc/ugc.pro +++ b/ugc/ugc.pro @@ -10,6 +10,7 @@ include($$ROOT_DIR/common.pri) HEADERS += \ api.hpp \ + serdes.hpp \ types.hpp \ SOURCES += \ diff --git a/ugc/ugc_tests/serdes_tests.cpp b/ugc/ugc_tests/serdes_tests.cpp index 5e13420555..a38d0016a6 100644 --- a/ugc/ugc_tests/serdes_tests.cpp +++ b/ugc/ugc_tests/serdes_tests.cpp @@ -44,12 +44,11 @@ UGC GetTestUGC() vector reviews; reviews.emplace_back(20 /* id */, Text("Damn good coffee", StringUtf8Multilang::kEnglishCode), Author(UID(987654321 /* hi */, 123456789 /* lo */), "Cole"), - 5.0 /* rating */, Review::Sentiment::Positive, - Review::Time(FromDays(10))); + 5.0 /* rating */, Sentiment::Positive, Time(FromDays(10))); reviews.emplace_back(67812 /* id */, Text("Clean place, reasonably priced", StringUtf8Multilang::kDefaultCode), Author(UID(0 /* hi */, 315 /* lo */), "Cooper"), 5.0 /* rating */, - Review::Sentiment::Positive, Review::Time(FromDays(1))); + Sentiment::Positive, Time(FromDays(1))); vector attributes; attributes.emplace_back("best-drink", "Coffee");