New features: Heterogeneous Assign

 

The semantics of the method Assign() has been changed in comparison to TCollection. In NCollection classes the method Assign() is virtual and it receives the object of the abstract BaseCollection class (see the previous section). Therefore this method can be used to assign any collection type to any other if only these collections are instantiated on the same ItemType.

For example, conversion of Map into Array1 is performed like this:

 

#include <NCollection_Map.hxx>

#include <NCollection_Array1.hxx>

typedef NCollection_Map<gp_Pnt> MyPackage_MapOfPnt;

typedef NCollection_Array1<gp_Pnt> MyPackage_Array1OfPnt;

....

MyPackage_MapOfPnt aMapPnt;

....

MyPackage_Array1OfPnt anArr1Pnt (1, aMapPnt.Size());

anArr1Pnt.Assign (aMapPnt); // heterogeneous assignment

 

There are some aspects to mention:

 

MyPackage_Array1OfPnt anArr1Pnt (1, 100);

MyPackage_MapOfPnt aMapPnt;

....

aMapPnt.Assign(anArr1Pnt);

anArr1Pnt.Assign(aMapPnt);

 

Objects of classes parameterised with two types (DoubleMap, DataMap and  IndexedDataMap) cannot be assigned. Their method Assign throws the exception Standard_TypeMismatch (because it is impossible to check if the passed BaseCollection parameter belongs to the same collection type).