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:

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:

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.