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