2018-07-21 18:05:53 +02:00
|
|
|
|
2021-07-28 20:59:31 +02:00
|
|
|
#ifndef __cxz_x_to_string_h__
|
|
|
|
#define __cxz_x_to_string_h__
|
2018-07-21 18:05:53 +02:00
|
|
|
|
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
|
|
|
#include <array>
|
|
|
|
#include <tuple>
|
2019-12-11 15:16:50 +01:00
|
|
|
#include <algorithm>
|
2018-07-21 18:05:53 +02:00
|
|
|
|
2018-10-29 14:19:42 +01:00
|
|
|
#include "ranges/dynamic_meta.h"
|
|
|
|
|
2021-07-28 20:29:56 +02:00
|
|
|
namespace CNORXZInternal
|
2018-07-21 18:05:53 +02:00
|
|
|
{
|
2018-09-17 11:06:24 +02:00
|
|
|
template <typename T>
|
|
|
|
inline std::string xToString(const T& x);
|
|
|
|
|
|
|
|
|
|
|
|
template <>
|
|
|
|
inline std::string xToString<char>(const char& x);
|
|
|
|
|
|
|
|
template <>
|
|
|
|
inline std::string xToString<std::string>(const std::string& x);
|
|
|
|
|
2021-07-28 20:29:56 +02:00
|
|
|
using CNORXZ::DynamicMetaT;
|
2018-10-29 14:19:42 +01:00
|
|
|
|
|
|
|
template <>
|
|
|
|
inline std::string xToString<DynamicMetaT>(const DynamicMetaT& x);
|
|
|
|
|
2018-09-17 11:06:24 +02:00
|
|
|
template <typename T>
|
2019-02-13 21:59:13 +01:00
|
|
|
inline std::string xToString(const vector<T>& x);
|
2018-09-17 11:06:24 +02:00
|
|
|
|
|
|
|
template <typename T, size_t N>
|
|
|
|
inline std::string xToString(const std::array<T,N>& x);
|
|
|
|
|
|
|
|
template <typename... Ts>
|
|
|
|
inline std::string xToString(const std::tuple<Ts...>& tp);
|
|
|
|
|
|
|
|
// TEMPLATE CODE
|
|
|
|
|
2018-07-21 18:05:53 +02:00
|
|
|
template <typename T>
|
|
|
|
inline std::string xToString(const T& x)
|
|
|
|
{
|
2019-12-11 15:16:50 +01:00
|
|
|
std::string out = std::to_string(x);
|
|
|
|
std::replace(out.begin(), out.end(), ',', '.');
|
|
|
|
return out;
|
2018-07-21 18:05:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
template <size_t N>
|
|
|
|
struct TupleToString
|
|
|
|
{
|
|
|
|
template <typename... Ts>
|
|
|
|
static inline std::string mk(const std::tuple<Ts...>& tp)
|
|
|
|
{
|
2019-02-25 18:56:37 +01:00
|
|
|
return TupleToString<N-1>::mk(tp) + "," + xToString(std::get<N>(tp));
|
2018-07-21 18:05:53 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
template <>
|
|
|
|
struct TupleToString<0>
|
|
|
|
{
|
|
|
|
template <typename... Ts>
|
|
|
|
static inline std::string mk(const std::tuple<Ts...>& tp)
|
|
|
|
{
|
|
|
|
return xToString(std::get<0>(tp));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
template <>
|
|
|
|
inline std::string xToString<char>(const char& x)
|
|
|
|
{
|
|
|
|
std::string out = "";
|
|
|
|
return out += x;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <>
|
|
|
|
inline std::string xToString<std::string>(const std::string& x)
|
|
|
|
{
|
|
|
|
return x;
|
|
|
|
}
|
|
|
|
|
2018-10-29 14:19:42 +01:00
|
|
|
template <>
|
|
|
|
inline std::string xToString<DynamicMetaT>(const DynamicMetaT& x)
|
|
|
|
{
|
2019-02-25 18:56:37 +01:00
|
|
|
std::string out = "[";
|
2018-10-29 14:19:42 +01:00
|
|
|
for(size_t i = 0; i != x.size(); ++i){
|
|
|
|
out += x[i].first;
|
2019-02-25 18:56:37 +01:00
|
|
|
out += ",";
|
2018-10-29 14:19:42 +01:00
|
|
|
}
|
2019-02-25 18:56:37 +01:00
|
|
|
//out.pop_back();
|
2018-10-29 14:19:42 +01:00
|
|
|
out.back() = ']';
|
|
|
|
return out;
|
|
|
|
}
|
|
|
|
|
2018-07-21 18:05:53 +02:00
|
|
|
template <typename T>
|
2019-02-13 21:59:13 +01:00
|
|
|
inline std::string xToString(const vector<T>& x)
|
2018-07-21 18:05:53 +02:00
|
|
|
{
|
2019-02-25 18:56:37 +01:00
|
|
|
std::string out = "[";
|
2018-07-21 18:05:53 +02:00
|
|
|
for(auto& y: x){
|
2019-02-25 18:56:37 +01:00
|
|
|
out += xToString(y) + ",";
|
2018-07-21 18:05:53 +02:00
|
|
|
}
|
2019-02-25 18:56:37 +01:00
|
|
|
//out.pop_back();
|
2018-07-21 18:05:53 +02:00
|
|
|
out.back() = ']';
|
|
|
|
return out;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T, size_t N>
|
|
|
|
inline std::string xToString(const std::array<T,N>& x)
|
|
|
|
{
|
2019-02-25 18:56:37 +01:00
|
|
|
std::string out = "[";
|
2018-07-21 18:05:53 +02:00
|
|
|
for(auto& y: x){
|
2019-02-25 18:56:37 +01:00
|
|
|
out += xToString(y) + ",";
|
2018-07-21 18:05:53 +02:00
|
|
|
}
|
2019-02-25 18:56:37 +01:00
|
|
|
//out.pop_back();
|
2018-07-21 18:05:53 +02:00
|
|
|
out.back() = ']';
|
|
|
|
return out;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename... Ts>
|
|
|
|
inline std::string xToString(const std::tuple<Ts...>& tp)
|
|
|
|
{
|
2019-02-25 18:56:37 +01:00
|
|
|
return "{" + TupleToString<sizeof...(Ts)-1>::mk(tp) + "}";
|
2018-07-21 18:05:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|