xtd 0.2.0
read_only_collection.hpp
Go to the documentation of this file.
1
4#pragma once
5#include "../generic/ilist.hpp"
6#include "../../helpers/throw_helper.hpp"
7#include "../../size.hpp"
8#include <limits>
9
11namespace xtd {
13 namespace collections {
15 namespace object_model {
37 template<class type_t>
39 template<class list_type_t>
40 class empty_list : public generic::ilist<list_type_t> {
41 public:
44
45 inline static constexpr xtd::size npos = std::numeric_limits<xtd::size>::max();
46
47 bool contains(const list_type_t& item) const noexcept override {return false;}
48 void copy_to(xtd::array<list_type_t>& array, xtd::size array_index) const override {}
49 generic::enumerator<list_type_t> get_enumerator() const noexcept {
50 class empty_enumerator : public generic::ienumerator<list_type_t> {
51 public:
53 bool move_next() override {return false;}
54 void reset() override {}
55 private:
56 };
57 return {new_ptr<empty_enumerator>()};
58 }
59 xtd::size index_of(const list_type_t& item) const noexcept override {return npos;}
60
61 const list_type_t& operator [](xtd::size index) const override {xtd::helpers::throw_helper::throws(xtd::helpers::exception_case::argument_out_of_range);}
63
64 private:
65 bool is_fixed_size() const noexcept override {return false;}
66 bool is_synchronized() const noexcept override {return false;}
67 void add(const list_type_t& item) override {}
68 void clear() override {}
69 void insert(xtd::size index, const list_type_t& item) override {}
70 bool remove(const list_type_t& item) override {return false;}
71 void remove_at(xtd::size index) override {}
72 };
73 public:
75
78 using value_type = type_t;
92 using const_pointer = const value_type*;
98
100
103 inline static constexpr xtd::size npos = std::numeric_limits<xtd::size>::max();
105
107
122
124
136 xtd::size count() const noexcept override {return items_->count();}
137
142 auto result = read_only_collection<value_type> {new_ptr<empty_list<value_type>>()};
143 return result;
144 }
145
146 const xtd::object& sync_root() const noexcept override {return items_->sync_root();}
148
150
164 bool contains(const type_t& item) const noexcept override {return items_->contains(item);}
165
180 void copy_to(xtd::array<type_t>& array, xtd::size array_index) const override {return items_->copy_to(array, array_index);}
181
200 generic::enumerator<type_t> get_enumerator() const noexcept override {return items_->get_enumerator();}
201
215 xtd::size index_of(const type_t& item) const noexcept override {return items_->index_of(item);}
217
219
234 const_reference operator [](size_type index) const override {return (*items_)[index];}
236
237 protected:
239
251 base_type items() noexcept {return items_;}
253
254 private:
256 bool is_fixed_size() const noexcept override {return false;}
257 bool is_read_only() const noexcept override {return false;}
258 bool is_synchronized() const noexcept override {return false;}
259 void add(const value_type& item) override {}
260 void clear() override {}
261 void insert(xtd::size index, const value_type& item) override {}
262 bool remove(const value_type& item) override {return false;}
263 void remove_at(xtd::size index) override {}
264 base_type items_;
265 };
266 }
267 }
268}
Provides methods for creating, manipulating, searching, and sorting arrays, thereby serving as the ba...
Definition array.hpp:61
typename xtd::linq::enumerable::list< type_t > list
Represents the list value type.
Definition enumerable.hpp:47
virtual void copy_to(xtd::array< type_t > &array, xtd::size array_index) const =0
Copies the elements of the xtd::collections::generic::icollection <type_t> to an xtd::array,...
virtual bool contains(const type_t &item) const noexcept=0
Determines whether the xtd::collections::generic::icollection <type_t> contains a specific value.
typename xtd::collections::generic::ienumerable< type_t >::const_iterator const_iterator
Represents the const iterator of xtd::collections::generic::ienumerable value type.
Definition icollection.hpp:55
virtual bool remove(const type_t &item)=0
Removes the first occurrence of a specific object from the xtd::collections::generic::icollection <ty...
typename xtd::collections::generic::ienumerable< type_t >::iterator iterator
Represents the iterator of xtd::collections::generic::ienumerable value type.
Definition icollection.hpp:53
Supports a simple iteration over a generic collection.
Definition ienumerator.hpp:58
Represents a collection of objects that can be individually accessed by index.
Definition ilist.hpp:41
typename icollection< type_t >::iterator iterator
Represents the iterator of xtd::collections::generic::ienumerable value type.
Definition ilist.hpp:47
typename icollection< type_t >::const_iterator const_iterator
Represents the const iterator of xtd::collections::generic::ienumerable value type.
Definition ilist.hpp:49
Provides the base class for a generic read-only collection.
Definition read_only_collection.hpp:38
static const read_only_collection< value_type > & empty()
Gets an empty xtd::collections::object_model::read_only_collection <type_t>.
Definition read_only_collection.hpp:141
value_type & reference
Represents the reference of list value type.
Definition read_only_collection.hpp:86
typename generic::icollection< type_t >::iterator iterator
Represents the iterator of list value type.
Definition read_only_collection.hpp:94
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:164
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:180
const_reference operator[](size_type index) const override
Returns a reference to the element at specified location pos.
Definition read_only_collection.hpp:234
ptr< xtd::collections::generic::ilist< value_type > > base_type
Represents the list base type.
Definition read_only_collection.hpp:80
const value_type * const_pointer
Represents the const pointer of list value type.
Definition read_only_collection.hpp:92
xtd::ptrdiff difference_type
Represents the list difference type (usually xtd::ptrdiff).
Definition read_only_collection.hpp:84
xtd::size size_type
Represents the list size type (usually xtd::size).
Definition read_only_collection.hpp:82
type_t value_type
Represents the list value type.
Definition read_only_collection.hpp:78
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:251
typename generic::icollection< type_t >::const_iterator const_iterator
Represents the const iterator of list value type.
Definition read_only_collection.hpp:96
static constexpr xtd::size npos
This is a special value equal to the maximum value representable by the type xtd::size.
Definition read_only_collection.hpp:103
read_only_collection(ptr< 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:120
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:200
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:215
const xtd::object & sync_root() const noexcept override
Gets an object that can be used to synchronize access to the the xtd::collections::generic::icollecti...
Definition read_only_collection.hpp:146
const value_type & const_reference
Represents the const reference of list value type.
Definition read_only_collection.hpp:88
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:136
value_type * pointer
Represents the pointer of list value type.
Definition read_only_collection.hpp:90
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:43
The xtd::shared_ptr_object is a shared pointer as std::shared_ptr.
Definition shared_ptr_object.hpp:30
@ argument_out_of_range
The argument is out of range.
@ invalid_operation
The operation is not valid.
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
@ clear
The CLEAR key.
@ add
The Add key.
@ insert
The INS (INSERT) key.
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition xtd_about_box.hpp:10
Supports a simple iteration over a generic collection.
Definition enumerator.hpp:38