ATL Collections and Enumerators

A collection is a COM object that provides an interface that allows access to a group of data items (raw data or other objects). An interface that follows the standards for providing access to a group of objects is known as a collection interface.

At a minimum, collection interfaces must provide a Count property that returns the number of items in the collection, an Item property that returns an item from the collection based on an index, and a _NewEnum property that returns an enumerator for the collection. Optionally, collection interfaces can provide Add and Remove methods to allow items to be inserted into or deleted from the collection, and a Clear method to remove all items.

Note   You can learn more about collection interfaces and the importance of the _NewEnum property to Visual Basic clients in the article Implementing OLE Automation Collections by Charlie Kindel.

An enumerator is a COM object that provides an interface for iterating through items in a collection. Enumerator interfaces provide serial access to the elements of a collection via four required methods Next, Skip, Reset, and Clone.

You can learn more about enumerator interfaces by reading about the archetypal (but entirely imaginary) IEnumXXXX interface.

Note   There are different design principles behind each type of interface:

Each type of interface plays a different role in providing access to the elements in a collection.

ATL Classes

Class Description
ICollectionOnSTLImpl Collection interface implementation
IEnumOnSTLImpl Enumerator interface implementation (assumes data stored in an STL-compatible container)
CComEnumImpl Enumerator interface implementation (assumes data stored in an array)
CComEnumOnSTL Enumerator object implementation (uses IEnumOnSTLImpl)
CComEnum Enumerator object implementation (uses CComEnumImpl)
_Copy Copy policy class
_CopyInterface Copy policy class
CAdapt Adapter class (hides operator & allowing CComPtr, CComQIPtr, and CComBSTR to be stored in STL containers)

For an example of implementing an STL-based collection, see Implementing an STL-Based Collection.