CodePorting.Translator Cs2Cpp
CodePorting.Translator.Cs2Cpp.Framework
json_value_of_t_primitive.h
1#pragma once
2
3#include <system/scope_guard.h>
4#include <system/object_ext.h>
5#include <system/nullable.h>
6#include <system/exceptions.h>
7#include <system/diagnostics/debug.h>
8#include <system/details/pointer_collection_helpers.h>
9#include <system/details/patterns.h>
10#include <system/details/equality_helper.h>
11#include <cstdint>
12
13#include "system/text/json/serialization/json_converter.h"
14#include "system/text/json/nodes/json_node_options.h"
15#include "system/text/json/serialization/converter_strategy.h"
16#include "system/text/json/document/json_value_kind.h"
17#include "system/text/json/nodes/json_node.h"
18#include "system/text/json/nodes/json_value_of_t.h"
19#include "system/text/json/writer/utf8_json_writer.h"
20#include "system/text/json/serialization/json_serializer_options.h"
21#include "system/text/json/serialization/json_number_handling.h"
22
23namespace System
24{
25namespace Text
26{
27namespace Json
28{
29namespace Serialization
30{
31template <typename> class JsonConverter;
32} // namespace Serialization
33} // namespace Json
34} // namespace Text
35} // namespace System
36
37namespace System {
38
39namespace Text {
40
41namespace Json {
42
43namespace Nodes {
44
45template<typename TValue>
46class JsonValuePrimitive final : public JsonValue<TValue>
47{
50
51 typedef ::System::BaseTypesInfo<BaseType> ThisTypeBaseTypesInfo;
52 RTTI_INFO_TEMPLATE_CLASS(ThisType, ThisTypeBaseTypesInfo);
53
54 template<typename FT0> friend class JsonValuePrimitive;
55
56public:
57
59 : JsonValue<TValue>(value, options), _valueKind((JsonValueKind)0)
60 {
61 System::Details::ThisProtector __local_self_ref(this);
62
63 CODEPORTING_DEBUG_ASSERT2(JsonValue<TValue>::get_TypeIsSupportedPrimitive(), System::String::Format(u"The type {0} is not a supported primitive.", System::ObjectExt::GetType<TValue>()));
64
65 _converter = converter;
67 }
68
70 {
71 return System::MakeObject<JsonValuePrimitive<TValue>>(JsonValue<TValue>::Value, _converter, this->get_Options());
72 }
73
75 {
76 System::SharedPtr<JsonValueBase> otherValue; TValue v;
77 if (System::Is<JsonValueBase>(otherNode, otherValue) && otherValue->template TryGetValue<TValue>(v))
78 {
79 // Because TValue is equatable and otherNode returns a matching
80 // type we can short circuit the comparison in this case.
81 return System::Details::AreEqual(JsonValue<TValue>::Value, v);
82 }
83
85 }
86
88 {
89 if (System::IsNull(writer))
90 {
91 throw System::ArgumentNullException(u"writer");
92 }
93
95 System::ObjectExt::CoalesceAssign(options, [&]{return JsonNode::s_defaultOptions;});
96
97 if (converter->get_IsInternalConverterForNumberType())
98 {
99 converter->WriteNumberWithCustomHandling(writer, JsonValue<TValue>::Value, options->get_NumberHandling());
100 }
101 else
102 {
103 converter->Write(writer, JsonValue<TValue>::Value, options);
104 }
105 }
106
107 void SetTemplateWeakPtr(uint32_t argument) override
108 {
109 switch (argument)
110 {
111 case 0:
113 System::Details::CollectionHelpers::SetWeakPointer(0, _converter);
114 break;
115
116 }
117 }
118
119protected:
120
121 #ifdef ASPOSE_GET_SHARED_MEMBERS
122 void GetSharedMembers(System::Object::shared_members_type& result) const override
123 {
125
126 result.Add("System::Text::Json::Nodes::JsonValuePrimitive::_converter", this->_converter);
127 result.Add("System::Text::Json::Nodes::JsonValuePrimitive::_valueKind", this->_valueKind);
128 }
129 #endif
130
131private:
132
134 JsonValueKind _valueKind;
135
136 JsonValueKind GetValueKindCore() override
137 {
138 return _valueKind;
139 }
140
141};
142
143} // namespace Nodes
144} // namespace Json
145} // namespace Text
146} // namespace System
Forward declaration.
Definition: nullable.h:75
static auto CoalesceAssign(T0 &value, T1 func) -> T0 &
Implementation of '??=' operator translation.
Definition: object_ext.h:748
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
static String Format(const SharedPtr< IFormatProvider > &fp, const String &format, const Args &... args)
Formats string in C# style.
Definition: string.h:1449
Definition: json_node.h:54
Nullable< JsonNodeOptions > get_Options()
bool DeepEqualsCore(System::SharedPtr< JsonNode > otherNode) override
Definition: json_value_of_t.h:53
void SetTemplateWeakPtr(uint32_t argument) override
Set n'th template argument a weak pointer (rather than shared). Allows switching pointers in containe...
Definition: json_value_of_t.h:156
Definition: json_value_of_t_primitive.h:47
void WriteTo(System::SharedPtr< Utf8JsonWriter > writer, System::SharedPtr< JsonSerializerOptions > options=nullptr) override
Definition: json_value_of_t_primitive.h:87
System::SharedPtr< JsonNode > DeepCloneCore() override
Definition: json_value_of_t_primitive.h:69
void SetTemplateWeakPtr(uint32_t argument) override
Set n'th template argument a weak pointer (rather than shared). Allows switching pointers in containe...
Definition: json_value_of_t_primitive.h:107
JsonValuePrimitive(TValue value, System::SharedPtr< Serialization::JsonConverter< TValue > > converter, Nullable< JsonNodeOptions > options)
Definition: json_value_of_t_primitive.h:58
bool DeepEqualsCore(System::SharedPtr< JsonNode > otherNode) override
Definition: json_value_of_t_primitive.h:74
Definition: json_converter_of_t.h:80
@ Text
Defines color adjustment information for text.
JsonValueKind
Definition: json_value_kind.h:12
Definition: db_command.h:9