CodePorting.Translator Cs2Cpp
CodePorting.Translator.Cs2Cpp.Framework
stack_or_queue_converter.h
1#pragma once
2
3#include <system/type_info.h>
4#include <system/object_ext.h>
5#include <system/nullable.h>
6#include <system/func.h>
7#include <system/details/pointer_collection_helpers.h>
8#include <system/constraints.h>
9#include <system/collections/ienumerator_ng.h>
10#include <system/collections/ienumerable_ng.h>
11#include <system/action.h>
12#include <cstdint>
13
14#include "system/text/json/serialization/converters/collection/json_collection_converter.h"
15#include "system/text/json/serialization/read_stack.h"
16#include "system/text/json/serialization/read_stack_frame.h"
17#include "system/text/json/reader/utf8_json_reader.h"
18#include "system/text/json/serialization/json_serializer_options.h"
19#include "system/text/json/throw_helper.h"
20#include "system/text/json/writer/utf8_json_writer.h"
21#include "system/text/json/serialization/write_stack.h"
22#include "system/text/json/serialization/write_stack_frame.h"
23#include "system/text/json/serialization/json_converter.h"
24
25namespace System {
26
27namespace Text {
28
29namespace Json {
30
31namespace Serialization {
32
33namespace Converters {
34
35template<typename TCollection>
36class StackOrQueueConverter : public JsonCollectionConverter<TCollection, System::SharedPtr<Object>>
37{
39 assert_is_base_of(BaseT_IEnumerable, TCollection);
40
43
44 typedef ::System::BaseTypesInfo<BaseType> ThisTypeBaseTypesInfo;
45 RTTI_INFO_TEMPLATE_CLASS(ThisType, ThisTypeBaseTypesInfo);
46
47 template<typename FT0> friend class StackOrQueueConverter;
48
49public:
50
51 bool get_CanPopulate() override
52 {
53 return true;
54 }
55
56 void SetTemplateWeakPtr(uint32_t argument) override
57 {
58 switch (argument)
59 {
60 case 0:
62 break;
63
64 }
65 }
66
67protected:
68
69 void Add(const System::SharedPtr<Object>& value, ReadStack& state) override
70 {
71 Action<TCollection, System::SharedPtr<Object>> addMethodDelegate = (System::ExplicitCast<System::Action<TCollection, System::SharedPtr<System::Object>>>(state.Current.JsonTypeInfo->get_AddMethodDelegate()));
72
73 addMethodDelegate(System::ExplicitCast<TCollection>(state.Current.ReturnValue), value);
74 }
75
77 {
78 ASPOSE_UNUSED(options);
79 if (System::SafeInvoke(state.get_ParentProperty(), [&](auto&& expr){return expr->TryGetPrePopulatedValue(System::Ref(state));}) == true)
80 {
81 return;
82 }
83
85
86 if (!typeInfo->get_HasCreateObject())
87 {
89 }
90
91 state.Current.ReturnValue = typeInfo->CreateObjectInstance();
92
93
94 }
95
97 {
99 if (state.Current.CollectionEnumerator == nullptr)
100 {
101 enumerator = System::ExplicitCast<Collections::IEnumerable>(value)->GetEnumerator();
102 state.Current.CollectionEnumerator = enumerator;
103 if (!enumerator->MoveNext())
104 {
105 return true;
106 }
107 }
108 else
109 {
110 enumerator = System::ExplicitCast<Collections::IEnumerator>(state.Current.CollectionEnumerator);
111 }
112
114 do
115 {
116 if (this->ShouldFlush(System::Ref(state), writer))
117 {
118 return false;
119 }
120
121 System::SharedPtr<Object> element = enumerator->get_Current();
122 if (!converter->TryWrite(writer, element, options, System::Ref(state)))
123 {
124 return false;
125 }
126
128 } while (enumerator->MoveNext());
129
130 return true;
131 }
132
133
134};
135
136} // namespace Converters
137} // namespace Serialization
138} // namespace Json
139} // namespace Text
140} // namespace System
IEnumerable is the base interface for all non-generic collections that can be enumerated.
Definition: ienumerable_ng.h:10
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
System::SharedPtr< System::Text::Json::Serialization::Metadata::JsonTypeInfoBase > JsonTypeInfo
Definition: read_stack_frame.h:60
Definition: read_stack.h:35
ReadStackFrame Current
Definition: read_stack.h:44
System::SharedPtr< Serialization::Metadata::JsonPropertyInfoBase > get_ParentProperty()
bool get_CanPopulate() override
Definition: stack_or_queue_converter.h:51
bool OnWriteResume(System::SharedPtr< Utf8JsonWriter > writer, TCollection value, System::SharedPtr< JsonSerializerOptions > options, WriteStack &state) override
Definition: stack_or_queue_converter.h:96
void Add(const System::SharedPtr< Object > &value, ReadStack &state) override
Definition: stack_or_queue_converter.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: stack_or_queue_converter.h:56
void CreateCollection(Utf8JsonReader &reader, ReadStack &state, System::SharedPtr< JsonSerializerOptions > options) override
Definition: stack_or_queue_converter.h:76
Definition: json_collection_converter.h:43
static System::SharedPtr< JsonConverter< System::SharedPtr< Object > > > GetElementConverter(System::SharedPtr< Metadata::JsonTypeInfoBase > elementTypeInfo)
Definition: json_collection_converter.h:358
void SetTemplateWeakPtr(uint32_t argument) override
Definition: json_collection_converter.h:316
static bool ShouldFlush(WriteStack &state, System::SharedPtr< Utf8JsonWriter > writer)
Definition: json_converter_of_t.h:80
static void ThrowNotSupportedException_CannotPopulateCollection(const TypeInfo &type, Utf8JsonReader &reader, ReadStack &state)
Definition: utf8_json_reader.h:78
System::SharedPtr< Object > CollectionEnumerator
Definition: write_stack_frame.h:53
Definition: write_stack.h:34
WriteStackFrame Current
Definition: write_stack.h:45
@ Text
Defines color adjustment information for text.
Definition: db_command.h:9
MulticastDelegate< void(Args...)> Action
Delegate type that references methods that have no return value.
Definition: action.h:40
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
static auto SafeInvoke(T0 &&expr, T1 &&func)
Implementation of '?.' operator translation.
Definition: object_ext.h:1434