CodePorting.Translator Cs2Cpp
CodePorting.Translator.Cs2Cpp.Framework
object_collection.h
1
2#pragma once
3
4#include <cstdint>
5#include <system/action.h>
6#include <system/collections/ilist.h>
7#include <system/collections/list.h>
8#include <system/collections/object_model/collection.h>
9#include <system/details/pointer_collection_helpers.h>
10#include <system/exceptions.h>
11#include <system/object.h>
12#include <system/shared_ptr.h>
13
14namespace System { namespace Net { namespace Http { namespace Headers {
15
21template <typename T>
22class ASPOSECPP_SHARED_CLASS ObjectCollection final : public System::Collections::ObjectModel::Collection<T>
23{
28
30 typedef ::System::BaseTypesInfo<BaseType> ThisTypeBaseTypesInfo;
32 RTTI_INFO_TEMPLATE_CLASS(ThisType, ThisTypeBaseTypesInfo);
33
34public:
36 ObjectCollection() : ObjectCollection(static_cast<Action<T>>(s_defaultValidator))
37 {}
38
42 : System::Collections::ObjectModel::Collection<T>(System::MakeObject<Collections::Generic::List<T>>())
43 {
44 _validator = validator;
45 }
46
48 void SetTemplateWeakPtr(uint32_t argument) override
49 {
50 switch (argument)
51 {
52 case 0:
53 System::Details::CollectionHelpers::SetWeakPointer(0, _validator);
54 BaseType::SetTemplateWeakPtr(0);
55 break;
56 }
57 }
58
59protected:
63 virtual void InsertItem(int32_t index, T item)
64 {
65 if (_validator != nullptr)
66 {
67 _validator(item);
68 }
70 }
71
75 virtual void SetItem(int32_t index, T item)
76 {
77 if (_validator != nullptr)
78 {
79 _validator(item);
80 }
82 }
83
84private:
86 static Action<T> s_defaultValidator;
88 Action<T> _validator;
89
91 static void CheckNotNull(T item)
92 {
93 // Null values cannot be added to the collection.
94 if (item == nullptr)
95 {
96 throw ArgumentNullException(u"item");
97 }
98 }
99};
100
101template <typename T>
102Action<T> ObjectCollection<T>::s_defaultValidator = CheckNotNull;
103
104}}}} // namespace System::Net::Http::Headers
Base type for generic collection. Objects of this class should only be allocated using System::MakeOb...
Definition: collection.h:19
virtual void InsertItem(int index, const T &item)
Inserts item into specified position.
Definition: collection.h:291
virtual void SetItem(int index, const T &item)
Sets item at specified position.
Definition: collection.h:304
Represents the collection of the objects.
Definition: object_collection.h:23
ObjectCollection(Action< T > validator)
Constructs a new instance.
Definition: object_collection.h:41
virtual void SetItem(int32_t index, T item)
Sets an item at the specified index.
Definition: object_collection.h:75
virtual void InsertItem(int32_t index, T item)
Adds an item to the specified index.
Definition: object_collection.h:63
void SetTemplateWeakPtr(uint32_t argument) override
Set n'th template argument a weak pointer (rather than shared). Allows switching pointers in containe...
Definition: object_collection.h:48
ObjectCollection()
Constructs a new instance.
Definition: object_collection.h:36
Definition: db_command.h:9
MulticastDelegate< void(Args...)> Action
Delegate type that references methods that have no return value.
Definition: action.h:40
std::enable_if<!IsSmartPtr< T >::value, SmartPtr< T > >::type MakeObject(Args &&... args)
Creates object on heap and returns shared pointer to it.
Definition: smart_ptr.h:1506