3#include "system/object.h"
4#include "system/array.h"
5#include <system/exceptions.h>
6#include "system/collections/iset.h"
7#include "system/collections/base_enumerator.h"
8#include "system/cycles_detection.h"
9#include "system/collections/iequality_comparer.h"
12namespace Collections {
15template<
typename T,
typename SET_T>
20 ASPOSE_COLLECTION_POINTER_MODE_CONTROL(T)
68 BaseSet() : ASPOSE_COLLECTION_INIT_ALLOCATOR() {}
71 BaseSet(
int capacity) : ASPOSE_COLLECTION_INIT_ALLOCATOR()
75 throw ArgumentOutOfRangeException(u
"capacity");
77 m_data.reserve(capacity);
85 : m_data(8, hashAdapter, comparerAdapter, ASPOSE_COLLECTION_ALLOCATOR)
93 : m_data(comparerAdapter, ASPOSE_COLLECTION_ALLOCATOR)
100 auto e = items->GetEnumerator();
101 while (e->MoveNext())
102 m_data.insert(e->get_Current());
129 int get_Count()
const override {
return ASPOSECPP_CHECKED_CAST(
int, m_data.size()); }
133 void Add(
const T& item)
override
142 if (m_data.find(item) != m_data.end())
153 auto it = m_data.find(item);
154 if (it == m_data.end())
170 return m_data.find(item) != m_data.end();
183 std::for_each(list.begin(), list.end(), [
this](
const T &v) { m_data.insert(v); });
187 using BaseType::get_Count;
195 throw ArgumentNullException();
198 throw ArgumentOutOfRangeException();
200 if (index + get_Count() > arr->get_Length())
201 throw ArgumentException();
204 while (e->MoveNext())
205 (*arr)[index++] = e->get_Current();
211 return new System::Details::NativeIteratorWrapper<T, iterator>(m_data.begin(), m_data.end());
216 return new System::Details::NativeIteratorWrapper<T, iterator>(m_data.end(), m_data.end());
221 return new System::Details::NativeConstIteratorWrapper<T, const_iterator>(m_data.begin(), m_data.end());
226 return new System::Details::NativeConstIteratorWrapper<T, const_iterator>(m_data.end(), m_data.end());
229#ifdef __DBG_FOR_EACH_MEMBER
233 void DBG_for_each_member(DBG::for_each_member_visitor &visitor)
const override
235 visitor.add_self(
this);
236 DBG::for_each_of_Object(
this, m_data, visitor);
240 const char* DBG_class_name()
const override {
return "BaseSet<T>"; }
246#ifdef ASPOSE_GET_SHARED_MEMBERS
248 DEFINE_GET_SHARED_MEMBERS(m_data);
Enumerator class. Objects of this class should only be allocated using System::MakeObject() function....
Definition: base_set.h:55
RTTI_INFO_TEMPLATE_CLASS(ThisType, System::BaseTypesInfo< System::Object >)
RTTI information.
Enumerator(const ThisPtr &set)
Creates enumerator iterating through set object.
Definition: base_set.h:61
Definition: base_set.h:19
System::Details::VirtualizedIteratorBase< T > * virtualizeEndIterator() override
Gets the implementation of end iterator for the current container.
Definition: base_set.h:214
const_iterator begin() const noexcept
Gets iterator to the first element of the const-qualified collection.
Definition: base_set.h:108
void Add(const T &item) override
Adds element into set.
Definition: base_set.h:133
bool TryAdd(const T &item)
Adds element into set.
Definition: base_set.h:140
typename set_t::const_iterator const_iterator
Const iterator type.
Definition: base_set.h:32
BaseSet()
Creates empty set.
Definition: base_set.h:68
System::Details::VirtualizedIteratorBase< T > * virtualizeBeginIterator() override
Gets the implementation of begin iterator for the current container.
Definition: base_set.h:209
set_t m_data
Internal data structure.
Definition: base_set.h:38
BaseSet(int capacity)
Creates empty set with specified capacity.
Definition: base_set.h:71
BaseSet(const SharedPtr< IEnumerable< T > > &items)
Creates set based on enumerable values.
Definition: base_set.h:98
const_iterator cbegin() const noexcept
Gets iterator to the first const-qualified element of collection.
Definition: base_set.h:115
BaseSet(const ComparerAdapter< T > &comparerAdapter)
Creates empty set that uses the specified comparer adapter Used for creation SortedSet.
Definition: base_set.h:92
bool Remove(const T &item) override
Removes element from set.
Definition: base_set.h:151
int get_Count() const override
Gets number of elements in set.
Definition: base_set.h:129
SET_T set_t
Underlying data type.
Definition: base_set.h:28
RTTI_INFO_TEMPLATE_CLASS(ThisType, System::BaseTypesInfo< System::Object >)
RTTI information.
void _add_range(std::initializer_list< T > list)
C++ specific.
Definition: base_set.h:181
typename set_t::iterator iterator
Iterator type.
Definition: base_set.h:30
System::Details::VirtualizedIteratorBase< T > * virtualizeEndConstIterator() const override
Gets the implementation of end const iterator for the current container.
Definition: base_set.h:224
BaseSet(const EqualityComparerHashAdapter< T > &hashAdapter, const EqualityComparerAdapter< T > &comparerAdapter)
Creates empty set that uses the specified equality comparer adapters Used for creation HashSet.
Definition: base_set.h:84
set_t & data()
Underlying data structure accessor.
Definition: base_set.h:175
~BaseSet() override
Destructor.
Definition: base_set.h:245
bool Contains(const T &item) const override
Checks if element is present in set.
Definition: base_set.h:168
const_iterator cend() const noexcept
Gets iterator for a non-existent const-qualified element behind the end of the collection.
Definition: base_set.h:118
IEnumeratorPtr GetEnumerator() override
Creates enumerator.
Definition: base_set.h:122
T ValueType
Value type.
Definition: base_set.h:42
const_iterator end() const noexcept
Gets iterator for a non-existent element behind the end of the const-qualified collection.
Definition: base_set.h:111
void Clear() override
Deletes all elements in set.
Definition: base_set.h:161
System::Details::VirtualizedIteratorBase< T > * virtualizeBeginConstIterator() const override
Gets the implementation of begin const iterator for the current container.
Definition: base_set.h:219
void CopyTo(ArrayPtr< T > arr, int index) override
Copies hash contents into existing array elements.
Definition: base_set.h:192
const set_t & data() const
Underlying data structure accessor.
Definition: base_set.h:178
Interface of collection of elements. Objects of this class should only be allocated using System::Mak...
Definition: icollection.h:20
Interface of object providing enumerator on contained elements.
Definition: ienumerable.h:25
Iterator class for simple containers holding elements directly using rbegin() and rend() functions....
Definition: base_enumerator.h:81
Base class that enables using methods available for System.Object class in C#. All non-trivial classe...
Definition: object.h:62
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
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