Re: ATL Headache #89: IEnum____
Jason S <jmsachs@gmail.com> wrote:
1) the point of an enumerator is to provide for COM objects what C++
iterators do for C++ objects, namely a means of traversing over the
members of an array or other collection in a standardized manner. COM
objects would have some method to implement this, the standard one
being the _NewEnum property with ID DISPID_NEWENUM, that returns an
IEnumVARIANT so that Visual Basic can use the "For Each m in obj"
syntax. If I don't care about VB then I can do whatever I want, or I
could neglect the enumerator thing altogether and just provide a Count
property & some kind of array member accessor.
Right. Case in point - IHTMLElementCollection, e.g. returned by
document.all property on HTML document. It has length and item
properties for indexed access, and also supports _NewEnum for VBScript's
benefit.
I'm still trying to understand the subtleties of CComEnum vs.
CComEnumOnSTL vs. that weird ICollectionOnSTLCopyImpl<> template given
in the ATL Collections sample.
ICollection* classes implement collection properties Count, Item and
_NewEnum. Typically, you would derive your COM object from one of these,
to turn it into a collection.
CComEnum* classes implement an enumerator object itself (remember, an
enumerator is a separate COM object in its own right, independent from
the collection object). A collection's _NewEnum would normally create an
instance of this class.
ICollectionOnSTLImpl owns the underlying STL container and creates a
enumerator that walks the same container. This only really works for
read-only collections. ICollectionOnSTLCopyImpl differs in that it gives
the enumerator its own copy of the container.
At one point (e.g. MapCollection.h) the
template's member m_coll is referenced, and I can't seem to find
where that member is defined or whether I have to declare it myself.
It's a documented data member of ICollectionOnSTLImpl.
--
With best wishes,
Igor Tandetnik
With sufficient thrust, pigs fly just fine. However, this is not
necessarily a good idea. It is hard to be sure where they are going to
land, and it could be dangerous sitting under them as they fly
overhead. -- RFC 1925