MapInterface< K, V > Class Template Reference

#include <map.h>

Inheritance diagram for MapInterface< K, V >:

Detailed Description

template<typename K, typename V>
class maxon::MapInterface< K, V >

MapInterface is an interface which provides the usual map functions as virtual methods. Each standard map 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 map.

If the function won't modify both the structure and values of the map, you should use a const MapInterface with const values:

void Func(const MapInterface<Int, const String>& map);
HashMap<Int, String> myMap;
Func(myMap); // OK
ArrayMap<Int, String> myMap2;
Func(myMap2); // OK

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 map which shall be modified, use WritableMapInterface as type of the function parameter instead.

Template Parameters
KType of keys of the map.
VType of values of the map.

Classes

class  IteratorTemplate
 

Public Types

using KeyType = K
 
using ValueType = V
 
using Iterator = IteratorTemplate< false >
 
using ConstIterator = IteratorTemplate< true >
 
- Public Types inherited from MapBase0< MapInterface< K, V >, K, V, EmptyClass, DefaultCompare >
using MapType = MapInterface< K, V >
 
using Super = BaseCollection< MapInterface< K, V >, EmptyClass >
 
using KeyType = K
 
using ValueType = V
 
- 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 ResultRef< V > InsertKey (const K &key, Bool &created=BoolLValue())
 
MAXON_METHOD ResultRef< V > InsertKey (K &&key, Bool &created=BoolLValue())
 
template<typename VALUE >
MAXON_FUNCTION ResultRef< V > Insert (const K &key, VALUE &&value, Bool &created=BoolLValue())
 
template<typename VALUE >
MAXON_FUNCTION ResultRef< V > Insert (K &&key, VALUE &&value, Bool &created=BoolLValue())
 
MAXON_METHOD V * FindValue (const K &key)
 
MAXON_METHOD const V * FindValue (const K &key) const
 
MAXON_METHOD Result< BoolErase (const K &key)
 
MAXON_METHOD Iterator Erase (const Iterator &iterator)
 
MAXON_METHOD void Reset ()
 
MAXON_METHOD void Flush ()
 
MAXON_METHOD Result< void > CopyFrom (const MapInterface &other)
 
MAXON_METHOD Result< MapInterface * > Clone (Bool copyContent=true) const
 
MAXON_METHOD const DataTypeGetKeyDataType () 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 KT , typename VT >
MAXON_FUNCTION Bool HasType () const
 
template<typename KT , typename VT >
MAXON_FUNCTION void AssertType () const
 
template<typename KT , typename VT >
MapInterface< KT, VT > & AssertCast ()
 
template<typename KT , typename VT >
const MapInterface< KT, VT > & AssertCast () const
 
 operator const MapInterface< K, const V > & () const
 
 operator const MapInterface< Generic, typename std::conditional< STD_IS_REPLACEMENT (same, const V, const Generic)
 
 operator MapInterface< Generic, typename std::conditional< STD_IS_REPLACEMENT (same, V, Generic)
 
Generic ::typeoperator const NonConstMap< K, V > & ()
 
 operator const NonConstMap< Generic, typename std::conditional< STD_IS_REPLACEMENT (same, V, Generic)
 
ConstIterator Begin () const
 
Iterator Begin ()
 
ConstIterator End () const
 
Iterator End ()
 
- Public Member Functions inherited from MapBase0< MapInterface< K, V >, K, V, EmptyClass, DefaultCompare >
MAXON_ATTRIBUTE_FORCE_INLINE MapBase0 (ARGS &&... args)
 
MAXON_ATTRIBUTE_FORCE_INLINE Bool Contains (typename ByValueParam< K >::type key) const
 
MAXON_ATTRIBUTE_FORCE_INLINE SFINAEHelper< Bool, typename PAIR::KeyType >::type Contains (const PAIR &pair) const
 
ResultRef< V > Append (const K &key)
 
SFINAEHelper< ResultRef< V >, typename PAIR::KeyType >::type Append (const PAIR &pair)
 
Result< void > Add (COLLECTION2 &&other, COLLECTION_RESIZE_FLAGS resizeFlags=COLLECTION_RESIZE_FLAGS::ON_GROW_RESERVE_CAPACITY)
 
Result< void > AppendAll (COLLECTION2 &&other, COLLECTION_RESIZE_FLAGS resizeFlags=COLLECTION_RESIZE_FLAGS::ON_GROW_RESERVE_CAPACITY)
 
Result< void > AppendAllInverse (COLLECTION2 &&other)
 
