- char* startAddress = address + elementSize;
- const char* endAddress = reinterpret_cast< char* >( mData ) + Count() * elementSize;
- SizeType numberOfBytes = endAddress - startAddress;
- // addresses overlap so use memmove
- memmove( address, startAddress, numberOfBytes );
- SetCount( Count() - 1 );
+ // erase can be called on an unallocated vector
+ if( mData )
+ {
+ char* startAddress = address + elementSize;
+ const char* endAddress = reinterpret_cast< char* >( mData ) + Count() * elementSize;
+ SizeType numberOfBytes = endAddress - startAddress;
+ // addresses overlap so use memmove
+ memmove( address, startAddress, numberOfBytes );
+ SetCount( Count() - 1u );
+ }
+}
+
+char* VectorBase::Erase( char* first, char* last, SizeType elementSize )
+{
+ char* next = NULL;
+
+ if( mData )
+ {
+ char* startAddress = last;
+ const char* endAddress = reinterpret_cast< char* >( mData ) + Count() * elementSize;
+ SizeType numberOfBytes = endAddress - startAddress;
+ // addresses overlap so use memmove
+ memmove( first, startAddress, numberOfBytes );
+ SetCount( Count() - ( last - first ) / elementSize );
+
+ next = first;
+ }
+
+ return next;
+}
+
+void VectorBase::CopyMemory( char* destination, const char* source, size_t numberOfBytes )
+{
+ if( ( ( source < destination ) && ( source + numberOfBytes > destination ) ) ||
+ ( ( destination < source ) && ( destination + numberOfBytes > source ) ) )
+ {
+ // If there is overlap, use memmove.
+ memmove( destination, source, numberOfBytes );
+ }
+ else
+ {
+ // It's safe to use memcpy if there isn't overlap.
+ memcpy( destination, source, numberOfBytes );
+ }