xtd 1.0.0
Loading...
Searching...
No Matches
read_only_collection.hpp
Go to the documentation of this file.
1
4#pragma once
7#include "../../string.hpp"
8#include "../../usize.hpp"
9#include <limits>
10
12namespace xtd {
14 namespace collections {
16 namespace object_model {
38 template<typename type_t>
39 class read_only_collection : public xtd::object, public xtd::collections::generic::ilist<type_t> {
40 template<typename list_type_t>
41 class empty_list : public generic::ilist<list_type_t> {
42 public:
43 using iterator = typename generic::ilist<list_type_t>::iterator;
44 using const_iterator = typename generic::ilist<list_type_t>::const_iterator;
45
46 [[nodiscard]] auto contains(const list_type_t& item) const noexcept -> bool override {return false;}
47 auto copy_to(xtd::array<list_type_t>& array, xtd::usize array_index) const -> void override {}
48 [[nodiscard]] generic::enumerator<list_type_t> get_enumerator() const noexcept override {
49 struct empty_list_enumerator : public generic::ienumerator<list_type_t> {
50 [[nodiscard]] const list_type_t& current() const override {xtd::helpers::throw_helper::throws(xtd::helpers::exception_case::argument_out_of_range);}
51 [[nodiscard]] bool move_next() override {return false;}
52 void reset() override {}
53 };
55 }
56 [[nodiscard]] auto index_of(const list_type_t& item) const noexcept -> xtd::usize override {return npos;}
57
60
61 private:
62 auto is_fixed_size() const noexcept -> bool override {return false;}
63 auto is_synchronized() const noexcept -> bool override {return false;}
64 auto add(const list_type_t& item) -> void override {}
65 auto clear() -> void override {}
66 auto insert(xtd::usize index, const list_type_t& item) -> void override {}
67 auto remove(const list_type_t& item) -> bool override {return false;}
68 auto remove_at(xtd::usize index) -> void override {}
69 };
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 xtd::collections::generic::ilist<value_type>& list) : items_(list) {}
113
115
127 [[nodiscard]] auto count() const noexcept -> xtd::usize override {return items_.count();}
128
132 [[nodiscard]] static auto empty_collection() -> const read_only_collection<value_type>& {
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 [[nodiscard]] const xtd::object& sync_root() const noexcept override {return items_.sync_root();}
140
142
156 [[nodiscard]] auto contains(const type_t& item) const noexcept -> bool override {return items_.contains(item);}
157
172 auto copy_to(xtd::array<type_t>& array, xtd::usize array_index) const -> void override {return items_.copy_to(array, array_index);}
173
192 [[nodiscard]] generic::enumerator<value_type> get_enumerator() const noexcept override {return items_.get_enumerator();}
193
207 [[nodiscard]] auto index_of(const type_t& item) const noexcept -> xtd::usize override {return items_.index_of(item);}
208
211 [[nodiscard]] auto to_string() const noexcept -> xtd::string override {return xtd::string::format("[{}]", xtd::string::join(", ", self_));}
213
215
230 auto operator [](size_type index) const -> const_reference override {return items_[index];}
237
238 protected:
240
252 auto items() noexcept -> base_type {return items_;}
254
255 private:
256 auto is_fixed_size() const noexcept -> bool override {return false;}
257 auto is_read_only() const noexcept -> bool override {return true;}
258 auto is_synchronized() const noexcept -> bool override {return false;}
259 auto add(const value_type& item) -> void override {}
260 auto clear() -> void override {}
261 auto insert(xtd::usize index, const value_type& item) -> void override {}
262 auto remove(const value_type& item) -> bool override {return false;}
263 auto remove_at(xtd::usize index) -> void override {}
264 base_type items_;
265 };
266
268 // Deduction guides for xtd::collections::object_model::list
269 // {
270 template<typename type_t>
271 read_only_collection(const xtd::collections::generic::ilist<type_t>&) -> read_only_collection<type_t>;
272 // }
274 }
275 }
276}
Provides methods for creating, manipulating, searching, and sorting arrays, thereby serving as the ba...
Definition array.hpp:64
static auto join(const basic_string &separator, const collection_t &values) noexcept -> basic_string
Definition basic_string.hpp:1258
Supports a simple iteration over a generic collection.
Definition ienumerator.hpp:58
Provides the base class for a generic read-only collection.
Definition read_only_collection.hpp:39
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
auto to_string() const noexcept -> xtd::string override
Returns a xtd::string that represents the current object.
Definition read_only_collection.hpp:211
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:192
const value_type * const_pointer
Definition read_only_collection.hpp:90
xtd::ptrdiff difference_type
Definition read_only_collection.hpp:82
auto index_of(const type_t &item) const noexcept -> xtd::usize override
Searches for the specified object and returns the zero-based index of the first occurrence within the...
Definition read_only_collection.hpp:207
auto copy_to(xtd::array< type_t > &array, xtd::usize 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:172
value_type value_type
Definition read_only_collection.hpp:76
typename generic::icollection< type_t >::const_iterator const_iterator
Represents the const iterator of list value type.
Definition read_only_collection.hpp:94
xtd::usize size_type
Definition read_only_collection.hpp:80
auto operator[](size_type index) const -> const_reference override
Returns a reference to the element at specified location pos.
Definition read_only_collection.hpp:230
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:156
auto count() const noexcept -> xtd::usize override
Gets the number of elements contained in the xtd::collections::object_model::read_only_collection <ty...
Definition read_only_collection.hpp:127
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:252
read_only_collection(const xtd::collections::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
const value_type & const_reference
Definition read_only_collection.hpp:86
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:132
value_type * pointer
Definition read_only_collection.hpp:88
static auto throws(xtd::helpers::exception_case exception_case, const source_location &location=source_location::current()) -> void
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:45
Contains xtd::collections::generic::ilist <type_t> interface.
static auto format(const basic_string< char > &fmt, args_t &&... args) -> basic_string
@ 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
#define self_
The self_ expression is a reference value expression whose value is the reference of the implicit obj...
Definition self.hpp:20
constexpr auto npos
Represents a value that is not a valid position in a collection.
Definition npos.hpp:26
std::ptrdiff_t ptrdiff
Represent the signed integer type of the result of subtracting two pointers.
Definition ptrdiff.hpp:23
std::size_t usize
Represents an unsigned size of any object in bytes.
Definition usize.hpp:22
auto new_ptr(args_t &&... args) -> xtd::ptr< type_t >
The xtd::new_ptr operator creates a xtd::ptr object.
Definition new_ptr.hpp:24
Contains classes that can be used as collections in the object model of a reusable library....
Definition read_only_collection.hpp:16
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
Contains xtd::string alias.
Supports a simple iteration over a generic collection.
Definition enumerator.hpp:39
Contains xtd::helpers::throw_helper class.
Contains xtd::usize type.