CodePorting.Translator Cs2Cpp
CodePorting.Translator.Cs2Cpp.Framework
ienumerable.h
1
2#pragma once
3
4#include <iterator>
5#include <memory>
6
7#include <system/collections/ienumerator.h>
8#include <system/collections/virtualized_iterator.h>
9#include <system/func.h>
10#include <system/linq/igrouping.h>
11
12namespace System { namespace Linq {
13template <typename T> class IOrderedEnumerable;
14}}
15
16namespace System { namespace Collections { namespace Generic {
17
18template<typename T> class ASPOSECPP_SHARED_CLASS List;
19template<typename T> class EnumerableExt;
20template<typename T> class IEqualityComparer;
21
24template<typename T>
25class ASPOSECPP_SHARED_CLASS IEnumerable: virtual public Object
26{
28 RTTI_INFO_TEMPLATE_CLASS(System::Collections::Generic::IEnumerable<T>, System::BaseTypesInfo<System::Object>);
29
30public:
33
34 using ValueType = T;
35
36 // There no need to define an empty virtual dtor, virtual dtor for inheritance already defined in the Object class
40
41 // Implementation of some of LINQ extension methods as usual class methods
42 // header <system/linq/enumerable.h> should be included in order to use
43
47 T LINQ_Aggregate(const Func<T, T, T>& func);
48
52 T LINQ_ElementAt(int index);
53
57 T LINQ_ElementAtOrDefault(int index);
58
62 T LINQ_First();
63
68 T LINQ_First(const Func<T, bool>& predicate);
69
72 T LINQ_FirstOrDefault();
73
79 T LINQ_FirstOrDefault(std::function<bool(T)> predicate);
80
84 T LINQ_Last();
85
88 T LINQ_LastOrDefault();
89
93 T LINQ_Single();
94
100 T LINQ_Single(const Func<T, bool>& predicate);
101
104 T LINQ_SingleOrDefault();
105
110 T LINQ_SingleOrDefault(const Func<T, bool>& predicate);
111
114 SharedPtr<List<T>> LINQ_ToList();
115
118 int LINQ_Count();
119
123 int LINQ_Count(const Func<T, bool>& predicate);
124
129 SharedPtr<IEnumerable<T>> LINQ_Distinct();
130
133 System::ArrayPtr<T> LINQ_ToArray();
134
139 bool LINQ_All(std::function<bool(T)> predicate);
140
143 bool LINQ_Any();
144
148 bool LINQ_Any(std::function<bool(T)> predicate);
149
153 SharedPtr<IEnumerable<T>> LINQ_Where(std::function<bool(T)> predicate);
154
158 bool LINQ_Contains(T value);
159
164 template <typename ResultType>
166
170 template <typename Key>
172
176 template <typename Key>
178
182 template <typename ResultType>
184
189 template <typename ResultType>
191
196 template <typename ResultType>
198
203 bool LINQ_SequenceEqual(SharedPtr<IEnumerable<T>> second, const SharedPtr<IEqualityComparer<T>>& comparer);
204
208 bool LINQ_SequenceEqual(SharedPtr<IEnumerable<T>> second);
209
213 SharedPtr<IEnumerable<T>> LINQ_Concat(SharedPtr<IEnumerable<T>> sequence);
214
217 SharedPtr<IEnumerable<T>> LINQ_Reverse();
218
223 template <typename Key>
226
233 template <typename Key, typename Element>
236
241 template <typename ResultType>
243
248 SharedPtr<IEnumerable<T>> LINQ_Skip(int32_t count);
249
253 SharedPtr<IEnumerable<T>> LINQ_Take(int32_t count);
254
257 T LINQ_Min();
258
263 template <typename ResultType>
264 ResultType LINQ_Min(const Func<T, ResultType>& selector);
265
268 T LINQ_Max();
269
274 template <typename ResultType>
275 ResultType LINQ_Max(const Func<T, ResultType>& selector);
276
277
281 T LINQ_Average();
282
289 template <typename ResultType>
290 ResultType LINQ_Average(const Func<T, ResultType>& selector);
291
294 T LINQ_Sum();
295
303 template <typename TSecond, typename TResult>
305 const Func<T, TSecond, TResult>& resultSelector);
306
308 using iterator = System::Details::VirtualizedIterator<T>;
310 using const_iterator = System::Details::VirtualizedConstIterator<T>;
311
317 {
318 return iterator(virtualizeBeginIterator());
319 }
325 {
326 return iterator(virtualizeEndIterator());
327 }
328
332 {
333 return const_iterator(virtualizeBeginConstIterator());
334 }
339 {
340 return const_iterator(virtualizeEndConstIterator());
341 }
342
346 {
347 return const_iterator(virtualizeBeginConstIterator());
348 }
352 {
353 return const_iterator(virtualizeEndConstIterator());
354 }
355
357 using virtualized_iterator = System::Details::VirtualizedIteratorBase<T>;
360
364 {
365 return GetEnumeratorAsVirtualizedIterator();
366 }
370 {
371 return new System::Details::EnumeratorBasedEndIterator<T>();
372 }
376 {
377 return GetEnumeratorAsVirtualizedIterator();
378 }
382 {
383 return new System::Details::EnumeratorBasedEndIterator<T>();
384 }
385
386protected:
388 ~IEnumerable() override {}
389
393 {
395 {
396 auto enumerator = GetEnumerator();
397 if (enumerator->SharedCount() != 1)
398 {
399 enumerator->InitializeIterator();
400 return new EnumeratorWrapperIterator<T>(enumerator);
401 }
402 iterator = enumerator->AsVirtualizedIterator();
403 }
404 iterator->MarkOwnedByVirtualizedIterator();
405 return iterator;
406 }
410 {
411 return const_cast<IEnumerable<T>*>(this)->GetEnumeratorAsVirtualizedIterator();
412 }
413};
414
415}}} // namespace System::Collections::Generic
Iterator that wraps the pre-created enumerator and redirects all calls into it.
Definition: ienumerator.h:164
Interface of object providing enumerator on contained elements.
Definition: ienumerable.h:26
iterator end()
Gets iterator pointing right after the last element (if any) of the collection. This iterator can't b...
Definition: ienumerable.h:324
SharedPtr< IEnumerable< ResultType > > LINQ_Select(const Func< T, ResultType > &selector)
Transforms elements of a sequence.
System::SharedPtr< IEnumerable< System::SharedPtr< System::Linq::IGrouping< Key, Element > > > > LINQ_GroupBy(System::Func< T, Key > keyPredicate, System::Func< T, Element > elementSelector)
Groups the elements of a sequence.
virtualized_iterator * GetEnumeratorAsVirtualizedIterator() const
Gets enumerator instance and prepares it to be used as iterator kernel.
Definition: ienumerable.h:409
T virtualized_iterator_element
Inner iterator element type.
Definition: ienumerable.h:359
SharedPtr< IEnumerable< TResult > > LINQ_Zip(SharedPtr< IEnumerable< TSecond > > second, const Func< T, TSecond, TResult > &resultSelector)
Applies a specified function to the corresponding elements of two sequences, producing a sequence of ...
virtual virtualized_iterator * virtualizeBeginConstIterator() const
Gets the implementation of begin const iterator for the current container.
Definition: ienumerable.h:375
ResultType LINQ_Min(const Func< T, ResultType > &selector)
Invokes a transform function on each element of a generic sequence and returns the minimum resulting ...
System::Details::VirtualizedConstIterator< T > const_iterator
Const iterator type.
Definition: ienumerable.h:310
SharedPtr< IEnumerable< ResultType > > LINQ_Select(const Func< T, int32_t, ResultType > &selector)
Transforms each element of a sequence into a new form by incorporating the element's index.
IEnumerator< T > IEnumeratorType
Enumerator type.
Definition: ienumerable.h:32
System::Details::VirtualizedIteratorBase< T > virtualized_iterator
Inner iterator base type.
Definition: ienumerable.h:357
const_iterator cend() const
Gets iterator pointing right after the last const-qualified element (if any) of the collection.
Definition: ienumerable.h:351
const_iterator begin() const
Gets iterator pointing to the first element (if any) of the const-qualified instance of the collectio...
Definition: ienumerable.h:331
virtual virtualized_iterator * virtualizeBeginIterator()
Gets the implementation of begin iterator for the current container.
Definition: ienumerable.h:363
const_iterator end() const
Gets iterator pointing right after the last element (if any) of the const-qualified instance of the c...
Definition: ienumerable.h:338
SharedPtr< IEnumerable< ResultType > > LINQ_OfType()
Filters the elements of the sequence based on the specified type.
~IEnumerable() override
Destructor.
Definition: ienumerable.h:388
System::Details::VirtualizedIterator< T > iterator
Iterator type.
Definition: ienumerable.h:308
SharedPtr< Linq::IOrderedEnumerable< T > > LINQ_OrderBy(const Func< T, Key > &keySelector)
Sorts the elements of a sequence in ascending order according to the key values selected by keySelect...
SharedPtr< IEnumerable< ResultType > > LINQ_Cast()
Casts the elements to the specified type.
virtual virtualized_iterator * virtualizeEndIterator()
Gets the implementation of end iterator for the current container.
Definition: ienumerable.h:369
iterator begin()
Gets iterator pointing to the first element (if any) of the collection. This iterator can't be used t...
Definition: ienumerable.h:316
SharedPtr< IEnumerable< ResultType > > LINQ_SelectMany(const Func< T, SharedPtr< IEnumerable< ResultType > > > &selector)
Projects each element of a sequence and combines the resulting sequences into one sequence.
ResultType LINQ_Max(const Func< T, ResultType > &selector)
Invokes a transform function on each element of a generic sequence and returns the maximum resulting ...
virtual virtualized_iterator * virtualizeEndConstIterator() const
Gets the implementation of end const iterator for the current container.
Definition: ienumerable.h:381
const_iterator cbegin() const
Gets iterator pointing to the first const-qualified element (if any) of the collection.
Definition: ienumerable.h:345
virtual SharedPtr< IEnumerator< T > > GetEnumerator()=0
Gets enumerator.
SharedPtr< Linq::IOrderedEnumerable< T > > LINQ_OrderByDescending(const Func< T, Key > &keySelector)
Sorts the elements of a sequence in descending order according to the key values selected by keySelec...
virtualized_iterator * GetEnumeratorAsVirtualizedIterator()
Gets enumerator instance and prepares it to be used as iterator kernel.
Definition: ienumerable.h:392
System::SharedPtr< IEnumerable< System::SharedPtr< System::Linq::IGrouping< Key, T > > > > LINQ_GroupBy(System::Func< T, Key > keyPredicate)
Groups the elements of a sequence.
ResultType LINQ_Average(const Func< T, ResultType > &selector)
Computes the average of a sequence of values that are obtained by invoking a transform function on ea...
T ValueType
Definition: ienumerable.h:34
Interface of enumerator which can be used to iterate through some elements. Objects of this class sho...
Definition: ienumerator.h:63
Interface providing means to compare two objects for equality. Objects of this class should only be a...
Definition: iequality_comparer.h:18
List forward declaration.
Definition: list.h:129
Function delegate. This type should be allocated on stack and passed to functions by value or by refe...
Definition: func.h:82
Represents a sorted sequence.
Definition: iordered_enumerable.h:15
Base class that enables using methods available for System.Object class in C#. All non-trivial classe...
Definition: object.h:51
Pointer class to wrap types being allocated on heap. Use it to manage memory for classes inheriting O...
Definition: smart_ptr.h:180
Definition: db_command.h:9