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 bool contains(const list_type_t& item) const noexcept override {return false;}
46 void copy_to(xtd::array<list_type_t>& array, xtd::size array_index) const override {}
48 class empty_enumerator : public generic::ienumerator<list_type_t> {
49 public:
51 bool move_next() override {return false;}
52 void reset() override {}
53 private:
54 };
56 }
57 xtd::size index_of(const list_type_t& item) const noexcept override {return npos;}
58
59 const list_type_t& operator [](xtd::size index) const override {xtd::helpers::throw_helper::throws(xtd::helpers::exception_case::argument_out_of_range);}
61
62 private:
63 bool is_fixed_size() const noexcept override {return false;}
64 bool is_synchronized() const noexcept override {return false;}
65 void add(const list_type_t& item) override {}
66 void clear() override {}
67 void insert(xtd::size index, const list_type_t& item) override {}
68 bool remove(const list_type_t& item) override {return false;}
69 void remove_at(xtd::size index) override {}
70 };
71 public:
73
76 using value_type = type_t;
78 using base_type = const xtd::collections::generic::ilist<value_type>& ;
90 using const_pointer = const value_type*;
92 using iterator = typename generic::icollection<type_t>::iterator;
94 using const_iterator = typename generic::icollection<type_t>::const_iterator;
96
98
111 explicit read_only_collection(const generic::ilist<value_type>& list) : items_(list) {}
113
115
127 xtd::size count() const noexcept override {return items_.count();}
128
133 static auto el = empty_list<value_type> {};
134 static auto roc_el = read_only_collection<value_type> {el};
135 return roc_el;
136 }
137
138 const xtd::object& sync_root() const noexcept override {return items_.sync_root();}
140
142
156 bool contains(const type_t& item) const noexcept override {return items_.contains(item);}
157
172 void copy_to(xtd::array<type_t>& array, xtd::size array_index) const override {return items_.copy_to(array, array_index);}
173
192 generic::enumerator<type_t> get_enumerator() const noexcept override {return items_.get_enumerator();}
193
207 xtd::size index_of(const type_t& item) const noexcept override {return items_.index_of(item);}
209
211
226 const_reference operator [](size_type index) const override {return items_[index];}
233
234 protected:
236
248 base_type items() noexcept {return items_;}
250
251 private:
252 bool is_fixed_size() const noexcept override {return false;}
253 bool is_read_only() const noexcept override {return true;}
254 bool is_synchronized() const noexcept override {return false;}
255 void add(const value_type& item) override {}
256 void clear() override {}
257 void insert(xtd::size index, const value_type& item) override {}
258 bool remove(const value_type& item) override {return false;}
259 void remove_at(xtd::size index) override {}
260 base_type items_;
261 };
262 }
263 }
264}
Provides methods for creating, manipulating, searching, and sorting arrays, thereby serving as the ba...
Definition array.hpp:63
Supports a simple iteration over a generic collection.
Definition ienumerator.hpp:58
value_type & reference
Definition read_only_collection.hpp:84
const xtd::collections::generic::ilist< value_type > & base_type
Definition read_only_collection.hpp:78
typename generic::icollection< type_t >::iterator iterator
Represents the iterator of list value type.
Definition read_only_collection.hpp:92
bool contains(const type_t &item) const noexcept override
Determines whether an element is in the xtd::collections::object_model::read_only_collection <type_t>...
Definition read_only_collection.hpp:156
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:111
void copy_to(xtd::array< type_t > &array, xtd::size array_index) const override
Copies the entire xtd::collections::object_model::read_only_collection <type_t> to a compatible one-d...
Definition read_only_collection.hpp:172
const_reference operator[](size_type index) const override
Returns a reference to the element at specified location pos.
Definition read_only_collection.hpp:226
const value_type * const_pointer
Definition read_only_collection.hpp:90
xtd::ptrdiff difference_type
Definition read_only_collection.hpp:82
xtd::size size_type
Definition read_only_collection.hpp:80
value_type value_type
Definition read_only_collection.hpp:76
static const read_only_collection< value_type > & empty_collection()
Gets an empty xtd::collections::object_model::read_only_collection <type_t>.
Definition read_only_collection.hpp:132
base_type items() noexcept
Returns the xtd::collections::generic::ilist <type_t> that the xtd::collections::object_model::read_o...
Definition read_only_collection.hpp:248
typename generic::icollection< type_t >::const_iterator const_iterator
Represents the const iterator of list value type.
Definition read_only_collection.hpp:94
generic::enumerator< type_t > get_enumerator() const noexcept override
Returns an enumerator that iterates through the xtd::collections::object_model::read_only_collection ...
Definition read_only_collection.hpp:192
xtd::size index_of(const type_t &item) const noexcept override
Searches for the specified object and returns the zero-based index of the first occurrence within the...
Definition read_only_collection.hpp:207
const value_type & const_reference
Definition read_only_collection.hpp:86
xtd::size count() const noexcept override
Gets the number of elements contained in the xtd::collections::object_model::read_only_collection <ty...
Definition read_only_collection.hpp:127
value_type * pointer
Definition read_only_collection.hpp:88
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:75
@ 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::exception_case enum class.
Contains xtd::size type.