Bool ContainsAllImpl (COLLECTION2 &&other, OverloadRank0) const
 
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 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
 
const Generic ::typeconst
 
 DeleteReturnType02
 
 DeleteReturnType03
 

Private Member Functions

 MAXON_INTERFACE_SIMPLE_VIRTUAL (MapInterface, 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 Pair< const K &, V & > IteratorGet (const Iterator *it) const
 
MAXON_METHOD Pair< const K &, const V & > IteratorGet (const ConstIterator *it) const
 

Static Private Member Functions

static MapInterfaceAlloc (MAXON_SOURCE_LOCATION_DECLARATION)
 
static MapInterfaceAlloc (MAXON_SOURCE_LOCATION_DECLARATION, const MapInterface &src)
 

Friends

template<typename MAP >
class MapImpl
 

Additional Inherited Members

- Static Public Member Functions inherited from MapBase0< MapInterface< K, V >, K, V, EmptyClass, DefaultCompare >
static const K & GetMapKey (const K &key)
 
static const K & GetMapKey (const PAIR &pair)
 
- Static Public Attributes inherited from MapBase0< MapInterface< K, V >, K, V, EmptyClass, DefaultCompare >
static const COLLECTION_KIND KIND
 

Member Typedef Documentation

◆ KeyType

using KeyType = K

◆ ValueType

using ValueType = V

◆ Iterator

using Iterator = IteratorTemplate<false>

◆ ConstIterator

Member Function Documentation

◆ MAXON_INTERFACE_SIMPLE_VIRTUAL()

MAXON_INTERFACE_SIMPLE_VIRTUAL ( MapInterface< K, V >  ,
MAXON_REFERENCE_COPY_ON_WRITE   
)
private

◆ GetCount()

MAXON_METHOD Int GetCount ( ) const

Gets the number of map entries.

Returns
Number of map entries.

◆ IsEmpty()

MAXON_FUNCTION Bool IsEmpty ( ) const

@MAXON_ANNOTATION{default=true}

◆ IsPopulated()

MAXON_FUNCTION Bool IsPopulated ( void  ) const

◆ InsertKey() [1/2]

MAXON_METHOD ResultRef<V> InsertKey ( const K &  key,
Bool created = BoolLValue() 
)

Finds the value associated with the given key, or creates a corresponding entry if it doesn't exist yet. The value of a new entry has to be initialized afterwards (but its default constructor has already been invoked).

Parameters
[in]keyKey of the value to find or create.
[out]createdThis will be set to true if a new entry has been created successfully, otherwise it will be set to false.
Returns
Pointer to value for the given key, or nullptr if an entry didn't exist and allocation of a new entry failed.

◆ InsertKey() [2/2]

MAXON_METHOD ResultRef<V> InsertKey ( K &&  key,
Bool created = BoolLValue() 
)

Finds the value associated with the given key, or creates a corresponding entry if it doesn't exist yet. The value of a new entry has to be initialized afterwards (but its default constructor has already been invoked).

Parameters
[in]keyKey of the entry to find or create. If a new entry is created, its key will be constructed by move-semantics if possible.
[out]createdThis will be set to true if a new entry has been created successfully, otherwise it will be set to false.
Returns
Pointer to value for the given key, or nullptr if an entry didn't exist and allocation of a new entry failed.

◆ Insert() [1/2]

MAXON_FUNCTION ResultRef<V> Insert ( const K &  key,
VALUE &&  value,
Bool created = BoolLValue() 
)

Associates the given value with the given key. This adds a new entry for key if necessary, and then sets its value to the given value, whether the entry existed before or not.

Parameters
[in]keyKey which shall map to the value.
[in]valueValue to which the key shall map.
[out]createdThis will be set to true if a new entry has been created, otherwise it will be set to false.
Returns
Pointer to value for the given key, or nullptr if an entry didn't exist and allocation of a new entry failed.

◆ Insert() [2/2]

MAXON_FUNCTION ResultRef<V> Insert ( K &&  key,
VALUE &&  value,
Bool created = BoolLValue() 
)

Associates the given value with the given key. This adds a new entry for key if necessary, and then sets its value to the given value, whether the entry existed before or not.

Parameters
[in]keyKey of the entry to find or create. If a new entry is created, its key will be constructed by move-semantics if possible.
[in]valueValue to which the key shall map.
[out]createdThis will be set to true if a new entry has been created, otherwise it will be set to false.
Returns
Pointer to value for the given key, or nullptr if an entry didn't exist and allocation of a new entry failed.

◆ FindValue() [1/2]

MAXON_METHOD V* FindValue ( const K &  key)

Finds the value associated with the given key in this map.

Parameters
[in]keyKey to search for.
Returns
Pointer to value for the given key, or nullptr if no entry exists for the key.

◆ FindValue() [2/2]

MAXON_METHOD const V* FindValue ( const K &  key) const

Finds the value associated with the given key in this map.

Parameters
[in]keyKey to search for.
Returns
Pointer to value for the given key, or nullptr if no entry exists for the key.

◆ Erase() [1/2]

MAXON_METHOD Result<Bool> Erase ( const K &  key)

Removes an entry with the given key from this map (if possible).

Parameters
[in]keyKey of the map entry to be be removed.
Returns
True if an entry was found and removed for key, 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 MapInterface< K, V > &  other)

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

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

