description | title | ms.date | f1_keywords | helpviewer_keywords | ms.assetid | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Learn more about: CTypedPtrMap Class |
CTypedPtrMap Class |
11/04/2016 |
|
|
9f377385-c6e9-4471-8b40-8fe220c50164 |
Provides a type-safe "wrapper" for objects of the pointer-map classes CMapPtrToPtr
, CMapPtrToWord
, CMapWordToPtr
, and CMapStringToPtr
.
template<class BASE_CLASS, class KEY, class VALUE>
class CTypedPtrMap : public BASE_CLASS
BASE_CLASS
Base class of the typed pointer map class; must be a pointer map class ( CMapPtrToPtr
, CMapPtrToWord
, CMapWordToPtr
, or CMapStringToPtr
).
KEY
Class of the object used as the key to the map.
VALUE
Class of the object stored in the map.
Name | Description |
---|---|
CTypedPtrMap::GetNextAssoc | Gets the next element for iterating. |
CTypedPtrMap::Lookup | Returns a KEY based on a VALUE . |
CTypedPtrMap::RemoveKey | Removes an element specified by a key. |
CTypedPtrMap::SetAt | Inserts an element into the map; replaces an existing element if a matching key is found. |
Name | Description |
---|---|
CTypedPtrMap::operator [ ] | Inserts an element into the map. |
When you use CTypedPtrMap
, the C++ type-checking facility helps eliminate errors caused by mismatched pointer types.
Because all CTypedPtrMap
functions are inline, use of this template does not significantly affect the size or speed of your code.
For more information on using CTypedPtrMap
, see the articles Collections and Template-Based Classes.
BASE_CLASS
CTypedPtrMap
Header: afxtempl.h
Retrieves the map element at rNextPosition
, then updates rNextPosition
to refer to the next element in the map.
void GetNextAssoc(
POSITION& rPosition,
KEY& rKey,
VALUE& rValue) const;
rPosition
Specifies a reference to a POSITION value returned by a previous GetNextAssoc
or BASE_CLASS
::GetStartPosition call.
KEY
Template parameter specifying the type of the map's keys.
rKey
Specifies the returned key of the retrieved element.
VALUE
Template parameter specifying the type of the map's values.
rValue
Specifies the returned value of the retrieved element.
This function is most useful for iterating through all the elements in the map. Note that the position sequence is not necessarily the same as the key value sequence.
If the retrieved element is the last in the map, then the new value of rNextPosition
is set to NULL.
This inline function calls BASE_CLASS
::GetNextAssoc.
Lookup
uses a hashing algorithm to quickly find the map element with a key that matches exactly.
BOOL Lookup(BASE_CLASS ::BASE_ARG_KEY key, VALUE& rValue) const;
BASE_CLASS
Template parameter specifying the base class of this map's class.
key
The key of the element to be looked up.
VALUE
Template parameter specifying the type of values stored in this map.
rValue
Specifies the returned value of the retrieved element.
Nonzero if the element was found; otherwise 0.
This inline function calls BASE_CLASS
::Lookup.
This operator can be used only on the left side of an assignment statement (an l-value).
VALUE& operator[ ](base_class ::base_arg_key key);
VALUE
Template parameter specifying the type of values stored in this map.
BASE_CLASS
Template parameter specifying the base class of this map's class.
key
The key of the element to be looked up or created in the map.
If there is no map element with the specified key, then a new element is created. There is no "right side" (r-value) equivalent to this operator because there is a possibility that a key may not be found in the map. Use the Lookup
member function for element retrieval.
This member function calls BASE_CLASS
::RemoveKey.
BOOL RemoveKey(KEY key);
KEY
Template parameter specifying the type of the map's keys.
key
Key for the element to be removed.
Nonzero if the entry was found and successfully removed; otherwise 0.
For more detailed remarks, see CMapStringToOb::RemoveKey.
This member function calls BASE_CLASS
::SetAt.
void SetAt(KEY key, VALUE newValue);
KEY
Template parameter specifying the type of the map's keys.
key
Specifies the key value of the newValue.
newValue
Specifies the object pointer that is the value of the new element.
For more detailed remarks, see CMapStringToOb::SetAt.
MFC Sample COLLECT
Hierarchy Chart
CMapPtrToPtr Class
CMapPtrToWord Class
CMapWordToPtr Class
CMapStringToPtr Class