CodePorting.Translator Cs2Cpp
CodePorting.Translator.Cs2Cpp.Framework
array_converter.h
1#pragma once
2
3#include <system/object_ext.h>
4#include <system/details/pointer_collection_helpers.h>
5#include <system/collections/list.h>
6#include <system/array.h>
7#include <cstdint>
8
9#include "system/text/json/serialization/converters/collection/i_enumerable_default_converter.h"
10#include "system/text/json/serialization/read_stack.h"
11#include "system/text/json/serialization/read_stack_frame.h"
12#include "system/text/json/reader/utf8_json_reader.h"
13#include "system/text/json/serialization/json_serializer_options.h"
14#include "system/text/json/writer/utf8_json_writer.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/json_converter.h"
18#include "system/text/json/serialization/converters/collection/json_collection_converter.h"
19
20namespace System {
21
22namespace Text {
23
24namespace Json {
25
26namespace Serialization {
27
28namespace Converters {
29
30template<typename TCollection, typename TElement>
31class ArrayConverter final : public IEnumerableDefaultConverter<System::SharedPtr<Array<TElement>>, TElement>
32{
35
36 typedef ::System::BaseTypesInfo<BaseType> ThisTypeBaseTypesInfo;
37 RTTI_INFO_TEMPLATE_CLASS(ThisType, ThisTypeBaseTypesInfo);
38
39 template<typename FT0, typename FT1> friend class ArrayConverter;
40
41public:
42
43 bool get_CanHaveMetadata() override
44 {
45 return false;
46 }
47
49 {
50 return false;
51 }
52
54 {
55 return true;
56 }
57
58 void SetTemplateWeakPtr(uint32_t argument) override
59 {
60 switch (argument)
61 {
62 case 0:
63 break;
64
65 case 1:
67 break;
68
69 }
70 }
71
72protected:
73
74 void Add(const TElement& value, ReadStack& state) override
75 {
76 (System::ExplicitCast<System::Collections::Generic::List<TElement>>(state.Current.ReturnValue))->Add(value);
77 }
78
80 {
81 ASPOSE_UNUSED(reader);
82 ASPOSE_UNUSED(options);
83 state.Current.ReturnValue = System::MakeObject<Collections::Generic::List<TElement>>();
84 }
85
87 {
88 ASPOSE_UNUSED(options);
89 System::SharedPtr<Collections::Generic::List<TElement>> list = System::ExplicitCast<System::Collections::Generic::List<TElement>>(state.Current.ReturnValue);
90 state.Current.ReturnValue = list->ToArray();
91 }
92
94 {
95 int32_t index = state.Current.EnumeratorIndex;
96
98 if (elementConverter->get_CanUseDirectReadOrWrite() && state.Current.NumberHandling == nullptr)
99 {
100 // Fast path that avoids validation and extra indirection.
101 for (; index < array->get_Length(); index++)
102 {
103 elementConverter->Write(writer, array[index], options);
104 }
105 }
106 else
107 {
108 for (; index < array->get_Length(); index++)
109 {
110 TElement element = array[index];
111 if (!elementConverter->TryWrite(writer, element, options, System::Ref(state)))
112 {
114 return false;
115 }
116
118
119 if (this->ShouldFlush(System::Ref(state), writer))
120 {
121 state.Current.EnumeratorIndex = ++index;
122 return false;
123 }
124 }
125 }
126
127 return true;
128 }
129
130};
131
132} // namespace Converters
133} // namespace Serialization
134} // namespace Json
135} // namespace Text
136} // namespace System
Class that represents an array data structure. Objects of this class should only be allocated using S...
Definition: array.h:296
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
bool OnWriteResume(System::SharedPtr< Utf8JsonWriter > writer, System::SharedPtr< Array< TElement > > array, System::SharedPtr< JsonSerializerOptions > options, WriteStack &state) override
Definition: array_converter.h:93
void Add(const TElement &value, ReadStack &state) override
Definition: array_converter.h:74
bool get_SupportsCreateObjectDelegate() override
Definition: array_converter.h:48
bool get_CanHaveMetadata() override
Definition: array_converter.h:43
void SetTemplateWeakPtr(uint32_t argument) override
Set n'th template argument a weak pointer (rather than shared). Allows switching pointers in containe...
Definition: array_converter.h:58
bool get_IsConvertibleCollection() override
Definition: array_converter.h:53
void ConvertCollection(ReadStack &state, System::SharedPtr< JsonSerializerOptions > options) override
Definition: array_converter.h:86
void CreateCollection(Utf8JsonReader &reader, ReadStack &state, System::SharedPtr< JsonSerializerOptions > options) override
Definition: array_converter.h:79
void SetTemplateWeakPtr(uint32_t argument) override
Definition: i_enumerable_default_converter.h:49
Definition: json_collection_converter.h:43
static System::SharedPtr< JsonConverter< TElement > > GetElementConverter(System::SharedPtr< Metadata::JsonTypeInfoBase > elementTypeInfo)
Definition: json_collection_converter.h:358
static bool ShouldFlush(WriteStack &state, System::SharedPtr< Utf8JsonWriter > writer)
Definition: utf8_json_reader.h:78
Nullable< Serialization::JsonNumberHandling > NumberHandling
Definition: write_stack_frame.h:66
int32_t EnumeratorIndex
Definition: write_stack_frame.h:61
Definition: write_stack.h:34
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