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











SourceForge.net Logo



ArrayMap

 

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

 

class ArrayMap

 

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.

Base classes

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

 

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.

Members

 

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

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.

 

void Add(const K& k, T *ptr)

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.

ptr

Value.

 

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

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.

 

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

 

ArrayMap()

Default constructor. Creates empty ArrayMap.