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"
10#include "system/collections/iread_only_collection.h"
13namespace Collections {
16template<
typename T,
typename SET_T>
22 ASPOSE_COLLECTION_POINTER_MODE_CONTROL(T)
70 BaseSet() : ASPOSE_COLLECTION_INIT_ALLOCATOR() {}
73 BaseSet(
int capacity) : ASPOSE_COLLECTION_INIT_ALLOCATOR()
79 m_data.reserve(capacity);
87 : m_data(8, hashAdapter, comparerAdapter, ASPOSE_COLLECTION_ALLOCATOR)
95 : m_data(comparerAdapter, ASPOSE_COLLECTION_ALLOCATOR)
102 auto e = items->GetEnumerator();
103 while (e->MoveNext())
104 m_data.insert(e->get_Current());
131 int get_Count()
const override {
return ASPOSECPP_CHECKED_CAST(
int, m_data.size()); }
135 void Add(
const T& item)
override
144 if (m_data.find(item) != m_data.end())
155 auto it = m_data.find(item);
156 if (it == m_data.end())
172 return m_data.find(item) != m_data.end();
177 if (other ==
nullptr)
179 throw ArgumentNullException(u
"other");
182 auto enumerator = other->GetEnumerator();
183 while (enumerator->MoveNext())
185 if (!Contains(enumerator->get_Current()))
187 Add(enumerator->get_Current());
202 std::for_each(list.begin(), list.end(), [
this](
const T &v) { m_data.insert(v); });
206 using BaseType::get_Count;
214 throw ArgumentNullException();
219 if (
index + get_Count() > arr->get_Length())
223 while (e->MoveNext())
224 (*arr)[
index++] = e->get_Current();
230 return new System::Details::NativeIteratorWrapper<T, iterator>(m_data.begin(), m_data.end());
235 return new System::Details::NativeIteratorWrapper<T, iterator>(m_data.end(), m_data.end());
240 return new System::Details::NativeConstIteratorWrapper<T, const_iterator>(m_data.begin(), m_data.end());
245 return new System::Details::NativeConstIteratorWrapper<T, const_iterator>(m_data.end(), m_data.end());
248#ifdef __DBG_FOR_EACH_MEMBER
252 void DBG_for_each_member(DBG::for_each_member_visitor &visitor)
const override
254 visitor.add_self(
this);
255 DBG::for_each_of_Object(
this, m_data, visitor);
259 const char* DBG_class_name()
const override {
return "BaseSet<T>"; }
265#ifdef ASPOSE_GET_SHARED_MEMBERS
267 DEFINE_GET_SHARED_MEMBERS(m_data);
Enumerator class. Objects of this class should only be allocated using System::MakeObject() function....
Definition: base_set.h:57
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:63
Definition: base_set.h:21
System::Details::VirtualizedIteratorBase< T > * virtualizeEndIterator() override
Gets the implementation of end iterator for the current container.
Definition: base_set.h:233
const_iterator begin() const noexcept
Gets iterator to the first element of the const-qualified collection.
Definition: base_set.h:110
void Add(const T &item) override
Adds element into set.
Definition: base_set.h:135
void UnionWith(const SharedPtr< IEnumerable< T > > &other)
Definition: base_set.h:175
bool TryAdd(const T &item)
Adds element into set.
Definition: base_set.h:142
typename set_t::const_iterator const_iterator
Const iterator type.
Definition: base_set.h:34
BaseSet()
Creates empty set.
Definition: base_set.h:70
System::Details::VirtualizedIteratorBase< T > * virtualizeBeginIterator() override
Gets the implementation of begin iterator for the current container.
Definition: base_set.h:228
set_t m_data
Internal data structure.
Definition: base_set.h:40
BaseSet(int capacity)
Creates empty set with specified capacity.
Definition: base_set.h:73
BaseSet(const SharedPtr< IEnumerable< T > > &items)
Creates set based on enumerable values.
Definition: base_set.h:100
const_iterator cbegin() const noexcept
Gets iterator to the first const-qualified element of collection.
Definition: base_set.h:117
BaseSet(const ComparerAdapter< T > &comparerAdapter)
Creates empty set that uses the specified comparer adapter Used for creation SortedSet.
Definition: base_set.h:94
bool Remove(const T &item) override
Removes element from set.
Definition: base_set.h:153
int get_Count() const override
Gets number of elements in set.
Definition: base_set.h:131
SET_T set_t
Underlying data type.
Definition: base_set.h:30
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:200
typename set_t::iterator iterator
Iterator type.
Definition: base_set.h:32
System::Details::VirtualizedIteratorBase< T > * virtualizeEndConstIterator() const override
Gets the implementation of end const iterator for the current container.
Definition: base_set.h:243
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:86
set_t & data()
Underlying data structure accessor.
Definition: base_set.h:194
~BaseSet() override
Destructor.
Definition: base_set.h:264
bool Contains(const T &item) const override
Checks if element is present in set.
Definition: base_set.h:170
const_iterator cend() const noexcept
Gets iterator for a non-existent const-qualified element behind the end of the collection.
Definition: base_set.h:120
IEnumeratorPtr GetEnumerator() override
Creates enumerator.
Definition: base_set.h:124
T ValueType
Value type.
Definition: base_set.h:44
const_iterator end() const noexcept
Gets iterator for a non-existent element behind the end of the const-qualified collection.
Definition: base_set.h:113
void Clear() override
Deletes all elements in set.
Definition: base_set.h:163
System::Details::VirtualizedIteratorBase< T > * virtualizeBeginConstIterator() const override
Gets the implementation of begin const iterator for the current container.
Definition: base_set.h:238
void CopyTo(ArrayPtr< T > arr, int index) override
Copies hash contents into existing array elements.
Definition: base_set.h:211
const set_t & data() const
Underlying data structure accessor.
Definition: base_set.h:197
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:26
Interface of read-only collection of elements. Objects of this class should only be allocated using S...
Definition: iread_only_collection.h:19
Iterator class for simple containers holding elements directly using rbegin() and rend() functions....
Definition: base_enumerator.h:98
Template that represents wrapper of exceptions that are derived from Exception class.
Definition: exception.h:118
Base class that enables using methods available for System.Object class in C#. All non-trivial classe...
Definition: object.h:51
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:1640
System::ExceptionWrapper< Details_ArgumentOutOfRangeException > ArgumentOutOfRangeException
Definition: throw_helper.h:24
Adapter to use IComparer within STL environment. Uses IComparer if set; otherwise,...
Definition: icomparer.h:45
Adapter making it possible using IEqualityComparer with STL-styled collections and algorithms....
Definition: iequality_comparer.h:39
Adapter to use IEqualityComparer for hashing. Uses comparator object, if set; otherwise,...
Definition: iequality_comparer.h:181