CodePorting.Translator Cs2Cpp
CodePorting.Translator.Cs2Cpp.Framework
json_value.h
1#pragma once
2
3#include <system/object_ext.h>
4#include <system/nullable.h>
5#include <system/guid.h>
6#include <system/exceptions.h>
7#include <system/diagnostics/debug.h>
8#include <system/details/patterns.h>
9#include <system/decimal.h>
10#include <system/date_time_offset.h>
11#include <system/date_time.h>
12#include <cstdint>
13
14#include "system/text/json/nodes/json_node.h"
15#include "system/text/json/nodes/json_node_options.h"
16#include "system/text/json/document/json_element.h"
17#include "system/text/json/throw_helper.h"
18#include "system/text/json/serialization/json_converter.h"
19#include "system/text/json/serialization/json_number_handling.h"
20
21namespace System
22{
23namespace Text
24{
25namespace Json
26{
27namespace Nodes
28{
29class JsonArray;
30class JsonObject;
31template <typename> class JsonValue;
32template <typename> class JsonValueCustomized;
33class JsonValueOfElement;
34class JsonValueOfJsonBool;
35class JsonValueOfJsonNumber;
36class JsonValueOfJsonString;
37template <typename> class JsonValuePrimitive;
38} // namespace Nodes
39namespace Serialization
40{
41namespace Converters
42{
43class JsonValueConverter;
44} // namespace Converters
45} // namespace Serialization
46} // namespace Json
47class ValueStringBuilder;
48} // namespace Text
49} // namespace System
50
51namespace System {
52
53namespace Text {
54
55namespace Json {
56
57namespace Nodes {
58
59class JsonValueBase : public JsonNode
60{
61 typedef JsonValueBase ThisType;
62 typedef JsonNode BaseType;
63
64 typedef ::System::BaseTypesInfo<BaseType> ThisTypeBaseTypesInfo;
65 RTTI_INFO_DECL();
66
67 friend class JsonArray;
68 friend class JsonObject;
69 friend class JsonValueOfElement;
70 friend class JsonValueOfJsonBool;
74 template<typename FT0> friend class JsonValue;
75 template<typename FT0> friend class JsonValuePrimitive;
76
77public:
78
81 static System::SharedPtr<JsonValueBase> Create(uint8_t value, Nullable<JsonNodeOptions> options = nullptr);
83 static System::SharedPtr<JsonValueBase> Create(char16_t value, Nullable<JsonNodeOptions> options = nullptr);
91 static System::SharedPtr<JsonValueBase> Create(double value, Nullable<JsonNodeOptions> options = nullptr);
95 static System::SharedPtr<JsonValueBase> Create(int16_t value, Nullable<JsonNodeOptions> options = nullptr);
97 static System::SharedPtr<JsonValueBase> Create(int32_t value, Nullable<JsonNodeOptions> options = nullptr);
99 static System::SharedPtr<JsonValueBase> Create(int64_t value, Nullable<JsonNodeOptions> options = nullptr);
106 static System::SharedPtr<JsonValueBase> Create(uint16_t value, Nullable<JsonNodeOptions> options = nullptr);
108 static System::SharedPtr<JsonValueBase> Create(uint32_t value, Nullable<JsonNodeOptions> options = nullptr);
110 static System::SharedPtr<JsonValueBase> Create(uint64_t value, Nullable<JsonNodeOptions> options = nullptr);
114 template<typename T>
115 /*virtual*/ bool TryGetValue(T& value)
116 {
117 value = System::Default<T>();
118 return false;
119 }
120 template<typename T>
122 {
123 if (System::IsNull(jsonTypeInfo))
124 {
125 throw System::ArgumentNullException(u"jsonTypeInfo");
126 }
127
128 if (System::IsNull(value))
129 {
130 return nullptr;
131 }
132
133 if (System::ObjectExt::Is<JsonNode>(value))
134 {
136 }
137
138 jsonTypeInfo->EnsureConfigured();
139
140 JsonElement element;
141 if (System::Is<JsonElement>(value, element) && jsonTypeInfo->get_EffectiveConverter()->get_IsInternalConverter())
142 {
143 return CreateFromElement(System::Ref(element), options);
144 }
145
146 return CreateFromTypeInfo<T>(value, jsonTypeInfo, options);
147 }
148
149protected:
150
153
156 template<typename T>
158 {
159 if (JsonValue<T>::get_TypeIsSupportedPrimitive() && System::Is(jsonTypeInfo, (_== true)) && (jsonTypeInfo->get_EffectiveNumberHandling() & System::Text::Json::Serialization::JsonNumberHandling::WriteAsString) == 0)
160 {
161 // If the type is using the built-in converter for a known primitive,
162 // switch to the more efficient JsonValuePrimitive<T> implementation.
163 return System::MakeObject<JsonValuePrimitive<T>>(value, jsonTypeInfo->get_EffectiveConverter(), options);
164 }
165
166 return System::MakeObject<JsonValueCustomized<T>>(value, jsonTypeInfo, options);
167 }
168
170
171 virtual ~JsonValueBase();
172
173private:
174
176
177};
178
179} // namespace Nodes
180} // namespace Json
181} // namespace Text
182} // namespace System
Represents a specific date and time value on the time continuum. This type should be allocated on sta...
Definition: date_time.h:50
Contains the date and time of day relative to Coordinated Universal Time. Objects of this class shoul...
Definition: date_time_offset.h:16
Represents a decimal number. This type should be allocated on stack and passed to functions by value ...
Definition: decimal.h:107
Represents a Globally Unique IDentifier This type should be allocated on stack and passed to function...
Definition: guid.h:34
Forward declaration.
Definition: nullable.h:75
Base class that enables using methods available for System.Object class in C#. All non-trivial classe...
Definition: object.h:51
Pointer class to wrap types being allocated on heap. Use it to manage memory for classes inheriting O...
Definition: smart_ptr.h:180
String class used across the library. Is a substitute for C# System.String when translating code....
Definition: string.h:126
Definition: json_element.h:59
Definition: json_array.h:56
Definition: json_node.h:54
friend class JsonValueBase
Definition: json_node.h:63
Definition: json_object.h:56
Definition: json_value.h:60
static System::SharedPtr< JsonValueBase > Create(uint64_t value, Nullable< JsonNodeOptions > options=nullptr)
static System::SharedPtr< JsonValueBase > Create(uint8_t value, Nullable< JsonNodeOptions > options=nullptr)
static System::SharedPtr< JsonValueBase > CreateFromTypeInfo(T value, System::SharedPtr< Serialization::Metadata::JsonTypeInfo< T > > jsonTypeInfo, Nullable< JsonNodeOptions > options=nullptr)
Definition: json_value.h:157
static System::SharedPtr< JsonValueBase > Create(Nullable< int64_t > value, Nullable< JsonNodeOptions > options=nullptr)
bool TryGetValue(T &value)
Definition: json_value.h:115
static System::SharedPtr< JsonValueBase > Create(Nullable< int8_t > value, Nullable< JsonNodeOptions > options=nullptr)
static System::SharedPtr< JsonValueBase > Create(JsonElement value, Nullable< JsonNodeOptions > options=nullptr)
static System::SharedPtr< JsonValueBase > Create(Nullable< int32_t > value, Nullable< JsonNodeOptions > options=nullptr)
static System::SharedPtr< JsonValueBase > Create(DateTimeOffset value, Nullable< JsonNodeOptions > options=nullptr)
static System::SharedPtr< JsonValueBase > Create(Nullable< Guid > value, Nullable< JsonNodeOptions > options=nullptr)
static System::SharedPtr< JsonValueBase > Create(Nullable< DateTimeOffset > value, Nullable< JsonNodeOptions > options=nullptr)
static System::SharedPtr< JsonValueBase > Create(Nullable< uint64_t > value, Nullable< JsonNodeOptions > options=nullptr)
static System::SharedPtr< JsonValueBase > Create(String value, Nullable< JsonNodeOptions > options=nullptr)
static System::SharedPtr< JsonValueBase > Create(char16_t value, Nullable< JsonNodeOptions > options=nullptr)
static System::SharedPtr< JsonValueBase > Create(int32_t value, Nullable< JsonNodeOptions > options=nullptr)
static System::SharedPtr< JsonValueBase > Create(DateTime value, Nullable< JsonNodeOptions > options=nullptr)
static System::SharedPtr< JsonValueBase > Create(int8_t value, Nullable< JsonNodeOptions > options=nullptr)
static System::SharedPtr< JsonValueBase > Create(Nullable< char16_t > value, Nullable< JsonNodeOptions > options=nullptr)
static System::SharedPtr< JsonValueBase > Create(Nullable< int16_t > value, Nullable< JsonNodeOptions > options=nullptr)
static System::SharedPtr< JsonValueBase > Create(int16_t value, Nullable< JsonNodeOptions > options=nullptr)
static System::SharedPtr< JsonValueBase > Create(Nullable< JsonElement > value, Nullable< JsonNodeOptions > options=nullptr)
static System::SharedPtr< JsonValueBase > Create(int64_t value, Nullable< JsonNodeOptions > options=nullptr)
static System::SharedPtr< JsonValueBase > Create(bool value, Nullable< JsonNodeOptions > options=nullptr)
static System::SharedPtr< JsonValueBase > Create(Decimal value, Nullable< JsonNodeOptions > options=nullptr)
static System::SharedPtr< JsonValueBase > Create(uint16_t value, Nullable< JsonNodeOptions > options=nullptr)
static const String CreateDynamicCodeMessage
Definition: json_value.h:152
static System::SharedPtr< JsonValueBase > Create(Nullable< float > value, Nullable< JsonNodeOptions > options=nullptr)
static System::SharedPtr< JsonValueBase > Create(T value, System::SharedPtr< Serialization::Metadata::JsonTypeInfo< T > > jsonTypeInfo, Nullable< JsonNodeOptions > options=nullptr)
Definition: json_value.h:121
static System::SharedPtr< JsonValueBase > CreateFromElement(JsonElement element, Nullable< JsonNodeOptions > options=nullptr)
static System::SharedPtr< JsonValueBase > Create(Nullable< double > value, Nullable< JsonNodeOptions > options=nullptr)
static System::SharedPtr< JsonValueBase > Create(Nullable< DateTime > value, Nullable< JsonNodeOptions > options=nullptr)
bool DeepEqualsCore(System::SharedPtr< JsonNode > otherNode) override
static System::SharedPtr< JsonValueBase > Create(Nullable< Decimal > value, Nullable< JsonNodeOptions > options=nullptr)
static System::SharedPtr< JsonValueBase > Create(Guid value, Nullable< JsonNodeOptions > options=nullptr)
void GetPath(ValueStringBuilder &path, System::SharedPtr< JsonNode > child) override
static System::SharedPtr< JsonValueBase > Create(Nullable< uint8_t > value, Nullable< JsonNodeOptions > options=nullptr)
static const String CreateUnreferencedCodeMessage
Definition: json_value.h:151
static System::SharedPtr< JsonValueBase > Create(Nullable< uint16_t > value, Nullable< JsonNodeOptions > options=nullptr)
static System::SharedPtr< JsonValueBase > Create(Nullable< uint32_t > value, Nullable< JsonNodeOptions > options=nullptr)
static System::SharedPtr< JsonValueBase > Create(double value, Nullable< JsonNodeOptions > options=nullptr)
static System::SharedPtr< JsonValueBase > Create(float value, Nullable< JsonNodeOptions > options=nullptr)
static System::SharedPtr< JsonValueBase > Create(Nullable< bool > value, Nullable< JsonNodeOptions > options=nullptr)
static System::SharedPtr< JsonValueBase > Create(uint32_t value, Nullable< JsonNodeOptions > options=nullptr)
Definition: json_value_of_t.h:53
Definition: json_value_of_element.h:47
Definition: json_value_of_json_primitive.h:167
Definition: json_value_of_json_primitive.h:223
Definition: json_value_of_json_primitive.h:65
Definition: json_value_of_t_primitive.h:47
static void ThrowArgumentException_NodeValueNotAllowed(String paramName)
Definition: value_string_builder.h:17
@ Text
Defines color adjustment information for text.
Definition: db_command.h:9
decltype(Ref(std::declval< T & >())) Ref(const std::reference_wrapper< T > &wrapper)
Wrapper to make sure Ref(std::ref(DynamicWeakPtr)) works.
Definition: dynamic_weak_ptr.h:207