xtd 0.2.0
xtd::collections::generic::idictionary< key_t, value_t > Class Template Referenceabstract
Inheritance diagram for xtd::collections::generic::idictionary< key_t, value_t >:
xtd::collections::generic::dictionary< xtd::string, xtd::string > xtd::collections::generic::dictionary< key_t, value_t, hasher_t, equator_t, allocator_t >

Definition

template<class key_t, class value_t>
class xtd::collections::generic::idictionary< key_t, value_t >

Represents a generic collection of key/value pairs.

Definition
template<class key_t, class value_t>
class idictionary : public xtd::collections::generic::icollection<xtd::collections::generic::key_value_pair<key_t, value_t>>;
Represents a generic collection of key/value pairs.
Definition idictionary.hpp:44
Header
#include <xtd/collections/generic/idictionary>
Namespace
xtd::collections::generic
Library
xtd.core
Remarks
The xtd::collections::generic::idictionary <key_t, value_t> interface is the base interface for generic collections of key/value pairs.
Each element is a key/value pair stored in a xtd::collections::generic::key_value_pair <key_t, value_t> object.
Each pair must have a unique key. Implementations can vary in whether they allow key to be empty. The value can be empty and does not have to be unique. The idictionary <key_t, value_t> interface allows the contained keys and values to be enumerated, but it does not imply any particular sort order.
The for each statement returns an object of the type of the elements in the collection. Since each element of the xtd::collections::generic::idictionary <key_t, value_t> is a key/value pair, the element type is not the type of the key or the type of the value. Instead, the element type is xtd::collections::generic::key_value_pair <key_t, value_t>. For example:
for (const key_value_pair<int, string>& kvp : my_dictionary)
console::write_line("key = {}, value = {}", kvp.key(), kvp.value());
static void write_line()
Writes the current line terminator to the standard output stream using the specified format informati...
Defines a key/value pair that can be set or retrieved.
Definition key_value_pair.hpp:37
Or with auto key type and the value type. For example:
for (const auto& [key, value] : my_dictionary)
console::write_line("key = {}, value = {}", key, value);

Public Aliases

using key_type
 Represents the dictionary key type.
 
using mapped_type
 Represents the dictionary mapped type.
 
using value_type
 Represents the xtd::collections::generic::idictionary value type.
 
using iterator
 Represents the iterator of xtd::collections::generic::ienumerable value type.
 
using const_iterator
 Represents the const iterator of xtd::collections::generic::ienumerable value type.
 
using key_collection
 Represents the idictionary key collection type.
 
using value_collection
 Represents the idictionary value collection type.
 

Public Properties

virtual key_collection keys () const noexcept=0
 Gets an xtd::collections::generic::icollection <type_t> containing the keys of the xtd::collections::generic::idictionary <key_t, value_t>.
 
virtual value_collection values () const noexcept=0
 Gets an xtd::collections::generic::icollection <type_t> containing the values of the xtd::collections::generic::idictionary <key_t, value_t>.
 

Public Methods

virtual void add (const key_t &key, const value_t value)=0
 Adds an element with the provided key and value to the xtd::collections::generic::idictionary <key_t, value_t>.
 
virtual bool contains_key (const key_t &key) const noexcept=0
 Determines whether the xtd::collections::generic::idictionary <key_t, value_t> contains an element with the specified key.
 
virtual bool remove (const key_t &key) noexcept=0
 Removes the element with the specified key from the xtd::collections::generic::idictionary <key_t, value_t>.
 
virtual bool try_get_value (const key_t &key, value_t &value) const =0
 Gets the value associated with the specified key.
 

Public Operators

virtual value_t & operator[] (const key_t &key)=0
 Sets the element with the specified key. /.
 

Member Typedef Documentation

◆ key_type

template<class key_t, class value_t>
using xtd::collections::generic::idictionary< key_t, value_t >::key_type

Represents the dictionary key type.

◆ mapped_type

template<class key_t, class value_t>
using xtd::collections::generic::idictionary< key_t, value_t >::mapped_type

Represents the dictionary mapped type.

◆ value_type

template<class key_t, class value_t>
using xtd::collections::generic::idictionary< key_t, value_t >::value_type

Represents the xtd::collections::generic::idictionary value type.

◆ iterator

template<class key_t, class value_t>
using xtd::collections::generic::idictionary< key_t, value_t >::iterator

Represents the iterator of xtd::collections::generic::ienumerable value type.

◆ const_iterator

template<class key_t, class value_t>
using xtd::collections::generic::idictionary< key_t, value_t >::const_iterator

Represents the const iterator of xtd::collections::generic::ienumerable value type.

◆ key_collection

template<class key_t, class value_t>
using xtd::collections::generic::idictionary< key_t, value_t >::key_collection

Represents the idictionary key collection type.

◆ value_collection

template<class key_t, class value_t>
using xtd::collections::generic::idictionary< key_t, value_t >::value_collection

Represents the idictionary value collection type.

