SetInterface< TYPE > Class Template Reference

#include <set.h>

Inheritance diagram for SetInterface< TYPE >:

详细描述

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
TYPE Type 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< SetInterface< TYPE >, TYPE, EmptyClass >
using  Super = BaseCollection < SetInterface < TYPE >, EmptyClass >
using  ValueType = TYPE
-  Public Types inherited from BaseCollection< SetInterface< TYPE >, EmptyClass >
using  IsCollection = std::true_type

公共成员函数

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 < Bool Erase (const TYPE &value)
MAXON_METHOD Iterator   Erase (const Iterator &iterator)
MAXON_METHOD void  重置 ()
MAXON_METHOD void  Flush ()
MAXON_METHOD Result < void >  CopyFrom (const SetInterface &other)
MAXON_METHOD Result < SetInterface * >  Clone ( Bool cloneElements=true) const
const MAXON_METHOD DataType GetValueDataType () 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)
const Generic :: type &const  operator SetInterface< typename std::conditional< STD_IS_REPLACEMENT (same, TYPE, Generic)
const Generic :: type &const volatile Generic :: type operator 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 TYPE Append (typename ByValueParam < TYPE >:: type v)
Bool   ContainsAllImpl (COLLECTION2 &&other, OverloadRank0 ) const
MAXON_ATTRIBUTE_FORCE_INLINE Result < void >  添加 (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
-  Public Member Functions inherited from Collection< SetInterface< TYPE >, TYPE, EmptyClass >
MAXON_ATTRIBUTE_FORCE_INLINE   Collection (ARGS &&... args)
ResultOk < void >  VariadicAppend ()
Result < void >  VariadicAppend (V &&value, VALUES &&... rest)
  operator ValueReceiver< const TYPE & > ()
  operator ValueReceiver< TYPE && > ()
  operator ValueReceiver< typename std::conditional< STD_IS_REPLACEMENT (scalar, TYPE )
DummyParamType &  type ()
Result < Bool ForEach (FN &&callback) const
Result < Bool ForEach (FN &&callback)
H::Iterator  Find (typename ByValueParam < TYPE >:: type v)
H::ConstIterator  Find (typename ByValueParam < TYPE >:: type v) const
Int   FindIndex (typename ByValueParam < TYPE >:: type v) const
MAXON_ATTRIBUTE_FORCE_INLINE Bool   Contains (typename ByValueParam < TYPE >:: type v) const
-  Public Member Functions inherited from BaseCollection< SetInterface< TYPE >, EmptyClass >
MAXON_ATTRIBUTE_FORCE_INLINE   BaseCollection (ARGS &&... args)
MAXON_ATTRIBUTE_FORCE_INLINE std::enable_if< maxon::IsCollection< COLLECTION2 >::value, Bool >::type  operator== (const COLLECTION2 &other) const
MAXON_ATTRIBUTE_FORCE_INLINE std::enable_if< maxon::IsCollection< COLLECTION2 >::value, Bool >::type  operator!= (const COLLECTION2 &other) const
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
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 )
MAXON_ATTRIBUTE_FORCE_INLINE Result < void >  Subtract (COLLECTION2 &&other)
MAXON_ATTRIBUTE_FORCE_INLINE Result < void >  Intersect (const COLLECTION2 &other)
Bool   Intersects (const COLLECTION2 &other) const
MAXON_ATTRIBUTE_FORCE_INLINE Result < void >  CopyFromImpl (COLLECTION2 &&other, COLLECTION_RESIZE_FLAGS resizeFlags, OverloadRank0 )
Result < void >  AppendAllImpl (COLLECTION2 &&other, COLLECTION_RESIZE_FLAGS resizeFlags, Bool overwrite, OverloadRank0 )
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
MAXON_ATTRIBUTE_FORCE_INLINE Bool   ContainsAll (COLLECTION2 &&other) const
Bool   ContainsAllImpl (COLLECTION2 &&other, OverloadRank0 ) const

Public Attributes

const  DummyReturnType
const Generic :: type &const volatile  DummyReturnType
  DummyReturnType
-  Public Attributes inherited from Collection< SetInterface< TYPE >, TYPE, EmptyClass >
  VALUETYPE

私有成员函数

  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
const MAXON_METHOD TYPE *  IteratorGet (const Iterator *it) const
const MAXON_METHOD TYPE *  IteratorGet (const ConstIterator *it) const

Static Private Member Functions

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

Friends

template<typename SET >
class  SetImpl

Additional Inherited Members

-  Static Public Member Functions inherited from Collection< SetInterface< TYPE >, TYPE, EmptyClass >
static const TYPE GetMapKey (const TYPE &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

using ConstIterator = IteratorTemplate <true>

成员函数文档编制

◆  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.

返回
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 .

参数
[in] value The value to check.
返回
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 被设为 false .

参数
[in] value Value to add to this set.
[out] added This 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.
返回
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 被设为 false .

参数
[in] value Value to add to this set. When a new element has to be added, value will be moved into the new element.
[out] added This 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.
返回
OK on success.

◆  Erase() [1/2]

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

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

参数
[in] value Value to remove from this set.
返回
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.

参数
[in] iterator Iterator pointing to the element to be removed.
返回
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.

参数
[in] other Source set.
返回
Success of operation.

◆  Clone()

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

Returns a clone of this set.

参数
[in] cloneElements True if also the elements shall be cloned, false otherwise (then just a new object sharing the same SetInterface implementation is created).
返回
Pointer to the new set object, nullptr if allocation or copying failed.

◆  GetValueDataType()

const MAXON_METHOD 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.

返回
DataType of the elements or nullptr.

◆  ToString()

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

◆  GetMemorySize()

MAXON_METHOD Int GetMemorySize ( ) const

Calculates the memory usage for this set.

返回
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
T Type 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
T Element type of the destination set.
返回
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
T Element type of the destination set.
返回
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()

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

◆  operator const NonConstSet< TYPE > &()

const Generic :: type & const volatile 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.

返回
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.

返回
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.

返回
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.

返回
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]

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

◆  IteratorGet() [2/2]

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

◆  Alloc() [1/2]

static SetInterface * Alloc ( MAXON_SOURCE_LOCATION_DECLARATION   )
static private

◆  Alloc() [2/2]

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

Friends And Related Function Documentation

◆  SetImpl

friend class SetImpl
friend

Member Data Documentation

◆  DummyReturnType [1/3]

const DummyReturnType

◆  DummyReturnType [2/3]

const Generic :: type & const volatile DummyReturnType

◆  DummyReturnType [3/3]

DummyReturnType