DAW JSON Link
daw_json_enums.h
Go to the documentation of this file.
1// Copyright (c) Darrell Wright
2//
3// Distributed under the Boost Software License, Version 1.0. (See accompanying
4// file LICENSE or copy at http://www.boost.org/LICENSE_1_0.txt)
5//
6// Official repository: https://github.com/beached/daw_json_link
7//
8
9#pragma once
10
11#include "version.h"
12
13#include <daw/daw_utility.h>
14
15#include <cstdint>
16#include <string_view>
17#include <utility>
18
19namespace daw::json {
20 inline namespace DAW_JSON_VER {
22 enum class JsonParseTypes : std::uint_fast8_t {
23 Real,
24 Signed,
25 Unsigned,
26 Bool,
27 StringRaw,
29 Date,
30 Class,
31 Array,
34 Null,
35 KeyValue,
38 Custom,
40 Variant,
47 Tuple,
49 Unknown,
50 };
51
53 enum class JsonBaseParseTypes : std::uint_fast8_t {
54 Number,
55 Bool,
56 String,
57 Class,
58 Array,
59 Null,
60 None
61 };
62
63 constexpr std::string_view to_string( JsonBaseParseTypes pt ) {
64 switch( pt ) {
66 return "Number";
68 return "Bool";
70 return "String";
72 return "Class";
74 return "Array";
76 return "Null";
78 default:
79 return "None";
80 }
81 }
82
83 /***
84 * Control whether a type can be missing or null.
85 * MustExist - members make it an error if their value is null or they are
86 * missing
87 * Nullable - members can have a value of null or be missing
88 * NullVisible - members must exist but can have a value of null
89 */
90 enum class JsonNullable : unsigned { MustExist, Nullable, NullVisible };
91
92 /***
93 * When not MustExist, the default Null type for unspecified _null json
94 * types
95 */
97
98 namespace json_details {
99 template<JsonNullable nullable>
101 std::bool_constant<nullable != JsonNullable::MustExist>;
102
103 template<JsonNullable nullable>
104 inline constexpr bool is_nullable_json_value_v =
106 } // namespace json_details
107
108 inline namespace details {
109 template<JsonParseTypes ParseType, JsonNullable Nullable>
111 json_details::is_nullable_json_value_v<Nullable> ? JsonParseTypes::Null
112 : ParseType;
113 } // namespace details
114
118 template<JsonParseTypes v>
119 using ParseTag = daw::constant<v>;
120
121 } // namespace DAW_JSON_VER
122} // namespace daw::json
constexpr JsonParseTypes get_parse_type_v
Definition: daw_json_enums.h:110
std::bool_constant< nullable !=JsonNullable::MustExist > is_nullable_json_value
Definition: daw_json_enums.h:101
constexpr bool is_nullable_json_value_v
Definition: daw_json_enums.h:104
JsonParseTypes
The tags used by the parser to determine what parser to call.
Definition: daw_json_enums.h:22
@ KeyValueArray
Class - Member names form the string key into a key/value,map, or dictionary like type.
@ Array
A class type with named members.
@ Date
String - Fully processed string.
@ Variant
Can be a literal, string, or either and allows for some customized parsing.
@ VariantIntrusive
A variant with up to N types and a Switcher callable that takes uses another member to determine what...
@ SizedArray
An array type with homogenous members.
@ Signed
Number - Floating Point.
@ Unknown
Array - An array type where each element is mapped to the member of a C++ class.
@ Custom
Array - Each element has a key and a value submember.
@ Unsigned
Number - Signed Integer.
@ Tuple
A variant type where the Switcher is based on a submember of the class being parsed.
@ Null
An array with a fixed size. This allows for size_t/ptr like combinations.
@ StringEscaped
String - A raw string as is. Escapes are left in.
@ Bool
Number - Unsigned Integer.
@ VariantTagged
Any one of the basic json types class/array/boolean/number/string.
constexpr std::string_view to_string(JsonBaseParseTypes pt)
Definition: daw_json_enums.h:63
daw::constant< v > ParseTag
Definition: daw_json_enums.h:119
JsonNullable
Definition: daw_json_enums.h:90
JsonBaseParseTypes
The fundamental JSON types.
Definition: daw_json_enums.h:53
constexpr JsonNullable JsonNullDefault
Definition: daw_json_enums.h:96
Definition: daw_from_json.h:22
#define DAW_JSON_VER
The version string used in namespace definitions. Must be a valid namespace name.
Definition: version.h:16