Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
UppHub
Status & Roadmap
FAQ
Authors & License
Forums
Funding U++
Search on this site











SourceForge.net Logo

SourceForge.net Logo

GitHub Logo

Discord Logo

ArrayMap

 

template <class K, class T, class HashFn = StdHash<K> >

class ArrayMap : public MoveableAndDeepCopyOption< ArrayMap<K, T, HashFn> >, public AMap< K, T, Array<T>, HashFn > 

K

Type of keys. K must have deep copy constructor, be moveable and must have operator== defined.

T

Type or base class of the values stored in ArrayMap. There is no common requirement for T.

HashFn

Hashing class. Must have defined unsigned operator()(const K& x) method returning hash value for elements.

Array flavor of map. Inherits most of its functionality from AMap and adds only members specific for its flavor.

Like any other NTL container, ArrayMap is a moveable type with pick and optional deep copy transfer semantics. Calling methods of a picked VectorMap is logic error with the exceptions of:

 

void operator=(pick_ ArrayMap& v) (defined by composition)

void operator<<=(const AMap& v) (defined in AMap)

void Clear()

bool IsPicked() const

Optional deep copy operator is inherited from AMap class. Pick operator is implicitly defined by composition.

 

Base classes

AMap< K, T, Array<T>, HashFn >

 

 

Constructor Detail

 

ArrayMap()

Default constructor. Creates empty ArrayMap.

 


 

ArrayMap(std::initializer_list<std::pair<K, T>> init)

C++ 11 initialization.

 


 

template <class KK, class TTArrayMap& operator()(KK&& k, TT&& v)

Same as Add(k, v), returns *this. Syntax sugar for creating map. Note the use of universal reference that gets resolved to correct Add variant.

 


 

ArrayMap(const ArrayMap& s, int)

Optional deep copy constructor.

Requires T to have deep copy constructor or optional deep copy constructor if Array stores only objects of type T.

Requires polymorphic deep copy if Array also stores objects of type derived from T.

s

Source ArrayMap.

 


 

ArrayMap(Index<K>&& ndx, Array<T>&& val)

Pick-constructs ArrayMap from Index of keys and Array of values. The source containers should have equal number of elements.

 


 

ArrayMap(Vector<K>&& ndx, Array<T>&& val)

Pick-constructs ArrayMap from Vector of keys and Array of values. The source containers should have equal number of elements.

 

Public Member List

 

T& Add(const K& k, const T& x)

T& Add(const K& k, T&& x)

T& Add(const K& k)

T& Add(const K& k, T *newt)

T& Add(K&& k, const T& x)

T& Add(K&& k, T&& x)

T& Add(K&& k)

T& Add(K&& k, T *newt)

Adds a key-value pair to the ArrayMap. newt specifies the new value as a pointer to the object created using default 'new' operator of the heap. ArrayMap takes over ownership of this object. This variant allows use of ArrayMap as polymorphic container, because type of added element can be also derived from T as well. Value can be also copied picked from x or default constructed.

 


 

T& Insert(int i, const K& k, T *newt)

T& Insert(int i, K&& k, T *newt)

Inserts a key-value pair to the ArrayMap. newt specifies the new value as a pointer to the object created using default 'new' operator of the heap. ArrayMap takes over ownership of this object.

 


 

template <class TT, class... ArgsTT& Create(const K& k, Args&&... args)

template <class TT, class... ArgsTT& Create(K&& k, Args&&... args)

Adds a new key k with value element of type TT (must be derived from T). Value is constructd in-place, with args as constructor parameters.

 


 

T& Set(int i, T *ptr)

Sets value at specified index. Value is specified by a pointer to the object. ArrayMap takes over ownership of this object. Returns a reference to the element.

 


 

T *PopDetach()

Drops last element in the ArrayMap, giving up ownership of value. Client is responsible for deletion of the element.

Invalidates iterators to ArrayMap.

Return value

Value.

 


 

T *Detach(int i)

Removes element i. but does not destroy it - the heap pointer to the element is returned. Client is responsible for deletion of the element.

 


 

T *Swap(int i, T *newt)

Sets element at i to newt.and returns a pointer to original element. Client is responsible for deletion of the original element.

 

 

Do you want to contribute?