Aspose.Tasks for C++
TaskCollection.h
1 #pragma once
2 //-----------------------------------------------------------------------
3 // <copyright file="TaskCollection.cs" company="Aspose Pty Ltd">
4 // Copyright (c) 2002-2024 Aspose Pty Ltd. All Rights Reserved.
5 // </copyright>
6 //-----------------------------------------------------------------------
7 
8 #include <system/collections/list.h>
9 #include <system/collections/ilist.h>
10 #include <system/array.h>
11 #include <cstdint>
12 
13 #include "aspose.tasks.cpp/aspose_tasks_api_defs.h"
14 
15 namespace Aspose
16 {
17 namespace Tasks
18 {
19 namespace Calculations
20 {
21 class SummaryTaskCalculator;
22 } // namespace Calculations
23 namespace Connectivity
24 {
25 class MspTaskMapper;
26 class PmTaskMapper;
27 } // namespace Connectivity
28 namespace IO
29 {
30 namespace Html
31 {
32 class HtmlTaskTableReader;
33 } // namespace Html
34 namespace Mpx
35 {
36 class MpxReader;
37 } // namespace Mpx
38 namespace MSProject
39 {
40 class MppTaskTreeBuilder;
41 } // namespace MSProject
42 namespace PrimaveraXml
43 {
44 class P6XmlUtils;
45 class PrimaveraActivityNodeReader;
46 class PrimaveraProjectNodeReader;
47 } // namespace PrimaveraXml
48 namespace Pwa
49 {
50 namespace InternalApi
51 {
52 namespace Mapping
53 {
54 class ProjectTasksMapper;
55 } // namespace Mapping
56 } // namespace InternalApi
57 } // namespace Pwa
58 namespace Xer
59 {
60 class XerPrimaveraReader;
61 class XerProjectNormalizer;
62 } // namespace Xer
63 } // namespace IO
64 class PercentCompleteCalculator;
65 class Project;
66 class ProjectState;
67 class RecurringTaskBuilder;
68 class RecurringTaskParameters;
69 class SummaryTaskTotals;
70 class Task;
71 class TaskTreeBuilder;
72 namespace Util
73 {
74 class RemoveTask;
75 class TaskUtils;
76 } // namespace Util
77 namespace Visualization
78 {
79 class LegendItemsFlowLayoutBuilder;
80 } // namespace Visualization
81 } // namespace Tasks
82 } // namespace Aspose
83 namespace System
84 {
85 namespace Collections
86 {
87 namespace Generic
88 {
89 template <typename> class IComparer;
90 template <typename> class IEnumerator;
91 } // namespace Generic
92 } // namespace Collections
93 } // namespace System
94 
95 namespace Aspose {
96 
97 namespace Tasks {
98 
99 /// <summary>
100 /// Represents a collection of <see cref="Task"></see> objects.
101 /// </summary>
102 class ASPOSE_TASKS_SHARED_CLASS TaskCollection : public System::Collections::Generic::IList<System::SharedPtr<Aspose::Tasks::Task>>
103 {
104  typedef TaskCollection ThisType;
105  typedef System::Collections::Generic::IList<System::SharedPtr<Aspose::Tasks::Task>> BaseType;
106 
107  typedef ::System::BaseTypesInfo<BaseType> ThisTypeBaseTypesInfo;
108  ASPOSE_TASKS_SHARED_RTTI_INFO_DECL();
109 
110  friend class Aspose::Tasks::Calculations::SummaryTaskCalculator;
111  friend class Aspose::Tasks::IO::PrimaveraXml::P6XmlUtils;
112  friend class Aspose::Tasks::IO::PrimaveraXml::PrimaveraActivityNodeReader;
113  friend class Aspose::Tasks::IO::PrimaveraXml::PrimaveraProjectNodeReader;
114  friend class Aspose::Tasks::Project;
115  friend class Aspose::Tasks::SummaryTaskTotals;
116  friend class Aspose::Tasks::Task;
117  friend class Aspose::Tasks::Connectivity::MspTaskMapper;
118  friend class Aspose::Tasks::Connectivity::PmTaskMapper;
119  friend class Aspose::Tasks::IO::Html::HtmlTaskTableReader;
120  friend class Aspose::Tasks::IO::MSProject::MppTaskTreeBuilder;
121  friend class Aspose::Tasks::IO::Mpx::MpxReader;
122  friend class Aspose::Tasks::TaskTreeBuilder;
123  friend class Aspose::Tasks::IO::Xer::XerPrimaveraReader;
124  friend class Aspose::Tasks::IO::Xer::XerProjectNormalizer;
125  friend class Aspose::Tasks::IO::Pwa::InternalApi::Mapping::ProjectTasksMapper;
126  friend class Aspose::Tasks::ProjectState;
127  friend class Aspose::Tasks::PercentCompleteCalculator;
128  friend class Aspose::Tasks::RecurringTaskBuilder;
129  friend class Aspose::Tasks::Util::RemoveTask;
130  friend class Aspose::Tasks::Util::TaskUtils;
131  friend class Aspose::Tasks::Visualization::LegendItemsFlowLayoutBuilder;
132 
133 public:
134  /// A collection type whose iterator types is used as iterator types in the current collection.
135  using iterator_holder_type = System::Collections::Generic::List<System::SharedPtr<Task>>;
136  /// Iterator type.
137  using iterator = typename iterator_holder_type::iterator;
138  /// Const iterator type.
139  using const_iterator = typename iterator_holder_type::const_iterator;
140  /// Virtualized element type.
141  using virtualized_iterator_element = typename iterator_holder_type::virtualized_iterator_element;
142  /// Virtualized type.
143  using virtualized_iterator = typename iterator_holder_type::virtualized_iterator;
144 
145 public:
146 
147  /// <summary>
148  /// Gets the number of objects contained in the TaskCollection.
149  /// </summary>
150  ASPOSE_TASKS_SHARED_API int32_t get_Count() const override;
151  /// <summary>
152  /// Gets the parent project of the TaskCollection object.
153  /// </summary>
154  ASPOSE_TASKS_SHARED_API System::SharedPtr<Project> get_ParentProject();
155  /// <summary>
156  /// Gets a value indicating whether this collection is read only.
157  /// </summary>
158  ASPOSE_TASKS_SHARED_API bool get_IsReadOnly() const override;
159 
160  /// <summary>
161  /// Returns the element at the specified index.
162  /// </summary>
163  /// <param name="index">The zero-based index of the element to get.</param>
164  /// <returns>the element at the specified index.</returns>
165  ASPOSE_TASKS_SHARED_API System::SharedPtr<Task> idx_get(int32_t index) const override;
166  /// <summary>
167  /// Returns the element at the specified index.
168  /// </summary>
169  /// <param name="index">The zero-based index of the element to get.</param>
170  /// <param name="value">the element at the specified index.</param>
171  ASPOSE_TASKS_SHARED_API void idx_set(int32_t index, System::SharedPtr<Task> value) override;
172 
173  /// <summary>
174  /// Returns an enumerator for this collection.
175  /// </summary>
176  /// <returns>an enumerator for this collection.</returns>
177  ASPOSE_TASKS_SHARED_API System::SharedPtr<System::Collections::Generic::IEnumerator<System::SharedPtr<Task>>> GetEnumerator() override;
178  /// <summary>
179  /// Add the specified task to the instance of the <see cref="TaskCollection"></see> class.
180  /// If ParentProject.CalculationMode is None user should invoke Project.Recalculate() after using this method (It will reschedule all project tasks (start/finish dates, sets early/late dates) and calculate the dependent fields such as slacks, work and cost fields, ids and outline levels).
181  /// If ParentProject.CalculationMode is Manual the method will calculate only task id, outline level and outline numbers automatically.
182  /// If ParentProject.CalculationMode is Automatic the method reschedules all project's tasks automatically
183  /// (start/finish dates, sets early/late dates, calculates slacks, work and cost fields, recalculates ids and outline levels).
184  /// </summary>
185  /// <param name="item">the specified task which should be added to this task collection.</param>
186  ASPOSE_TASKS_SHARED_API void Add(const System::SharedPtr<Task>& item) override;
187  /// <summary>
188  /// This is the stub implementation of IList's Insert
189  /// method, that only throws NotSupportedException
190  /// </summary>
191  /// <param name="index">The index to insert at.</param>
192  /// <param name="item">The item to insert.</param>
193  ASPOSE_TASKS_SHARED_API void Insert(int32_t index, const System::SharedPtr<Task>& item) override;
194  /// <summary>
195  /// This is the stub implementation of ICollection's Remove
196  /// method, that only throws NotSupportedException
197  /// </summary>
198  /// <param name="item">The item to remove.</param>
199  /// <returns><c>true</c> if the item was removed; <c>false</c> otherwise.</returns>
200  ASPOSE_TASKS_SHARED_API bool Remove(const System::SharedPtr<Task>& item) override;
201  /// <summary>
202  /// Adds new task to project tasks collection on the same outline level of the last task.
203  /// </summary>
204  /// <returns>returns the newly added instance of the <see cref="Task"></see> class.</returns>
205  ASPOSE_TASKS_SHARED_API System::SharedPtr<Task> Add();
206  /// <summary>
207  /// Adds a new task to children tasks collection.
208  /// </summary>
209  /// <param name="taskName">the specified task name.</param>
210  /// <returns>returns the newly added instance of the <see cref="Task"></see> class.</returns>
211  ASPOSE_TASKS_SHARED_API System::SharedPtr<Task> Add(const System::String& taskName);
212  /// <summary>
213  /// Adds a new recurring task to children tasks collection.
214  /// </summary>
215  /// <param name="taskName">the specified task name.</param>
216  /// <param name="beforeTaskId">The specified id of a task before which a new task will be inserted.</param>
217  /// <returns>returns a task which was inserted before a task with the specified id.</returns>
218  /// <exception cref="ArgumentOutOfRangeException">ArgumentOutOfRangeException is thrown if the specified id is not a valid task id.</exception>
219  ASPOSE_TASKS_SHARED_API System::SharedPtr<Task> Add(const System::String& taskName, int32_t beforeTaskId);
220  /// <summary>
221  /// Inserts a new task before a task with the specified id and on the same outline level.
222  /// </summary>
223  /// <param name="parameters">The parameters the specified parameters for creation of recurring task.</param>
224  /// <returns>returns the newly added instance of the <see cref="Task"></see> class.</returns>
225  /// <exception cref="ArgumentNullException">Thrown if the specified parameters are null.</exception>
226  /// <exception cref="ArgumentException">Thrown if the specified parameters are invalid.</exception>
227  ASPOSE_TASKS_SHARED_API System::SharedPtr<Task> Add(const System::SharedPtr<RecurringTaskParameters>& parameters);
228  /// <summary>
229  /// Converts the TaskCollection object to a list of <see cref="Task"></see> objects.
230  /// </summary>
231  /// <returns>returns a list which contains the <see cref="Task"></see> class instances of this collection.</returns>
232  ASPOSE_TASKS_SHARED_API System::SharedPtr<System::Collections::Generic::List<System::SharedPtr<Task>>> ToList();
233  /// <summary>
234  /// Returns a task with the specified Uid whose ancestor is parent task of this collection .
235  /// </summary>
236  /// <param name="uid">TaskEntity Uid.</param>
237  /// <returns>returns the instance of <see cref="Task"></see> class with the specified uid whose ancestor is parent task of this collection.</returns>
238  ASPOSE_TASKS_SHARED_API System::SharedPtr<Task> GetByUid(int32_t uid);
239  /// <summary>
240  /// Returns a task with the specified Id whose ancestor is parent task of this collection .
241  /// </summary>
242  /// <param name="id">TaskEntity Id</param>
243  /// <returns>returns the instance of <see cref="Task"></see> class with the specified id whose ancestor is parent task of this collection.</returns>
244  ASPOSE_TASKS_SHARED_API System::SharedPtr<Task> GetById(int32_t id);
245  /// <summary>
246  /// Checks if collection contains specified item.
247  /// </summary>
248  /// <param name="item">The item to check.</param>
249  /// <returns>true, if collection contains an item, false otherwise.</returns>
250  ASPOSE_TASKS_SHARED_API bool Contains(const System::SharedPtr<Task>& item) const override;
251  /// Gets iterator pointing to the first element (if any) of the collection.
252  /// @return An iterator pointing to the first element (if any) of the collection
253  ASPOSE_TASKS_SHARED_API iterator begin() noexcept;
254  /// Gets iterator pointing right after the last element (if any) of the collection.
255  /// @return An iterator pointing right after the last element (if any) of the collection
256  ASPOSE_TASKS_SHARED_API iterator end() noexcept;
257  /// Gets iterator pointing to the first element (if any) of the const-qualified instance of the collection.
258  /// @return An iterator pointing to the first element (if any) of the const-qualified instance of the collection
259  ASPOSE_TASKS_SHARED_API const_iterator begin() const noexcept;
260  /// Gets iterator pointing right after the last element (if any) of the const-qualified instance of the collection.
261  /// @return An iterator pointing right after the last element (if any) of the const-qualified instance of the collection
262  ASPOSE_TASKS_SHARED_API const_iterator end() const noexcept;
263  /// Gets iterator pointing to the first const-qualified element (if any) of the collection.
264  /// @return An iterator pointing to the first const-qualified element (if any) of the collection
265  ASPOSE_TASKS_SHARED_API const_iterator cbegin() const noexcept;
266  /// Gets iterator pointing right after the last const-qualified element (if any) of the collection.
267  /// @return An iterator pointing right after the last const-qualified element (if any) of the collection
268  ASPOSE_TASKS_SHARED_API const_iterator cend() const noexcept;
269  /// Gets iterator pointing to the first element (if any) of the collection.
270  /// @return An iterator pointing to the first element (if any) of the collection
271  /// Provides iterator implementation to container's first element.
272  /// @return Newly-created iterator object.
273  ASPOSE_TASKS_SHARED_API virtualized_iterator* virtualizeBeginIterator() override;
274  /// Gets iterator pointing right after the last element (if any) of the collection.
275  /// @return An iterator pointing right after the last element (if any) of the collection
276  /// Provides iterator implementation to container's end.
277  /// @return Newly-created iterator object.
278  ASPOSE_TASKS_SHARED_API virtualized_iterator* virtualizeEndIterator() override;
279  /// Gets iterator pointing to the first element (if any)of the const-qualified instance of the collection.
280  /// @return An iterator pointing to the first element (if any)of the const-qualified instance of the collection
281  /// Provides const iterator implementation to container's first element.
282  /// @return Newly-created iterator object.
283  ASPOSE_TASKS_SHARED_API virtualized_iterator* virtualizeBeginConstIterator() const override;
284  /// Gets iterator pointing right after the last element (if any)of the const-qualified instance of the collection.
285  /// @return An iterator pointing right after the last element (if any)of the const-qualified instance of the collection
286  /// Provides const iterator implementation to container's end.
287  /// @return Newly-created iterator object.
288  ASPOSE_TASKS_SHARED_API virtualized_iterator* virtualizeEndConstIterator() const override;
289 
290 protected:
291 
292  System::SharedPtr<SummaryTaskTotals> Totals;
293 
294  /// <summary>
295  /// Gets the parent task of the collection.
296  /// </summary>
297  ASPOSE_TASKS_SHARED_API System::SharedPtr<Task> get_ParentTask() const;
298 
299  ASPOSE_TASKS_SHARED_API TaskCollection(const System::SharedPtr<Task>& parentTask, bool isReadOnly, const System::SharedPtr<System::Collections::Generic::List<System::SharedPtr<Task>>>& tasks);
300 
301  ASPOSE_TASKS_SHARED_API MEMBER_FUNCTION_MAKE_OBJECT_DECLARATION(TaskCollection, CODEPORTING_ARGS(const System::SharedPtr<Task>& parentTask, bool isReadOnly, const System::SharedPtr<System::Collections::Generic::List<System::SharedPtr<Task>>>& tasks));
302 
303  ASPOSE_TASKS_SHARED_API TaskCollection(const System::SharedPtr<Task>& parentTask);
304 
305  ASPOSE_TASKS_SHARED_API MEMBER_FUNCTION_MAKE_OBJECT_DECLARATION(TaskCollection, CODEPORTING_ARGS(const System::SharedPtr<Task>& parentTask));
306 
307  ASPOSE_TASKS_SHARED_API TaskCollection(const System::SharedPtr<System::Collections::Generic::List<System::SharedPtr<Task>>>& tasks, const System::SharedPtr<Task>& parentTask);
308 
309  ASPOSE_TASKS_SHARED_API MEMBER_FUNCTION_MAKE_OBJECT_DECLARATION(TaskCollection, CODEPORTING_ARGS(const System::SharedPtr<System::Collections::Generic::List<System::SharedPtr<Task>>>& tasks, const System::SharedPtr<Task>& parentTask));
310  ASPOSE_TASKS_SHARED_API void AddInternal(const System::SharedPtr<Task>& task);
311  ASPOSE_TASKS_SHARED_API bool RemoveInternal(const System::SharedPtr<Task>& task);
312  /// <summary>
313  /// Recalculate uids of tasks (from 0).
314  /// </summary>
315  ASPOSE_TASKS_SHARED_API void CalcTaskUids();
316  ASPOSE_TASKS_SHARED_API void InsertInternal(int32_t index, const System::SharedPtr<Task>& item);
317  ASPOSE_TASKS_SHARED_API void Sort(const System::SharedPtr<System::Collections::Generic::IComparer<System::SharedPtr<Task>>>& comparer);
318 
319  virtual ASPOSE_TASKS_SHARED_API ~TaskCollection();
320 
321  #ifdef ASPOSE_GET_SHARED_MEMBERS
322  ASPOSE_TASKS_SHARED_API void GetSharedMembers(System::Object::shared_members_type& result) const override;
323  #endif
324 
325 
326 private:
327 
328  System::WeakPtr<Task> parentTask;
329  bool isReadOnly;
330  System::SharedPtr<System::Collections::Generic::List<System::SharedPtr<Task>>> tasks;
331 
332  void RemoveAt(int32_t index) override;
333  void Clear() override;
334  void CopyTo(System::ArrayPtr<System::SharedPtr<Task>> array, int32_t arrayIndex) override;
335  int32_t IndexOf(const System::SharedPtr<Task>& item) const override;
336  void SetParentTaskToAutomatic();
337  void Calculate(const System::SharedPtr<Task>& task);
338  void AssignNewTaskId(const System::SharedPtr<Task>& addedTask);
339  static bool IsLastTask(const System::SharedPtr<Task>& task);
340  bool IsLastTaskInCollection(const System::SharedPtr<Task>& task);
341  void Init();
342  void UpdateEstimated(const System::SharedPtr<Task>& task);
343 
344 };
345 
346 } // namespace Tasks
347 } // namespace Aspose
348 
349 
Represents a project.
Definition: Project.h:551
Represents a collection of Task objects.
Definition: TaskCollection.h:103
System::SharedPtr< Task > GetByUid(int32_t uid)
Returns a task with the specified Uid whose ancestor is parent task of this collection .
bool Contains(const System::SharedPtr< Task > &item) const override
Checks if collection contains specified item.
typename iterator_holder_type::iterator iterator
Iterator type.
Definition: TaskCollection.h:137
System::SharedPtr< Task > Add()
Adds new task to project tasks collection on the same outline level of the last task.
void Add(const System::SharedPtr< Task > &item) override
Add the specified task to the instance of the TaskCollection class. If ParentProject....
int32_t get_Count() const override
Gets the number of objects contained in the TaskCollection.
System::SharedPtr< Task > Add(const System::String &taskName)
Adds a new task to children tasks collection.
typename iterator_holder_type::const_iterator const_iterator
Const iterator type.
Definition: TaskCollection.h:139
typename iterator_holder_type::virtualized_iterator_element virtualized_iterator_element
Virtualized element type.
Definition: TaskCollection.h:141
System::SharedPtr< Task > Add(const System::String &taskName, int32_t beforeTaskId)
Adds a new recurring task to children tasks collection.
System::Collections::Generic::List< System::SharedPtr< Task > > iterator_holder_type
A collection type whose iterator types is used as iterator types in the current collection.
Definition: TaskCollection.h:135
System::SharedPtr< System::Collections::Generic::IEnumerator< System::SharedPtr< Task > > > GetEnumerator() override
Returns an enumerator for this collection.
void Insert(int32_t index, const System::SharedPtr< Task > &item) override
This is the stub implementation of IList's Insert method, that only throws NotSupportedException
System::SharedPtr< Task > idx_get(int32_t index) const override
Returns the element at the specified index.
iterator begin() noexcept
typename iterator_holder_type::virtualized_iterator virtualized_iterator
Virtualized type.
Definition: TaskCollection.h:143
System::SharedPtr< System::Collections::Generic::List< System::SharedPtr< Task > > > ToList()
Converts the TaskCollection object to a list of Task objects.
bool get_IsReadOnly() const override
Gets a value indicating whether this collection is read only.
System::SharedPtr< Task > Add(const System::SharedPtr< RecurringTaskParameters > &parameters)
Inserts a new task before a task with the specified id and on the same outline level.
System::SharedPtr< Project > get_ParentProject()
Gets the parent project of the TaskCollection object.
void idx_set(int32_t index, System::SharedPtr< Task > value) override
Returns the element at the specified index.
System::SharedPtr< Task > GetById(int32_t id)
Returns a task with the specified Id whose ancestor is parent task of this collection .
bool Remove(const System::SharedPtr< Task > &item) override
This is the stub implementation of ICollection's Remove method, that only throws NotSupportedExceptio...
Represents a task in a project.
Definition: Task.h:383
Removes the specified task from a tree of tasks.
Definition: RemoveTask.h:31
Helper class which provides useful operations with tasks.
Definition: TaskUtils.h:40
Definition: Asn.h:13