Defines methods to manipulate generic collections.
box
objects named box_collection
. Each box
has height
, length
, and width
properties, which are used to define equality. Equality can be defined as all dimensions being the same or the volume being the same. The box
class implements the xtd::iequatable <type_t> interface to define the default equality as the dimensions being the same.The box_collection
class implements the xtd::collections::generic::icollection::contains method to use the default equality to determine whether a box
is in the collection. This method is used by the xtd::collections::generic::icollection::add method so that each box
added to the collection has a unique set of dimensions. The box_collection
class also provides an overload of the xtd::collections::generic::icollection::contains method that takes a specified xtd::collections::generic::iequality_comparer <type_t> interface, such as b
ox_same_dimensionsand
box_same_volume` classes in the example.
This example also implements an xtd::collections::generic::ienumerator <type_t> interface for the box_collection
class so that the collection can be enumerated.
Public Aliases | |
using | iterator = typename ienumerable< type_t >::iterator |
Represents the iterator of xtd::collections::generic::ienumerable value type. | |
using | const_iterator = typename ienumerable< type_t >::const_iterator |
Represents the const iterator of xtd::collections::generic::ienumerable value type. | |
Public Properties | |
virtual xtd::size | count () const noexcept=0 |
Gets the number of elements contained in the xtd::collections::generic::icollection <type_t>. | |
virtual bool | is_read_only () const noexcept=0 |
Gets a value indicating whether the xtd::collections::generic::icollection <type_t> is read-only. | |
virtual bool | is_synchronized () const noexcept=0 |
Gets a value indicating whether access to the xtd::collections::generic::icollection <type_t> is synchronized (thread safe). | |
virtual const xtd::object & | sync_root () const noexcept=0 |
Gets an object that can be used to synchronize access to the the xtd::collections::generic::icollection <type_t>. | |
Public Methods | |
virtual void | add (const type_t &item)=0 |
Adds an item to the xtd::collections::generic::icollection <type_t>. | |
virtual void | clear ()=0 |
Removes all items from the xtd::collections::generic::icollection <type_t>. | |
virtual bool | contains (const type_t &item) const noexcept=0 |
Determines whether the xtd::collections::generic::icollection <type_t> contains a specific value. | |
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, starting at a particular xtd::array index. | |
virtual bool | remove (const type_t &item)=0 |
Removes the first occurrence of a specific object from the xtd::collections::generic::icollection <type_t>. | |
Additional Inherited Members | |
Public Types inherited from xtd::collections::generic::ienumerable< type_t > | |
using | iterator = typename xtd::collections::generic::extensions::enumerable_iterators< type_t, xtd::collections::generic::ienumerable< type_t > >::iterator |
Represents the iterator of xtd::collections::generic::ienumerable value type. | |
using | const_iterator = typename xtd::collections::generic::extensions::enumerable_iterators< type_t, xtd::collections::generic::ienumerable< type_t > >::const_iterator |
Represents the const iterator of xtd::collections::generic::ienumerable value type. | |
Public Types inherited from xtd::collections::generic::extensions::enumerable_iterators< type_t, xtd::collections::generic::ienumerable< type_t > > | |
using | const_iterator = const iterator |
Represents the const iterator of enumarable value type. | |
Public Member Functions inherited from xtd::collections::generic::ienumerable< type_t > | |
virtual xtd::collections::generic::enumerator< type_t > | get_enumerator () const =0 |
Returns an enumerator that iterates through a collection. | |
Public Member Functions inherited from xtd::collections::generic::extensions::enumerable_iterators< type_t, xtd::collections::generic::ienumerable< type_t > > | |
virtual const_iterator | begin () const |
Returns an iterator to the first element of the enumarable. | |
virtual iterator | begin () |
Returns an iterator to the first element of the enumarable. | |
virtual const_iterator | cbegin () const |
Returns an iterator to the first element of the enumarable. | |
virtual const_iterator | cend () const |
Returns an iterator to the element following the last element of the enumarable. | |
virtual const_iterator | end () const |
Returns an iterator to the element following the last element of the enumarable. | |
virtual iterator | end () |
Returns an iterator to the element following the last element of the enumarable. | |
using xtd::collections::generic::icollection< type_t >::iterator = typename ienumerable<type_t>::iterator |
Represents the iterator of xtd::collections::generic::ienumerable value type.
using xtd::collections::generic::icollection< type_t >::const_iterator = typename ienumerable<type_t>::const_iterator |
Represents the const iterator of xtd::collections::generic::ienumerable value type.
|
pure virtualnoexcept |
Gets the number of elements contained in the xtd::collections::generic::icollection <type_t>.
Implemented in xtd::basic_array< type_t, allocator_t >, xtd::basic_array< type_t, allocator_t >, xtd::basic_array< value_type, allocator_t >, xtd::collections::generic::list< type_t, allocator_t >, and xtd::collections::object_model::read_only_collection< type_t >.
|
pure virtualnoexcept |
Gets a value indicating whether the xtd::collections::generic::icollection <type_t> is read-only.
Implemented in xtd::basic_array< type_t, allocator_t >, xtd::basic_array< type_t, allocator_t >, xtd::basic_array< value_type, allocator_t >, and xtd::collections::generic::list< type_t, allocator_t >.
|
pure virtualnoexcept |
Gets a value indicating whether access to the xtd::collections::generic::icollection <type_t> is synchronized (thread safe).
synchronized
method, which provides a synchronized wrapper around the underlying collection. Implemented in xtd::basic_array< type_t, allocator_t >, xtd::basic_array< type_t, allocator_t >, xtd::basic_array< value_type, allocator_t >, and xtd::collections::generic::list< type_t, allocator_t >.
|
pure virtualnoexcept |
Gets an object that can be used to synchronize access to the the xtd::collections::generic::icollection <type_t>.
sync_root
property. synchronized
method, which provides a synchronized wrapper around the underlying collection. However, derived classes can provide their own synchronized version of the collection using the xtd::collections::generic::icollection::sync_root property. The synchronizing code must perform operations on the xtd::collections::generic::icollection::sync_root property of the collection, not directly on the collection. This ensures proper operation of collections that are derived from other objects. Specifically, it maintains proper synchronization with other threads that might be simultaneously modifying the collection instance. synchronized
method on a collection, the expected usage for the xtd::collections::generic::icollection::sync_root looks as follows: Implemented in xtd::basic_array< type_t, allocator_t >, xtd::basic_array< type_t, allocator_t >, xtd::basic_array< value_type, allocator_t >, xtd::collections::generic::list< type_t, allocator_t >, and xtd::collections::object_model::read_only_collection< type_t >.
|
pure virtual |
Adds an item to the xtd::collections::generic::icollection <type_t>.
item | The object to add to the xtd::collections::generic::icollection <type_t>. |
xtd::not_supported_exception | The xtd::collections::generic::icollection <type_t> is read-only. |
Implemented in xtd::collections::generic::list< type_t, allocator_t >.
|
pure virtual |
Removes all items from the xtd::collections::generic::icollection <type_t>.
xtd::not_supported_exception | The xtd::collections::generic::icollection <type_t> is read-only. |
Implemented in xtd::collections::generic::list< type_t, allocator_t >.
|
pure virtualnoexcept |
Determines whether the xtd::collections::generic::icollection <type_t> contains a specific value.
item | The object to locate in the xtd::collections::generic::icollection <type_t>. |
Implemented in xtd::collections::object_model::read_only_collection< type_t >, xtd::basic_array< type_t, allocator_t >, xtd::basic_array< type_t, allocator_t >, and xtd::collections::generic::list< type_t, allocator_t >.
|
pure virtual |
Copies the elements of the xtd::collections::generic::icollection <type_t> to an xtd::array, starting at a particular xtd::array index.
array | The one-dimensional xtd::array that is the destination of the elements copied from xtd::collections::generic::icollection <type_t>. The xtd::array must have zero-based indexing. |
array_index | The zero-based index in array at which copying begins. |
xtd::argument_exception | The number of elements in the source xtd::collections::generic::icollection <type_t> is greater than the available space from `array_index` to the end of the destination `array`. |
Implemented in xtd::collections::generic::list< type_t, allocator_t >, xtd::array< type_t, 1, allocator_t >, xtd::basic_array< type_t, allocator_t >, xtd::basic_array< type_t, allocator_t >, and xtd::collections::object_model::read_only_collection< type_t >.
|
pure virtual |
Removes the first occurrence of a specific object from the xtd::collections::generic::icollection <type_t>.
item | The object to remove from the xtd::collections::generic::icollection <type_t>. |
xtd::not_supported_exception | The xtd::collections::generic::icollection <type_t> is read-only. |
Implemented in xtd::collections::generic::list< type_t, allocator_t >.