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