Skip to content

Commit

Permalink
wrapper_maker -> iostream_wrapper_maker
Browse files Browse the repository at this point in the history
  • Loading branch information
Nomango committed Sep 27, 2022
1 parent a6272e3 commit bcd2ade
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 3 deletions.
2 changes: 1 addition & 1 deletion include/configor/configor_serializer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ class serializable
}

// dump to string
template <typename _TargetCharTy = typename value_type::char_type>
template <typename _TargetCharTy>
static void dump(typename _Args::template string_type<_TargetCharTy>& str, const value_type& v,
std::initializer_list<serializer_option<_TargetCharTy>> options = {})
{
Expand Down
30 changes: 29 additions & 1 deletion include/configor/configor_wrapper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,34 @@ class ostream_wrapper
const _Ty& v_;
};

template <typename _ConfigTy, typename _Args>
class ostream_wrapper<_ConfigTy, basic_value<_Args>>
{
public:
using config_type = _ConfigTy;
using value_type = typename _ConfigTy::value;

explicit ostream_wrapper(const value_type& v)
: v_(v)
{
}

template <typename _TargetCharTy, typename _Traits>
friend std::basic_ostream<_TargetCharTy, _Traits>& operator<<(std::basic_ostream<_TargetCharTy, _Traits>& out,
const ostream_wrapper& wrapper)
{
typename std::basic_ostream<_TargetCharTy, _Traits>::sentry s(out);
if (s)
{
config_type::dump(out, wrapper.v_);
}
return out;
}

private:
const value_type& v_;
};

template <typename _ConfigTy, typename _Ty>
class iostream_wrapper : public ostream_wrapper<_ConfigTy, _Ty>
{
Expand Down Expand Up @@ -118,7 +146,7 @@ class iostream_wrapper<_ConfigTy, basic_value<_Args>> : public ostream_wrapper<_
};

template <typename _ConfigTy, typename _ValTy>
class wrapper_maker
class iostream_wrapper_maker
{
public:
using config_type = _ConfigTy;
Expand Down
2 changes: 1 addition & 1 deletion include/configor/json.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class basic_json final
: public detail::serializable<_Args, detail::json_serializer, _DefaultEncoding>
, public detail::parsable<_Args, detail::json_parser, _DefaultEncoding>
, public detail::value_maker<basic_value<_Args>>
, public detail::wrapper_maker<basic_json<_Args, _DefaultEncoding>, basic_value<_Args>>
, public detail::iostream_wrapper_maker<basic_json<_Args, _DefaultEncoding>, basic_value<_Args>>
{
public:
using value = basic_value<_Args>;
Expand Down

0 comments on commit bcd2ade

Please sign in to comment.