CodePorting.Translator Cs2Cpp
CodePorting.Translator.Cs2Cpp.Framework
value_queue.h
1#pragma once
2
3#include <system/object_ext.h>
4#include <system/diagnostics/debug.h>
5#include <system/details/pointer_collection_helpers.h>
6#include <system/details/patterns.h>
7#include <system/default.h>
8#include <system/collections/queue.h>
9#include <cstdint>
10
11namespace System {
12
13namespace Text {
14
15namespace Json {
16
17template<typename T>
18class ValueQueue : public System::Object, public System::Details::BoxableObjectBase
19{
20 typedef ValueQueue<T> ThisType;
22
23 typedef ::System::BaseTypesInfo<BaseType> ThisTypeBaseTypesInfo;
24 RTTI_INFO_TEMPLATE_CLASS(ThisType, ThisTypeBaseTypesInfo);
25
26 template<typename FT0> friend class ValueQueue;
27
28public:
29
30 int32_t get_Count()
31 {
32 return _state < 2 ? _state : _multiple->get_Count();
33 }
34
35 void Enqueue(T value)
36 {
37 switch (_state)
38 {
39 case 0:
40 _single = value;
41 _state = 1;
42 break;
43 case 1:
44 (System::ObjectExt::CoalesceAssign(_multiple, [&]{return System::MakeObject<Collections::Generic::Queue<T>>();}))->Enqueue(_single);
45 _single = System::Default<T>();
46 _state = 2;
47 goto case_label_0_2;
48 default:
49 case_label_0_2:
50 _multiple->Enqueue(value);
51 break;
52 }
53 }
54
55 bool TryDequeue(T& value)
56 {
57 switch (_state)
58 {
59 case 0:
60 value = System::Default<T>();
61 return false;
62 case 1:
63 value = _single;
64 _single = System::Default<T>();
65 _state = 0;
66 return true;
67 default:
68 if (_multiple->get_Count() > 0)
69 {
70 value = _multiple->Dequeue();
71 if (_multiple->get_Count() == 0)
72 {
73 _multiple = nullptr;
74 _state = 0;
75 }
76 return true;
77 }
78 value = System::Default<T>();
79 return false;
80 }
81 }
82
83 bool operator==(const ValueQueue<T>& other) const
84 {
85 if (_state != other._state)
86 {
87 return false;
88 }
89 if (_state == 0)
90 {
91 return true;
92 }
93 if (_state == 1)
94 {
95 return _single == other._single;
96 }
97 return _multiple->data() == other._multiple->data();
98 }
99
100 ValueQueue() : _state(0), _single(T())
101 {
102 }
103
104 void SetTemplateWeakPtr(uint32_t argument) override
105 {
106 switch (argument)
107 {
108 case 0:
109 System::Details::CollectionHelpers::SetWeakPointer(_single);
110 System::Details::CollectionHelpers::SetWeakPointer(0, _multiple);
111 break;
112
113 }
114 }
115
116protected:
117
118 #ifdef ASPOSE_GET_SHARED_MEMBERS
119 void GetSharedMembers(System::Object::shared_members_type& result) const override
120 {
121 Object::GetSharedMembers(result);
122
123 result.Add("System::Text::Json::ValueQueue::_single", this->_single);
124 result.Add("System::Text::Json::ValueQueue::_multiple", this->_multiple);
125 }
126 #endif
127
128private:
129
130 uint8_t _state;
131 T _single;
133
134};
135
136} // namespace Json
137} // namespace Text
138} // namespace System
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
Definition: value_queue.h:19
bool TryDequeue(T &value)
Definition: value_queue.h:55
void Enqueue(T value)
Definition: value_queue.h:35
bool operator==(const ValueQueue< T > &other) const
Definition: value_queue.h:83
ValueQueue()
Definition: value_queue.h:100
int32_t get_Count()
Definition: value_queue.h:30
void SetTemplateWeakPtr(uint32_t argument) override
Set n'th template argument a weak pointer (rather than shared). Allows switching pointers in containe...
Definition: value_queue.h:104
@ Text
Defines color adjustment information for text.
Definition: db_command.h:9