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 <cstdint>
14 #include <string_view>
15 #include <utility>
16 
17 namespace daw::json {
18  inline namespace DAW_JSON_VER {
19  enum class JsonParseTypes : std::uint_fast8_t {
20  Real,
21  Signed,
22  Unsigned,
23  Bool,
24  StringRaw,
26  Date,
27  Class,
28  Array,
29  SizedArray,
30  Null,
31  KeyValue,
33  Custom,
34  Variant,
36  Tuple,
37  Unknown
38  };
39 
40  enum class JsonBaseParseTypes : std::uint_fast8_t {
41  Number,
42  Bool,
43  String,
44  Class,
45  Array,
46  Null,
47  None
48  };
49 
50  constexpr std::string_view to_string( JsonBaseParseTypes pt ) {
51  switch( pt ) {
53  return "Number";
55  return "Bool";
57  return "String";
59  return "Class";
61  return "Array";
63  return "Null";
65  default:
66  return "None";
67  }
68  }
69 
70  /***
71  * Control whether a type can be missing or null.
72  * MustExist - members make it an error if their value is null or they are
73  * missing
74  * Nullable - members can have a value of null or be missing
75  * NullVisible - members must exist but can have a value of null
76  */
77  enum class JsonNullable : unsigned { MustExist, Nullable, NullVisible };
78 
79  /***
80  * When not MustExist, the default Null type for unspecified _null json
81  * types
82  */
84 
85  namespace json_details {
86  template<JsonNullable nullable>
88  std::bool_constant<nullable != JsonNullable::MustExist>;
89 
90  template<JsonNullable nullable>
91  inline constexpr bool is_nullable_json_value_v =
93  } // namespace json_details
94 
95  inline namespace details {
96  template<JsonParseTypes ParseType, JsonNullable Nullable>
97  inline constexpr JsonParseTypes get_parse_type_v =
98  json_details::is_nullable_json_value_v<Nullable> ? JsonParseTypes::Null
99  : ParseType;
100  } // namespace details
101 
105  template<JsonParseTypes v>
106  using ParseTag = std::integral_constant<JsonParseTypes, v>;
107 
108  } // namespace DAW_JSON_VER
109 } // namespace daw::json
constexpr JsonParseTypes get_parse_type_v
Definition: daw_json_enums.h:97
std::bool_constant< nullable !=JsonNullable::MustExist > is_nullable_json_value
Definition: daw_json_enums.h:88
constexpr bool is_nullable_json_value_v
Definition: daw_json_enums.h:91
JsonParseTypes
Definition: daw_json_enums.h:19
constexpr std::string_view to_string(JsonBaseParseTypes pt)
Definition: daw_json_enums.h:50
std::integral_constant< JsonParseTypes, v > ParseTag
Definition: daw_json_enums.h:106
JsonNullable
Definition: daw_json_enums.h:77
JsonBaseParseTypes
Definition: daw_json_enums.h:40
constexpr JsonNullable JsonNullDefault
Definition: daw_json_enums.h:83
Definition: daw_from_json.h:22
#define DAW_JSON_VER
Definition: version.h:11