JSON Voorhees
Killer JSON for C++
Loading...
Searching...
No Matches
context.hpp
Go to the documentation of this file.
1/// \file jsonv/serialization/context.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#include <jsonv/version.hpp>
15
16#include <optional>
17
18namespace jsonv
19{
20
21/// \addtogroup Serialization
22/// \{
23
24/// Provides extra information to routines used for extraction and serialization.
26{
27public:
28 /// Create a new instance using the default \c formats (\c formats::global).
30
31 /// Create a new instance using the given \a fmt, \a ver and \a userdata.
33 std::optional<jsonv::version> ver = std::nullopt,
34 const void* userdata = nullptr
35 );
36
37 virtual ~context() noexcept = 0;
38
39 /// Get the \c formats object backing extraction and encoding.
41 const jsonv::formats& formats() const
42 {
43 return _formats;
44 }
45
46 /// Get the version this context was created with. If no version was specified, this is \c std::nullopt -- which
47 /// means the caller did not care about versioning, not that the version is \c 0.0.
49 const std::optional<jsonv::version>& version() const
50 {
51 return _version;
52 }
53
54 /// Get a pointer to arbitrary user data.
56 const void* user_data() const
57 {
58 return _user_data;
59 }
60
61private:
62 jsonv::formats _formats;
63 std::optional<jsonv::version> _version;
64 const void* _user_data;
65};
66
67/// \}
68
69}
Provides extra information to routines used for extraction and serialization.
Definition context.hpp:26
const std::optional< jsonv::version > & version() const
Get the version this context was created with.
Definition context.hpp:49
context()
Create a new instance using the default formats (formats::global).
context(jsonv::formats fmt, std::optional< jsonv::version > ver=std::nullopt, const void *userdata=nullptr)
Create a new instance using the given fmt, ver and userdata.
const void * user_data() const
Get a pointer to arbitrary user data.
Definition context.hpp:56
An adapter for enumeration types.
Simply put, this class is a collection of extractor and serializer instances.
Definition formats.hpp:160
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) 2015-2020 by Travis Gockel.