JSON Voorhees
Killer JSON for C++
Loading...
Searching...
No Matches
wrapper_adapter.hpp
Go to the documentation of this file.
1/// \file jsonv/serialization/wrapper_adapter.hpp
2///
3/// Copyright (c) 2015-2020 by Travis Gockel. All rights reserved.
4///
5/// This program is free software: you can redistribute it and/or modify it under the terms of the Apache License
6/// as published by the Apache Software Foundation, either version 2 of the License, or (at your option) any later
7/// version.
8///
9/// \author Travis Gockel (travis@gockelhut.com)
10#pragma once
11
12#include <jsonv/config.hpp>
14
15#include "adapter_for.hpp"
16
17namespace jsonv
18{
19
20/// \addtogroup Serialization
21/// \{
22
23/// An adapter for "wrapper" types.
24///
25/// \tparam TWrapper A wrapper type with a member \c value_type which represents the underlying wrapped type. This must
26/// be explicitly convertible to and from the \c value_type.
27template <typename TWrapper>
29 public adapter_for<TWrapper>
30{
31 using element_type = typename TWrapper::value_type;
32
33protected:
34 virtual TWrapper create(const extraction_context& context, const value& from) const override
35 {
36 return TWrapper(context.extract<element_type>(from));
37 }
38
39 virtual value to_json(const serialization_context& context, const TWrapper& from) const override
40 {
41 return context.to_json(element_type(from));
42 }
43};
44
45/// \}
46
47}
An adapter for the type T.
virtual void extract(const extraction_context &context, const value &from, void *into) const override
Extract a the type from a value into a region of memory.
An adapter for enumeration types.
Represents a single JSON value, which can be any one of a potential kind, each behaving slightly diff...
Definition value.hpp:107
An adapter for "wrapper" types.
Copyright (c) 2014-2020 by Travis Gockel.
Conversion between C++ types and JSON values.