Member Function Documentation

◆ keys()

template<class key_t, class value_t>
virtual key_collection xtd::collections::generic::idictionary< key_t, value_t >::keys ( ) const
pure virtualnoexcept

Gets an xtd::collections::generic::icollection <type_t> containing the keys of the xtd::collections::generic::idictionary <key_t, value_t>.

Returns
An xtd::collections::generic::icollection <type_t> containing the keys of the object that implements xtd::collections::generic::idictionary <key_t, value_t>.
Remarks
The order of the keys in the returned xtd::collections::generic::icollection <type_t> is unspecified, but it is guaranteed to be the same order as the corresponding values in the xtd::collections::generic::icollection <type_t> returned by the xtd::collections::generic::idictionary::values property.

Implemented in xtd::collections::generic::dictionary< key_t, value_t, hasher_t, equator_t, allocator_t >, xtd::collections::generic::dictionary< xtd::any_object, xtd::any_object >, xtd::collections::generic::dictionary< xtd::any_object, xtd::any_object >, xtd::collections::generic::dictionary< xtd::string, xtd::string >, and xtd::collections::generic::dictionary< xtd::string, xtd::string >.

◆ values()

template<class key_t, class value_t>
virtual value_collection xtd::collections::generic::idictionary< key_t, value_t >::values ( ) const
pure virtualnoexcept

Gets an xtd::collections::generic::icollection <type_t> containing the values of the xtd::collections::generic::idictionary <key_t, value_t>.

Returns
An xtd::collections::generic::icollection <type_t> containing the values of the object that implements xtd::collections::generic::idictionary <key_t, value_t>.
Remarks
The order of the values in the returned xtd::collections::generic::icollection <type_t> is unspecified, but it is guaranteed to be the same order as the corresponding values in the xtd::collections::generic::icollection <type_t> returned by the xtd::collections::generic::idictionary::keys property.

Implemented in xtd::collections::generic::dictionary< key_t, value_t, hasher_t, equator_t, allocator_t >, xtd::collections::generic::dictionary< xtd::any_object, xtd::any_object >, xtd::collections::generic::dictionary< xtd::any_object, xtd::any_object >, xtd::collections::generic::dictionary< xtd::string, xtd::string >, and xtd::collections::generic::dictionary< xtd::string, xtd::string >.

◆ add()

template<class key_t, class value_t>
virtual void xtd::collections::generic::idictionary< key_t, value_t >::add ( const key_t & key,
const value_t value )
pure virtual

Adds an element with the provided key and value to the xtd::collections::generic::idictionary <key_t, value_t>.

Parameters
keyThe object to use as the key of the element to add.
valueThe object to use as the value of the element to add.
Exceptions
xtd::argument_exceptionAn element with the same key already exists in the xtd::collections::generic::idictionary <key_t, value_t>.
xtd::not_supported_exceptionThe xtd::collections::generic::idictionary <key_t, value_t> is read-only.
Remarks
You can also use the operator [] to add new elements by setting the value of a key that does not exist in the dictionary; for example, my_collection["my_nonexistent_key"] = my_value. However, if the specified key already exists in the dictionary, setting the operator [] overwrites the old value. In contrast, the xtd::collections::generic::idictionary::add method does not modify existing elements.
Implementations can vary in how they determine equality of objects; for example, the xtd::collections::generic::list <type_t> class uses xtd::collections::generic::comparer::default_comparer, whereas the xtd::collections::generic::dictionary <key_t,value_t> class allows the user to specify the xtd::collections::generic::icomparer <type_t> implementation to use for comparing keys.

Implemented in xtd::collections::generic::dictionary< key_t, value_t, hasher_t, equator_t, allocator_t >, xtd::collections::generic::dictionary< xtd::any_object, xtd::any_object >, and xtd::collections::generic::dictionary< xtd::any_object, xtd::any_object >.

◆ contains_key()

template<class key_t, class value_t>
virtual bool xtd::collections::generic::idictionary< key_t, value_t >::contains_key ( const key_t & key) const
pure virtualnoexcept

Determines whether the xtd::collections::generic::idictionary <key_t, value_t> contains an element with the specified key.

Parameters
keyThe key to locate in the xtd::collections::generic::idictionary <key_t, value_t>.
Returns
true if the xtd::collections::generic::idictionary <key_t, value_t> contains an element with the key; otherwise, false.
Remarks
Implementations can vary in how they determine equality of objects; for example, the xtd::collections::generic::list <type_t> class uses xtd::collections::generic::comparer <type_t>.Default, whereas the xtd::collections::generic::dictionary <key_t, value_t> class allows the user to specify the xtd::collections::generic::icomparer <type_t>x implementation to use for comparing keys.

Implemented in xtd::collections::generic::dictionary< key_t, value_t, hasher_t, equator_t, allocator_t >, xtd::collections::generic::dictionary< xtd::any_object, xtd::any_object >, and xtd::collections::generic::dictionary< xtd::any_object, xtd::any_object >.

