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-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>
13#include <jsonv/forward.hpp>
14#include <jsonv/value.hpp>
15
16#include <typeinfo>
17
18namespace jsonv
19{
20
21/// \addtogroup Serialization
22/// \{
23
24/// A \c serializer holds the method for converting an arbitrary C++ type into a \c value.
26{
27public:
28 virtual ~serializer() noexcept;
29
30 /// Get the run-time type this \c serialize knows how to encode. Once this \c serializer is registered with a
31 /// \c formats, it is not allowed to change.
33 virtual const std::type_info& get_type() const = 0;
34
35 /// Create a \c value \a from the value in the given region of memory.
36 ///
37 /// \param context Extra information to help you encode sub-objects for your type, such as the ability to find other
38 /// \c formats. It also tracks the progression of types in the encoding heirarchy, so any exceptions
39 /// thrown will have \c type information in the error message.
40 /// \param from The region of memory that represents the C++ value to convert to JSON. The pointer comes as the
41 /// result of a <tt>static_cast&lt;void*&gt;</tt>, so performing a \c static_cast back to your type is
42 /// okay.
45 const void* from
46 ) const = 0;
47};
48
49/// \}
50
51}
Provides extra information to routines used for extraction and serialization.
Definition context.hpp:26
An adapter for enumeration types.
A serializer holds the method for converting an arbitrary C++ type into a value.
virtual value to_json(const serialization_context &context, const void *from) const =0
Create a value from the value in the given region of memory.
virtual const std::type_info & get_type() const =0
Get the run-time type this serialize knows how to encode.
Represents a single JSON value, which can be any one of a potential kind, each behaving slightly diff...
Definition value.hpp:113
Copyright (c) 2014-2020 by Travis Gockel.
#define JSONV_NODISCARD
Warn if the caller discards the result of this function.
Definition config.hpp:121
#define JSONV_PUBLIC
This function or class is part of the public API for JSON Voorhees.
Definition config.hpp:102
Copyright (c) 2012-2020 by Travis Gockel.
Copyright (c) 2012-2020 by Travis Gockel.