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