◆ remove()

template<class key_t, class value_t>
virtual bool xtd::collections::generic::idictionary< key_t, value_t >::remove ( const key_t & key)
pure virtualnoexcept

Removes the element with the specified key from the xtd::collections::generic::idictionary <key_t, value_t>.

Parameters
keyThe key of the element to remove.
Returns
true if the element is successfully removed; otherwise, false. This method also returns false if key was not found in the original xtd::collections::generic::idictionary <key_t, value_t>.
Remarks
Implementations can vary in how they determine equality of objects; for example, the xtd::collections::generic::list <type_t> class uses xtd::collections::generic::comparer <type_t>.Default, whereas the xtd::collections::generic::dictionary <key_t, value_t> class allows the user to specify the xtd::collections::generic::icomparer <type_t>x implementation to use for comparing keys.

Implemented in xtd::collections::generic::dictionary< key_t, value_t, hasher_t, equator_t, allocator_t >, xtd::collections::generic::dictionary< xtd::any_object, xtd::any_object >, and xtd::collections::generic::dictionary< xtd::any_object, xtd::any_object >.

◆ try_get_value()

template<class key_t, class value_t>
virtual bool xtd::collections::generic::idictionary< key_t, value_t >::try_get_value ( const key_t & key,
value_t & value ) const
pure virtual

Gets the value associated with the specified key.

Parameters
keyThe key whose value to get.
valueWhen this method returns, the value associated with the specified key, if the key is found; otherwise, the default value for the type of the value parameter.
Returns
true if the object that implements xtd::collections::generic::idictionary <key_t, value_t> contains an element with the specified key; otherwise, false.
Remarks
This method combines the functionality of the xtd::collections::generic::idictionary::contains_key method and the xtd::collections::generic::idictionary::operator [] property.
If the key is not found, then the value parameter gets the appropriate default value for the type value_t; for example, zero (0) for integer types, false for Boolean types, and null for reference types

Implemented in xtd::collections::generic::dictionary< key_t, value_t, hasher_t, equator_t, allocator_t >, xtd::collections::generic::dictionary< xtd::any_object, xtd::any_object >, and xtd::collections::generic::dictionary< xtd::any_object, xtd::any_object >.

◆ operator[]()

template<class key_t, class value_t>
virtual value_t & xtd::collections::generic::idictionary< key_t, value_t >::operator[] ( const key_t & key)
pure virtual

Sets the element with the specified key. /.

        @brief Gets the element with the specified key.
        @param key The key of the element to get.
        @return The element with the specified key.
        @exception xtd::collections::generic::key_not_found_exception The property is retrieved and key is not found.
        @exception xtd::not_supported_exception The property is set and the xtd::collections::generic::idictionary <key_t, value_t> is read-only.
        @remarks This property provides the ability to access a specific element in the collection by using the following syntax: `my_collection[key]`.
        @remarks You can also use the `operator []` to add new elements by setting the value of a key that does not exist in the dictionary; for example, `my_collection["my_nonexistent_key"] = my_value`. However, if the specified key already exists in the dictionary, setting the `o`perator []` overwrites the old value. In contrast, the xtd::collections::generic::idictionary::add method does not modify existing elements.

/

Remarks
Implementations can vary in how they determine equality of objects; for example, the xtd::collections::generic::list <type_t> class uses xtd::collections::generic::comparer::default_comparer, whereas the xtd::collections::generic::dictionary <key_t,value_t> class allows the user to specify the xtd::collections::generic::icomparer <type_t> implementation to use for comparing keys. virtual const value_t& operator [](const key_t& key) const = 0; /
Parameters
keyThe key of the element to set. /
Returns
The element with the specified key. /
Exceptions
xtd::collections::generic::key_not_found_exceptionThe property is retrieved and key is not found. /
xtd::not_supported_exceptionThe property is set and the xtd::collections::generic::idictionary <key_t, value_t> is read-only. /
Remarks
This property provides the ability to access a specific element in the collection by using the following syntax: my_collection[key]. /
You can also use the operator [] to add new elements by setting the value of a key that does not exist in the dictionary; for example, my_collection["my_nonexistent_key"] = my_value. However, if the specified key already exists in the dictionary, setting the operator [] overwrites the old value. In contrast, the xtd::collections::generic::idictionary::add method does not modify existing elements.
Implementations can vary in how they determine equality of objects; for example, the xtd::collections::generic::list <type_t> class uses xtd::collections::generic::comparer::default_comparer, whereas the xtd::collections::generic::dictionary <key_t,value_t> class allows the user to specify the xtd::collections::generic::icomparer <type_t> implementation to use for comparing keys.

Implemented in xtd::collections::generic::dictionary< key_t, value_t, hasher_t, equator_t, allocator_t >, xtd::collections::generic::dictionary< xtd::any_object, xtd::any_object >, and xtd::collections::generic::dictionary< xtd::any_object, xtd::any_object >.


The documentation for this class was generated from the following file: