13 #ifndef ZSERIO_DEBUG_STRING_UTIL_H_INC
14 #define ZSERIO_DEBUG_STRING_UTIL_H_INC
34 template <
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);
47 template <
typename T,
typename WALK_FILTER,
typename ALLOC>
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));
57 template <
typename T,
typename WALK_FILTER,
typename ALLOC>
58 void 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 <<
"'!";
71 throw CppRuntimeException(
"DebugStringUtil.toJsonFile: Failed to write '") << fileName <<
"'!";
78 template <typename ALLOC, typename std::enable_if<is_allocator<ALLOC>::value,
int>::type = 0>
79 struct DebugStringTraits
81 using ReflectableDataPtr = IBasicReflectableDataPtr<ALLOC>;
103 template <
typename T,
typename ALLOC =
typename T::allocator_type,
104 typename std::enable_if<is_allocator<ALLOC>::value,
int>::type = 0>
105 void toJsonStream(
const T&
object, std::ostream& stream,
const ALLOC& allocator = ALLOC())
131 template <
typename T,
typename ALLOC =
typename T::allocator_type,
132 typename std::enable_if<is_allocator<ALLOC>::value,
int>::type = 0>
133 void toJsonStream(
const T&
object, std::ostream& stream, uint8_t indent,
const ALLOC& allocator = ALLOC())
160 template <
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,
165 const T&
object, std::ostream& stream, WALK_FILTER&& walkFilter,
const ALLOC& allocator = ALLOC())
194 template <
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,
198 void toJsonStream(
const T&
object, std::ostream& stream, uint8_t indent, WALK_FILTER&& walkFilter,
199 const ALLOC& allocator = ALLOC())
221 template <
typename T,
typename ALLOC =
typename T::allocator_type,
222 typename std::enable_if<is_allocator<ALLOC>::value,
int>::type = 0>
249 template <
typename T,
typename ALLOC =
typename T::allocator_type,
250 typename std::enable_if<is_allocator<ALLOC>::value,
int>::type = 0>
252 const T&
object, uint8_t indent,
const ALLOC& allocator = ALLOC())
278 template <
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,
283 const T&
object, WALK_FILTER&& walkFilter,
const ALLOC& allocator = ALLOC())
311 template <
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,
316 const T&
object, uint8_t indent, WALK_FILTER&& walkFilter,
const ALLOC& allocator = ALLOC())
336 template <
typename T,
typename ALLOC =
typename T::allocator_type,
337 typename std::enable_if<is_allocator<ALLOC>::value,
int>::type = 0>
338 void toJsonFile(
const T&
object, std::string_view fileName,
const ALLOC& allocator = ALLOC())
364 template <
typename T,
typename ALLOC =
typename T::allocator_type,
365 typename std::enable_if<is_allocator<ALLOC>::value,
int>::type = 0>
366 void toJsonFile(
const T&
object, std::string_view fileName, uint8_t indent,
const ALLOC& allocator = ALLOC())
392 template <
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,
397 const T&
object, std::string_view fileName, WALK_FILTER&& walkFilter,
const ALLOC& allocator = ALLOC())
423 template <
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,
428 WALK_FILTER&& walkFilter,
const ALLOC& allocator = ALLOC())
457 template <
typename ALLOC = std::allocator<u
int8_t>>
489 template <
typename T,
typename ALLOC =
typename T::allocator_type>
492 return std::move(ReflectableUtil::getValue<T, ALLOC>(
fromJsonStream(typeInfo<T>(), is, allocator)));
519 template <
typename ALLOC = std::allocator<u
int8_t>>
522 const ALLOC& allocator = ALLOC())
552 template <
typename T,
typename ALLOC =
typename T::allocator_type>
555 return std::move(ReflectableUtil::getValue<T, ALLOC>(
fromJsonString(typeInfo<T>(), json, allocator)));
581 template <
typename ALLOC = std::allocator<u
int8_t>>
582 typename detail::DebugStringTraits<ALLOC>::ReflectableDataPtr
fromJsonFile(
585 std::ifstream is = std::ifstream(fileName.data());
588 throw CppRuntimeException(
"DebugStringUtil.fromJsonFile: Failed to open '") << fileName <<
"'!";
617 template <
typename T,
typename ALLOC =
typename T::allocator_type>
618 T
fromJsonFile(std::string_view fileName,
const ALLOC& allocator = ALLOC())
620 return std::move(ReflectableUtil::getValue<T, ALLOC>(
fromJsonFile(typeInfo<T>(), fileName, allocator)));
IBasicReflectableDataPtr< ALLOC > read(const IBasicTypeInfo< ALLOC > &typeInfo)
detail::DebugStringTraits< ALLOC >::ReflectableDataPtr fromJsonStream(const IBasicTypeInfo< ALLOC > &typeInfo, std::istream &is, const ALLOC &allocator=ALLOC())
std::basic_string< char, std::char_traits< char >, ALLOC > BasicString
BasicString< RebindAlloc< ALLOC, char > > toJsonString(const T &object, uint8_t indent, WALK_FILTER &&walkFilter, const ALLOC &allocator=ALLOC())
BasicString< RebindAlloc< ALLOC, char > > toJsonString(const T &object, const ALLOC &allocator=ALLOC())
IBasicReflectableDataConstPtr< ALLOC > reflectable(const T &value, const ALLOC &allocator=ALLOC())
void toJsonStream(const T &object, std::ostream &stream, uint8_t indent, WALK_FILTER &&walkFilter, const ALLOC &allocator=ALLOC())
typename std::allocator_traits< ALLOC >::template rebind_alloc< T > RebindAlloc
const IBasicTypeInfo< ALLOC > & typeInfo()
void toJsonFile(const T &object, const BasicString< RebindAlloc< ALLOC, char >> &fileName, uint8_t indent, WALK_FILTER &&walkFilter, const ALLOC &allocator=ALLOC())
void toJsonStream(const T &object, std::ostream &stream, const ALLOC &allocator=ALLOC())
void toJsonFile(const T &object, std::string_view fileName, const ALLOC &allocator=ALLOC())
detail::DebugStringTraits< ALLOC >::ReflectableDataPtr fromJsonString(const IBasicTypeInfo< ALLOC > &typeInfo, const BasicString< RebindAlloc< ALLOC, char >> &json, const ALLOC &allocator=ALLOC())
detail::DebugStringTraits< ALLOC >::ReflectableDataPtr fromJsonFile(const IBasicTypeInfo< ALLOC > &typeInfo, std::string_view fileName, const ALLOC &allocator=ALLOC())