nfx-serialization 0.9.3
Cross-platform C++ JSON serialization library with extensible trait capabilities
Loading...
Searching...
No Matches
Concepts.h
Go to the documentation of this file.
1/*
2 * MIT License
3 *
4 * Copyright (c) 2025 nfx
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in all
14 * copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 * SOFTWARE.
23 */
24
31
32#pragma once
33
34#include <nfx/json/Document.h>
35#include <type_traits>
36
37namespace nfx::serialization::json
38{
39 //=====================================================================
40 // Import types from nfx::json
41 //=====================================================================
42
43 using nfx::json::Document;
44 using nfx::json::Array;
45 using nfx::json::Object;
46 using nfx::json::Type;
47
48 // Import type trait from nfx::json
49 using nfx::json::is_json_container_v;
50
51 //=====================================================================
52 // Forward declarations
53 //=====================================================================
54
60 template <typename T>
62
63 //=====================================================================
64 // Type trait to detect SerializationTraits specializations
65 //=====================================================================
66
67 namespace detail
68 {
69 using nfx::json::Document;
70
78 template <typename T, typename = void>
79 struct has_serialization_traits : std::false_type
80 {
81 };
82
83 template <typename T>
85 T,
86 std::void_t<decltype( SerializationTraits<std::decay_t<T>>::toDocument(
87 std::declval<const std::decay_t<T>&>(), std::declval<Document&>() ) )>> : std::true_type
88 {
89 };
90
94 template <typename T>
96
97 //=====================================================================
98 // Type trait to identify nfx extension types
99 //=====================================================================
100
113 template <typename T>
114 struct is_nfx_extension_type : std::false_type
115 {
116 };
117
121 template <typename T>
123 } // namespace detail
124
125 //=====================================================================
126 // Concepts for template overload resolution
127 //=====================================================================
128
136 template <typename T>
138 !detail::is_nfx_extension_type_v<T> && !nfx::json::Primitive<T> && !is_json_container_v<T> &&
139 !std::is_base_of_v<nfx::json::Document, std::remove_cvref_t<T>>;
140
147 template <typename T>
149 detail::is_nfx_extension_type_v<T> && !nfx::json::Primitive<T> && !is_json_container_v<T> &&
150 !std::is_base_of_v<nfx::json::Document, std::remove_cvref_t<T>>;
151} // namespace nfx::serialization::json
constexpr bool is_nfx_extension_type_v
Helper variable template for is_nfx_extension_type.
Definition Concepts.h:122
constexpr bool has_serialization_traits_v
Helper variable template for has_serialization_traits.
Definition Concepts.h:95
Serialization traits template (forward declaration).
Detect if a type has a custom SerializationTraits specialization.
Definition Concepts.h:80
Identifies types from nfx:: namespaces that have SerializationTraits.
Definition Concepts.h:115
Concept for STL types that use Serializer<T>.
Definition Concepts.h:137
Concept for nfx extension types that use SerializationTraits<T>.
Definition Concepts.h:148