1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
|
// Remove the image at position pos from the image list.
CImgl& remove(constunsignedint pos) {
if (shared)
throw CImgInstanceException("CImgl<%s>::remove() : Removal from a shared list is not allowed.",pixel_type());
if (pos>=size)
cimg::warn(true,"CImgl<%s>::remove() : Cannot remove an image from a list (%p,%u), at position %u.",
pixel_type(),data,size,pos);
else {
data[pos].empty();
if (!(--size)) empty();
if (size<16 || size>allocsize/4) { // Removing item without reallocation.
if (pos!=size) {
std::memmove(data+pos,data+pos+1,sizeof(CImg<T>)*(size-pos));
CImg<T> &tmp = data[size];
tmp.width = tmp.height = tmp.depth = tmp.dim = 0; tmp.data = NULL;
}
} else { // Removing item with reallocation.
allocsize/=4;
CImg<T> *new_data = new CImg<T>[allocsize];
std::memcpy(new_data,data,sizeof(CImg<T>)*pos);
if (pos!=size) std::memcpy(new_data+pos,data+pos+1,sizeof(CImg<T>)*(size-pos));
std::memset(data,0,sizeof(CImg<T>)*size);
delete[] data;
data = new_data;
}
}
return *this;
}
//! Remove last element of the list;
CImgl& pop_back() { remove(size-1); }
//! Remove first element of the list;
CImgl& pop_front() { remove(0); }
|