Common/Analytics: add basic support for vector serialization

Only supports u32 for now since that's the only thing we need.
This commit is contained in:
Pierre Bourdon
2018-10-27 04:58:39 +02:00
parent 64e04eb38c
commit d98c0da41b
2 changed files with 31 additions and 1 deletions

View File

@ -95,6 +95,15 @@ public:
return *this;
}
template <typename T>
AnalyticsReportBuilder& AddData(const std::string& key, const std::vector<T>& value)
{
std::lock_guard<std::mutex> lk(m_lock);
AppendSerializedValue(&m_report, key);
AppendSerializedValueVector(&m_report, value);
return *this;
}
std::string Get() const
{
std::lock_guard<std::mutex> lk(m_lock);
@ -118,6 +127,8 @@ protected:
static void AppendSerializedValue(std::string* report, s32 v);
static void AppendSerializedValue(std::string* report, float v);
static void AppendSerializedValueVector(std::string* report, const std::vector<u32>& v);
// Should really be a std::shared_mutex, unfortunately that's C++17 only.
mutable std::mutex m_lock;
std::string m_report;