CodePorting.Translator Cs2Cpp
CodePorting.Translator.Cs2Cpp.Framework
object_with_parameterized_constructor_converter_large.h
1#pragma once
2
3#include <system/type_info.h>
4#include <system/span.h>
5#include <system/object_ext.h>
6#include <system/func.h>
7#include <system/diagnostics/debug.h>
8#include <system/details/pointer_collection_helpers.h>
9#include <system/details/patterns.h>
10#include <system/constraints.h>
11#include <system/collections/ienumerator.h>
12#include <system/array.h>
13#include <cstdint>
14
15#include "system/text/json/serialization/converters/object/object_with_parameterized_constructor_converter.h"
16#include "system/text/json/serialization/read_stack.h"
17#include "system/text/json/reader/utf8_json_reader.h"
18#include "system/text/json/serialization/json_converter.h"
19#include "system/text/json/serialization/json_serializer_options.h"
20#include "system/text/json/throw_helper.h"
21#include "system/text/json/serialization/read_stack_frame.h"
22#include "system/text/json/serialization/argument_state.h"
23
24namespace System {
25
26namespace Text {
27
28namespace Json {
29
30namespace Serialization {
31
32namespace Converters {
33
34template<typename T>
36{
39
40 typedef ::System::BaseTypesInfo<BaseType> ThisTypeBaseTypesInfo;
41 RTTI_INFO_TEMPLATE_CLASS(ThisType, ThisTypeBaseTypesInfo);
42
43 template<typename FT0> friend class LargeObjectWithParameterizedConstructorConverter;
44
45public:
46
47 void SetTemplateWeakPtr(uint32_t argument) override
48 {
49 switch (argument)
50 {
51 case 0:
53 break;
54
55 }
56 }
57
58protected:
59
61 {
63 bool success = jsonParameterInfo->get_EffectiveConverter()->TryReadAsObject(System::Ref(reader), jsonParameterInfo->get_ParameterType(), jsonParameterInfo->get_Options(), System::Ref(state), arg);
64
65 if (success && !(arg == nullptr && jsonParameterInfo->get_IgnoreNullTokensOnRead()))
66 {
67 (System::ExplicitCast<System::Array<System::SharedPtr<System::Object>>>(state.Current.CtorArgumentState->Arguments))[jsonParameterInfo->get_Position()] = arg;
68 }
69
70 return success;
71 }
72
74 {
75 System::SharedPtr<Array<System::SharedPtr<Object>>> arguments = System::ExplicitCast<System::Array<System::SharedPtr<System::Object>>>(frame.CtorArgumentState->Arguments);
76 frame.CtorArgumentState->Arguments = nullptr;
77
78 Func<System::SharedPtr<Array<System::SharedPtr<Object>>>, T> createObject = System::ExplicitCast<System::Func<System::ArrayPtr<System::SharedPtr<System::Object>>, T>>(frame.JsonTypeInfo->get_CreateObjectWithArgs());
79
80 System::SharedPtr<Object> obj = System::ExplicitCast<System::Object>(createObject(arguments));
81
82 Buffers::ArrayPool<System::SharedPtr<Object>>::get_Shared()->Return(arguments, true);
83 return obj;
84 }
85
87 {
88 ASPOSE_UNUSED(options);
90
91 System::SharedPtr<Array<System::SharedPtr<Object>>> arguments = Buffers::ArrayPool<System::SharedPtr<Object>>::get_Shared()->Rent(typeInfo->get_ParameterCache().get_Length());
92 {
93 auto parameterInfo_enumerator = (typeInfo->get_ParameterCache()).GetEnumerator();
94 while (parameterInfo_enumerator.MoveNext())
95 {
96 auto&& parameterInfo = parameterInfo_enumerator.get_Current();
97
98 arguments[parameterInfo->get_Position()] = parameterInfo->get_EffectiveDefaultValue();
99 }
100 }
101
102 state.Current.CtorArgumentState->Arguments = arguments;
103 }
104
105};
106
107} // namespace Converters
108} // namespace Serialization
109} // namespace Json
110} // namespace Text
111} // namespace System
Provides a thread-safe pool for reusing managed array instances (ArrayPtr<T>).
Definition: array_pool.h:21
void Return(const ArrayPtr< T > &array, bool clearArray=false)
Returns a previously rented buffer back to the pool.
Definition: array_pool.h:104
ArrayPtr< T > Rent(int32_t minimumLength)
Obtains a buffer that is at least minimumLength long.
Definition: array_pool.h:68
Function delegate. This type should be allocated on stack and passed to functions by value or by refe...
Definition: func.h:82
Pointer class to wrap types being allocated on heap. Use it to manage memory for classes inheriting O...
Definition: smart_ptr.h:180
Definition: read_stack_frame.h:42
System::SharedPtr< ArgumentState > CtorArgumentState
Definition: read_stack_frame.h:72
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
Definition: object_with_parameterized_constructor_converter_large.h:36
bool ReadAndCacheConstructorArgument(ReadStack &state, Utf8JsonReader &reader, System::SharedPtr< Metadata::JsonParameterInfoBase > jsonParameterInfo) override
Definition: object_with_parameterized_constructor_converter_large.h:60
System::SharedPtr< Object > CreateObject(ReadStackFrame &frame) override
Definition: object_with_parameterized_constructor_converter_large.h:73
void SetTemplateWeakPtr(uint32_t argument) override
Set n'th template argument a weak pointer (rather than shared). Allows switching pointers in containe...
Definition: object_with_parameterized_constructor_converter_large.h:47
void InitializeConstructorArgumentCaches(ReadStack &state, System::SharedPtr< JsonSerializerOptions > options) override
Definition: object_with_parameterized_constructor_converter_large.h:86
Definition: object_with_parameterized_constructor_converter.h:64
void SetTemplateWeakPtr(uint32_t argument) override
Set n'th template argument a weak pointer (rather than shared). Allows switching pointers in containe...
Definition: object_with_parameterized_constructor_converter.h:293
Definition: json_object_converter.h:19
Definition: json_resumable_converter_of_t.h:42
Definition: utf8_json_reader.h:78
@ 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