CodePorting.Translator Cs2Cpp
CodePorting.Translator.Cs2Cpp.Framework
dictionary_of_t_key_t_value_converter.h
1#pragma once
2
3#include <system/object_ext.h>
4#include <system/details/pointer_collection_helpers.h>
5#include <system/constraints.h>
6#include <system/collections/keyvalue_pair.h>
7#include <system/collections/ienumerator_ng.h>
8#include <system/collections/dictionary.h>
9#include <cstdint>
10
11#include "system/text/json/json_collection_extensions.h"
12#include "system/text/json/serialization/converters/collection/dictionary_default_converter.h"
13#include "system/text/json/writer/utf8_json_writer.h"
14#include "system/text/json/serialization/json_serializer_options.h"
15#include "system/text/json/serialization/write_stack.h"
16#include "system/text/json/serialization/write_stack_frame.h"
17#include "system/text/json/serialization/converters/collection/json_dictionary_converter.h"
18#include "system/text/json/serialization/json_converter.h"
19#include "system/text/json/serialization/stack_frame_property_state.h"
20#include "system/text/json/serialization/read_stack.h"
21#include "system/text/json/serialization/read_stack_frame.h"
22#include "system/text/json/throw_helper.h"
23
24namespace System {
25
26namespace Text {
27
28namespace Json {
29
30namespace Serialization {
31
32namespace Converters {
33
34template<typename TCollection, typename TKey, typename TValue>
35class DictionaryOfTKeyTValueConverter final : public DictionaryDefaultConverter<TCollection, TKey, TValue>
36{
38 assert_is_base_of(BaseT_Dictionary, TCollection);
39
42
43 typedef ::System::BaseTypesInfo<BaseType> ThisTypeBaseTypesInfo;
44 RTTI_INFO_TEMPLATE_CLASS(ThisType, ThisTypeBaseTypesInfo);
45
46 template<typename FT0, typename FT1, typename FT2> friend class DictionaryOfTKeyTValueConverter;
47
48public:
49
50 bool get_CanPopulate() override
51 {
52 return true;
53 }
54
56 {
58 if (state.Current.CollectionEnumerator == nullptr)
59 {
60 enumerator = System::ExplicitCast<typename System::Collections::Generic::Dictionary<TKey, TValue>::Enumerator>(value->GetEnumerator());
61 if (!enumerator->MoveNext())
62 {
63 enumerator->Dispose();
64 return true;
65 }
66 }
67 else
68 {
69 enumerator = System::ExplicitCast<typename System::Collections::Generic::Dictionary<TKey, TValue>::Enumerator>(state.Current.CollectionEnumerator);
70 }
71
75
76 if (!state.SupportContinuation && JsonDictionaryConverter<TCollection, TKey, TValue>::_valueConverter->get_CanUseDirectReadOrWrite() && state.Current.NumberHandling == nullptr)
77 {
78 // Fast path that avoids validation and extra indirection.
79 do
80 {
81 TKey key = enumerator->get_Current().get_Key();
83 JsonDictionaryConverter<TCollection, TKey, TValue>::_valueConverter->Write(writer, enumerator->get_Current().get_Value(), options);
84 } while (enumerator->MoveNext());
85 }
86 else
87 {
88 do
89 {
90 if (this->ShouldFlush(System::Ref(state), writer))
91 {
92 state.Current.CollectionEnumerator = enumerator;
93 return false;
94 }
95
97 {
99
100 TKey key = enumerator->get_Current().get_Key();
102 }
103
104 TValue element = enumerator->get_Current().get_Value();
105 if (!JsonDictionaryConverter<TCollection, TKey, TValue>::_valueConverter->TryWrite(writer, element, options, System::Ref(state)))
106 {
107 state.Current.CollectionEnumerator = enumerator;
108 return false;
109 }
110
112 } while (enumerator->MoveNext());
113 }
114
115 enumerator->Dispose();
116 return true;
117 }
118
119 void SetTemplateWeakPtr(uint32_t argument) override
120 {
121 switch (argument)
122 {
123 case 0:
125 break;
126
127 case 1:
129 break;
130
131 case 2:
133 break;
134
135 }
136 }
137
138protected:
139
140 void Add(TKey key, const TValue& value, System::SharedPtr<JsonSerializerOptions> options, ReadStack& state) override
141 {
142 TCollection dictionary = System::ExplicitCast<TCollection>(state.Current.ReturnValue);
143
144 dictionary->idx_set(key, value);
145 }
146
147};
148
149} // namespace Converters
150} // namespace Serialization
151} // namespace Json
152} // namespace Text
153} // namespace System
Forward declaration of Dictionary class.
Definition: dictionary.h:96
static auto CoalesceAssign(T0 &value, T1 func) -> T0 &
Implementation of '??=' operator translation.
Definition: object_ext.h:748
Pointer class to wrap types being allocated on heap. Use it to manage memory for classes inheriting O...
Definition: smart_ptr.h:180
System::SharedPtr< Object > ReturnValue
Definition: read_stack_frame.h:59
Definition: read_stack.h:35
ReadStackFrame Current
Definition: read_stack.h:44
void SetTemplateWeakPtr(uint32_t argument) override
Definition: dictionary_default_converter.h:100
Definition: dictionary_of_t_key_t_value_converter.h:36
void Add(TKey key, const TValue &value, System::SharedPtr< JsonSerializerOptions > options, ReadStack &state) override
Definition: dictionary_of_t_key_t_value_converter.h:140
bool OnWriteResume(System::SharedPtr< Utf8JsonWriter > writer, TCollection value, System::SharedPtr< JsonSerializerOptions > options, WriteStack &state) override
Definition: dictionary_of_t_key_t_value_converter.h:55
void SetTemplateWeakPtr(uint32_t argument) override
Definition: dictionary_of_t_key_t_value_converter.h:119
bool get_CanPopulate() override
Definition: dictionary_of_t_key_t_value_converter.h:50
System::SharedPtr< Object > CollectionEnumerator
Definition: write_stack_frame.h:53
Nullable< Serialization::JsonNumberHandling > NumberHandling
Definition: write_stack_frame.h:66
bool IsWritingExtensionDataProperty
Definition: write_stack_frame.h:55
System::SharedPtr< System::Text::Json::Serialization::Metadata::JsonTypeInfoBase > JsonTypeInfo
Definition: write_stack_frame.h:56
StackFramePropertyState PropertyState
Definition: write_stack_frame.h:60
Definition: write_stack.h:34
bool SupportContinuation
Definition: write_stack.h:54
WriteStackFrame Current
Definition: write_stack.h:45
@ 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