SetInterface< TYPE > Class Template Reference

#include <set.h>

Inheritance diagram for SetInterface< TYPE >:

Detailed Description

template<typename TYPE>
class maxon::SetInterface< TYPE >

SetInterface is an interface which provides the usual set functions as virtual methods. Each standard set of the MAXON API can be represented as such an interface, so this allows to write non-template functions which nevertheless are able to deal with any kind of set.

The access to the set happens via virtual methods, so there is an inevitable performance penalty, but this will be negligible for most use cases.

For a set which shall be modified, use WritableSetInterface as type of the function parameter instead.

Template Parameters
TYPEType of elements of the set.

Classes

class  IteratorTemplate
 

Public Types

using ValueType = TYPE
 
using Iterator = IteratorTemplate< false >
 
using ConstIterator = IteratorTemplate< true >
 
- Public Types inherited from SetBase0< SetInterface< TYPE >, TYPE, EmptyClass, DefaultCompare >
using SetType = SetInterface< TYPE >
 
- Public Types inherited from Collection< COLLECTION, VALUETYPE, SUPER >
using Super = BaseCollection< COLLECTION, SUPER >
 
using ValueType = VALUETYPE
 
- Public Types inherited from BaseCollection< COLLECTION, SUPER >
using IsCollection = std::true_type
 
using IsBaseArray = std::false_type
 

Public Member Functions

MAXON_METHOD Int GetCount () const
 
MAXON_FUNCTION Bool IsEmpty () const
 
MAXON_FUNCTION Bool IsPopulated () const
 
MAXON_METHOD Bool Contains (const TYPE &value) const
 
MAXON_METHOD Result< void > Insert (const TYPE &value, Bool &added=BoolLValue())
 
MAXON_METHOD Result< void > Insert (TYPE &&value, Bool &added=BoolLValue())
 
MAXON_METHOD Result< BoolErase (const TYPE &value)
 
MAXON_METHOD Iterator Erase (const Iterator &iterator)
 
MAXON_METHOD void Reset ()
 
MAXON_METHOD void Flush ()
 
MAXON_METHOD Result< void > CopyFrom (const SetInterface &other)
 
MAXON_METHOD Result< SetInterface * > Clone (Bool copyContent=true) const
 
MAXON_METHOD const DataTypeGetValueDataType () const
 
MAXON_METHOD String ToString (const FormatStatement *formatStatement=nullptr) const
 
MAXON_METHOD Int GetMemorySize () const
 
 MAXON_ADD_TO_CONST_REFERENCE_CLASS (HashInt GetHashCode() const { CriticalStop("Not implemented.");return 0;};)
 
template<typename T >
MAXON_FUNCTION Bool HasType () const
 
template<typename T >
MAXON_FUNCTION void AssertType () const
 
template<typename T >
SetInterface< T > & AssertCast ()
 
template<typename T >
const SetInterface< T > & AssertCast () const
 
 operator const SetInterface< typename std::conditional< STD_IS_REPLACEMENT (same, const TYPE, const Generic)
 
 operator SetInterface< typename std::conditional< STD_IS_REPLACEMENT (same, TYPE, Generic)
 
Generic ::typeoperator const NonConstSet< TYPE > & ()
 
 operator const NonConstSet< typename std::conditional< STD_IS_REPLACEMENT (same, TYPE, Generic)
 
ConstIterator Begin () const
 
Iterator Begin ()
 
ConstIterator End () const
 
Iterator End ()
 
- Public Member Functions inherited from SetBase0< SetInterface< TYPE >, TYPE, EmptyClass, DefaultCompare >
MAXON_ATTRIBUTE_FORCE_INLINE SetBase0 (ARGS &&... args)
 
MAXON_ATTRIBUTE_FORCE_INLINE ResultRef< const TYPEAppend (typename ByValueParam< TYPE >::type v)
 
Bool ContainsAllImpl (COLLECTION2 &&other, OverloadRank0) const
 
MAXON_ATTRIBUTE_FORCE_INLINE Result< void > Add (COLLECTION2 &&other, COLLECTION_RESIZE_FLAGS resizeFlags=COLLECTION_RESIZE_FLAGS::ON_GROW_RESERVE_CAPACITY)
 
