Aspose.Tasks for C++
ListUtils.h
1 #pragma once
2 //-----------------------------------------------------------------------
3 // <copyright file="ListUtils.cs" company="Aspose Pty Ltd">
4 // Copyright (c) 2002-2024 Aspose Pty Ltd. All Rights Reserved.
5 // </copyright>
6 //-----------------------------------------------------------------------
7 
8 #include <system/enumerator_adapter.h>
9 #include <system/default.h>
10 #include <system/collections/list.h>
11 #include <system/collections/ilist.h>
12 #include <system/collections/ienumerable.h>
13 #include <system/collections/icomparer.h>
14 #include <system/collections/icollection.h>
15 #include <system/array.h>
16 
17 #include "aspose.tasks.cpp/Util/ICondition.h"
18 #include "aspose.tasks.cpp/Util/IAlgorithm.h"
19 #include "aspose.tasks.cpp/aspose_tasks_api_defs.h"
20 
21 namespace Aspose
22 {
23 namespace LicenseV2
24 {
25 class LicenseCore;
26 } // namespace LicenseV2
27 namespace Tasks
28 {
29 class GroupCollection;
30 namespace IO
31 {
32 namespace MSProject
33 {
34 namespace Decryptor
35 {
36 class AgilePasswordVerifier;
37 class MPP14StreamEncryptorDecryptorBase;
38 } // namespace Decryptor
39 class FixedWriter;
40 namespace Metadata
41 {
42 class FixedDataOffsets;
43 class VarDataOffsets;
44 } // namespace Metadata
45 class Mpp12CalendarWriter;
46 class MPP12TaskReader;
47 class MPP14TaskReader;
48 class Mpp9CalendarWriter;
49 class MPP9ExtendedAttributeDefinitionWriter;
50 class MPP9OutlineCodeDefinitionWriter;
51 class MPPExtendedAttributeWriter;
52 class MppGroupWriter;
53 class MPPOutlineCodeDefinitionWriter;
54 class MppPdfOleObjectWriter;
55 class MppTimephasedDataWriter;
56 class VarVarWriter;
57 } // namespace MSProject
58 namespace PrimaveraXml
59 {
60 class PrimaveraReader;
61 } // namespace PrimaveraXml
62 } // namespace IO
63 class OptimizedForSearchingTimephasedDataCollection;
64 class PluginLicensesHelper;
65 namespace Saving
66 {
67 class MpxSavingUtils;
68 class TemplateProjectLoader;
69 } // namespace Saving
70 namespace Util
71 {
72 class ByteSpan;
73 } // namespace Util
74 } // namespace Tasks
75 } // namespace Aspose
76 
77 namespace Aspose {
78 
79 namespace Tasks {
80 
81 namespace Util {
82 
83 /// <summary>
84 /// Utility class for list processing.
85 /// </summary>
86 class ASPOSE_TASKS_SHARED_CLASS ListUtils
87 {
88  typedef ListUtils ThisType;
89 
90  friend class Aspose::Tasks::IO::MSProject::Metadata::VarDataOffsets;
91  friend class Aspose::Tasks::IO::MSProject::Decryptor::MPP14StreamEncryptorDecryptorBase;
92  friend class Aspose::Tasks::IO::MSProject::Metadata::FixedDataOffsets;
93  friend class Aspose::Tasks::IO::MSProject::MppPdfOleObjectWriter;
94  friend class Aspose::Tasks::IO::MSProject::MppGroupWriter;
95  friend class Aspose::Tasks::IO::PrimaveraXml::PrimaveraReader;
96  friend class Aspose::Tasks::PluginLicensesHelper;
97  friend class Aspose::Tasks::Saving::TemplateProjectLoader;
98  friend class Aspose::Tasks::GroupCollection;
99  friend class Aspose::Tasks::IO::MSProject::Decryptor::AgilePasswordVerifier;
100  friend class Aspose::Tasks::IO::MSProject::MPP12TaskReader;
101  friend class Aspose::Tasks::IO::MSProject::MPP14TaskReader;
102  friend class Aspose::Tasks::IO::MSProject::FixedWriter;
103  friend class Aspose::Tasks::IO::MSProject::Mpp12CalendarWriter;
104  friend class Aspose::Tasks::IO::MSProject::MPPExtendedAttributeWriter;
105  friend class Aspose::Tasks::IO::MSProject::MPPOutlineCodeDefinitionWriter;
106  friend class Aspose::Tasks::IO::MSProject::Mpp9CalendarWriter;
107  friend class Aspose::Tasks::IO::MSProject::MPP9ExtendedAttributeDefinitionWriter;
108  friend class Aspose::Tasks::IO::MSProject::MPP9OutlineCodeDefinitionWriter;
109  friend class Aspose::Tasks::IO::MSProject::MppTimephasedDataWriter;
110  friend class Aspose::Tasks::IO::MSProject::VarVarWriter;
111  friend class Aspose::Tasks::OptimizedForSearchingTimephasedDataCollection;
112  friend class Aspose::Tasks::Saving::MpxSavingUtils;
113  friend class Aspose::LicenseV2::LicenseCore;
114 
115 public:
116 
117  /// <summary>
118  /// Apply algorithm for each list element starting from specified position.
119  /// </summary>
120  /// <param name="list">List to process.</param>
121  /// <param name="algorithm">Applied algorithm.</param>
122  /// <param name="startIndex">Start element position.</param>
123  /// <typeparam name="T">The type of object to apply algorithm to.</typeparam>
124  template <typename T>
125  static void Apply(const System::SharedPtr<System::Collections::Generic::IList<T>>& list, const System::SharedPtr<IAlgorithm<T>>& algorithm, int32_t startIndex)
126  {
127  for (int32_t i = startIndex; i < list->get_Count(); i++)
128  {
129  T el = list->idx_get(i);
130  algorithm->PreAlg(el, i);
131  algorithm->Alg(el, i);
132  algorithm->PostAlg(el, i);
133  }
134  }
135 
136  /// <summary>
137  /// Filter list elements by specified condition.
138  /// </summary>
139  /// <param name="list">A list to process.</param>
140  /// <param name="cond">Condition used to filter the specified list.</param>
141  /// <typeparam name="T">The type of object to apply filter to.</typeparam>
142  /// <returns>Filtered list.</returns>
143  template <typename T>
144  static System::SharedPtr<System::Collections::Generic::IList<T>> Filter(const System::SharedPtr<System::Collections::Generic::IList<T>>& list, const System::SharedPtr<ICondition<T>>& cond)
145  {
146  System::SharedPtr<System::Collections::Generic::IList<T>> result = System::MakeObject<System::Collections::Generic::List<T>>();
147  for (int32_t i = 0; i < list->get_Count(); i++)
148  {
149  if (cond->Check(list->idx_get(i)))
150  {
151  result->Add(list->idx_get(i));
152  }
153  }
154 
155  return result;
156  }
157 
158  /// <summary>
159  /// Find first occurrence of an list element which satisfy specified condition.
160  /// </summary>
161  /// <param name="list">A list to process.</param>
162  /// <param name="cond">Condition used to find an element in the specified list.</param>
163  /// <typeparam name="T">The type of object to find.</typeparam>
164  /// <returns>List element or null.</returns>
165  template <typename T>
166  static T Find(const System::SharedPtr<System::Collections::Generic::IList<T>>& list, const System::SharedPtr<ICondition<T>>& cond)
167  {
168  for (int32_t i = 0; i < list->get_Count(); i++)
169  {
170  if (cond->Check(list->idx_get(i)))
171  {
172  return list->idx_get(i);
173  }
174  }
175 
176  return System::Default<T>();
177  }
178 
179 
180 protected:
181 
182  static ASPOSE_TASKS_SHARED_API void Resize(System::ArrayPtr<uint8_t>& array, int32_t newSize);
183  static ASPOSE_TASKS_SHARED_API System::ArrayPtr<uint8_t> Concat(const System::ArrayPtr<uint8_t>& arr1, const System::ArrayPtr<uint8_t>& arr2);
184  static ASPOSE_TASKS_SHARED_API bool Equal(const System::ArrayPtr<uint8_t>& arr1, const System::ArrayPtr<uint8_t>& arr2);
185  static ASPOSE_TASKS_SHARED_API bool IsBlank(const System::ArrayPtr<uint8_t>& arr);
186  static ASPOSE_TASKS_SHARED_API bool IsBlank(ByteSpan span);
187  template <typename T>
188  static System::SharedPtr<System::Collections::Generic::List<T>> ToList(const System::SharedPtr<System::Collections::Generic::IEnumerable<T>>& sequence)
189  {
190  System::SharedPtr<System::Collections::Generic::List<T>> result = System::MakeObject<System::Collections::Generic::List<T>>();
191  for (auto&& element : System::IterateOver(sequence))
192  {
193  result->Add(element);
194  }
195 
196  return result;
197  }
198 
199  template <typename T>
200  static int32_t BinarySearch(const System::SharedPtr<System::Collections::Generic::IList<T>>& array, int32_t index, int32_t length, T value, const System::SharedPtr<System::Collections::Generic::IComparer<T>>& comparer)
201  {
202  int32_t num = index;
203  int32_t num2 = index + length - 1;
204  while (num <= num2)
205  {
206  int32_t num3 = num + ((num2 - num) >> 1);
207  int32_t num4 = comparer->Compare(array->idx_get(num3), value);
208  if (num4 == 0)
209  {
210  return num3;
211  }
212 
213  if (num4 < 0)
214  {
215  num = num3 + 1;
216  }
217  else
218  {
219  num2 = num3 - 1;
220  }
221  }
222 
223  return ~num;
224  }
225 
226  template <typename T>
227  static void CopyElements(const System::SharedPtr<System::Collections::Generic::ICollection<T>>& source, const System::SharedPtr<System::Collections::Generic::ICollection<T>>& target)
228  {
229  for (auto&& element : System::IterateOver(source))
230  {
231  target->Add(element);
232  }
233  }
234 
235 
236 public:
237  ListUtils() = delete;
238 };
239 
240 } // namespace Util
241 } // namespace Tasks
242 } // namespace Aspose
243 
244 
static T Find(const System::SharedPtr< System::Collections::Generic::IList< T >> &list, const System::SharedPtr< ICondition< T >> &cond)
Find first occurrence of an list element which satisfy specified condition.
Definition: ListUtils.h:166
static void Apply(const System::SharedPtr< System::Collections::Generic::IList< T >> &list, const System::SharedPtr< IAlgorithm< T >> &algorithm, int32_t startIndex)
Apply algorithm for each list element starting from specified position.
Definition: ListUtils.h:125
Utility class for list processing.
Definition: ListUtils.h:86
static System::SharedPtr< System::Collections::Generic::IList< T > > Filter(const System::SharedPtr< System::Collections::Generic::IList< T >> &list, const System::SharedPtr< ICondition< T >> &cond)
Filter list elements by specified condition.
Definition: ListUtils.h:144
Contains a list of Group objects. Implements ICollection<Group> interface.
Definition: GroupCollection.h:56
Represents an algorithm that can be applied to a list of objects T .
Definition: IAlgorithm.h:22