◆ Clone()

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

Returns a clone of this map.

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

◆ GetKeyDataType()

MAXON_METHOD const DataType& GetKeyDataType ( ) const

Returns the data type of this map's keys. This may be nullptr if there is no DataType for the template parameter K.

Returns
DataType of the keys or nullptr.

◆ GetValueDataType()

MAXON_METHOD const DataType& GetValueDataType ( ) const

Returns the data type of this map's values. This may be nullptr if there is no DataType for the template parameter V.

Returns
DataType of the values 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 map.

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 DataTypes of this map doesn't match KT/VT. For Generic, no check happens.

Template Parameters
KTType of keys to check.
VTType of values to check.

◆ AssertCast() [1/2]

MapInterface<KT, VT>& AssertCast ( )

Casts this map to a map with keys of type KT and values of type VT. If one of they types doesn't match the actual data type of this map, a failed DebugAssert is issued. This function only makes sense when the original map uses Generic for at least one of its types.

Template Parameters
KTAssumed key type of the map.
VTAssumed value type of the map.
Returns
This map, cast to a MapInterface<KT, VT>.

◆ AssertCast() [2/2]

const MapInterface<KT, VT>& AssertCast ( ) const

Casts this map to a map with keys of type KT and values of type VT. If one of they types doesn't match the actual data type of this map, a failed DebugAssert is issued. This function only makes sense when the original map uses Generic for at least one of its types.

Template Parameters
KTAssumed key type of the map.
VTAssumed value type of the map.
Returns
This map, cast to a MapInterface<KT, VT>.

◆ operator const MapInterface< K, const V > &()

operator const MapInterface< K, const V > & ( ) const

◆ operator const MapInterface< Generic, typename std::conditional< STD_IS_REPLACEMENT()

operator const MapInterface< Generic, typename std::conditional< STD_IS_REPLACEMENT ( same  ,
const  V,
const  Generic 
)

◆ operator MapInterface< Generic, typename std::conditional< STD_IS_REPLACEMENT()

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

◆ operator const NonConstMap< K, V > &()

Generic ::type& operator const NonConstMap< K, V > & ( )

◆ operator const NonConstMap< Generic, typename std::conditional< STD_IS_REPLACEMENT()

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

◆ Begin() [1/2]

ConstIterator Begin ( ) const

Returns an iterator pointing to the first map entry.

Returns
Iterator for the first map entry (equal to End() if the map is empty).

◆ Begin() [2/2]

Iterator Begin ( )

Returns an iterator pointing to the first map entry.

Returns
Iterator for the first map entry (equal to End() if the map is empty).

◆ End() [1/2]

ConstIterator End ( ) const

Returns an iterator pointing one behind the last map entry.

Returns
Iterator for the map end, this is one behind the last map entry.

◆ End() [2/2]

Iterator End ( )

Returns an iterator pointing one behind the last map entry.

Returns
Iterator for the map end, this is one behind the last map entry.

◆ 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 Pair<const K&, V&> IteratorGet ( const Iterator it) const
private

◆ IteratorGet() [2/2]

MAXON_METHOD Pair<const K&, const V&> IteratorGet ( const ConstIterator it) const
private

◆ Alloc() [1/2]

static MapInterface* Alloc ( MAXON_SOURCE_LOCATION_DECLARATION  )
staticprivate

◆ Alloc() [2/2]

static MapInterface* Alloc ( MAXON_SOURCE_LOCATION_DECLARATION  ,
const MapInterface< K, V > &  src 
)
staticprivate

Friends And Related Function Documentation

◆ MapImpl

friend class MapImpl
friend

Member Data Documentation

◆ DeleteReturnType01

DeleteReturnType01

◆ const

const Generic ::type& const

◆ DeleteReturnType02

DeleteReturnType02

◆ DeleteReturnType03

DeleteReturnType03