Enumerators provide a consistent way to iterate through a collection of objects. For example, you can define a simple enumerator to access strings in a collection. A complex enumerator can access records from a database.
This article describes:
ATL does not define any standard objects for enumerators. However, it does provide you with the infrastructure for building them easily using the CComEnum and _Copy templates.
In COM, enumerators are implemented as separate objects that usually support a single interface IEnumxxxx where xxxx is the type that is being enumerated. Standard enumerator types defined by COM include: IEnumUnknown, IEnumMoniker, IEnumString, IEnumVARIANT, IEnumFORMATETC, IEnumSTATSTG, IEnumSTATDATA, and IEnumOLEVERB.
In ATL, CComEnum<Base, piid, T, Copy> defines an enumerator object that enumerates objects of type T. The parameter Base is the name of the interface that represents this enumerator (for example, IEnumVARIANT), and piid is a pointer to the IID of that interface. The parameter Copy is the name of a class used by CComEnum to implement copying the type and is typically used when cloning the enumerator.
A _Copy<class T> class is used to perform deep copy semantics for the particular type T. ATL predefines certain copy classes for your convenience: _Copy<VARIANT>, _Copy<LPOLESTR>, _Copy<OLEVERB>, _Copy<CONNECTDATA>, and _CopyInterface<>. These can be used to build quickly many of the standard enumerators.
CComIEnum is a pure virtual class that defines an enumeration interface.
CComIEnumImpl implements the methods on the enumeration interface: Next, Skip, Reset, and Clone. This is generally only used internally by ATL in the implementation of CComIEnum.
For further information, see IEnumUnknown, IEnumMoniker, IEnumString, IEnumVARIANT, IEnumFORMATETC, IEnumSTATSTG, IEnumSTATDATA, and IEnumOLEVERB in the Win32 SDK.