xtd 0.2.0
Loading...
Searching...
No Matches
read_only_collection.hpp
Go to the documentation of this file.
1
4#pragma once
7#include "../../size.hpp"
8#include <limits>
9
11namespace xtd {
13 namespace collections {
15 namespace object_model {
37 template<class type_t>
38 class read_only_collection : public xtd::object, public xtd::collections::generic::ilist<type_t> {
39 template<class list_type_t>
40 class empty_list : public generic::ilist<list_type_t> {
41 public:
42 using iterator = typename generic::ilist<list_type_t>::iterator;
43 using const_iterator = typename generic::ilist<list_type_t>::const_iterator;
44
45 auto contains(const list_type_t& item) const noexcept -> bool override {return false;}
46 auto copy_to(xtd::array<list_type_t>& array, xtd::size array_index) const -> void override {}
47 generic::enumerator<list_type_t> get_enumerator() const noexcept override {
48 struct empty_list_enumerator : public generic::ienumerator<list_type_t> {
50 bool move_next() override {return false;}
51 void reset() override {}
52 };
54 }
55 auto index_of(const list_type_t& item) const noexcept -> xtd::size override {return npos;}
56
57 const list_type_t& operator [](xtd::size index) const override {xtd::helpers::throw_helper::throws(xtd::helpers::exception_case::argument_out_of_range);}
59
60 private:
61 auto is_fixed_size() const noexcept -> bool override {return false;}
62 auto is_synchronized() const noexcept -> bool override {return false;}
63 auto add(const list_type_t& item) -> void override {}
64 auto clear() -> void override {}
65 auto insert(xtd::size index, const list_type_t& item) -> void override {}
66 auto remove(const list_type_t& item) -> bool override {return false;}
67 auto remove_at(xtd::size index) -> void override {}
68 };
69
70 public:
72
75 using value_type = type_t;
77 using base_type = const xtd::collections::generic::ilist<value_type>& ;
89 using const_pointer = const value_type*;
91 using iterator = typename generic::icollection<type_t>::iterator;
93 using const_iterator = typename generic::icollection<type_t>::const_iterator;
95
97
110 explicit read_only_collection(const generic::ilist<value_type>& list) : items_(list) {}
112
114
126 auto count() const noexcept -> xtd::size override {return items_.count();}
127
132 static auto el = empty_list<value_type> {};
133 static auto roc_el = read_only_collection<value_type> {el};
134 return roc_el;
135 }
136
137 const xtd::object& sync_root() const noexcept override {return items_.sync_root();}
139
141
155 auto contains(const type_t& item) const noexcept -> bool override {return items_.contains(item);}
156
171 auto copy_to(xtd::array<type_t>& array, xtd::size array_index) const -> void override {return items_.copy_to(array, array_index);}
172
191 generic::enumerator<value_type> get_enumerator() const noexcept override {return items_.get_enumerator();}
192
206 auto index_of(const type_t& item) const noexcept -> xtd::size override {return items_.index_of(item);}
208
210
225 auto operator [](size_type index) const -> const_reference override {return items_[index];}
232
233 protected:
235
247 auto items() noexcept -> base_type {return items_;}
249
250 private:
251 auto is_fixed_size() const noexcept -> bool override {return false;}
252 auto is_read_only() const noexcept -> bool override {return true;}
253 auto is_synchronized() const noexcept -> bool override {return false;}
254 auto add(const value_type& item) -> void override {}
255 auto clear() -> void override {}
256 auto insert(xtd::size index, const value_type& item) -> void override {}
257 auto remove(const value_type& item) -> bool override {return false;}
258 auto remove_at(xtd::size index) -> void override {}
259 base_type items_;
260 };
261 }
262 }
263}
Provides methods for creating, manipulating, searching, and sorting arrays, thereby serving as the ba...
Definition array.hpp:64
Supports a simple iteration over a generic collection.
Definition ienumerator.hpp:58
value_type & reference
Definition read_only_collection.hpp:83
const xtd::collections::generic::ilist< value_type > & base_type
Definition read_only_collection.hpp:77
auto index_of(const type_t &item) const noexcept -> xtd::size override
Searches for the specified object and returns the zero-based index of the first occurrence within the...
Definition read_only_collection.hpp:206
typename generic::icollection< type_t >::iterator iterator
Represents the iterator of list value type.
Definition read_only_collection.hpp:91
read_only_collection(const generic::ilist< value_type > &list)
Initializes a new instance of the xtd::collections::object_model::read_only_collection <type_t> class...
Definition read_only_collection.hpp:110
generic::enumerator< value_type > get_enumerator() const noexcept override
Returns an enumerator that iterates through the xtd::collections::object_model::read_only_collection ...
Definition read_only_collection.hpp:191
auto copy_to(xtd::array< type_t > &array, xtd::size array_index) const -> void override
Copies the entire xtd::collections::object_model::read_only_collection <type_t> to a compatible one-d...
Definition read_only_collection.hpp:171
const value_type * const_pointer
Definition read_only_collection.hpp:89
xtd::ptrdiff difference_type
Definition read_only_collection.hpp:81
xtd::size size_type
Definition read_only_collection.hpp:79
value_type value_type
Definition read_only_collection.hpp:75
typename generic::icollection< type_t >::const_iterator const_iterator
Represents the const iterator of list value type.
Definition read_only_collection.hpp:93
auto operator[](size_type index) const -> const_reference override
Returns a reference to the element at specified location pos.
Definition read_only_collection.hpp:225
auto contains(const type_t &item) const noexcept -> bool override
Determines whether an element is in the xtd::collections::object_model::read_only_collection <type_t>...
Definition read_only_collection.hpp:155
auto items() noexcept -> base_type
Returns the xtd::collections::generic::ilist <type_t> that the xtd::collections::object_model::read_o...
Definition read_only_collection.hpp:247
auto count() const noexcept -> xtd::size override
Gets the number of elements contained in the xtd::collections::object_model::read_only_collection <ty...
Definition read_only_collection.hpp:126
const value_type & const_reference
Definition read_only_collection.hpp:85
static auto empty_collection() -> const read_only_collection< value_type > &
Gets an empty xtd::collections::object_model::read_only_collection <type_t>.
Definition read_only_collection.hpp:131
value_type * pointer
Definition read_only_collection.hpp:87
static void throws(xtd::helpers::exception_case exception_case, const source_location &location=source_location::current())
Throws an exption with specified exception case.
Supports all classes in the xtd class hierarchy and provides low-level services to derived classes....
Definition object.hpp:44
Contains xtd::collections::generic::ilist <type_t> interface.
@ not_supported
The method or operation is not supported.
Definition exception_case.hpp:77
@ argument_out_of_range
The argument is out of range.
Definition exception_case.hpp:35
constexpr xtd::size npos
Represents a value that is not a valid position in a collection.
Definition npos.hpp:26
size_t size
Represents a size of any object in bytes.
Definition size.hpp:23
std::ptrdiff_t ptrdiff
Represent the signed integer type of the result of subtracting two pointers.
Definition ptrdiff.hpp:23
ptr< type_t > new_ptr(args_t &&... args)
The xtd::new_ptr operator creates a xtd::ptr object.
Definition new_ptr.hpp:24
@ add
The Add key.
Definition console_key.hpp:170
@ insert
The INS (INSERT) key.
Definition console_key.hpp:62
Contains classes that can be used as collections in the object model of a reusable library....
Definition read_only_collection.hpp:15
The xtd::collections namespace contains interfaces and classes that define various collections of obj...
Definition any_pair.hpp:10
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition abstract_object.hpp:8
Supports a simple iteration over a generic collection.
Definition enumerator.hpp:38
Contains xtd::helpers::throw_helper class.
Contains xtd::size type.