MAXON_ATTRIBUTE_FORCE_INLINE Result< void > AppendAll (COLLECTION2 &&other, COLLECTION_RESIZE_FLAGS resizeFlags=COLLECTION_RESIZE_FLAGS::ON_GROW_RESERVE_CAPACITY)
 
MAXON_ATTRIBUTE_FORCE_INLINE Result< void > CopyFrom (COLLECTION2 &&other, COLLECTION_RESIZE_FLAGS resizeFlags=COLLECTION_RESIZE_FLAGS::FIT_TO_SIZE)
 
Result< void > SubtractImpl (COLLECTION2 &&other, OverloadRank0)
 
Bool IsEqualImpl (const COLLECTION2 &other, COMPARE &&cmp, OverloadRank0) const
 
HashInt GetHashCode () const
 
UniqueHash GetUniqueHashCode () const
 
- Public Member Functions inherited from Collection< COLLECTION, VALUETYPE, SUPER >
template<typename... ARGS>
MAXON_ATTRIBUTE_FORCE_INLINE Collection (ARGS &&... args)
 
ResultOk< void > VariadicAppend ()
 
template<typename V , typename... VALUES>
Result< void > VariadicAppend (V &&value, VALUES &&... rest)
 
 operator ValueReceiver< const VALUETYPE & > ()
 
 operator ValueReceiver< VALUETYPE && > ()
 
 operator ValueReceiver< typename std::conditional< STD_IS_REPLACEMENT (scalar, VALUETYPE)
 
DummyParamType & type ()
 
template<typename FN >
Result< BoolForEach (FN &&callback) const
 
template<typename FN >
Result< BoolForEach (FN &&callback)
 
template<typename H = COLLECTION>
H::Iterator Find (typename ByValueParam< VALUETYPE >::type v)
 
template<typename H = COLLECTION>
H::ConstIterator Find (typename ByValueParam< VALUETYPE >::type v) const
 
Int FindIndex (typename ByValueParam< VALUETYPE >::type v) const
 
MAXON_ATTRIBUTE_FORCE_INLINE Bool Contains (typename ByValueParam< VALUETYPE >::type v) const
 
- Public Member Functions inherited from BaseCollection< COLLECTION, SUPER >
template<typename... ARGS>
MAXON_ATTRIBUTE_FORCE_INLINE BaseCollection (ARGS &&... args)
 
template<typename COLLECTION2 >
MAXON_ATTRIBUTE_FORCE_INLINE std::enable_if< maxon::IsCollection< COLLECTION2 >::value, Bool >::type operator== (const COLLECTION2 &other) const
 
template<typename COLLECTION2 >
MAXON_ATTRIBUTE_FORCE_INLINE std::enable_if< maxon::IsCollection< COLLECTION2 >::value, Bool >::type operator!= (const COLLECTION2 &other) const
 
template<typename COMPARE = EqualityCompare, typename COLLECTION2 >
MAXON_ATTRIBUTE_FORCE_INLINE std::enable_if< maxon::IsCollection< COLLECTION2 >::value &&!STD_IS_REPLACEMENT(same, typename std::decay< COMPARE >::type, EQUALITY), Bool >::type IsEqual (const COLLECTION2 &other, COMPARE &&cmp=COMPARE()) const
 
template<typename COLLECTION2 >
MAXON_ATTRIBUTE_FORCE_INLINE Result< void > AppendAll (COLLECTION2 &&other, COLLECTION_RESIZE_FLAGS resizeFlags=COLLECTION_RESIZE_FLAGS::ON_GROW_RESERVE_CAPACITY)
 
template<typename COLLECTION2 >
MAXON_ATTRIBUTE_FORCE_INLINE Result< void > CopyFrom (COLLECTION2 &&other, COLLECTION_RESIZE_FLAGS resizeFlags=COLLECTION_RESIZE_FLAGS::FIT_TO_SIZE)
 
template<typename COLLECTION2 >
MAXON_ATTRIBUTE_FORCE_INLINE Result< void > Subtract (COLLECTION2 &&other)
 
