- // ----------------------------------------------------------------------
- //! Nested class MemBlock
- class MemBlock : public NCollection_BaseVector::MemBlock
- {
- public:
- DEFINE_STANDARD_ALLOC
-
- //! Empty constructor
- MemBlock (NCollection_BaseAllocator* theAlloc)
- : NCollection_BaseVector::MemBlock(0,0,theAlloc)
- {}
- //! Constructor
- MemBlock (const Standard_Integer theFirstInd,
- const Standard_Integer theSize,
- NCollection_BaseAllocator* theAlloc)
- : NCollection_BaseVector::MemBlock (theFirstInd, theSize, theAlloc)
- {
- myData = myAlloc->Allocate(theSize * sizeof(TheItemType));
- for (Standard_Integer i=0; i < theSize; i++)
- new (&((TheItemType *) myData)[i]) TheItemType;
- }
- //! Copy constructor
- MemBlock (const MemBlock& theOther)
- : NCollection_BaseVector::MemBlock (theOther.FirstIndex(),theOther.Size(),
- theOther.myAlloc)
- {
- myLength = theOther.Length();
- myData = myAlloc->Allocate(Size() * sizeof(TheItemType));
- Standard_Integer i;
- for (i=0; i < Length(); i++)
- new (&((TheItemType *) myData)[i]) TheItemType(theOther.Value(i));
- for (; i < Size(); i++)
- new (&((TheItemType *) myData)[i]) TheItemType;
- }
- //! Reinit
- virtual void Reinit (const Standard_Integer theFirst,
- const Standard_Integer theSize)
- {
- if (myData) {
- for (Standard_Integer i=0; i < mySize; i++)
- ((TheItemType *) myData)[i].~TheItemTypeD();
- myAlloc->Free(myData);
- myData = NULL;
- }
- if (theSize > 0) {
- myData = myAlloc->Allocate(theSize * sizeof(TheItemType));
- for (Standard_Integer i=0; i < theSize; i++)
- new (&((TheItemType *) myData)[i]) TheItemType;
- }
- myFirstInd = theFirst;
- mySize = theSize;
- myLength = 0;
- }
- //! Destructor
- virtual ~MemBlock ()
- {
- if (myData) {
- for (Standard_Integer i=0; i < Size(); i++)
- ((TheItemType *) myData)[i].~TheItemTypeD();
- myAlloc->Free(myData);
- myData = NULL;
- }
- }
- //! Operator () const
- const TheItemType& Value (const Standard_Integer theIndex) const
- { return ((TheItemType *) myData) [theIndex]; }
- //! Operator ()
- TheItemType& ChangeValue (const Standard_Integer theIndex)
- { return ((TheItemType *) myData) [theIndex]; }
- //! GetIndex
- Standard_Integer GetIndex (const TheItemType& theItem) const {
- return GetIndexV ((void *)&theItem, sizeof(TheItemType));
- }
- }; // End of the nested class MemBlock