CodePorting.Translator Cs2Cpp
CodePorting.Translator.Cs2Cpp.Framework
json_element.h
1#pragma once
2
3#include <system/default.h>
4#include <system/collections/ienumerator.h>
5#include <system/collections/ienumerable.h>
6#include <system/array.h>
7#include <cstdint>
8
9#include "system/text/json/document/json_document_options.h"
10
11namespace System
12{
13class DateTime;
14class DateTimeOffset;
15class Decimal;
16class Guid;
17namespace IO
18{
19class Stream;
20} // namespace IO
21template <typename> class Nullable;
22template <typename> class ReadOnlyMemory;
23template <typename> class ReadOnlySpan;
24namespace Text
25{
26namespace Json
27{
28class JsonDocument;
29class JsonProperty;
30class JsonSerializer;
31enum class JsonTokenType : uint8_t;
32enum class JsonValueKind : uint8_t;
33namespace Nodes
34{
35class JsonNode;
36} // namespace Nodes
37namespace Serialization
38{
39namespace Converters
40{
41class DefaultObjectConverter;
42class JsonElementConverter;
43class JsonValueConverter;
44} // namespace Converters
45} // namespace Serialization
46class Utf8JsonReader;
47class Utf8JsonWriter;
48} // namespace Json
49} // namespace Text
50} // namespace System
51
52namespace System {
53
54namespace Text {
55
56namespace Json {
57
58class ASPOSECPP_SHARED_CLASS JsonElement : public System::Object, public System::Details::BoxableObjectBase
59{
60 typedef JsonElement ThisType;
62
63 typedef ::System::BaseTypesInfo<BaseType> ThisTypeBaseTypesInfo;
64 ASPOSECPP_SHARED_RTTI_INFO_DECL();
65
66 friend class JsonDocument;
67 friend class JsonProperty;
68 friend class JsonSerializer;
73
74public:
75
76 class ArrayEnumerator;
77 class ObjectEnumerator;
78
79public:
80
81 ASPOSECPP_SHARED_API JsonValueKind get_ValueKind();
82
83 ASPOSECPP_SHARED_API JsonElement idx_get(int32_t index);
84
85 ASPOSECPP_SHARED_API int32_t GetArrayLength();
86 ASPOSECPP_SHARED_API int32_t GetPropertyCount();
87 ASPOSECPP_SHARED_API JsonElement GetProperty(String propertyName);
88 ASPOSECPP_SHARED_API JsonElement GetProperty(ReadOnlySpan<char16_t> propertyName);
89 ASPOSECPP_SHARED_API JsonElement GetProperty(ReadOnlySpan<uint8_t> utf8PropertyName);
90 ASPOSECPP_SHARED_API bool TryGetProperty(String propertyName, JsonElement& value);
91 ASPOSECPP_SHARED_API bool TryGetProperty(ReadOnlySpan<char16_t> propertyName, JsonElement& value);
92 ASPOSECPP_SHARED_API bool TryGetProperty(ReadOnlySpan<uint8_t> utf8PropertyName, JsonElement& value);
93 ASPOSECPP_SHARED_API bool GetBoolean();
94 ASPOSECPP_SHARED_API String GetString();
95 ASPOSECPP_SHARED_API bool TryGetBytesFromBase64(System::SharedPtr<Array<uint8_t>>& value);
97 ASPOSECPP_SHARED_API bool TryGetSByte(int8_t& value);
98 ASPOSECPP_SHARED_API int8_t GetSByte();
99 ASPOSECPP_SHARED_API bool TryGetByte(uint8_t& value);
100 ASPOSECPP_SHARED_API uint8_t GetByte();
101 ASPOSECPP_SHARED_API bool TryGetInt16(int16_t& value);
102 ASPOSECPP_SHARED_API int16_t GetInt16();
103 ASPOSECPP_SHARED_API bool TryGetUInt16(uint16_t& value);
104 ASPOSECPP_SHARED_API uint16_t GetUInt16();
105 ASPOSECPP_SHARED_API bool TryGetInt32(int32_t& value);
106 ASPOSECPP_SHARED_API int32_t GetInt32();
107 ASPOSECPP_SHARED_API bool TryGetUInt32(uint32_t& value);
108 ASPOSECPP_SHARED_API uint32_t GetUInt32();
109 ASPOSECPP_SHARED_API bool TryGetInt64(int64_t& value);
110 ASPOSECPP_SHARED_API int64_t GetInt64();
111 ASPOSECPP_SHARED_API bool TryGetUInt64(uint64_t& value);
112 ASPOSECPP_SHARED_API uint64_t GetUInt64();
113 ASPOSECPP_SHARED_API bool TryGetDouble(double& value);
114 ASPOSECPP_SHARED_API double GetDouble();
115 ASPOSECPP_SHARED_API bool TryGetSingle(float& value);
116 ASPOSECPP_SHARED_API float GetSingle();
117 ASPOSECPP_SHARED_API bool TryGetDecimal(Decimal& value);
118 ASPOSECPP_SHARED_API Decimal GetDecimal();
119 ASPOSECPP_SHARED_API bool TryGetDateTime(DateTime& value);
120 ASPOSECPP_SHARED_API DateTime GetDateTime();
121 ASPOSECPP_SHARED_API bool TryGetDateTimeOffset(DateTimeOffset& value);
122 ASPOSECPP_SHARED_API DateTimeOffset GetDateTimeOffset();
123 ASPOSECPP_SHARED_API bool TryGetGuid(Guid& value);
124 ASPOSECPP_SHARED_API Guid GetGuid();
125 ASPOSECPP_SHARED_API String GetRawText();
126 static ASPOSECPP_SHARED_API bool DeepEquals(JsonElement element1, JsonElement element2);
127 ASPOSECPP_SHARED_API bool ValueEquals(String text);
128 ASPOSECPP_SHARED_API bool ValueEquals(ReadOnlySpan<uint8_t> utf8Text);
129 ASPOSECPP_SHARED_API bool ValueEquals(ReadOnlySpan<char16_t> text);
130 ASPOSECPP_SHARED_API void WriteTo(System::SharedPtr<Utf8JsonWriter> writer);
133 ASPOSECPP_SHARED_API JsonElement Clone();
134 static ASPOSECPP_SHARED_API JsonElement ParseValue(Utf8JsonReader& reader);
135 static ASPOSECPP_SHARED_API JsonElement Parse(ReadOnlySpan<uint8_t> utf8Json, JsonDocumentOptions options = System::Default<System::Text::Json::JsonDocumentOptions>());
136 static ASPOSECPP_SHARED_API JsonElement Parse(ReadOnlySpan<char16_t> json, JsonDocumentOptions options = System::Default<System::Text::Json::JsonDocumentOptions>());
137 static ASPOSECPP_SHARED_API JsonElement Parse(String json, JsonDocumentOptions options = System::Default<System::Text::Json::JsonDocumentOptions>());
138 static ASPOSECPP_SHARED_API bool TryParseValue(Utf8JsonReader& reader, Nullable<JsonElement>& element);
139
140 ASPOSECPP_SHARED_API JsonElement();
141
142 ASPOSECPP_SHARED_API String ToString() const override;
143
144 ASPOSECPP_SHARED_API bool Equals(const JsonElement& other) const;
145
146 ASPOSECPP_SHARED_API bool operator==(const JsonElement& other) const;
147
148 ASPOSECPP_SHARED_API bool operator!=(const JsonElement& other) const;
149
150protected:
151
155
156 ASPOSECPP_SHARED_API JsonElement(System::SharedPtr<JsonDocument> parent, int32_t idx);
157
159
164 bool TextEqualsHelper(ReadOnlySpan<uint8_t> utf8Text, bool isPropertyName, bool shouldUnescape);
165 bool TextEqualsHelper(ReadOnlySpan<char16_t> text, bool isPropertyName);
166 bool ValueIsEscapedHelper(bool isPropertyName);
168 static JsonElement ParseValue(Utf8JsonReader& reader, bool allowDuplicateProperties);
170 #ifdef ASPOSE_GET_SHARED_MEMBERS
171 void GetSharedMembers(System::Object::shared_members_type& result) const override;
172 #endif
173
174private:
175
177 int32_t _idx;
178
179 JsonTokenType get_TokenType();
180 String get_DebuggerDisplay();
181
182 String ToString_NonConst();
183 void CheckValidInstance();
184
185};
186
187class JsonElement::ArrayEnumerator : public Collections::Generic::IEnumerator<JsonElement>, public System::Details::BoxableObjectBase
188{
191
192 typedef ::System::BaseTypesInfo<BaseType> ThisTypeBaseTypesInfo;
193 RTTI_INFO_DECL();
194
195 friend class JsonElement;
196
197public:
198
200
201public:
202
203 ASPOSECPP_SHARED_API JsonElement get_Current() const override;
204
206 ASPOSECPP_SHARED_API void Dispose() override;
207 ASPOSECPP_SHARED_API void Reset() override;
208 ASPOSECPP_SHARED_API bool MoveNext() override;
209
210 ASPOSECPP_SHARED_API ArrayEnumerator();
211 ASPOSECPP_SHARED_API ArrayEnumerator(JsonElement target, int32_t currentIndex = -1);
212
213protected:
214
215 MEMBER_FUNCTION_MAKE_OBJECT_DECLARATION(ArrayEnumerator, CODEPORTING_ARGS(JsonElement target, int32_t currentIndex = -1));
216
217#ifdef ASPOSE_GET_SHARED_MEMBERS
218 void GetSharedMembers(System::Object::shared_members_type& result) const override;
219#endif
220
221private:
222
223 JsonElement _target;
224 int32_t _curIdx;
225 int32_t _endIdxOrVersion;
226
227};
228
229} // namespace Json
230} // namespace Text
231} // namespace System
232
233// JsonElement::ObjectEnumerator depends on the complete JsonProperty type.
234// It is defined in json_property.h, so we pull it in here to keep this header
235// self-sufficient for all JsonElement usage.
236#include "system/text/json/document/json_property.h"
Class that represents an array data structure. Objects of this class should only be allocated using S...
Definition: array.h:296
Interface of enumerator which can be used to iterate through some elements. Objects of this class sho...
Definition: ienumerator.h:63
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
Forward to use within Span class.
Definition: span.h:415
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_document.h:71
Definition: json_document_options.h:26
JsonElement::ArrayEnumerator GetEnumerator()
bool MoveNext() override
Moves enumerator to the next element. If no element was referenced before, sets reference to the firs...
ArrayEnumerator(JsonElement target, int32_t currentIndex=-1)
MEMBER_FUNCTION_MAKE_OBJECT_DECLARATION(ArrayEnumerator, CODEPORTING_ARGS(JsonElement target, int32_t currentIndex=-1))
JsonElement get_Current() const override
Gets current element.
void Reset() override
Resets enumerator to position before first element.
Definition: json_element.h:59
static JsonElement ParseValue(Utf8JsonReader &reader, bool allowDuplicateProperties)
bool TryGetSingle(float &value)
bool TryGetInt32(int32_t &value)
ReadOnlyMemory< uint8_t > GetRawValue()
ReadOnlySpan< uint8_t > GetPropertyNameRaw()
System::SharedPtr< Array< uint8_t > > GetBytesFromBase64()
bool TryGetProperty(String propertyName, JsonElement &value)
bool TryGetInt64(int64_t &value)
bool TryGetUInt16(uint16_t &value)
bool TryGetUInt64(uint64_t &value)
static JsonElement Parse(ReadOnlySpan< char16_t > json, JsonDocumentOptions options=System::Default< System::Text::Json::JsonDocumentOptions >())
bool ValueIsEscapedHelper(bool isPropertyName)
static JsonElement Parse(String json, JsonDocumentOptions options=System::Default< System::Text::Json::JsonDocumentOptions >())
JsonElement idx_get(int32_t index)
JsonElement GetProperty(ReadOnlySpan< char16_t > propertyName)
bool Equals(const JsonElement &other) const
void WritePropertyNameTo(System::SharedPtr< Utf8JsonWriter > writer)
ReadOnlySpan< uint8_t > get_ValueSpan()
static JsonElement ParseValue(System::SharedPtr< IO::Stream > utf8Json, JsonDocumentOptions options)
JsonElement::ObjectEnumerator EnumerateObject()
JsonElement GetProperty(ReadOnlySpan< uint8_t > utf8PropertyName)
bool TryGetDouble(double &value)
bool ValueEquals(ReadOnlySpan< char16_t > text)
MEMBER_FUNCTION_MAKE_OBJECT_DECLARATION(JsonElement, CODEPORTING_ARGS(System::SharedPtr< JsonDocument > parent, int32_t idx))
static bool TryParseValue(Utf8JsonReader &reader, Nullable< JsonElement > &element)
JsonElement(System::SharedPtr< JsonDocument > parent, int32_t idx)
bool ValueEquals(ReadOnlySpan< uint8_t > utf8Text)
bool TryGetInt16(int16_t &value)
bool TryGetProperty(ReadOnlySpan< char16_t > propertyName, JsonElement &value)
bool TryGetSByte(int8_t &value)
void WriteTo(System::SharedPtr< Utf8JsonWriter > writer)
bool TryGetDateTime(DateTime &value)
bool TextEqualsHelper(ReadOnlySpan< uint8_t > utf8Text, bool isPropertyName, bool shouldUnescape)
static JsonElement ParseValue(Utf8JsonReader &reader)
bool TryGetByte(uint8_t &value)
DateTimeOffset GetDateTimeOffset()
bool TryGetDateTimeOffset(DateTimeOffset &value)
JsonElement GetProperty(String propertyName)
static bool DeepEquals(JsonElement element1, JsonElement element2)
bool operator!=(const JsonElement &other) const
bool TryGetDecimal(Decimal &value)
bool operator==(const JsonElement &other) const
String ToString() const override
Analog of C# Object.ToString() method. Enables converting custom objects to string.
bool TryGetProperty(ReadOnlySpan< uint8_t > utf8PropertyName, JsonElement &value)
bool TryGetBytesFromBase64(System::SharedPtr< Array< uint8_t > > &value)
static JsonElement Parse(ReadOnlySpan< uint8_t > utf8Json, JsonDocumentOptions options=System::Default< System::Text::Json::JsonDocumentOptions >())
JsonElement::ArrayEnumerator EnumerateArray()
bool TextEqualsHelper(ReadOnlySpan< char16_t > text, bool isPropertyName)
bool TryGetUInt32(uint32_t &value)
Definition: json_property.h:30
Definition: json_serializer_helpers.h:91
Definition: json_node.h:54
Definition: utf8_json_reader.h:78
@ Text
Defines color adjustment information for text.
@ Stream
The type that supports reliable, two-way, connection-based byte streams without duplication of data a...
JsonTokenType
Definition: json_token_type.h:12
JsonValueKind
Definition: json_value_kind.h:12
Definition: db_command.h:9