New features: Class BaseCollection

There is a common abstract base class for all collections for a given item type (e.g., gp_Pnt). Developer X can arbitrarily name this base class like MyPackage_BaseCollPnt in the examples above. This name is further used in the declarations of any (non-abstract) collection class to designate the C++ inheritance.

This base class has the public API:

- abstract class Iterator as the base class for all Iterators descried above;

- Iterator& CreateIterator () const - creates and returns the Iterator on this collection;

- Standard_Integer Size () const - returns the number of items in this collection;

- void Assign (const NCollection_BaseCollection& theOther) - copies the contents of the Other to this collection object;

These members enable accessing any collection without knowing its exact type. In particular, it makes possible to implement methods receiving objects of the abstract collection type: #include

DEFINE_MAP(MyPackage_MapOfPnt, MyPackage_BaseCollPnt, gp_Pnt)

MyPackage_MapOfPnt aMapPnt;

....

Standard_Boolean aResult = Perform (aMapPnt);

....

Standard_Boolean MyClass::Perform(const MyPackage_BaseCollPnt& theColl)

{

// create type-independent iterator (this iterator is abstract class)

MyPackage_BaseCollPnt::Iterator& anIter = theColl.CreateIterator();

for (; anIter.More(); anIter.Next())

myCentre += anIter.Value().XYZ();

...

}

Note that there are fundamental differences between the shown type-independent iterator and the iterator belonging to a particular non-abstract collection:

- Type-independent iterator can only be obtained via the call CreateIterator() ; the typed iterator & only via the explicit construction.

- Type-independent iterator is an abstract class, so it is impossible to copy it or to assign it to another collection object; the typed iterators can be copied and reassigned using the method Init() .

- Type-independent iterator is actually destroyed when its collection object is destroyed; the typed iterator is destroyed as any other C++ object.

The common point between them is that it is possible to create an unlimited number of both types of iterators on the same collection object.