template<typename COLLECTION2 >
MAXON_ATTRIBUTE_FORCE_INLINE Result< void > Intersect (const COLLECTION2 &other)
 
template<typename COLLECTION2 >
Bool Intersects (const COLLECTION2 &other) const
 
template<typename COLLECTION2 >
MAXON_ATTRIBUTE_FORCE_INLINE Result< void > CopyFromImpl (COLLECTION2 &&other, COLLECTION_RESIZE_FLAGS resizeFlags, OverloadRank0)
 
template<typename COLLECTION2 >
Result< void > AppendAllImpl (COLLECTION2 &&other, COLLECTION_RESIZE_FLAGS resizeFlags, Bool overwrite, OverloadRank0)
 
template<typename COLLECTION2 >
Result< void > IntersectImpl (COLLECTION2 &&other, OverloadRank0)
 
MAXON_ATTRIBUTE_FORCE_INLINE Bool IsEmpty () const
 
MAXON_ATTRIBUTE_FORCE_INLINE Bool IsPopulated () const
 
String ToString (const FormatStatement *formatStatement=nullptr) const
 
template<typename COLLECTION2 >
MAXON_ATTRIBUTE_FORCE_INLINE Bool ContainsAll (COLLECTION2 &&other) const
 
template<typename COLLECTION2 >
Bool ContainsAllImpl (COLLECTION2 &&other, OverloadRank0) const
 

Public Attributes

 DeleteReturnType01
 
Generic ::typeconst
 
 DeleteReturnType02
 
 DeleteReturnType03
 
- Public Attributes inherited from Collection< COLLECTION, VALUETYPE, SUPER >
 VALUETYPE
 

Private Member Functions

 MAXON_INTERFACE_SIMPLE_VIRTUAL (SetInterface, MAXON_REFERENCE_COPY_ON_WRITE)
 
MAXON_METHOD void IteratorInit (Iterator *it, Bool end)
 
MAXON_METHOD void IteratorInit (ConstIterator *it, Bool end) const
 
MAXON_METHOD void IteratorInitMove (Iterator *dest, Iterator *src) const
 
MAXON_METHOD void IteratorInitMove (ConstIterator *dest, ConstIterator *src) const
 
MAXON_METHOD void IteratorFree (Iterator *it) const
 
MAXON_METHOD void IteratorFree (ConstIterator *it) const
 
MAXON_METHOD Bool IteratorIsEqual (const Iterator *a, const Iterator *b) const
 
MAXON_METHOD Bool IteratorIsEqual (const ConstIterator *a, const ConstIterator *b) const
 
MAXON_METHOD void IteratorInc (Iterator *it) const
 
MAXON_METHOD void IteratorInc (ConstIterator *it) const
 
MAXON_METHOD const TYPE * IteratorGet (const Iterator *it) const
 
MAXON_METHOD const TYPE * IteratorGet (const ConstIterator *it) const
 

Static Private Member Functions

static SetInterfaceAlloc (MAXON_SOURCE_LOCATION_DECLARATION)
 
static SetInterfaceAlloc (MAXON_SOURCE_LOCATION_DECLARATION, const SetInterface &src)
 

Friends

template<typename SET >
class SetImpl
 

Additional Inherited Members

- Static Public Member Functions inherited from Collection< COLLECTION, VALUETYPE, SUPER >
static const VALUETYPEGetMapKey (const VALUETYPE &key)
 
- Static Public Attributes inherited from SetBase0< SetInterface< TYPE >, TYPE, EmptyClass, DefaultCompare >
static const COLLECTION_KIND KIND
 

Member Typedef Documentation

◆ ValueType

using ValueType = TYPE

◆ Iterator

using Iterator = IteratorTemplate<false>

◆ ConstIterator

Member Function Documentation

◆ MAXON_INTERFACE_SIMPLE_VIRTUAL()

MAXON_INTERFACE_SIMPLE_VIRTUAL ( SetInterface< TYPE >  ,
MAXON_REFERENCE_COPY_ON_WRITE   
)
private

◆ GetCount()

MAXON_METHOD Int GetCount ( ) const

Gets the number of set elements.

Returns
Number of set elements.

◆ IsEmpty()

