This commit is contained in:
55
include/sp/protocol/MessagePrinter.h
Normal file
55
include/sp/protocol/MessagePrinter.h
Normal file
@@ -0,0 +1,55 @@
|
||||
#pragma once
|
||||
|
||||
#include <map>
|
||||
#include <sp/common/Templates.h>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace sp {
|
||||
|
||||
template <typename T, std::enable_if_t<details::is_general_t<T>::value, bool> = true>
|
||||
inline std::string PrintData(const T& a_Data);
|
||||
|
||||
template <typename T, std::enable_if_t<details::is_primitive<T>::value, bool> = true>
|
||||
inline std::string PrintData(T a_Data) {
|
||||
return std::to_string(a_Data);
|
||||
}
|
||||
|
||||
template <>
|
||||
inline std::string PrintData(const std::string& a_Data) {
|
||||
return "\"" + a_Data + "\"";
|
||||
}
|
||||
|
||||
template <typename K, typename V>
|
||||
std::string PrintData(const std::pair<K, V>& a_Data);
|
||||
|
||||
template <typename K, typename V>
|
||||
std::string PrintData(const std::map<K, V>& a_Data);
|
||||
|
||||
template <typename T>
|
||||
std::string PrintData(const std::vector<T>& a_Data);
|
||||
|
||||
template <typename K, typename V>
|
||||
std::string PrintData(const std::pair<K, V>& a_Data) {
|
||||
return "{" + PrintData(a_Data.first) + " => " + PrintData(a_Data.second) + "}";
|
||||
}
|
||||
|
||||
template <typename K, typename V>
|
||||
std::string PrintData(const std::map<K, V>& a_Data) {
|
||||
std::string result = "{";
|
||||
for (const auto& pair : a_Data) {
|
||||
result += PrintData(pair) + ", ";
|
||||
}
|
||||
return result.substr(0, result.size() - 2) + "}";
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
std::string PrintData(const std::vector<T>& a_Data) {
|
||||
std::string result = "{";
|
||||
for (const T& value : a_Data) {
|
||||
result += PrintData(value) + ", ";
|
||||
}
|
||||
return result.substr(0, result.size() - 2) + "}";
|
||||
}
|
||||
|
||||
} // namespace sp
|
||||
Reference in New Issue
Block a user