xtd 0.2.0
Loading...
Searching...
No Matches
__enumerable_collection.hpp
Go to the documentation of this file.
1
4#pragma once
6#if !defined(__XTD_CORE_INTERNAL__)
7#error "Do not include this file: Internal use only"
8#endif
10
13#include "../istringable.hpp"
14
16namespace xtd::linq {
17 class enumerable;
18};
19
20template<class type_t, class param_t>
21struct __opaque_xtd_linq_lazy_enumerable__ : xtd::collections::generic::ienumerable<type_t>, xtd::istringable {
22 xtd::collections::generic::enumerator<type_t> get_enumerator() const override {
23 struct lazy_enumerator : xtd::collections::generic::ienumerator<type_t> {
24 lazy_enumerator(param_type& params, move_next_type& move_next, reset_type& reset) : params_ {params}, move_next_ {move_next}, reset_ {reset} {}
25
26 const type_t& current() const override {return std::get<0>(params_);}
27 bool move_next() override {return move_next_(params_);}
28 void reset() override {reset_(params_);}
29
30 private:
31 param_type& params_;
32 move_next_type& move_next_;
33 reset_type& reset_;
34 };
35
36 return {xtd::new_ptr<lazy_enumerator>(data_->params, data_->move_next, data_->reset)};
37 }
38
39 xtd::string to_string() const override;
40
41private:
42 friend class xtd::linq::enumerable;
43 using param_type = param_t;
44 using move_next_type = std::function<bool(param_type&)>;
45 using reset_type = std::function<void(param_type&)>;
46
47 __opaque_xtd_linq_lazy_enumerable__() = default;
48 __opaque_xtd_linq_lazy_enumerable__(__opaque_xtd_linq_lazy_enumerable__&&) = default;
49 __opaque_xtd_linq_lazy_enumerable__(const __opaque_xtd_linq_lazy_enumerable__&) = default;
50 __opaque_xtd_linq_lazy_enumerable__& operator =(const __opaque_xtd_linq_lazy_enumerable__&) = default;
51 __opaque_xtd_linq_lazy_enumerable__(const param_type& params, move_next_type move_next, reset_type reset) {
52 data_->params = params;
53 data_->move_next = move_next;
54 data_->reset = reset;
55 }
56
57 struct data {
58 param_type params;
59 move_next_type move_next;
60 reset_type reset;
61 };
62
63 mutable xtd::ptr<data> data_ = xtd::new_ptr<data>();
64};
65
66template<class type_t>
67struct __opaque_xtd_linq_enumerable_collection__ : xtd::collections::generic::ienumerable<type_t>, xtd::istringable {
68 xtd::collections::generic::enumerator<type_t> get_enumerator() const override {return xtd::collections::generic::enumerator<>::create(items);}
69
70 xtd::string to_string() const override;
71
72 operator const typename xtd::collections::generic::helpers::raw_array<type_t>::base_type& () const noexcept {return items;}
73 operator typename xtd::collections::generic::helpers::raw_array<type_t>::base_type& () noexcept {return items;}
74
75private:
76 friend class xtd::linq::enumerable;
77 __opaque_xtd_linq_enumerable_collection__() = default;
78 xtd::collections::generic::helpers::raw_array<type_t> items;
79};
Exposes the enumerator, which supports a simple iteration over a collection of a specified type.
Definition ienumerable.hpp:40
virtual auto get_enumerator() const -> xtd::collections::generic::enumerator< type_t >=0
Returns an enumerator that iterates through a collection.
Provides a way to represent the current object as a string.
Definition istringable.hpp:22
Provides a set of static methods for querying objects that implement ienumerable <type_t>.
Definition enumerable.hpp:67
Contains xtd::collections::generic::enumerator <type_t> class.
Contains xtd::collections::generic::ienumerable <type_t> interface.
xtd::basic_string< char > string
Represents text as a sequence of UTF-8 code units.
Definition __string_definitions.hpp:43
xtd::sptr< type_t > ptr
The xtd::ptr object is a shared pointer.
Definition ptr.hpp:27
ptr< type_t > new_ptr(args_t &&... args)
The xtd::new_ptr operator creates a xtd::ptr object.
Definition new_ptr.hpp:24
@ current
Specifies the current position within a stream.
Definition seek_origin.hpp:20
Contains xtd::istringable interface.
Provides classes and interfaces that support queries that use Language-Integrated Query (LINQ).
Definition enumerable.hpp:50
string to_string() const noexcept override
Returns the string representation of this xtd::read_only_span <type_t> object.
Definition read_only_span.hpp:375
constexpr const_pointer data() const noexcept
Gets direct access to the underlying contiguous storage.
Definition read_only_span.hpp:201
static auto create(const collection_t &items, const version_t *current_version=nullptr) noexcept
Create an enumerator from specified collection and version.
Definition enumerator.hpp:114