Skip to content

Commit

Permalink
FIX STREAM_AS
Browse files Browse the repository at this point in the history
  • Loading branch information
pwojcikdev committed Jan 24, 2024
1 parent 658ce17 commit 5402802
Showing 1 changed file with 22 additions and 22 deletions.
44 changes: 22 additions & 22 deletions nano/lib/object_stream.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ class object_stream : private object_stream_base
void write (std::string_view name, Value const & value)
{
ctx.begin_field (name, std::exchange (first_field, false));
stream_as (value, ctx);
stream_as_value (value, ctx);
ctx.end_field ();
}

Expand Down Expand Up @@ -232,7 +232,7 @@ class array_stream : private object_stream_base
void write (Value const & value)
{
ctx.begin_array_element (std::exchange (first_element, false));
stream_as (value, ctx);
stream_as_value (value, ctx);
ctx.end_array_element ();
}

Expand Down Expand Up @@ -292,7 +292,7 @@ class root_object_stream : private object_stream_base
void write (Value const & value)
{
ctx.os << boost::typeindex::type_id<Value> ().pretty_name ();
stream_as (value, ctx);
stream_as_value (value, ctx);
}

// Handle `.write_range (container)`
Expand Down Expand Up @@ -406,7 +406,7 @@ struct object_stream_formatter
*/

template <class Value>
inline void stream_as (Value const & value, object_stream_context & ctx)
inline void stream_as_value (Value const & value, object_stream_context & ctx)
{
using magic_enum::ostream_operators::operator<<; // Support ostream operator for all enums

Expand All @@ -419,7 +419,7 @@ inline void stream_as (Value const & value, object_stream_context & ctx)
}

template <object_streamable Value>
inline void stream_as (Value const & value, object_stream_context & ctx)
inline void stream_as_value (Value const & value, object_stream_context & ctx)
{
ctx.begin_object ();

Expand All @@ -431,7 +431,7 @@ inline void stream_as (Value const & value, object_stream_context & ctx)
}

template <array_streamable Value>
inline void stream_as (Value const & value, object_stream_context & ctx)
inline void stream_as_value (Value const & value, object_stream_context & ctx)
{
ctx.begin_array ();

Expand Down Expand Up @@ -479,57 +479,57 @@ inline void stream_as (Value const & value, array_stream & ars)

namespace nano
{
inline void stream_as (bool const & value, object_stream_context & ctx)
inline void stream_as_value (bool const & value, object_stream_context & ctx)
{
ctx.os << (value ? ctx.config.true_value : ctx.config.false_value);
}

inline void stream_as (const int8_t & value, object_stream_context & ctx)
inline void stream_as_value (const int8_t & value, object_stream_context & ctx)
{
ctx.os << static_cast<uint32_t> (value); // Avoid printing as char
}

inline void stream_as (const uint8_t & value, object_stream_context & ctx)
inline void stream_as_value (const uint8_t & value, object_stream_context & ctx)
{
ctx.os << static_cast<uint32_t> (value); // Avoid printing as char
}

inline void stream_as (const int16_t & value, object_stream_context & ctx)
inline void stream_as_value (const int16_t & value, object_stream_context & ctx)
{
ctx.os << value;
}

inline void stream_as (const uint16_t & value, object_stream_context & ctx)
inline void stream_as_value (const uint16_t & value, object_stream_context & ctx)
{
ctx.os << value;
}

inline void stream_as (const int32_t & value, object_stream_context & ctx)
inline void stream_as_value (const int32_t & value, object_stream_context & ctx)
{
ctx.os << value;
}

inline void stream_as (const uint32_t & value, object_stream_context & ctx)
inline void stream_as_value (const uint32_t & value, object_stream_context & ctx)
{
ctx.os << value;
}

inline void stream_as (const int64_t & value, object_stream_context & ctx)
inline void stream_as_value (const int64_t & value, object_stream_context & ctx)
{
ctx.os << value;
}

inline void stream_as (const uint64_t & value, object_stream_context & ctx)
inline void stream_as_value (const uint64_t & value, object_stream_context & ctx)
{
ctx.os << value;
}

inline void stream_as (const float & value, object_stream_context & ctx)
inline void stream_as_value (const float & value, object_stream_context & ctx)
{
ctx.os << std::fixed << std::setprecision (ctx.config.precision) << value;
}

inline void stream_as (const double & value, object_stream_context & ctx)
inline void stream_as_value (const double & value, object_stream_context & ctx)
{
ctx.os << std::fixed << std::setprecision (ctx.config.precision) << value;
}
Expand All @@ -539,7 +539,7 @@ inline void stream_as_optional (const Opt & opt, object_stream_context & ctx)
{
if (opt)
{
stream_as (*opt, ctx);
stream_as_value (*opt, ctx);
}
else
{
Expand All @@ -548,25 +548,25 @@ inline void stream_as_optional (const Opt & opt, object_stream_context & ctx)
}

template <class Value>
inline void stream_as (std::shared_ptr<Value> const & value, object_stream_context & ctx)
inline void stream_as_value (std::shared_ptr<Value> const & value, object_stream_context & ctx)
{
stream_as_optional (value, ctx);
}

template <class Value>
inline void stream_as (std::unique_ptr<Value> const & value, object_stream_context & ctx)
inline void stream_as_value (std::unique_ptr<Value> const & value, object_stream_context & ctx)
{
stream_as_optional (value, ctx);
}

template <class Value>
inline void stream_as (std::weak_ptr<Value> const & value, object_stream_context & ctx)
inline void stream_as_value (std::weak_ptr<Value> const & value, object_stream_context & ctx)
{
stream_as_optional (value.lock (), ctx);
}

template <class Value>
inline void stream_as (std::optional<Value> const & value, object_stream_context & ctx)
inline void stream_as_value (std::optional<Value> const & value, object_stream_context & ctx)
{
stream_as_optional (value, ctx);
}
Expand Down

0 comments on commit 5402802

Please sign in to comment.