xtd 0.2.0
__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
11#include "../collections/generic/enumerator.hpp"
12#include "../collections/generic/ienumerable.hpp"
13#include "../istringable.hpp"
14#include <vector>
15
17namespace xtd::linq {
18 class enumerable;
19};
20
21template<class type_t, class param_t>
22struct __opaque_xtd_linq_lazy_enumerable__ : xtd::collections::generic::ienumerable<type_t>, xtd::istringable {
24 return {xtd::new_ptr<lazy_enumerator>(data_->params, data_->move_next, data_->reset)};
25 }
26
27 xtd::string to_string() const override;
28
29private:
30 friend class xtd::linq::enumerable;
31 using param_type = param_t;
32 using move_next_type = std::function<bool(param_type&)>;
33 using reset_type = std::function<void(param_type&)>;
34
35 __opaque_xtd_linq_lazy_enumerable__() = default;
36 __opaque_xtd_linq_lazy_enumerable__(__opaque_xtd_linq_lazy_enumerable__&&) = default;
37 __opaque_xtd_linq_lazy_enumerable__(const __opaque_xtd_linq_lazy_enumerable__&) = default;
38 __opaque_xtd_linq_lazy_enumerable__& operator =(const __opaque_xtd_linq_lazy_enumerable__&) = default;
39 __opaque_xtd_linq_lazy_enumerable__(const param_type& params, move_next_type move_next, reset_type reset) {
40 data_->params = params;
41 data_->move_next = move_next;
42 data_->reset = reset;
43 }
44
45 struct lazy_enumerator : xtd::collections::generic::ienumerator<type_t> {
46 lazy_enumerator(param_type& params, move_next_type& move_next, reset_type& reset) : params_ {params}, move_next_ {move_next}, reset_ {reset} {}
47
48 const type_t& current() const override {
49 return std::get<0>(params_);
50 }
51 bool move_next() override {
52 return move_next_(params_);
53 }
54 void reset() override {
55 reset_(params_);
56 }
57
58 private:
59 param_type& params_;
60 move_next_type& move_next_;
61 reset_type& reset_;
62 };
63
64 struct data {
65 param_type params;
66 move_next_type move_next;
67 reset_type reset;
68 };
69
70 mutable xtd::ptr<data> data_ = xtd::new_ptr<data>();
71};
72
73template<class type_t>
74struct __opaque_xtd_linq_enumerable_collection__ : xtd::collections::generic::ienumerable<type_t>, xtd::istringable {
77 }
78
79 xtd::string to_string() const override;
80
81private:
82 friend class xtd::linq::enumerable;
83 __opaque_xtd_linq_enumerable_collection__() = default;
84 std::vector<type_t> items;
85};
Represents text as a sequence of character units.
Definition basic_string.hpp:71
Exposes the enumerator, which supports a simple iteration over a collection of a specified type.
Definition ienumerable.hpp:36
virtual xtd::collections::generic::enumerator< type_t > get_enumerator() const =0
Returns an enumerator that iterates through a collection.
Supports a simple iteration over a generic collection.
Definition ienumerator.hpp:58
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:58
The xtd::shared_ptr_object is a shared pointer as std::shared_ptr.
Definition shared_ptr_object.hpp:30
std::string to_string(const value_t &value, const std::string &fmt, const std::locale &loc)
Convert a specified value into a string with specified format and locale.
Definition to_string.hpp:41
@ current
Specifies the current position within a stream.
Provides classes and interfaces that support queries that use Language-Integrated Query (LINQ).
Definition enumerable.hpp:41
Supports a simple iteration over a generic collection.
Definition enumerator.hpp:38