xtd 0.2.0
Loading...
Searching...
No Matches
read_only_collection.h
Go to the documentation of this file.
1
4#pragma once
5#include "../generic/ilist.h"
6#define __XTD_CORE_INTERNAL__
7#include "../../internal/__external_exceptions.h"
8#undef __XTD_CORE_INTERNAL__
9#include "../../size.h"
10#include <limits>
11
13namespace xtd {
15 namespace collections {
17 namespace object_model {
39 template<typename type_t>
41 template<typename list_type_t>
42 class empty_list : public generic::ilist<list_type_t> {
43 public:
46
47 inline static constexpr xtd::size npos = std::numeric_limits<xtd::size>::max();
48
49 bool contains(const list_type_t& item) const noexcept override {return false;}
50 void copy_to(xtd::array<list_type_t>& array, xtd::size array_index) const override {}
51 generic::enumerator<list_type_t> get_enumerator() const noexcept {
52 class empty_enumerator : public generic::ienumerator<list_type_t> {
53 public:
54 const list_type_t& current() const override {__throw_argument_out_of_range_exception(__FILE__, __LINE__, __func__);}
55 bool move_next() override {return false;}
56 void reset() override {}
57 private:
58 };
59 return {new_ptr<empty_enumerator>()};
60 }
61 xtd::size index_of(const list_type_t& item) const noexcept override {return npos;}
62
63 const list_type_t& operator [](xtd::size index) const override {__throw_argument_out_of_range_exception(__FILE__, __LINE__, __func__);}
64 list_type_t& operator [](xtd::size index) override {__throw_argument_out_of_range_exception(__FILE__, __LINE__, __func__);}
65
66 private:
67 bool is_fixed_size() const noexcept override {return false;}
68 bool is_synchronized() const noexcept override {return false;}
69 void add(const list_type_t& item) override {}
70 void clear() override {}
71 void insert(xtd::size index, const list_type_t& item) override {}
72 bool remove(const list_type_t& item) override {return false;}
73 void remove_at(xtd::size index) override {}
74 };
75 public:
77
80 using value_type = type_t;
94 using const_pointer = const value_type*;
100
102
105 inline static constexpr xtd::size npos = std::numeric_limits<xtd::size>::max();
107
109
122 explicit read_only_collection(ptr<generic::ilist<value_type>> list) : items_(list) {}
124
126
138 xtd::size count() const noexcept override {return items_->count();}
139
144 auto result = read_only_collection<value_type> {new_ptr<empty_list<value_type>>()};
145 return result;
146 }
147
148 const xtd::object& sync_root() const noexcept override {return items_->sync_root();}
150
152
166 bool contains(const type_t& item) const noexcept override {return items_->contains(item);}
167
182 void copy_to(xtd::array<type_t>& array, xtd::size array_index) const override {return items_->copy_to(array, array_index);}
183
202 generic::enumerator<type_t> get_enumerator() const noexcept override {return items_->get_enumerator();}
203
217 xtd::size index_of(const type_t& item) const noexcept override {return items_->index_of(item);}
219
221
236 const_reference operator [](size_type index) const override {return (*items_)[index];}
238
239 protected:
241
253 base_type items() noexcept {return items_;}
255
256 private:
257 reference operator [](size_type index) override {__throw_invalid_operation_exception(__FILE__, __LINE__, __func__);}
258 bool is_fixed_size() const noexcept override {return false;}
259 bool is_read_only() const noexcept override {return false;}
260 bool is_synchronized() const noexcept override {return false;}
261 void add(const value_type& item) override {}
262 void clear() override {}
263 void insert(xtd::size index, const value_type& item) override {}
264 bool remove(const value_type& item) override {return false;}
265 void remove_at(xtd::size index) override {}
266 base_type items_;
267 };
268 }
269 }
270}
Supports a simple iteration over a generic collection.
Definition enumerator.h:31
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.
virtual bool remove(const type_t &item)=0
Removes the first occurrence of a specific object from the xtd::collections::generic::icollection <ty...
typename ienumerable< type_t >::const_iterator const_iterator
Represents the const iterator of xtd::collections::generic::ienumerable value type.
Definition icollection.h:52
typename ienumerable< type_t >::iterator iterator
Represents the iterator of xtd::collections::generic::ienumerable value type.
Definition icollection.h:50
Supports a simple iteration over a generic collection.
Definition ienumerator.h:58
Represents a collection of objects that can be individually accessed by index.
Definition ilist.h:41
typename icollection< type_t >::iterator iterator
Represents the iterator of xtd::collections::generic::ienumerable value type.
Definition ilist.h:47
typename icollection< type_t >::const_iterator const_iterator
Represents the const iterator of xtd::collections::generic::ienumerable value type.
Definition ilist.h:49
Provides the base class for a generic read-only collection.
Definition read_only_collection.h:40
static const read_only_collection< value_type > & empty()
Gets an empty xtd::collections::object_model::read_only_collection <type_t>.
Definition read_only_collection.h:143
value_type & reference
Represents the reference of list value type.
Definition read_only_collection.h:88
typename generic::icollection< type_t >::iterator iterator
Represents the iterator of list value type.
Definition read_only_collection.h:96
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.h:166
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.h:182
const_reference operator[](size_type index) const override
Returns a reference to the element at specified location pos.
Definition read_only_collection.h:236
ptr< xtd::collections::generic::ilist< value_type > > base_type
Represents the list base type.
Definition read_only_collection.h:82
const value_type * const_pointer
Represents the const pointer of list value type.
Definition read_only_collection.h:94
xtd::ptrdiff difference_type
Represents the list difference type (usually xtd::ptrdiff).
Definition read_only_collection.h:86
xtd::size size_type
Represents the list size type (usually xtd::size).
Definition read_only_collection.h:84
type_t value_type
Represents the list value type.
Definition read_only_collection.h:80
base_type items() noexcept
Returns the xtd::collections::generic::ilist <type_t> that the xtd::collections::object_model::read_o...
Definition read_only_collection.h:253
typename generic::icollection< type_t >::const_iterator const_iterator
Represents the const iterator of list value type.
Definition read_only_collection.h:98
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.h:105
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.h:122
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.h:202
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.h:217
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.h:148
const value_type & const_reference
Represents the const reference of list value type.
Definition read_only_collection.h:90
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.h:138
value_type * pointer
Represents the pointer of list value type.
Definition read_only_collection.h:92
Supports all classes in the xtd class hierarchy and provides low-level services to derived classes....
Definition object.h:42
xtd::sptr< type_t > ptr
The xtd::ptr object is a shared pointer.
Definition ptr.h:27
size_t size
Represents a size of any object in bytes.
Definition size.h:23
std::ptrdiff_t ptrdiff
Represent the signed integer type of the result of subtracting two pointers.
Definition ptrdiff.h: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.h:10
std::vector< type_t > array
Definition __array_definition.h:18