PMap< K, V > Class Template Reference

Detailed Description

template<typename K, typename V>
class PMap< K, V >

Generic (templated) associative container; NOT thread-safe.

How to iterate over a PMap?

// ...
for (PStringMapIterator it = map.Iterator() ; it.HasNext() ; it.Next()) // or for (auto it = map.Iterator() ; it.HasNext() ; it.Next())
{
const PString& key = it.GetValue();
const PObject& value = it.GetKey();
// ...
}

Definition at line 47 of file PMap.h.

#include <PMap.h>

Constructor & Destructor Documentation

◆ PMap() [1/2]

template<typename K, typename V>
PMap< K, V >::PMap ( )

Constructs an empty map.

◆ PMap() [2/2]

template<typename K, typename V>
PMap< K, V >::PMap ( const PMap< K, V > &  other)

Constructs a shared copy of other.

Member Function Documentation

◆ Clear()

template<typename K, typename V>
void PMap< K, V >::Clear ( )

Clears this map.

See also
IsEmpty()

◆ Get() [1/6]

template<typename K, typename V>
PResult PMap< K, V >::Get ( const K &  key,
V &  value 
) const

Returns PResult::C_OK and the value to which the specified key is mapped.

If there is no mapping for the specified key, then an error is returned; output value (2nd argument) remains unchanged.

◆ Get() [2/6]

template<typename K, typename V>
PResult PMap< K, V >::Get ( const K &  key,
bool &  value 
) const

Returns PResult::C_OK and the value to which the specified key is mapped (if the value is a PBool (see PBoxing) or a PString representing a boolean value, see PString::ToBool()).

If there is no mapping for the specified key, then an error is returned; output value (2nd argument) remains unchanged.

◆ Get() [3/6]

template<typename K, typename V>
PResult PMap< K, V >::Get ( const K &  key,
papillon::int32 &  value 
) const

Returns PResult::C_OK and the value to which the specified key is mapped (if the value is a PInt32 (see PBoxing) or a PString representing an int32 value, see PString::ToInt32()).

If there is no mapping for the specified key, then an error is returned; output value (2nd argument) remains unchanged.

◆ Get() [4/6]

template<typename K, typename V>
PResult PMap< K, V >::Get ( const K &  key,
papillon::int64 &  value 
) const

Returns PResult::C_OK and the value to which the specified key is mapped (if the value is a PInt64, PInt32 (see PBoxing) or a PString representing an int64 value, see PString::ToInt64()).

If there is no mapping for the specified key, then an error is returned; output value (2nd argument) remains unchanged.

◆ Get() [5/6]

template<typename K, typename V>
PResult PMap< K, V >::Get ( const K &  key,
float &  value 
) const

Returns PResult::C_OK and the value to which the specified key is mapped (if the value is a PFloat, PInt64, PInt32 (see PBoxing) or a PString representing a float value, see PString::ToFloat()).

If there is no mapping for the specified key, then an error is returned; output value (2nd argument) remains unchanged.

◆ Get() [6/6]

template<typename K, typename V>
PResult PMap< K, V >::Get ( const K &  key,
double &  value 
) const

Returns PResult::C_OK and the value to which the specified key is mapped (if the value is a PDouble, PFloat, PInt64, PInt32 (see PBoxing) or a PString representing a double value, see PString::ToDouble()).

If there is no mapping for the specified key, then an error is returned; output value (2nd argument) remains unchanged.

◆ GetKeyList()

template<typename K, typename V>
PList PMap< K, V >::GetKeyList ( ) const

Returns a list (unordered) of all the keys contained in this map.

◆ GetValueList()

template<typename K, typename V>
PList PMap< K, V >::GetValueList ( ) const

Returns a list (unordered) of all the values contained in this map.

◆ Has()

template<typename K, typename V>
bool PMap< K, V >::Has ( const K &  key) const

Returns true if this map contains an entry for the specified key, false otherwise.

◆ IsEmpty()

template<typename K, typename V>
bool PMap< K, V >::IsEmpty ( ) const

Returns true if this map is empty, false otherwise.

See also
Size()

◆ Iterator()

template<typename K, typename V>
PMapIterator<K, V> PMap< K, V >::Iterator ( ) const

Returns an iterator on this map.

◆ Merge()

template<typename K, typename V>
void PMap< K, V >::Merge ( const PMap< K, V > &  other)

Extracts all the elements contained in other and insert them into this map.

◆ operator=()

template<typename K, typename V>
PMap<K, V>& PMap< K, V >::operator= ( const PMap< K, V > &  other)

Performs a shared copy of other to this object.

◆ Put()

template<typename K, typename V>
PMap<K, V>& PMap< K, V >::Put ( const K &  key,
const V &  value 
)

Associates the specified value with the specified key in this map.

A new entry is added if the key does not exist, otherwise current value is replaced by the new one. Calls to Put() can be chained.

◆ Remove()

template<typename K, typename V>
PResult PMap< K, V >::Remove ( const K &  key)

Removes the mapping for the specified key from this map if present.

Returns PResult::C_OK if success, another result otherwise.

◆ Size()

template<typename K, typename V>
papillon::int32 PMap< K, V >::Size ( ) const

Returns the number of entries in this map.

See also
IsEmpty()