MAXON_FUNCTION Bool IsEmpty ( ) const

@MAXON_ANNOTATION{default=true}

◆ IsPopulated()

MAXON_FUNCTION Bool IsPopulated ( ) const

◆ Contains()

MAXON_METHOD Bool Contains ( const TYPE &  value) const

Checks if this set contains value.

Parameters
[in]valueThe value to check.
Returns
True if this set contains value.

◆ Insert() [1/2]

MAXON_METHOD Result<void> Insert ( const TYPE &  value,
Bool added = BoolLValue() 
)

Adds value to this set. If value is already contained in this set, nothing happens, and added is set to false.

Parameters
[in]valueValue to add to this set.
[out]addedThis will be set to true if the element didn't exist before in the set and it could be added successfully, otherwise it will be set to false.
Returns
OK on success.

◆ Insert() [2/2]

MAXON_METHOD Result<void> Insert ( TYPE &&  value,
Bool added = BoolLValue() 
)

Adds value to this set. If value is already contained in this set, nothing happens, and added is set to false.

Parameters
[in]valueValue to add to this set. When a new element has to be added, value will be moved into the new element.
[out]addedThis will be set to true if the element didn't exist before in the set and it could be added successfully, otherwise it will be set to false.
Returns
OK on success.

◆ Erase() [1/2]

MAXON_METHOD Result<Bool> Erase ( const TYPE &  value)

Remove value from this set. If value isn't contained in this set, nothing happens.

Parameters
[in]valueValue to remove from this set.
Returns
True if an entry was found and removed for value, otherwise false or an error if a memory allocation failed.

◆ Erase() [2/2]

MAXON_METHOD Iterator Erase ( const Iterator iterator)

Removes the element at iterator from this set. The returned iterator will point to the element behind the last removed element.

Parameters
[in]iteratorIterator pointing to the element to be removed.
Returns
Iterator pointing to the element behind the removed element.

◆ Reset()

MAXON_METHOD void Reset ( )

Deletes all elements (calls destructors and frees memory).

◆ Flush()

MAXON_METHOD void Flush ( )

Deletes all elements, but doesn't free memory (calls destructors though).

◆ CopyFrom()

MAXON_METHOD Result<void> CopyFrom ( const SetInterface< TYPE > &  other)

Sets this set to a copy of the given other set.

Parameters
[in]otherSource set.
Returns
Success of operation.

◆ Clone()

MAXON_METHOD Result<SetInterface*> Clone ( Bool  copyContent = true) const

Returns a clone of this set.

Parameters
[in]copyContentTrue if also the elements shall be cloned, false otherwise (then just a new object sharing the same SetInterface implementation is created).
Returns
Pointer to the new set object, nullptr if allocation or copying failed.

◆ GetValueDataType()

MAXON_METHOD const DataType& GetValueDataType ( ) const

Returns the data type of this set's elements. This may be nullptr if there is no DataType for the template parameter TYPE.

Returns
DataType of the elements or nullptr.

◆ ToString()

MAXON_METHOD String ToString ( const FormatStatement formatStatement = nullptr) const
Parameters
[in]formatStatementNullptr or additional formatting instruction. Currently no additional formatting instructions are supported.

◆ GetMemorySize()

MAXON_METHOD Int GetMemorySize ( ) const

Calculates the memory usage for this set.

Returns
Memory size in bytes.

◆ MAXON_ADD_TO_CONST_REFERENCE_CLASS()

MAXON_ADD_TO_CONST_REFERENCE_CLASS ( HashInt GetHashCode() const { CriticalStop("Not implemented.");return 0;};  )

◆ HasType()

MAXON_FUNCTION Bool HasType ( ) const

◆ AssertType()

MAXON_FUNCTION void AssertType ( ) const

Issues a failed DebugAssert if the DataType of this set doesn't match T. If T is Generic, no check happens.

Template Parameters
TType to check.

◆ AssertCast() [1/2]

SetInterface<T>& AssertCast ( )

Casts this set to a set with elements of type T. If T doesn't match the actual data type of this set, a failed DebugAssert is issued. This function only makes sense when the original set uses Generic as its type.

