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













SourceForge.net 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.

 


 

ArrayMap& operator()(const K& k, const T& v)

Same as Add(k, v), returns *this. Syntax sugar for creating map.

 


 

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(pick_ Index<K, HashFn>& ndx, pick_ Array<T>& val)

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

ndx

Source Index.

val

Source Array.

 


 

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

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

ndx

Source Index.

val

Source Array.

 

 

Public Member List

 

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

Adds a key and value pair to the ArrayMap. This method has to be reimplemented in ArrayMap (using simple forwarding) due to overloading of Add in other forms.Returns a reference to the element.

T must have deep copy constructor.

Invalidates iterators to the ArrayMap.

Invalidates references to keys.

k

Key.

x

Value.

 


 

T& Add(const K& k)

Adds a key to the ArrayMap and returns a reference to the corresponding default constructed value. This method has to be reimplemented in ArrayMap (using simple forwarding) due to overloading of Add in other forms.

T must have default constructor.

Invalidates iterators to the ArrayMap.

Invalidates references to keys.

k

Key.

Return value

Reference to value.

 


 

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

Adds a key-value pair to the ArrayMap. The value is specified by a pointer to the object. 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. No constructor is applied.

k

Key.

newt

Value.

 


 

template <class TT, class... ArgsTT& Create(const 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.

i

Index.

ptr

Value.

 


 

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.

 

 

Last edit by cxl on 07/02/2016. Do you want to contribute?. T++