Aspose.Tasks for C++
ResourceCollection.h
1 #pragma once
2 //-----------------------------------------------------------------------
3 // <copyright file="ResourceCollection.cs" company="Aspose Pty Ltd">
4 // Copyright (c) 2002-2024 Aspose Pty Ltd. All Rights Reserved.
5 // </copyright>
6 //-----------------------------------------------------------------------
7 
8 #include <system/collections/ilist.h>
9 #include <system/array.h>
10 #include <cstdint>
11 
12 #include "aspose.tasks.cpp/aspose_tasks_api_defs.h"
13 
14 namespace Aspose
15 {
16 namespace Tasks
17 {
18 namespace Connectivity
19 {
20 class MpdReader;
21 class MspDbReader;
22 class PrimaveraDbReader;
23 } // namespace Connectivity
24 class IdGenerator;
25 namespace IO
26 {
27 namespace Html
28 {
29 class HtmlResourceTableReader;
30 } // namespace Html
31 namespace Mpx
32 {
33 class MpxReader;
34 } // namespace Mpx
35 namespace MSProject
36 {
37 class MPP12Reader;
38 class MPP14Reader;
39 class MPP9Reader;
40 class MPPReader;
41 class MPPWriter;
42 } // namespace MSProject
43 namespace PrimaveraXml
44 {
45 class PrimaveraReader;
46 } // namespace PrimaveraXml
47 namespace Pwa
48 {
49 namespace InternalApi
50 {
51 namespace Mapping
52 {
53 class ProjectResourcesMapper;
54 } // namespace Mapping
55 } // namespace InternalApi
56 } // namespace Pwa
57 namespace Xer
58 {
59 class XerPrimaveraReader;
60 class XerProjectNormalizer;
61 } // namespace Xer
62 namespace Xml
63 {
64 class XmlReader;
65 } // namespace Xml
66 } // namespace IO
67 namespace Leveling
68 {
69 class LevelingAlgorithm;
70 } // namespace Leveling
71 class Project;
72 class Resource;
73 namespace Saving
74 {
75 class TemplateProjectLoader;
76 class XerResourceTable;
77 } // namespace Saving
78 } // namespace Tasks
79 } // namespace Aspose
80 namespace System
81 {
82 namespace Collections
83 {
84 namespace Generic
85 {
86 template <typename> class IComparer;
87 template <typename, typename> class IDictionary;
88 template <typename> class IEnumerator;
89 template <typename> class List;
90 } // namespace Generic
91 } // namespace Collections
92 } // namespace System
93 
94 namespace Aspose {
95 
96 namespace Tasks {
97 
98 /// <summary>
99 /// Represents a collection of <see cref="Resource"></see> objects.
100 /// </summary>
101 class ASPOSE_TASKS_SHARED_CLASS ResourceCollection : public System::Collections::Generic::IList<System::SharedPtr<Aspose::Tasks::Resource>>
102 {
104  typedef System::Collections::Generic::IList<System::SharedPtr<Aspose::Tasks::Resource>> BaseType;
105 
106  typedef ::System::BaseTypesInfo<BaseType> ThisTypeBaseTypesInfo;
107  ASPOSE_TASKS_SHARED_RTTI_INFO_DECL();
108 
109  friend class Aspose::Tasks::IO::PrimaveraXml::PrimaveraReader;
110  friend class Aspose::Tasks::Leveling::LevelingAlgorithm;
111  friend class Aspose::Tasks::Project;
112  friend class Aspose::Tasks::Resource;
113  friend class Aspose::Tasks::Saving::TemplateProjectLoader;
114  friend class Aspose::Tasks::Connectivity::MpdReader;
115  friend class Aspose::Tasks::Connectivity::MspDbReader;
116  friend class Aspose::Tasks::Connectivity::PrimaveraDbReader;
117  friend class Aspose::Tasks::IO::Html::HtmlResourceTableReader;
118  friend class Aspose::Tasks::IO::MSProject::MPP12Reader;
119  friend class Aspose::Tasks::IO::MSProject::MPPReader;
120  friend class Aspose::Tasks::IO::MSProject::MPP14Reader;
121  friend class Aspose::Tasks::IO::MSProject::MPPWriter;
122  friend class Aspose::Tasks::IO::MSProject::MPP9Reader;
123  friend class Aspose::Tasks::IO::Mpx::MpxReader;
124  friend class Aspose::Tasks::IO::Xer::XerPrimaveraReader;
125  friend class Aspose::Tasks::IO::Xer::XerProjectNormalizer;
126  friend class Aspose::Tasks::IO::Pwa::InternalApi::Mapping::ProjectResourcesMapper;
127  friend class Aspose::Tasks::IO::Xml::XmlReader;
128  friend class Aspose::Tasks::Saving::XerResourceTable;
129 
130 public:
131 
132  /// <summary>
133  /// Gets the number of elements contained in the ResourceCollection.
134  /// <remarks>Read-only <see cref="int32_t"></see>.</remarks>
135  /// </summary>
136  ASPOSE_TASKS_SHARED_API int32_t get_Count() const override;
137  /// <summary>
138  /// Gets the parent project of the ResourceCollection object.
139  /// </summary>
140  ASPOSE_TASKS_SHARED_API System::SharedPtr<Project> get_ParentProject() const;
141 
142  /// <summary>
143  /// Returns the element at the specified index.
144  /// </summary>
145  /// <param name="index">The zero-based index of the element to get.</param>
146  /// <returns>the element at the specified index.</returns>
147  ASPOSE_TASKS_SHARED_API System::SharedPtr<Resource> idx_get(int32_t index) const override;
148  /// <summary>
149  /// Returns the element at the specified index.
150  /// </summary>
151  /// <param name="index">The zero-based index of the element to get.</param>
152  /// <param name="value">the element at the specified index.</param>
153  ASPOSE_TASKS_SHARED_API void idx_set(int32_t index, System::SharedPtr<Resource> value) override;
154 
155  /// <summary>
156  /// Returns an enumerator for this collection.
157  /// </summary>
158  /// <returns>an enumerator for this collection.</returns>
159  ASPOSE_TASKS_SHARED_API System::SharedPtr<System::Collections::Generic::IEnumerator<System::SharedPtr<Resource>>> GetEnumerator() override;
160  /// <summary>
161  /// Adds new resource at the last position of a project resources collection.
162  /// </summary>
163  /// <returns>Added resource.</returns>
164  ASPOSE_TASKS_SHARED_API System::SharedPtr<Resource> Add();
165  /// <summary>
166  /// Adds new resource at the last position of a project resources collection.
167  /// </summary>
168  /// <param name="resourceName">Name of a resource.</param>
169  /// <returns>Added resource.</returns>
170  ASPOSE_TASKS_SHARED_API System::SharedPtr<Resource> Add(const System::String& resourceName);
171  /// <summary>
172  /// Adds new resource at the specified position of a project resources collection.
173  /// </summary>
174  /// <param name="resourceName">Name of a resource.</param>
175  /// <param name="beforeResourceId">Position of the previous resource in a project resources collection.</param>
176  /// <returns>Added resource.</returns>
177  ASPOSE_TASKS_SHARED_API System::SharedPtr<Resource> Add(const System::String& resourceName, int32_t beforeResourceId);
178  /// <summary>
179  /// Converts the ResourceCollection object to a list of <see cref="Resource"></see> objects.
180  /// </summary>
181  /// <returns>List of <see cref="Resource"></see> objects.</returns>
182  ASPOSE_TASKS_SHARED_API System::SharedPtr<System::Collections::Generic::List<System::SharedPtr<Resource>>> ToList();
183  /// <summary>
184  /// Returns a resource with the specified id.
185  /// </summary>
186  /// <param name="id">The specified id.</param>
187  /// <remarks>O(1) complexity.</remarks>
188  /// <returns>Resource with the specified id if present; otherwise, null.</returns>
189  ASPOSE_TASKS_SHARED_API System::SharedPtr<Resource> GetById(int32_t id);
190  /// <summary>
191  /// Returns a resource with the specified Uid.
192  /// </summary>
193  /// <param name="uid">The specified uid.</param>
194  /// <remarks>O(1) complexity.</remarks>
195  /// <returns>Resource with the specified uid if present; otherwise, null.</returns>
196  ASPOSE_TASKS_SHARED_API System::SharedPtr<Resource> GetByUid(int32_t uid);
197  /// <summary>
198  /// Direct clearing is not supported, this method just throw NotSupportedException.
199  /// </summary>
200  ASPOSE_TASKS_SHARED_API void Clear() override;
201  /// <summary>
202  /// This is the stub implementation of ICollection's Remove
203  /// method, that only throws NotSupportedException
204  /// </summary>
205  /// <param name="item">the item to remove.</param>
206  /// <returns><c>true</c> if the item was removed; <c>false</c> otherwise.</returns>
207  ASPOSE_TASKS_SHARED_API bool Remove(const System::SharedPtr<Resource>& item) override;
208 
209 protected:
210 
211  ASPOSE_TASKS_SHARED_API ResourceCollection(const System::SharedPtr<System::Collections::Generic::IList<System::SharedPtr<Resource>>>& resources, const System::SharedPtr<Project>& parentProject);
212 
213  ASPOSE_TASKS_SHARED_API MEMBER_FUNCTION_MAKE_OBJECT_DECLARATION(ResourceCollection, CODEPORTING_ARGS(const System::SharedPtr<System::Collections::Generic::IList<System::SharedPtr<Resource>>>& resources, const System::SharedPtr<Project>& parentProject));
214 
215  ASPOSE_TASKS_SHARED_API ResourceCollection(const System::SharedPtr<Project>& parentProject);
216 
217  ASPOSE_TASKS_SHARED_API MEMBER_FUNCTION_MAKE_OBJECT_DECLARATION(ResourceCollection, CODEPORTING_ARGS(const System::SharedPtr<Project>& parentProject));
218  ASPOSE_TASKS_SHARED_API void AddRootResource();
219  /// <summary>
220  /// Initializes id and uid and then adds resource at the end of a project resources collection.
221  /// </summary>
222  /// <param name="resource">Resource to be added</param>
223  ASPOSE_TASKS_SHARED_API void InitUidAndIdThenAdd(const System::SharedPtr<Resource>& resource);
224  ASPOSE_TASKS_SHARED_API bool RemoveInternal(const System::SharedPtr<Resource>& resource);
225  /// <summary>
226  /// Recalculate Ids of resources.
227  /// </summary>
228  ASPOSE_TASKS_SHARED_API void CalcResourceIds();
229  /// <summary>
230  /// Recalculate Uids of resources from 1 up to resources collection length - 1.
231  /// </summary>
232  ASPOSE_TASKS_SHARED_API void CalcResourceUids();
233  ASPOSE_TASKS_SHARED_API System::SharedPtr<System::Collections::Generic::List<System::SharedPtr<Resource>>> GetValidResources();
234  ASPOSE_TASKS_SHARED_API void Sort(const System::SharedPtr<System::Collections::Generic::IComparer<System::SharedPtr<Resource>>>& comparer);
235  ASPOSE_TASKS_SHARED_API void ClearInternal();
236  ASPOSE_TASKS_SHARED_API void ResetCache();
237 
238  virtual ASPOSE_TASKS_SHARED_API ~ResourceCollection();
239 
240  #ifdef ASPOSE_GET_SHARED_MEMBERS
241  ASPOSE_TASKS_SHARED_API void GetSharedMembers(System::Object::shared_members_type& result) const override;
242  #endif
243 
244 
245 private:
246 
247  System::WeakPtr<Project> parentProject;
248  System::SharedPtr<System::Collections::Generic::IList<System::SharedPtr<Resource>>> resources;
249  System::SharedPtr<System::Collections::Generic::IDictionary<int32_t, System::SharedPtr<Resource>>> idLookup;
250  System::SharedPtr<System::Collections::Generic::IDictionary<int32_t, System::SharedPtr<Resource>>> uidLookup;
251  System::SharedPtr<IdGenerator> idGenerator;
252  System::SharedPtr<IdGenerator> uidGenerator;
253 
254  bool get_IsReadOnly() const override;
255 
256  void Add(const System::SharedPtr<Resource>& item) override;
257  bool Contains(const System::SharedPtr<Resource>& item) const override;
258  void CopyTo(System::ArrayPtr<System::SharedPtr<Resource>> array, int32_t arrayIndex) override;
259  int32_t IndexOf(const System::SharedPtr<Resource>& item) const override;
260  void Insert(int32_t index, const System::SharedPtr<Resource>& item) override;
261  void RemoveAt(int32_t index) override;
262  void AddResourceCalendar(const System::SharedPtr<Resource>& resource);
263  bool ContainsRootResource();
264  void Init();
265  void CalcResourceIds(int32_t startId);
266  void InitParentAndAssignments();
267  void InitIdLookup();
268  void InitUidLookup();
269 
270 };
271 
272 } // namespace Tasks
273 } // namespace Aspose
274 
275 
Represents a project.
Definition: Project.h:551
Represents a collection of Resource objects.
Definition: ResourceCollection.h:102
System::SharedPtr< Resource > GetById(int32_t id)
Returns a resource with the specified id.
System::SharedPtr< Resource > idx_get(int32_t index) const override
Returns the element at the specified index.
int32_t get_Count() const override
Gets the number of elements contained in the ResourceCollection.
void Clear() override
Direct clearing is not supported, this method just throw NotSupportedException.
System::SharedPtr< Resource > Add()
Adds new resource at the last position of a project resources collection.
System::SharedPtr< Project > get_ParentProject() const
Gets the parent project of the ResourceCollection object.
System::SharedPtr< Resource > Add(const System::String &resourceName, int32_t beforeResourceId)
Adds new resource at the specified position of a project resources collection.
void idx_set(int32_t index, System::SharedPtr< Resource > value) override
Returns the element at the specified index.
bool Remove(const System::SharedPtr< Resource > &item) override
This is the stub implementation of ICollection's Remove method, that only throws NotSupportedExceptio...
System::SharedPtr< Resource > Add(const System::String &resourceName)
Adds new resource at the last position of a project resources collection.
System::SharedPtr< System::Collections::Generic::List< System::SharedPtr< Resource > > > ToList()
Converts the ResourceCollection object to a list of Resource objects.
System::SharedPtr< Resource > GetByUid(int32_t uid)
Returns a resource with the specified Uid.
System::SharedPtr< System::Collections::Generic::IEnumerator< System::SharedPtr< Resource > > > GetEnumerator() override
Returns an enumerator for this collection.
Represents a resource in a project.
Definition: Resource.h:206
Definition: Asn.h:13