CodePorting.Translator Cs2Cpp
CodePorting.Translator.Cs2Cpp.Framework
sorted_dictionary.h
1
2#ifndef _aspose_system_collections_sorted_dictionary_h_
3#define _aspose_system_collections_sorted_dictionary_h_
4
5#include "system/object.h"
6#include "system/collections/base_dictionary.h"
7#include "system/collections/keyvalue_collection.h"
8#include "system/cycles_detection.h"
9
10#include <map>
11
12namespace System {
13namespace Collections {
14namespace Generic {
15
17template<typename T, typename V> class SortedDictionary;
18
22template<typename T, typename V>
23class ASPOSECPP_SHARED_CLASS SortedDictionaryPtr : public SharedPtr<SortedDictionary<T, V> >
24{
25public:
28 { }
32 { }
33
37 V& operator[] (const T& key) const
38 {
39 return (*(this->GetPointer()))[key];
40 }
41};
42
49template<typename TKey, typename TValue>
50class ASPOSECPP_SHARED_CLASS SortedDictionary
51 : public BaseDictionary<std::map<TKey, TValue, ComparerAdapter<typename BasePointerType<TKey>::type>, ASPOSE_MAP_ALLOCATOR_TYPE(TKey, TValue)> >
52{
58 RTTI_INFO_TEMPLATE_CLASS(_ThisType, System::BaseTypesInfo<_BaseType>);
59
60protected:
62 using _BaseType::m_map;
63
64public:
70 typedef std::map<TKey, TValue, ComparerAdapter<typename BasePointerType<TKey>::type>, ASPOSE_MAP_ALLOCATOR_TYPE(TKey, TValue)> map_t;
81
83 typedef typename _BaseType::iterator iterator;
87 typedef typename map_t::reverse_iterator reverse_iterator;
89 typedef typename map_t::const_reverse_iterator const_reverse_iterator;
90
94 {
96 static std::once_flag once;
97 std::call_once(once, [] { value = MakeObject<DefaultComparer<typename BasePointerType<TKey>::type>>(); });
98 return value;
99 }
100
103 {
105 }
108 SortedDictionary(const SharedPtr<IComparer<typename BasePointerType<TKey>::type> >& comparer)
109 : _BaseType(0, ComparerAdapter<typename BasePointerType<TKey>::type>(comparer))
110 {
111 m_comparer = comparer;
112 }
116 : _BaseType(src.get())
117 {
119 }
120
125 const SharedPtr<IComparer<typename BasePointerType<TKey>::type>>& comparer)
126 : _BaseType(src.get(), comparer)
127 {
128 m_comparer = comparer;
129 }
130
133 {
134 return m_comparer;
135 }
136
141 class Enumerator : public SimpleEnumerator<map_t, KVPair>
142 {
143 public:
146 Enumerator(const Ptr& dict) : SimpleEnumerator<map_t, KVPair>(dict, dict->m_map) { }
150 RTTI_INFO_TEMPLATE_CLASS(Enumerator, System::BaseTypesInfo<System::Object>);
151 };
155 {
156 return MakeObject<Enumerator>(MakeSharedPtr(this));
157 }
158
162 {
163 return m_map.rbegin();
164 }
169 {
170 return m_map.rend();
171 }
172
176 {
177 return m_map.rbegin();
178 }
183 {
184 return m_map.rend();
185 }
186
190 {
191 return rbegin();
192 }
197 {
198 return rend();
199 }
200
201protected:
203 ~SortedDictionary() override {}
204
208 {
209 return MakeObject<_KeyCollection<SortedDictionary<TKey, TValue>>>(MakeSharedPtr(this));
210 }
214 {
215 return MakeObject<_ValueCollection<SortedDictionary<TKey, TValue>>>(MakeSharedPtr(this));
216 }
217#ifdef ASPOSE_GET_SHARED_MEMBERS
219 DEFINE_GET_SHARED_MEMBERS(_BaseType::m_map)
220#endif
221
222private:
224};
225
226} // namespace Generic
227} // namespace Collections
228} // namespace System
229
230#endif // _aspose_system_collections_sorted_dictionary_h_
Implements common code for various dictionary-alike data structures (e. g. Dictionary,...
Definition: base_dictionary.h:100
Interface of collection of elements. Objects of this class should only be allocated using System::Mak...
Definition: icollection.h:20
Interface that compares two objects in greater-equal-less sense. Objects of this class should only be...
Definition: icomparer.h:20
Interface for dictionary-alike containers. Objects of this class should only be allocated using Syste...
Definition: idictionary.h:21
Adapting iterator, wraps std::pair into KVPair expected from Dictionary.
Definition: base_enumerator.h:109
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
Enumerator type to iterate through dictionary. Objects of this class should only be allocated using S...
Definition: sorted_dictionary.h:142
Enumerator(const Ptr &dict)
Constructs enumerator over specific dictionary.
Definition: sorted_dictionary.h:146
RTTI_INFO_TEMPLATE_CLASS(Enumerator, System::BaseTypesInfo< System::Object >)
RTTI information.
SortedDictionary< TKey, TValue >::Enumerator EnumeratorType
Enumerator type alias.
Definition: sorted_dictionary.h:148
Sorted dictionary type forward declaration.
Definition: sorted_dictionary.h:52
map_t::reverse_iterator reverse_iterator
Reverse iterator type.
Definition: sorted_dictionary.h:87
SharedPtr< ValueCollection > get_ValuesInternal() const override
Implementation of get_ValuesInternal() method.
Definition: sorted_dictionary.h:213
ICollection< TValue > ValueCollection
Value collection type.
Definition: sorted_dictionary.h:68
_BaseType::iterator iterator
Iterator type.
Definition: sorted_dictionary.h:83
_BaseType::const_iterator const_iterator
Const iterator type.
Definition: sorted_dictionary.h:85
const_reverse_iterator crbegin() const noexcept
Gets a reverse iterator to the last const-qualified element of collection (first in reverse).
Definition: sorted_dictionary.h:189
SharedPtr< KeyCollection > get_KeysInternal() const override
Implementation of get_KeysInternal() method.
Definition: sorted_dictionary.h:207
KeyValuePair< TKey, TValue > KVPair
Key-value pair type.
Definition: sorted_dictionary.h:76
SharedPtr< this_t > Ptr
Pointer type.
Definition: sorted_dictionary.h:74
const_reverse_iterator crend() const noexcept
Gets a reverse iterator for a non-existent const-qualified element before the start of the collection...
Definition: sorted_dictionary.h:196
SharedPtr< IEnumerator< KVPair > > IEnumeratorPtr
Enumerator type.
Definition: sorted_dictionary.h:80
SortedDictionary< TKey, TValue > this_t
Self type.
Definition: sorted_dictionary.h:72
SharedPtr< System::Collections::Generic::IComparer< TKey > > get_Comparer() const
Gets the IComparer<TKey> used to order the elements of the SortedDictionary<TKey,TValue>.
Definition: sorted_dictionary.h:132
const_reverse_iterator rbegin() const noexcept
Gets a reverse iterator to the last element of the const-qualified collection (first in reverse).
Definition: sorted_dictionary.h:175
std::map< TKey, TValue, ComparerAdapter< typename BasePointerType< TKey >::type >, ASPOSE_MAP_ALLOCATOR_TYPE(TKey, TValue)> map_t
Underlying data type.
Definition: sorted_dictionary.h:70
map_t::const_reverse_iterator const_reverse_iterator
Const reverse iterator type.
Definition: sorted_dictionary.h:89
static SharedPtr< IComparer< typename BasePointerType< TKey >::type > > GetDefaultKeyComparer()
Singleton accessor function.
Definition: sorted_dictionary.h:93
SortedDictionary(const SharedPtr< IDictionary< TKey, TValue > > &src)
Copy constructor.
Definition: sorted_dictionary.h:115
SortedDictionary()
Constructs empty dictionary.
Definition: sorted_dictionary.h:102
ICollection< TKey > KeyCollection
Key collection type.
Definition: sorted_dictionary.h:66
IEnumeratorPtr GetEnumerator() override
Gets enumerator to iterate through current dictionary.
Definition: sorted_dictionary.h:154
const_reverse_iterator rend() const noexcept
Gets a reverse iterator for a non-existent element before the start of the const-qualified collection...
Definition: sorted_dictionary.h:182
SortedDictionary(const SharedPtr< IDictionary< TKey, TValue > > &src, const SharedPtr< IComparer< typename BasePointerType< TKey >::type > > &comparer)
Copy constructor.
Definition: sorted_dictionary.h:124
SortedDictionary(const SharedPtr< IComparer< typename BasePointerType< TKey >::type > > &comparer)
Constructs empty dictionary.
Definition: sorted_dictionary.h:108
reverse_iterator rend() noexcept
Gets a reverse iterator for a non-existent element before the start of the collection.
Definition: sorted_dictionary.h:168
~SortedDictionary() override
Destructor.
Definition: sorted_dictionary.h:203
SharedPtr< IEnumerable< KVPair > > IEnumerablePtr
Collection of same elements.
Definition: sorted_dictionary.h:78
reverse_iterator rbegin() noexcept
Gets a reverse iterator to the last element of collection (first in reverse).
Definition: sorted_dictionary.h:161
Sorted dictionary pointer with access operators. This type is a pointer to manage other object's dele...
Definition: sorted_dictionary.h:24
SortedDictionaryPtr(const SharedPtr< SortedDictionary< T, V > > &obj)
Constructs pointer to specified sorted dictionary.
Definition: sorted_dictionary.h:31
SortedDictionaryPtr()
Constructs null pointer.
Definition: sorted_dictionary.h:27
Pointer class to wrap types being allocated on heap. Use it to manage memory for classes inheriting O...
Definition: smart_ptr.h:180
Definition: db_command.h:9
SmartPtr< X > MakeSharedPtr(X *p)
Converts raw pointer to smart pointer.
Definition: smart_ptr.h:1650
Adapter to use IComparer within STL environment. Uses IComparer if set; otherwise,...
Definition: icomparer.h:44