Aspose.Tasks for C++
WorkingTimeCollection.h
1 #pragma once
2 //-----------------------------------------------------------------------
3 // <copyright file="WorkingTimeCollection.cs" company="Aspose Pty Ltd">
4 // Copyright (c) 2002-2024 Aspose Pty Ltd. All Rights Reserved.
5 // </copyright>
6 //-----------------------------------------------------------------------
7 
8 #include <system/timespan.h>
9 #include <system/eventhandler.h>
10 #include <system/collections/list.h>
11 #include <system/collections/ilist.h>
12 #include <system/array.h>
13 
14 #include "aspose.tasks.cpp/IReadOnlyWorkingTimeCollection.h"
15 #include "aspose.tasks.cpp/aspose_tasks_api_defs.h"
16 
17 namespace Aspose
18 {
19 namespace Tasks
20 {
21 class Calendar;
22 class CalendarDatesCalculator;
23 class CalendarException;
24 class CalendarWorkingTimesBackwardsEnumerator;
25 class CalendarWorkingTimesForwardEnumerator;
26 namespace IO
27 {
28 namespace Html
29 {
30 class HtmlCalendarExceptionsReader;
31 class HtmlCalendarTableReader;
32 } // namespace Html
33 namespace MSProject
34 {
35 class MPPTimephasedDataReader;
36 } // namespace MSProject
37 namespace Xml
38 {
39 class WeekDayNodeWriter;
40 } // namespace Xml
41 } // namespace IO
42 namespace Recalculation
43 {
44 class TimephasedDataCalculationUtil;
45 } // namespace Recalculation
46 class TimeScaledExceptions;
47 class WeekDay;
48 class WorkingTime;
49 } // namespace Tasks
50 } // namespace Aspose
51 namespace System
52 {
53 namespace Collections
54 {
55 namespace Generic
56 {
57 template <typename> class IEnumerable;
58 template <typename> class IEnumerator;
59 } // namespace Generic
60 } // namespace Collections
61 class DateTime;
62 namespace Text
63 {
64 class StringBuilder;
65 } // namespace Text
66 } // namespace System
67 
68 namespace Aspose {
69 
70 namespace Tasks {
71 
72 /// <summary>
73 /// Represents a collection of <see cref="WorkingTimeCollection"></see> objects.
74 /// </summary>
75 class ASPOSE_TASKS_SHARED_CLASS WorkingTimeCollection : public System::Collections::Generic::IList<System::SharedPtr<Aspose::Tasks::WorkingTime>>, public Aspose::Tasks::IReadOnlyWorkingTimeCollection
76 {
77  typedef WorkingTimeCollection ThisType;
78  typedef System::Collections::Generic::IList<System::SharedPtr<Aspose::Tasks::WorkingTime>> BaseType;
79  typedef Aspose::Tasks::IReadOnlyWorkingTimeCollection BaseType1;
80 
81  typedef ::System::BaseTypesInfo<BaseType, BaseType1> ThisTypeBaseTypesInfo;
82  ASPOSE_TASKS_SHARED_RTTI_INFO_DECL();
83 
84  friend class Aspose::Tasks::Calendar;
86  friend class Aspose::Tasks::CalendarWorkingTimesForwardEnumerator;
87  friend class Aspose::Tasks::Recalculation::TimephasedDataCalculationUtil;
88  friend class Aspose::Tasks::IO::Html::HtmlCalendarExceptionsReader;
89  friend class Aspose::Tasks::IO::Html::HtmlCalendarTableReader;
90  friend class Aspose::Tasks::IO::MSProject::MPPTimephasedDataReader;
91  friend class Aspose::Tasks::IO::Xml::WeekDayNodeWriter;
92  friend class Aspose::Tasks::CalendarDatesCalculator;
93  friend class Aspose::Tasks::CalendarWorkingTimesBackwardsEnumerator;
94  friend class Aspose::Tasks::TimeScaledExceptions;
95  friend class Aspose::Tasks::WeekDay;
96 
97 public:
98  /// A collection type whose iterator types is used as iterator types in the current collection.
99  using iterator_holder_type = System::Collections::Generic::List<System::SharedPtr<WorkingTime>>;
100  /// Iterator type.
101  using iterator = typename iterator_holder_type::iterator;
102  /// Const iterator type.
103  using const_iterator = typename iterator_holder_type::const_iterator;
104  /// Virtualized element type.
105  using virtualized_iterator_element = typename iterator_holder_type::virtualized_iterator_element;
106  /// Virtualized type.
107  using virtualized_iterator = typename iterator_holder_type::virtualized_iterator;
108 
109 public:
110 
111  /// <summary>
112  /// Gets the number of objects contained in this <see cref="WorkingTimeCollection"></see> object.
113  /// </summary>
114  ASPOSE_TASKS_SHARED_API int32_t get_Count() const override;
115 
116  /// <summary>
117  /// Returns the element at the specified index.
118  /// </summary>
119  /// <param name="index">The zero-based index of the element to get.</param>
120  /// <returns>the element at the specified index.</returns>
121  ASPOSE_TASKS_SHARED_API System::SharedPtr<WorkingTime> idx_get(int32_t index) const override;
122  /// <summary>
123  /// Returns the element at the specified index.
124  /// </summary>
125  /// <param name="index">The zero-based index of the element to get.</param>
126  /// <param name="value">the element at the specified index.</param>
127  ASPOSE_TASKS_SHARED_API void idx_set(int32_t index, System::SharedPtr<WorkingTime> value) override;
128 
129  /// <summary>
130  /// Returns an enumerator for this collection.
131  /// </summary>
132  /// <returns>an enumerator for this collection.</returns>
133  ASPOSE_TASKS_SHARED_API System::SharedPtr<System::Collections::Generic::IEnumerator<System::SharedPtr<WorkingTime>>> GetEnumerator() override;
134  /// <summary>
135  /// Removes <see cref="WorkingTime"></see> instance from this collection.
136  /// </summary>
137  /// <param name="item">The item to remove.</param>
138  /// <returns>true if WorkingTime instance was successfully removed from this collection; otherwise, false.</returns>
139  ASPOSE_TASKS_SHARED_API bool Remove(const System::SharedPtr<WorkingTime>& item) override;
140  /// <summary>
141  /// Converts the WorkingTimeCollection object to a list of <see cref="WorkingTime"></see> objects.
142  /// </summary>
143  /// <returns>List of <see cref="WorkingTime"></see> objects.</returns>
144  ASPOSE_TASKS_SHARED_API System::SharedPtr<System::Collections::Generic::List<System::SharedPtr<WorkingTime>>> ToList();
145  ASPOSE_TASKS_SHARED_API void Add(const System::SharedPtr<WorkingTime>& item) override;
146  /// <summary>
147  /// Checks if the specified element is in the List.
148  /// Performs a linear O(n) search.
149  /// </summary>
150  /// <param name="item">the specified item.</param>
151  /// <returns>True, if specified element found in the list, false otherwise.</returns>
152  ASPOSE_TASKS_SHARED_API bool Contains(const System::SharedPtr<WorkingTime>& item) const override;
153  /// <summary>
154  /// copies a collection content into an Array, starting at a particular index
155  /// </summary>
156  /// <param name="array">an array to copy to.</param>
157  /// <param name="arrayIndex">starting array index</param>
158  ASPOSE_TASKS_SHARED_API void CopyTo(System::ArrayPtr<System::SharedPtr<WorkingTime>> array, int32_t arrayIndex) override;
159  /// <summary>
160  /// Removes all <see cref="WorkingTime"></see> items from collection.
161  /// </summary>
162  ASPOSE_TASKS_SHARED_API void Clear() override;
163  /// Gets iterator pointing to the first element (if any) of the collection.
164  /// @return An iterator pointing to the first element (if any) of the collection
165  ASPOSE_TASKS_SHARED_API iterator begin() noexcept;
166  /// Gets iterator pointing right after the last element (if any) of the collection.
167  /// @return An iterator pointing right after the last element (if any) of the collection
168  ASPOSE_TASKS_SHARED_API iterator end() noexcept;
169  /// Gets iterator pointing to the first element (if any) of the const-qualified instance of the collection.
170  /// @return An iterator pointing to the first element (if any) of the const-qualified instance of the collection
171  ASPOSE_TASKS_SHARED_API const_iterator begin() const noexcept;
172  /// Gets iterator pointing right after the last element (if any) of the const-qualified instance of the collection.
173  /// @return An iterator pointing right after the last element (if any) of the const-qualified instance of the collection
174  ASPOSE_TASKS_SHARED_API const_iterator end() const noexcept;
175  /// Gets iterator pointing to the first const-qualified element (if any) of the collection.
176  /// @return An iterator pointing to the first const-qualified element (if any) of the collection
177  ASPOSE_TASKS_SHARED_API const_iterator cbegin() const noexcept;
178  /// Gets iterator pointing right after the last const-qualified element (if any) of the collection.
179  /// @return An iterator pointing right after the last const-qualified element (if any) of the collection
180  ASPOSE_TASKS_SHARED_API const_iterator cend() const noexcept;
181  /// Gets iterator pointing to the first element (if any) of the collection.
182  /// @return An iterator pointing to the first element (if any) of the collection
183  /// Provides iterator implementation to container's first element.
184  /// @return Newly-created iterator object.
185  ASPOSE_TASKS_SHARED_API virtualized_iterator* virtualizeBeginIterator() override;
186  /// Gets iterator pointing right after the last element (if any) of the collection.
187  /// @return An iterator pointing right after the last element (if any) of the collection
188  /// Provides iterator implementation to container's end.
189  /// @return Newly-created iterator object.
190  ASPOSE_TASKS_SHARED_API virtualized_iterator* virtualizeEndIterator() override;
191  /// Gets iterator pointing to the first element (if any)of the const-qualified instance of the collection.
192  /// @return An iterator pointing to the first element (if any)of the const-qualified instance of the collection
193  /// Provides const iterator implementation to container's first element.
194  /// @return Newly-created iterator object.
195  ASPOSE_TASKS_SHARED_API virtualized_iterator* virtualizeBeginConstIterator() const override;
196  /// Gets iterator pointing right after the last element (if any)of the const-qualified instance of the collection.
197  /// @return An iterator pointing right after the last element (if any)of the const-qualified instance of the collection
198  /// Provides const iterator implementation to container's end.
199  /// @return Newly-created iterator object.
200  ASPOSE_TASKS_SHARED_API virtualized_iterator* virtualizeEndConstIterator() const override;
201 
202 protected:
203 
204  static ASPOSE_TASKS_SHARED_API System::SharedPtr<WorkingTimeCollection> get_Empty();
205  ASPOSE_TASKS_SHARED_API System::SharedPtr<WorkingTime> get_First();
206  ASPOSE_TASKS_SHARED_API System::SharedPtr<WorkingTime> get_Last();
207  ASPOSE_TASKS_SHARED_API System::TimeSpan get_TotalFrom();
208  ASPOSE_TASKS_SHARED_API System::TimeSpan get_TotalTo();
209  ASPOSE_TASKS_SHARED_API System::TimeSpan get_TotalSpan();
210  ASPOSE_TASKS_SHARED_API System::String get_DebuggerDisplay();
211 
212  System::EventHandler<> CollectionChanged;
213 
214  ASPOSE_TASKS_SHARED_API WorkingTimeCollection();
215 
216  ASPOSE_TASKS_SHARED_API MEMBER_FUNCTION_MAKE_OBJECT_DECLARATION(WorkingTimeCollection, CODEPORTING_ARGS());
217 
218  ASPOSE_TASKS_SHARED_API WorkingTimeCollection(const System::SharedPtr<System::Collections::Generic::IEnumerable<System::SharedPtr<WorkingTime>>>& workingTimes);
219 
220  ASPOSE_TASKS_SHARED_API MEMBER_FUNCTION_MAKE_OBJECT_DECLARATION(WorkingTimeCollection, CODEPORTING_ARGS(const System::SharedPtr<System::Collections::Generic::IEnumerable<System::SharedPtr<WorkingTime>>>& workingTimes));
221  ASPOSE_TASKS_SHARED_API void Sort();
222  ASPOSE_TASKS_SHARED_API void UpdateWorkingTimes(const System::SharedPtr<System::Collections::Generic::IList<System::SharedPtr<WorkingTime>>>& times);
223  ASPOSE_TASKS_SHARED_API System::TimeSpan GetIntersectSpan(const System::SharedPtr<WorkingTime>& wt);
224  ASPOSE_TASKS_SHARED_API System::DateTime GetDayStart(System::DateTime date, System::TimeSpan nonWorkingDayStart);
225  ASPOSE_TASKS_SHARED_API System::TimeSpan GetWorkingHours();
226  ASPOSE_TASKS_SHARED_API System::TimeSpan GetDifferenceFromWorkStart(System::DateTime start);
227  ASPOSE_TASKS_SHARED_API System::SharedPtr<System::Text::StringBuilder> Dump(const System::SharedPtr<System::Text::StringBuilder>& sb);
228 
229  virtual ASPOSE_TASKS_SHARED_API ~WorkingTimeCollection();
230 
231  #ifdef ASPOSE_GET_SHARED_MEMBERS
232  ASPOSE_TASKS_SHARED_API void GetSharedMembers(System::Object::shared_members_type& result) const override;
233  #endif
234 
235 
236 private:
237 
238  static System::SharedPtr<WorkingTimeCollection>& EmptyInstance();
239 
240  System::SharedPtr<System::Collections::Generic::List<System::SharedPtr<WorkingTime>>> workingTimes;
241 
242  bool get_IsReadOnly() const override;
243 
244  bool valid;
245  bool sorted;
246  System::TimeSpan totalFrom;
247  System::TimeSpan totalTo;
248  System::TimeSpan totalSpan;
249 
250  /// <summary>
251  /// Returns the index of the first occurrence of a given item in a list
252  /// </summary>
253  /// <param name="item">value to search for.</param>
254  /// <returns>the index of the item</returns>
255  int32_t IndexOf(const System::SharedPtr<WorkingTime>& item) const override;
256  /// <summary>
257  /// Inserts an element into this list at a given index
258  /// </summary>
259  /// <param name="index">an index to insert to</param>
260  /// <param name="item">an element to insert</param>
261  void Insert(int32_t index, const System::SharedPtr<WorkingTime>& item) override;
262  /// <summary>
263  /// Removes an element at specified index.
264  /// </summary>
265  /// <param name="index">an index of item to remove.</param>
266  void RemoveAt(int32_t index) override;
267  bool AddInternal(const System::SharedPtr<WorkingTime>& item);
268  bool InvalidateSpans();
269  void Changed();
270 
271 };
272 
273 } // namespace Tasks
274 } // namespace Aspose
275 
276 
Represent exceptional time periods in a calendar.
Definition: CalendarException.h:73
Represents a calendar used in a project.
Definition: Calendar.h:287
Represents a weekday which either defines regular days of a week or exception days in a calendar.
Definition: WeekDay.h:62
Represents a collection of WorkingTimeCollection objects.
Definition: WorkingTimeCollection.h:76
bool Contains(const System::SharedPtr< WorkingTime > &item) const override
Checks if the specified element is in the List. Performs a linear O(n) search.
System::Collections::Generic::List< System::SharedPtr< WorkingTime > > iterator_holder_type
A collection type whose iterator types is used as iterator types in the current collection.
Definition: WorkingTimeCollection.h:99
typename iterator_holder_type::virtualized_iterator_element virtualized_iterator_element
Virtualized element type.
Definition: WorkingTimeCollection.h:105
void CopyTo(System::ArrayPtr< System::SharedPtr< WorkingTime >> array, int32_t arrayIndex) override
copies a collection content into an Array, starting at a particular index
int32_t get_Count() const override
Gets the number of objects contained in this WorkingTimeCollection object.
void idx_set(int32_t index, System::SharedPtr< WorkingTime > value) override
Returns the element at the specified index.
bool Remove(const System::SharedPtr< WorkingTime > &item) override
Removes WorkingTime instance from this collection.
System::SharedPtr< System::Collections::Generic::List< System::SharedPtr< WorkingTime > > > ToList()
Converts the WorkingTimeCollection object to a list of WorkingTime objects.
typename iterator_holder_type::const_iterator const_iterator
Const iterator type.
Definition: WorkingTimeCollection.h:103
void Clear() override
Removes all WorkingTime items from collection.
typename iterator_holder_type::virtualized_iterator virtualized_iterator
Virtualized type.
Definition: WorkingTimeCollection.h:107
System::SharedPtr< System::Collections::Generic::IEnumerator< System::SharedPtr< WorkingTime > > > GetEnumerator() override
Returns an enumerator for this collection.
typename iterator_holder_type::iterator iterator
Iterator type.
Definition: WorkingTimeCollection.h:101
System::SharedPtr< WorkingTime > idx_get(int32_t index) const override
Returns the element at the specified index.
Represents a working time during a weekday.
Definition: WorkingTime.h:44
Definition: Asn.h:13