13#ifndef ZSERIO_DEBUG_STRING_UTIL_H_INC
14#define ZSERIO_DEBUG_STRING_UTIL_H_INC
34template <
typename T,
typename WALK_FILTER,
typename ALLOC>
36 const T&
object, std::ostream& stream, uint8_t indent, WALK_FILTER&& walkFilter,
const ALLOC& allocator)
42 BasicJsonWriter<ALLOC> jsonWriter(stream, indent);
43 BasicWalker<ALLOC> walker(jsonWriter, walkFilter);
47template <
typename T,
typename WALK_FILTER,
typename ALLOC>
48BasicString<RebindAlloc<ALLOC, char>> toJsonString(
49 const T&
object, uint8_t indent, WALK_FILTER&& walkFilter,
const ALLOC& allocator)
51 auto stream = std::basic_ostringstream<char, std::char_traits<char>, RebindAlloc<ALLOC, char>>(
52 BasicString<RebindAlloc<ALLOC, char>>(allocator));
53 detail::toJsonStream(
object, stream, indent, walkFilter, allocator);
57template <
typename T,
typename WALK_FILTER,
typename ALLOC>
58void toJsonFile(
const T&
object, std::string_view fileName, uint8_t indent, WALK_FILTER&& walkFilter,
59 const ALLOC& allocator)
61 std::ofstream stream = std::ofstream(fileName.data(), std::ios::out | std::ios::trunc);
64 throw CppRuntimeException(
"DebugStringUtil.toJsonFile: Failed to open '") << fileName <<
"'!";
67 detail::toJsonStream(
object, stream, indent, walkFilter, allocator);
71 throw CppRuntimeException(
"DebugStringUtil.toJsonFile: Failed to write '") << fileName <<
"'!";
78template <typename ALLOC, typename std::enable_if<is_allocator<ALLOC>::value,
int>::type = 0>
79struct DebugStringTraits
81 using ReflectableDataPtr = IBasicReflectableDataPtr<ALLOC>;
103template <
typename T,
typename ALLOC =
typename T::allocator_type,
104 typename std::enable_if<is_allocator<ALLOC>::value,
int>::type = 0>
131template <
typename T,
typename ALLOC =
typename T::allocator_type,
132 typename std::enable_if<is_allocator<ALLOC>::value,
int>::type = 0>
160template <
typename T,
typename WALK_FILTER,
typename ALLOC =
typename T::allocator_type,
161 typename std::enable_if<
162 std::is_base_of<IBasicWalkFilter<ALLOC>,
typename std::decay<WALK_FILTER>::type>::value,
194template <
typename T,
typename WALK_FILTER,
typename ALLOC =
typename T::allocator_type,
195 typename std::enable_if<
196 std::is_base_of<IBasicWalkFilter<ALLOC>,
typename std::decay<WALK_FILTER>::type>::value,
221template <
typename T,
typename ALLOC =
typename T::allocator_type,
222 typename std::enable_if<is_allocator<ALLOC>::value,
int>::type = 0>
249template <
typename T,
typename ALLOC =
typename T::allocator_type,
250 typename std::enable_if<is_allocator<ALLOC>::value,
int>::type = 0>
278template <
typename T,
typename WALK_FILTER,
typename ALLOC =
typename T::allocator_type,
279 typename std::enable_if<
280 std::is_base_of<IBasicWalkFilter<ALLOC>,
typename std::decay<WALK_FILTER>::type>::value,
311template <
typename T,
typename WALK_FILTER,
typename ALLOC =
typename T::allocator_type,
312 typename std::enable_if<
313 std::is_base_of<IBasicWalkFilter<ALLOC>,
typename std::decay<WALK_FILTER>::type>::value,
336template <
typename T,
typename ALLOC =
typename T::allocator_type,
337 typename std::enable_if<is_allocator<ALLOC>::value,
int>::type = 0>
364template <
typename T,
typename ALLOC =
typename T::allocator_type,
365 typename std::enable_if<is_allocator<ALLOC>::value,
int>::type = 0>
392template <
typename T,
typename WALK_FILTER,
typename ALLOC =
typename T::allocator_type,
393 typename std::enable_if<
394 std::is_base_of<IBasicWalkFilter<ALLOC>,
typename std::decay<WALK_FILTER>::type>::value,
423template <
typename T,
typename WALK_FILTER,
typename ALLOC =
typename T::allocator_type,
424 typename std::enable_if<
425 std::is_base_of<IBasicWalkFilter<ALLOC>,
typename std::decay<WALK_FILTER>::type>::value,
457template <
typename ALLOC = std::allocator<u
int8_t>>
489template <
typename T,
typename ALLOC =
typename T::allocator_type>
519template <
typename ALLOC = std::allocator<u
int8_t>>
552template <
typename T,
typename ALLOC =
typename T::allocator_type>
581template <
typename ALLOC = std::allocator<u
int8_t>>
585 std::ifstream
is = std::ifstream(
fileName.data());
617template <
typename T,
typename ALLOC =
typename T::allocator_type>
const IBasicTypeInfo< ALLOC > & typeInfo()
detail::DebugStringTraits< ALLOC >::ReflectableDataPtr fromJsonFile(const IBasicTypeInfo< ALLOC > &typeInfo, std::string_view fileName, const ALLOC &allocator=ALLOC())
std::basic_string< char, std::char_traits< char >, ALLOC > BasicString
detail::DebugStringTraits< ALLOC >::ReflectableDataPtr fromJsonString(const IBasicTypeInfo< ALLOC > &typeInfo, const BasicString< RebindAlloc< ALLOC, char > > &json, const ALLOC &allocator=ALLOC())
BasicString< RebindAlloc< ALLOC, char > > toJsonString(const T &object, const ALLOC &allocator=ALLOC())
detail::DebugStringTraits< ALLOC >::ReflectableDataPtr fromJsonStream(const IBasicTypeInfo< ALLOC > &typeInfo, std::istream &is, const ALLOC &allocator=ALLOC())
void toJsonStream(const T &object, std::ostream &stream, const ALLOC &allocator=ALLOC())
IBasicReflectableDataConstPtr< ALLOC > reflectable(const T &value, const ALLOC &allocator=ALLOC())
void toJsonFile(const T &object, std::string_view fileName, const ALLOC &allocator=ALLOC())