.. _program_listing_file_uconfig_format_impl_Rapidjson.ipp: Program Listing for File Rapidjson.ipp ====================================== |exhale_lsh| :ref:`Return to documentation for file ` (``uconfig/format/impl/Rapidjson.ipp``) .. |exhale_lsh| unicode:: U+021B0 .. UPWARDS ARROW WITH TIP LEFTWARDS .. code-block:: cpp #pragma once namespace uconfig { template template std::optional RapidjsonFormat::Parse(const json_value_type* source, const std::string& path) const { const auto* target = Get(source, path); if (!target) { return std::nullopt; } T result; if (!this->Convert(*target, result)) { return std::nullopt; } return result; } template template void RapidjsonFormat::Emit(dest_type* dest, const std::string& path, const T& value) const { Set(MakeJson(value, dest->GetAllocator()), path, dest); } template std::string RapidjsonFormat::VectorElementPath(const std::string& vector_path, std::size_t index) const noexcept { return vector_path + "/" + std::to_string(index); } template const typename RapidjsonFormat::json_value_type* RapidjsonFormat::Get(const json_value_type* source, const std::string& path) { return json_pointer_type(path).Get(*source); } template void RapidjsonFormat::Set(json_value_type&& value, const std::string& path, dest_type* dest) { json_pointer_type(path).Set(*dest, std::move(value), dest->GetAllocator()); } template template ::value>::type*> bool RapidjsonFormat::Convert(const json_value_type& source, T& result) { switch (source.GetType()) { case rapidjson::kStringType: result = source.GetString(); break; default: return false; } return true; } template template ::value>::type*> bool RapidjsonFormat::Convert(const json_value_type& source, T& result) { switch (source.GetType()) { case rapidjson::kTrueType: case rapidjson::kFalseType: result = source.GetBool(); break; default: return false; } return true; } template template ::value>::type*> bool RapidjsonFormat::Convert(const json_value_type& source, T& result) { if (source.IsInt()) { result = source.GetInt(); return true; } return false; } template template ::value>::type*> bool RapidjsonFormat::Convert(const json_value_type& source, T& result) { if (source.IsInt64()) { result = source.GetInt64(); return true; } return false; } template template ::value>::type*> bool RapidjsonFormat::Convert(const json_value_type& source, T& result) { if (source.IsInt64()) { result = source.GetInt64(); return true; } return false; } template template ::value>::type*> bool RapidjsonFormat::Convert(const json_value_type& source, T& result) { if (source.IsUint()) { result = source.GetUint(); return true; } return false; } template template ::value>::type*> bool RapidjsonFormat::Convert(const json_value_type& source, T& result) { if (source.IsUint64()) { result = source.GetUint64(); return true; } return false; } template template ::value>::type*> bool RapidjsonFormat::Convert(const json_value_type& source, T& result) { if (source.IsUint64()) { result = source.GetUint64(); return true; } return false; } template template ::value>::type*> bool RapidjsonFormat::Convert(const json_value_type& source, T& result) { if (source.IsLosslessDouble()) { result = source.GetDouble(); return true; } return false; } template template ::value>::type*> bool RapidjsonFormat::Convert(const json_value_type& source, T& result) { if (source.IsLosslessFloat()) { result = source.GetFloat(); return true; } return false; } template template ::value || std::is_same::value || std::is_same::value || std::is_same::value || std::is_same::value || std::is_same::value || std::is_same::value>::type*> typename RapidjsonFormat::json_value_type RapidjsonFormat::MakeJson(const SrcT& source, allocator_type& /*alloc*/) { return json_value_type(source); } template template ::value>::type*> typename RapidjsonFormat::json_value_type RapidjsonFormat::MakeJson(const SrcT& source, allocator_type& /*alloc*/) { return json_value_type((int64_t)source); } template template ::value>::type*> typename RapidjsonFormat::json_value_type RapidjsonFormat::MakeJson(const SrcT& source, allocator_type& /*alloc*/) { return json_value_type((uint64_t)source); } template template ::value>::type*> typename RapidjsonFormat::json_value_type RapidjsonFormat::MakeJson(const SrcT& source, allocator_type& alloc) { return json_value_type(source, alloc); } } // namespace uconfig