CodePorting.Translator Cs2Cpp
CodePorting.Translator.Cs2Cpp.Framework
read_only_collection.h
1
2#ifndef _aspose_system_collection_read_only_collection_h_
3#define _aspose_system_collection_read_only_collection_h_
4
5#include <system/diagnostics/debug.h>
6
7#include "fwd.h"
8#include "system/object.h"
9#include "system/collections/ilist.h"
10#include "system/exceptions.h"
11#include "system/cycles_detection.h"
12#include "system/array.h"
13
14namespace System {
15namespace Collections {
16namespace ObjectModel {
17
23template<typename T>
24class ASPOSECPP_SHARED_CLASS ReadOnlyCollection
25 : virtual public Object
26 , public Generic::IList<T>
27{
29 RTTI_INFO_TEMPLATE_CLASS(ReadOnlyCollection<T>, System::BaseTypesInfo<System::Object>);
30
31protected:
36
37public:
39 typedef T ValueType;
42
43public:
46
50 {
51 if (!list)
52 throw System::ArgumentNullException(u"list");
53
54 m_list = list;
55 }
56
59 virtual IEnumeratorPtr GetEnumerator() override
60 {
61 return m_list->GetEnumerator();
62 }
63
66 virtual int get_Count() const override
67 {
68 return m_list->get_Count();
69 }
70
73 bool get_IsReadOnly() const override { return true; }
74
78 virtual bool Contains(const T& item) const override
79 {
80 return m_list->Contains(item);
81 }
85 virtual int IndexOf(const T& item) const override
86 {
87 return m_list->IndexOf(item);
88 }
89
93 virtual T idx_get(int index) const override
94 {
95 return m_list->idx_get(index);
96 }
97
101 virtual void CopyTo(System::ArrayPtr<T> array, int index) override
102 {
103 m_list->CopyTo(array, index);
104 }
105
107 void SetTemplateWeakPtr(uint32_t argument) override
108 {
109 CODEPORTING_DEBUG_ASSERT(!"ReadOnlyCollection is a wrapper and doesn't own any data, so it can't be used to store weak pointers if referenced container stores shared ones");
110 }
111
113 System::Details::VirtualizedIteratorBase<T>* virtualizeBeginIterator() override
114 {
115 return m_list->virtualizeBeginIterator();
116 }
118 System::Details::VirtualizedIteratorBase<T>* virtualizeEndIterator() override
119 {
120 return m_list->virtualizeEndIterator();
121 }
123 System::Details::VirtualizedIteratorBase<T>* virtualizeBeginConstIterator() const override
124 {
125 return m_list->virtualizeBeginConstIterator();
126 }
128 System::Details::VirtualizedIteratorBase<T>* virtualizeEndConstIterator() const override
129 {
130 return m_list->virtualizeEndConstIterator();
131 }
132
133protected:
136
137private:
139 virtual void Add(const T& item) override
140 {
141 throw NotSupportedException(u"Operation not supported on read-only collection");
142 }
144 virtual void Clear() override
145 {
146 throw NotSupportedException(u"Operation not supported on read-only collection");
147 }
149 virtual bool Remove(const T& item) override
150 {
151 throw NotSupportedException(u"Operation not supported on read-only collection");
152 }
154 void RemoveAt(int index) override
155 {
156 throw NotSupportedException(u"Operation not supported on read-only collection");
157 }
159 virtual void Insert(int index, const T& item) override
160 {
161 throw NotSupportedException(u"Operation not supported on read-only collection");
162 }
164 virtual T& operator[](int index)
165 {
166 throw NotSupportedException(u"Operation not supported on read-only collection");
167 }
169 virtual void idx_set(int index, T value) override
170 {
171 throw NotSupportedException(u"Operation not supported on read-only collection");
172 }
173
174protected:
175#ifdef ASPOSE_GET_SHARED_MEMBERS
177 virtual void GetSharedMembers(System::Object::shared_members_type& result) const override
178 {
179 Object::GetSharedMembers(result);
180 result.Add("System::Collections::ObjectModel::ReadOnlyCollection<T>::m_list[]", m_list);
181 }
182#endif
183
184#ifdef __DBG_FOR_EACH_MEMBER
185public:
188 void DBG_for_each_member(DBG::for_each_member_visitor &visitor) const override
189 {
190 Object::DBG_for_each_member(visitor);
191
192 visitor.add_self(this);
193 visitor.add_member(this, m_list.get_shared(), "m_list");
194 }
195
198 const char* DBG_class_name() const override { return "ReadOnlyCollection<T>"; }
199#endif
200};
201
202
203} // namespace ObjectModel
204} // namespace Collections
205} // namespace System
206
207#endif // _aspose_system_collection_read_only_collection_h_
Interface of indexed container of elements. Objects of this class should only be allocated using Syst...
Definition: ilist.h:19
Wraps specific container to access it in read-only mode. Objects of this class should only be allocat...
Definition: read_only_collection.h:27
System::Details::VirtualizedIteratorBase< T > * virtualizeEndConstIterator() const override
Gets the implementation of end const iterator for the current container.
Definition: read_only_collection.h:128
SharedPtr< ReadOnlyCollection< T > > ThisPtr
This pointer.
Definition: read_only_collection.h:33
void SetTemplateWeakPtr(uint32_t argument) override
Does nothing as read-only collection only wraps data and stores nothing.
Definition: read_only_collection.h:107
virtual T idx_get(int index) const override
Gets item at specific position.
Definition: read_only_collection.h:93
System::Details::VirtualizedIteratorBase< T > * virtualizeEndIterator() override
Gets the implementation of end iterator for the current container.
Definition: read_only_collection.h:118
virtual int get_Count() const override
Gets count of container elements.
Definition: read_only_collection.h:66
T ValueType
Value type.
Definition: read_only_collection.h:39
virtual bool Contains(const T &item) const override
Checks if container contains specific item.
Definition: read_only_collection.h:78
virtual void CopyTo(System::ArrayPtr< T > array, int index) override
Copies container elements to existing array elements.
Definition: read_only_collection.h:101
System::Details::VirtualizedIteratorBase< T > * virtualizeBeginConstIterator() const override
Gets the implementation of begin const iterator for the current container.
Definition: read_only_collection.h:123
virtual IEnumeratorPtr GetEnumerator() override
Gets collection enumerator.
Definition: read_only_collection.h:59
SharedPtr< Generic::IList< T > > m_list
Wrapped container.
Definition: read_only_collection.h:35
ReadOnlyCollection(const SharedPtr< Generic::IList< T > > &list)
Wraps read-only collection around specific collection.
Definition: read_only_collection.h:49
SharedPtr< System::Collections::Generic::IEnumerator< T > > IEnumeratorPtr
Container of same elements.
Definition: read_only_collection.h:45
~ReadOnlyCollection() override
Destructor.
Definition: read_only_collection.h:135
bool get_IsReadOnly() const override
Checks if collection is read only.
Definition: read_only_collection.h:73
System::Details::VirtualizedIteratorBase< T > * virtualizeBeginIterator() override
Gets the implementation of begin iterator for the current container.
Definition: read_only_collection.h:113
virtual int IndexOf(const T &item) const override
Looks for specific item in collection.
Definition: read_only_collection.h:85
Generic::IList< T > BaseType
Implemented interface.
Definition: read_only_collection.h:41
Base class that enables using methods available for System.Object class in C#. All non-trivial classe...
Definition: object.h:62
Pointer class to wrap types being allocated on heap. Use it to manage memory for classes inheriting O...
Definition: smart_ptr.h:180
Pointee_ * get_shared() const
Gets pointed object, but asserts that pointer is in shared mode.
Definition: smart_ptr.h:524
Definition: db_command.h:9