Aspose.Tasks for C++
ReadOnlyCollectionBase.h
1 #pragma once
2 //-----------------------------------------------------------------------
3 // <copyright file="ReadOnlyCollectionBase.cs" company="Aspose Pty Ltd">
4 // Copyright (c) 2002-2025 Aspose Pty Ltd. All Rights Reserved.
5 // </copyright>
6 //-----------------------------------------------------------------------
7 
8 #include <system/exceptions.h>
9 #include <system/details/pointer_collection_helpers.h>
10 #include <system/collections/list.h>
11 #include <system/collections/ilist.h>
12 #include <system/array.h>
13 #include <cstdint>
14 
15 namespace Aspose
16 {
17 namespace Tasks
18 {
19 namespace Vba
20 {
21 class VbaProjectReader;
22 class VbaProjectReferencesReader;
23 } // namespace Vba
24 class VbaModuleAttributeCollection;
25 class VbaModuleCollection;
26 class VbaReferenceCollection;
27 } // namespace Tasks
28 } // namespace Aspose
29 namespace System
30 {
31 namespace Collections
32 {
33 namespace Generic
34 {
35 template <typename> class IEnumerator;
36 } // namespace Generic
37 } // namespace Collections
38 } // namespace System
39 
40 namespace Aspose {
41 
42 namespace Tasks {
43 
44 /// <summary>
45 /// Represents a read-only collection of objects.
46 /// </summary>
47 /// <typeparam name="T">Type of collection items.</typeparam>
48 template<typename T>
49 class ReadOnlyCollectionBase : public System::Collections::Generic::IList<T>
50 {
52  typedef System::Collections::Generic::IList<T> BaseType;
53 
54  typedef ::System::BaseTypesInfo<BaseType> ThisTypeBaseTypesInfo;
55  RTTI_INFO_TEMPLATE_CLASS(ThisType, ThisTypeBaseTypesInfo);
56 
57  template<typename FT0> friend class ReadOnlyCollectionBase;
58  friend class Aspose::Tasks::Vba::VbaProjectReferencesReader;
59  friend class VbaModuleAttributeCollection;
60  friend class VbaReferenceCollection;
61  friend class VbaModuleCollection;
62  friend class Aspose::Tasks::Vba::VbaProjectReader;
63 
64 public:
65 
66  /// <summary>
67  /// Gets the number of objects contained in the object.
68  /// </summary>
69  int32_t get_Count() const override
70  {
71  return this->items->get_Count();
72  }
73 
74  /// <summary>
75  /// Returns the element at the specified index.
76  /// </summary>
77  /// <param name="index">The zero-based index of the element to get.</param>
78  /// <returns>the element at the specified index.</returns>
79  T idx_get(int32_t index) const override
80  {
81  return this->items->idx_get(index);
82  }
83 
84  /// <summary>
85  /// Returns the element at the specified index.
86  /// </summary>
87  /// <param name="index">The zero-based index of the element to get.</param>
88  /// <param name="value">the element at the specified index.</param>
89  void idx_set(int32_t index, T value) override
90  {
91  ASPOSE_UNUSED(index);
92  ASPOSE_UNUSED(value);
93  throw System::NotSupportedException(u"Collection is read-only.");
94  }
95 
96  /// <summary>
97  /// Returns an enumerator for this collection.
98  /// </summary>
99  /// <returns>An enumerator for this collection.</returns>
100  System::SharedPtr<System::Collections::Generic::IEnumerator<T>> GetEnumerator() override
101  {
102  return this->items->GetEnumerator();
103  }
104 
105  /// <summary>
106  /// This is the stub implementation of ICollection's Add method, that only throws NotSupportedException
107  /// </summary>
108  /// <param name="item">The item to add.</param>
109  void Add(const T& item) override
110  {
111  ASPOSE_UNUSED(item);
112  throw System::NotSupportedException(u"Collection is read-only.");
113  }
114 
115  /// <summary>
116  /// Converts the collection object to a list of <see cref="VbaModule"></see> objects.
117  /// </summary>
118  /// <returns>List of objects.</returns>
119  System::SharedPtr<System::Collections::Generic::List<T>> ToList()
120  {
121  return System::MakeObject<System::Collections::Generic::List<T>>(this->items);
122  }
123 
124  void SetTemplateWeakPtr(uint32_t argument) override
125  {
126  switch (argument)
127  {
128  case 0:
129  System::Details::CollectionHelpers::SetWeakPointer(0, items);
130  break;
131 
132  }
133  }
134 
135 protected:
136 
137  ReadOnlyCollectionBase() : items(System::MakeObject<System::Collections::Generic::List<T>>())
138  {
139  }
140 
141  ReadOnlyCollectionBase(const System::SharedPtr<System::Collections::Generic::IList<T>>& items)
142  : items(System::MakeObject<System::Collections::Generic::List<T>>())
143  {
144  this->items = items;
145  }
146 
147  void AddInternal(T attribute)
148  {
149  this->items->Add(attribute);
150  }
151 
152  virtual ~ReadOnlyCollectionBase()
153  {
154  }
155 
156  #ifdef ASPOSE_GET_SHARED_MEMBERS
157  void GetSharedMembers(System::Object::shared_members_type& result) const override
158  {
159  System::Object::GetSharedMembers(result);
160 
161  result.Add("Aspose::Tasks::ReadOnlyCollectionBase::items", this->items);
162  }
163  #endif
164 
165 
166 private:
167 
168  System::SharedPtr<System::Collections::Generic::IList<T>> items;
169 
170  bool get_IsReadOnly() const override
171  {
172  return true;
173  }
174 
175  int32_t IndexOf(const T& item) const override
176  {
177  return this->items->IndexOf(item);
178  }
179 
180  void CopyTo(System::ArrayPtr<T> array, int32_t arrayIndex) override
181  {
182  this->items->CopyTo(array, arrayIndex);
183  }
184 
185  bool Contains(const T& item) const override
186  {
187  return this->items->Contains(item);
188  }
189 
190  void Insert(int32_t index, const T& item) override
191  {
192  ASPOSE_UNUSED(index);
193  ASPOSE_UNUSED(item);
194  throw System::NotSupportedException(u"Collection is read-only.");
195  }
196 
197  bool Remove(const T& item) override
198  {
199  ASPOSE_UNUSED(item);
200  throw System::NotSupportedException(u"Collection is read-only.");
201  }
202 
203  void RemoveAt(int32_t index) override
204  {
205  ASPOSE_UNUSED(index);
206  throw System::NotSupportedException(u"Collection is read-only.");
207  }
208 
209  void Clear() override
210  {
211  throw System::NotSupportedException(u"Collection is read-only.");
212  }
213 
214 
215 };
216 
217 } // namespace Tasks
218 } // namespace Aspose
219 
220 
Represents a read-only collection of objects.
Definition: ReadOnlyCollectionBase.h:50
int32_t get_Count() const override
Gets the number of objects contained in the object.
Definition: ReadOnlyCollectionBase.h:69
T idx_get(int32_t index) const override
Returns the element at the specified index.
Definition: ReadOnlyCollectionBase.h:79
System::SharedPtr< System::Collections::Generic::IEnumerator< T > > GetEnumerator() override
Returns an enumerator for this collection.
Definition: ReadOnlyCollectionBase.h:100
void Add(const T &item) override
This is the stub implementation of ICollection's Add method, that only throws NotSupportedException
Definition: ReadOnlyCollectionBase.h:109
void idx_set(int32_t index, T value) override
Returns the element at the specified index.
Definition: ReadOnlyCollectionBase.h:89
System::SharedPtr< System::Collections::Generic::List< T > > ToList()
Converts the collection object to a list of VbaModule objects.
Definition: ReadOnlyCollectionBase.h:119
Represents a collection of VbaModuleAttribute objects.
Definition: VbaModuleAttributeCollection.h:46
Represents a collection of VbaModule objects.
Definition: VbaModuleCollection.h:42
Represents a collection of VbaReference objects.
Definition: VbaReferenceCollection.h:42
Aspose.
Definition: Asn.h:13