JSON Voorhees
Killer JSON for C++
Loading...
Searching...
No Matches
serializer.hpp
Go to the documentation of this file.
1
/// \file jsonv/serialization/serializer.hpp
2
///
3
/// Copyright (c) 2015-2026 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
>
13
#include <
jsonv/forward.hpp
>
14
#include <
jsonv/writer.hpp
>
15
16
#include <typeinfo>
17
18
namespace
jsonv
19
{
20
21
/// \addtogroup Serialization
22
/// \{
23
24
/// A \c serializer holds the method for converting an arbitrary C++ type into JSON, written token by token into a
25
/// \c writer.
26
class
JSONV_PUBLIC
serializer
27
{
28
public
:
29
virtual
~serializer
()
noexcept
;
30
31
/// Get the run-time type this \c serializer knows how to serialize. Once this \c serializer is registered with a
32
/// \c formats, it is not allowed to change.
33
JSONV_NODISCARD
34
virtual
const
std::type_info&
get_type
() const noexcept = 0;
35
36
/// Write the value in the given region of memory \a from into \a to.
37
///
38
/// \param context Extra information to help you serialize sub-objects for your type, such as the ability to find
39
/// other \c serializer implementations via \c formats. Serialize each part of your type through
40
/// \c serialization_context::serialize: anything thrown while doing so comes out of it as a
41
/// \c serialization_error naming the type and the position in the document, as
42
/// \c writer::current_path reports it.
43
/// \param from The region of memory that represents the C++ value to convert to JSON. The pointer comes as the
44
/// result of a <tt>static_cast<const void*></tt>, so performing a \c static_cast back to your
45
/// type is okay.
46
/// \param to The writer to write into, positioned where the value goes: at the root, as the next element of an open
47
/// array, or as the value of the key just written. Write exactly one value -- a scalar, or a structure
48
/// you open and close -- and nothing else. To refuse, throw: \c to.current_path() is where you are.
49
///
50
/// \see serializer_for
51
/// \see value_serializer_for
52
/// \see adapter_for
53
virtual
void
serialize(const
serialization_context
&
context
, const
void
* from,
writer
& to) const = 0;
54
};
55
56
/// \}
57
58
}
jsonv::context
Provides extra information to routines used for deserialization and serialization.
Definition
context.hpp:26
jsonv::serialization_context
Provides extra information to routines used for serialization: the formats to find other serializers ...
Definition
serialize.hpp:42
jsonv::serializer
A serializer holds the method for converting an arbitrary C++ type into JSON, written token by token ...
Definition
serializer.hpp:27
jsonv::serializer::get_type
virtual const std::type_info & get_type() const noexcept=0
Get the run-time type this serializer knows how to serialize.
jsonv::writer
A writer instance writes a JSON ast_node sequence to some form of sink: an encoder,...
Definition
writer.hpp:68
config.hpp
Copyright (c) 2014-2020 by Travis Gockel.
forward.hpp
Copyright (c) 2012-2020 by Travis Gockel.
JSONV_NODISCARD
#define JSONV_NODISCARD
Warn if the caller discards the result of this function.
Definition
config.hpp:143
JSONV_PUBLIC
#define JSONV_PUBLIC
This function or class is part of the public API for JSON Voorhees.
Definition
config.hpp:124
writer.hpp
Write a JSON AST.
jsonv
serialization
serializer.hpp
Generated by
1.9.8