Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYuri Gorshenin <y@maps.me>2017-06-20 19:04:31 +0300
committerYuri Gorshenin <mipt.vi002@gmail.com>2017-07-05 16:41:38 +0300
commit880bc83c8a94177f345231c7d9e6c415ed9f6f98 (patch)
tree0f38a3f46c8f615bac48d9b15022cfb323af7952
parent7da3a5c85d60f43f0814ec3ac9c45797d8d103be (diff)
[ugc] Various fixes.
-rw-r--r--ugc/serdes.hpp16
-rw-r--r--ugc/types.hpp55
-rw-r--r--ugc/ugc.pro1
-rw-r--r--ugc/ugc_tests/serdes_tests.cpp5
4 files changed, 36 insertions, 41 deletions
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 <typename T>
void operator()(vector<T> const & vs)
{
- SerVarUint(vs.size());
+ SerVarUint(static_cast<uint32_t>(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<uint8_t>(0));
- case Review::Sentiment::Positive: return (*this)(static_cast<uint8_t>(1));
+ case Sentiment::Negative: return (*this)(static_cast<uint8_t>(0));
+ case Sentiment::Positive: return (*this)(static_cast<uint8_t>(1));
}
}
@@ -160,7 +160,7 @@ public:
template <typename T>
void operator()(vector<T> & vs)
{
- auto const size = DesVarUint<size_t>();
+ auto const size = DesVarUint<uint32_t>();
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<int>(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<std::chrono::system_clock>;
+
+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<std::chrono::system_clock>;
-
- 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<std::chrono::system_clock> 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<std::chrono::system_clock> m_time;
+ Sentiment m_sentiment;
+ Time m_time;
};
struct ReviewAbuse
{
- ReviewAbuse(std::string const & reason,
- std::chrono::time_point<std::chrono::system_clock> 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<std::chrono::system_clock> 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<Review> 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<Attribute> attributes;
attributes.emplace_back("best-drink", "Coffee");