diff --git a/ugc/serdes.hpp b/ugc/serdes.hpp index 6ec99878e1..1bf92675cd 100644 --- a/ugc/serdes.hpp +++ b/ugc/serdes.hpp @@ -51,6 +51,11 @@ public: WriteVarUint(m_sink, t); } + void operator()(TranslationKey const & key, char const * /* name */ = nullptr) + { + (*this)(key.m_key); + } + void operator()(Time const & t, char const * /* name */ = nullptr) { VisitVarUint(ToDaysSinceEpoch(t)); @@ -124,6 +129,8 @@ public: return ReadVarUint(m_source); } + void operator()(TranslationKey & key, char const * /* name */ = nullptr) { (*this)(key.m_key); } + void operator()(Time & t, char const * /* name */ = nullptr) { t = FromDaysSinceEpoch(DesVarUint()); diff --git a/ugc/serdes_json.hpp b/ugc/serdes_json.hpp index 4a88860e4a..7fc8f36e01 100644 --- a/ugc/serdes_json.hpp +++ b/ugc/serdes_json.hpp @@ -32,6 +32,11 @@ public: ToJSONObject(*m_json, name, s); } + void operator()(TranslationKey const & key, char const * name = nullptr) + { + (*this)(key.m_key, name); + } + void operator()(Time const & t, char const * name = nullptr) { (*this)(ToDaysSinceEpoch(t), name); @@ -109,6 +114,10 @@ public: void operator()(uint32_t & d, char const * name = nullptr) { FromJSONObject(m_json, name, d); } void operator()(uint64_t & d, char const * name = nullptr) { FromJSONObject(m_json, name, d); } void operator()(std::string & s, char const * name = nullptr) { FromJSONObject(m_json, name, s); } + void operator()(TranslationKey & key, char const * name = nullptr) + { + (*this)(key.m_key, name); + } void operator()(Time & t, char const * name = nullptr) { uint32_t d = 0; diff --git a/ugc/types.hpp b/ugc/types.hpp index 7a6de3e533..8cbcda8347 100644 --- a/ugc/types.hpp +++ b/ugc/types.hpp @@ -26,10 +26,26 @@ namespace ugc { -using TranslationKey = std::string; using Clock = std::chrono::system_clock; using Time = std::chrono::time_point; +struct TranslationKey +{ + TranslationKey() = default; + TranslationKey(std::string const & key): m_key(key) {} + TranslationKey(char const * key): m_key(key) {} + + bool operator==(TranslationKey const & rhs) const { return m_key == rhs.m_key; } + bool operator<(TranslationKey const & rhs) const { return m_key < rhs.m_key; } + + friend std::string DebugPrint(TranslationKey const & key) + { + return "TranslationKey [ " + key.m_key + " ]"; + } + + std::string m_key; +}; + enum class Sentiment { Positive, @@ -81,7 +97,8 @@ struct RatingRecord friend std::string DebugPrint(RatingRecord const & ratingRecord) { std::ostringstream os; - os << "RatingRecord [ " << ratingRecord.m_key << " " << ratingRecord.m_value << " ]"; + os << "RatingRecord [ " << DebugPrint(ratingRecord.m_key) << " " << ratingRecord.m_value + << " ]"; return os.str(); } @@ -238,7 +255,8 @@ struct Attribute friend std::string DebugPrint(Attribute const & attribute) { std::ostringstream os; - os << "Attribute [ key:" << attribute.m_key << ", value:" << attribute.m_value << " ]"; + os << "Attribute [ key:" << DebugPrint(attribute.m_key) + << ", value:" << DebugPrint(attribute.m_value) << " ]"; return os.str(); } diff --git a/ugc/ugc_tests/CMakeLists.txt b/ugc/ugc_tests/CMakeLists.txt index 333d762dac..825c4205be 100644 --- a/ugc/ugc_tests/CMakeLists.txt +++ b/ugc/ugc_tests/CMakeLists.txt @@ -1,5 +1,7 @@ project(ugc_tests) +include_directories(${OMIM_ROOT}/3party/jansson/src) + set( SRC serdes_tests.cpp