Template Parameters
TElement type of the destination set.
Returns
This set, cast to a SetInterface of T elements.

◆ AssertCast() [2/2]

const SetInterface<T>& AssertCast ( ) const

Casts this set to a set with elements of type T. If T doesn't match the actual data type of this set, a failed DebugAssert is issued. This function only makes sense when the original set uses Generic as its type.

Template Parameters
TElement type of the destination set.
Returns
This set, cast to a SetInterface of T elements.

◆ operator const SetInterface< typename std::conditional< STD_IS_REPLACEMENT()

operator const SetInterface< typename std::conditional< STD_IS_REPLACEMENT ( same  ,
const  TYPE,
const  Generic 
)

◆ operator SetInterface< typename std::conditional< STD_IS_REPLACEMENT()

operator SetInterface< typename std::conditional< STD_IS_REPLACEMENT ( same  ,
TYPE  ,
Generic   
)

◆ operator const NonConstSet< TYPE > &()

Generic ::type& operator const NonConstSet< TYPE > & ( )

◆ operator const NonConstSet< typename std::conditional< STD_IS_REPLACEMENT()

operator const NonConstSet< typename std::conditional< STD_IS_REPLACEMENT ( same  ,
TYPE  ,
Generic   
)

◆ Begin() [1/2]

ConstIterator Begin ( ) const

Returns an iterator pointing to the first set element.

Returns
Iterator for the first element (equal to End() if the set is empty).

◆ Begin() [2/2]

Iterator Begin ( )

Returns an iterator pointing to the first set element.

Returns
Iterator for the first element (equal to End() if the set is empty).

◆ End() [1/2]

ConstIterator End ( ) const

Returns an iterator pointing one behind the last set element.

Returns
Iterator for the set end, this is one behind the last element.

◆ End() [2/2]

Iterator End ( )

Returns an iterator pointing one behind the last set element.

Returns
Iterator for the set end, this is one behind the last element.

◆ IteratorInit() [1/2]

MAXON_METHOD void IteratorInit ( Iterator it,
Bool  end 
)
private

◆ IteratorInit() [2/2]

MAXON_METHOD void IteratorInit ( ConstIterator it,
Bool  end 
) const
private

◆ IteratorInitMove() [1/2]

MAXON_METHOD void IteratorInitMove ( Iterator dest,
Iterator src 
) const
private

◆ IteratorInitMove() [2/2]

MAXON_METHOD void IteratorInitMove ( ConstIterator dest,
ConstIterator src 
) const
private

◆ IteratorFree() [1/2]

MAXON_METHOD void IteratorFree ( Iterator it) const
private

◆ IteratorFree() [2/2]

MAXON_METHOD void IteratorFree ( ConstIterator it) const
private

◆ IteratorIsEqual() [1/2]

MAXON_METHOD Bool IteratorIsEqual ( const Iterator a,
const Iterator b 
) const
private

◆ IteratorIsEqual() [2/2]

MAXON_METHOD Bool IteratorIsEqual ( const ConstIterator a,
const ConstIterator b 
) const
private

◆ IteratorInc() [1/2]

MAXON_METHOD void IteratorInc ( Iterator it) const
private

◆ IteratorInc() [2/2]

MAXON_METHOD void IteratorInc ( ConstIterator it) const
private

◆ IteratorGet() [1/2]

MAXON_METHOD const TYPE* IteratorGet ( const Iterator it) const
private

◆ IteratorGet() [2/2]

MAXON_METHOD const TYPE* IteratorGet ( const ConstIterator it) const
private

◆ Alloc() [1/2]

static SetInterface* Alloc ( MAXON_SOURCE_LOCATION_DECLARATION  )
staticprivate

◆ Alloc() [2/2]

static SetInterface* Alloc ( MAXON_SOURCE_LOCATION_DECLARATION  ,
const SetInterface< TYPE > &  src 
)
staticprivate

Friends And Related Function Documentation

◆ SetImpl

friend class SetImpl
friend

Member Data Documentation

◆ DeleteReturnType01

DeleteReturnType01

◆ const

Generic ::type& const

◆ DeleteReturnType02

DeleteReturnType02

◆ DeleteReturnType03

DeleteReturnType03