2#ifndef _aspose_system_collections_dictionary_h_
3#define _aspose_system_collections_dictionary_h_
5#include "system/object.h"
6#include "system/collections/base_dictionary.h"
7#include "system/collections/keyvalue_collection.h"
8#include "system/collections/iequality_comparer.h"
9#include "system/cycles_detection.h"
10#include "system/iequatable.h"
12#include <unordered_map>
15namespace Collections {
19template<
typename T,
typename V>
class Dictionary;
26template<
typename T,
typename V>
43 return (**
this)[T(key)];
93template<
typename TKey,
typename TValue>
95 :
public BaseDictionary<std::unordered_map<TKey, TValue, EqualityComparerHashAdapter<TKey>, EqualityComparerAdapter<TKey>, ASPOSE_MAP_ALLOCATOR_TYPE(TKey, TValue)> >
105 RTTI_INFO_TEMPLATE_CLASS(
ThisType, System::BaseTypesInfo<BaseType_>);
177 System::Details::VirtualizedIteratorBase<KVPair>*
CloneIterator()
const override
198 return MakeObject<_KeyCollection<Dictionary<TKey, TValue>>>(
MakeSharedPtr(
this));
204 return MakeObject<_ValueCollection<Dictionary<TKey, TValue>>>(
MakeSharedPtr(
this));
207#ifdef ASPOSE_GET_SHARED_MEMBERS
209 DEFINE_GET_SHARED_MEMBERS(BaseType::m_map)
218 virtual bool Equals(T x, T y)
const override
225 return obj->GetHashCode();
230 typename std::enable_if<IsSmartPtr<T>::value && std::is_base_of<IEquatable<T>,
typename T::Pointee_>::value, SharedPtr<IEqualityComparer<T>> >::type GetDefaultComparer()
232 return MakeObject<DefaultComparer<T>>();
236 typename std::enable_if<IsSmartPtr<T>::value && !std::is_base_of<IEquatable<T>,
typename T::Pointee_>::value, SharedPtr<IEqualityComparer<T>> >::type GetDefaultComparer()
238 return SharedPtr<IEqualityComparer<T> >();
242 typename std::enable_if<!IsSmartPtr<T>::value, SharedPtr<IEqualityComparer<T>> >::type GetDefaultComparer()
244 return SharedPtr<IEqualityComparer<T> >();
247#ifdef __DBG_FOR_EACH_MEMBER
251 void DBG_for_each_member(DBG::for_each_member_visitor &visitor)
const override
253 BaseType::DBG_for_each_member(visitor);
255 visitor.add_self(
this);
260 const char* DBG_class_name()
const override {
return "Dictionary<T>"; }
Implements common code for various dictionary-alike data structures (e. g. Dictionary,...
Definition: base_dictionary.h:100
Default comparator class. Uses operator < and operator == to compare values. Objects of this class sh...
Definition: icomparer.h:97
Enumerator that allows iterating through the dictionary. Objects of this class should only be allocat...
Definition: dictionary.h:166
System::Details::VirtualizedIteratorBase< KVPair > * CloneIterator() const override
Clones current iterator.
Definition: dictionary.h:177
RTTI_INFO_TEMPLATE_CLASS(EnumeratorType, System::BaseTypesInfo< System::Object >)
RTTI information.
Enumerator(Ptr dict)
Creates enumerator.
Definition: dictionary.h:172
Forward declaration of Dictionary class.
Definition: dictionary.h:96
std::unordered_map< TKey, TValue, EqualityComparerHashAdapter< TKey >, EqualityComparerAdapter< TKey >, ASPOSE_MAP_ALLOCATOR_TYPE(TKey, TValue)> map_t
Underlying data type.
Definition: dictionary.h:113
SharedPtr< Dictionary< TKey, TValue > > Ptr
Pointer type.
Definition: dictionary.h:116
Dictionary(const map_t &map)
Copies data from map.
Definition: dictionary.h:130
Dictionary(const SharedPtr< IDictionary< TKey, TValue > > &src)
Copy constructor.
Definition: dictionary.h:140
Dictionary(int capacity)
Overload which corresponds to creating pre-allocated dictionary; does no allocation,...
Definition: dictionary.h:135
Dictionary()
Creates empty dictionary.
Definition: dictionary.h:125
SharedPtr< ValueCollection > get_ValuesInternal() const override
Implementation of internal value collection accessor.
Definition: dictionary.h:202
~Dictionary() override
Destructor.
Definition: dictionary.h:192
ICollection< TKey > KeyCollection
Collection of keys to extract.
Definition: dictionary.h:109
Dictionary(int capacity, const SharedPtr< IEqualityComparer< TKey > > &comparer)
Creates empty dictionary.
Definition: dictionary.h:157
Dictionary(const SharedPtr< IEqualityComparer< TKey > > &comparer)
Creates empty dictionary.
Definition: dictionary.h:151
Dictionary(const SharedPtr< IDictionary< TKey, TValue > > &src, const SharedPtr< IEqualityComparer< TKey > > &comparer)
Copy constructor.
Definition: dictionary.h:146
SharedPtr< IEnumerator< KVPair > > IEnumeratorPtr
Pointer to enumerator.
Definition: dictionary.h:122
SharedPtr< IEnumerable< KVPair > > IEnumerablePtr
Pointer to enumerable interface.
Definition: dictionary.h:120
ICollection< TValue > ValueCollection
Collection of values to extract.
Definition: dictionary.h:111
KeyValuePair< TKey, TValue > KVPair
Key-value pair type.
Definition: dictionary.h:118
SharedPtr< KeyCollection > get_KeysInternal() const override
Implementation of internal keys collection accessor.
Definition: dictionary.h:196
virtual IEnumeratorPtr GetEnumerator() override
Creates enumerator object.
Definition: dictionary.h:185
Dictionary pointer class with operator overloads. This type is a pointer to manage other object's del...
Definition: dictionary.h:28
DictionaryPtr(const SharedPtr< Dictionary< T, V > > &obj)
Converts pointer type.
Definition: dictionary.h:34
DictionaryPtr()
Initializes null pointer.
Definition: dictionary.h:31
Interface of collection of elements. Objects of this class should only be allocated using System::Mak...
Definition: icollection.h:20
Interface for dictionary-alike containers. Objects of this class should only be allocated using Syste...
Definition: idictionary.h:21
Interface providing means to compare two objects for equality. Objects of this class should only be a...
Definition: iequality_comparer.h:17
Pair of key and value. This type should be allocated on stack and passed to functions by value or by ...
Definition: keyvalue_pair.h:20
Iterator class for simple containers holding elements directly using rbegin() and rend() functions....
Definition: base_enumerator.h:81
Pointer class to wrap types being allocated on heap. Use it to manage memory for classes inheriting O...
Definition: smart_ptr.h:180
decltype(System::Details::GetByIndex(std::declval< const SmartPtr_ * >(), std::declval< IdxType >()) operator[])(IdxType idx) const
Accessor for array elements. Only compiles if SmartPtr_ is specialization of System::Array.
Definition: smart_ptr.h:822
Definition: db_command.h:9
bool Equals(const TA &a, const TB &b)
Determines the equality of two values applying operator==() to them.
Definition: primitive_types.h:77
SmartPtr< X > MakeSharedPtr(X *p)
Converts raw pointer to smart pointer.
Definition: smart_ptr.h:1650
std::enable_if< std::is_scalar< T >::value, int >::type GetHashCode(const T &obj)
Returns a hash code for the specified scalar value.
Definition: get_hash_code.h:21
Adapter making it possible using IEqualityComparer with STL-styled collections and algorithms....
Definition: iequality_comparer.h:38
Adapter to use IEqualityComparer for hashing. Uses comparator object, if set; otherwise,...
Definition: iequality_comparer.h:159