💼 정보 ver1.0

Map(Template)

James Wetzel 2011. 11. 8. 14:47
728x90
반응형

CMap

template< class KEY, class ARG_KEY, class VALUE, class ARG_VALUE >class CMap : public CObject

Parameters

KEY

Class of the object used as the key to the map.

ARG_KEY

Data type used for KEY arguments; usually a reference to KEY.

VALUE

Class of the object stored in the map.

ARG_VALUE

Data type used for VALUE arguments; usually a reference to VALUE.

Remarks

CMap is a dictionary collection class that maps unique keys to values. Once you have inserted a key-value pair (element) into the map, you can efficiently retrieve or delete the pair using the key to access it. You can also iterate over all the elements in the map.

A variable of type POSITION is used for alternate access to entries. You can use a POSITION to “remember” an entry and to iterate through the map. You might think that this iteration is sequential by key value; it is not. The sequence of retrieved elements is indeterminate.

Certain member functions of this class call global helper functions that must be customized for most uses of the CMap class. See Collection Class Helpers in the Macros and Globals section of the MFC Reference.

CMap incorporates the IMPLEMENT_SERIAL macro to support serialization and dumping of its elements. Each element is serialized in turn if a map is stored to an archive, either with the overloaded insertion (<<) operator or with the Serialize member function.

If you need a diagnostic dump of the individual elements in the map (the keys and the values), you must set the depth of the dump context to 1 or greater.

When a CMap object is deleted, or when its elements are removed, the keys and values both are removed.

Map class derivation is similar to list derivation. See the article Collections in Visual C++ Programmer’s Guide for an illustration of the derivation of a special-purpose list class.

#include <afxtempl.h>

Class Members | Base Class | Hierarchy Chart

Sample MFC Sample COLLECT 

 

CMap Class Members

Construction

CMap Constructs a collection that maps keys to values.

Operations

Lookup Looks up the value mapped to a given key.
SetAt Inserts an element into the map; replaces an existing element if a matching key is found.
operator [] Inserts an element into the map — operator substitution for SetAt.
RemoveKey Removes an element specified by a key.
RemoveAll Removes all the elements from this map.
GetStartPosition Returns the position of the first element.
GetNextAssoc Gets the next element for iterating.
GetHashTableSize Returns the size (number of elements) of the hash table.
InitHashTable Initializes the hash table and specifies its size.

Status

GetCount Returns the number of elements in this map.
IsEmpty Tests for the empty-map condition (no elements).

CMap Overview | Base Class Members | Hierarchy Chart 

 

728x90
반응형