/* * Copyright 2006 The Android Open Source Project * * Use of this source code is governed by a BSD-style license that can be * found in the LICENSE file.
*/
// Deletion routines void erase(int index, int count); // Removes the entry at 'index' and replaces it with the last array element void removeShuffle(int index);
// Insertion routines void* prepend();
void append(); void append(int count); void* append(constvoid* src, int count);
void* insert(int index); void* insert(int index, int count, constvoid* src);
void pop_back() {
SkASSERT(fSize > 0);
fSize--;
}
friendbooloperator==(const SkTDStorage& a, const SkTDStorage& b); friendbooloperator!=(const SkTDStorage& a, const SkTDStorage& b) { return !(a == b);
}
// Adds delta to fSize. Crash if outside [0, INT_MAX] int calculateSizeOrDie(int delta);
// Move the tail of the array defined by the indexes tailStart and tailEnd to dstIndex. The // elements at dstIndex are overwritten by the tail. void moveTail(int dstIndex, int tailStart, int tailEnd);
// Copy src into the array at dstIndex. void copySrc(int dstIndex, constvoid* src, int count);
constint fSizeOfT;
std::byte* fStorage{nullptr}; int fCapacity{0}; // size of the allocation in fArray (#elements) int fSize{0}; // logical number of elements (fSize <= fCapacity)
};
staticinlinevoid swap(SkTDStorage& a, SkTDStorage& b) {
a.swap(b);
}
// SkTDArray<T> implements a std::vector-like array for raw data-only objects that do not require // construction or destruction. The constructor and destructor for T will not be called; T objects // will always be moved via raw memcpy. Newly created T objects will contain uninitialized memory. template <typename T> class SkTDArray { public:
SkTDArray() : fStorage{sizeof(T)} {}
SkTDArray(const T src[], int count) : fStorage{src, count, sizeof(T)} { }
SkTDArray(const std::initializer_list<T>& list) : SkTDArray(list.begin(), list.size()) {}
friendbooloperator==(const SkTDArray<T>& a, const SkTDArray<T>& b) { return a.fStorage == b.fStorage;
} friendbooloperator!=(const SkTDArray<T>& a, const SkTDArray<T>& b) { return !(a == b); }
void swap(SkTDArray<T>& that) { using std::swap;
swap(fStorage, that.fStorage);
}
bool empty() const { return fStorage.empty(); }
// Return the number of elements in the array int size() const { return fStorage.size(); }
// Return the total number of elements allocated. // Note: capacity() - size() gives you the number of elements you can add without causing an // allocation. int capacity() const { return fStorage.capacity(); }
// return the number of bytes in the array: count * sizeof(T)
size_t size_bytes() const { return fStorage.size_bytes(); }
// Sets the number of elements in the array. // If the array does not have space for count elements, it will increase // the storage allocated to some amount greater than that required. // It will never shrink the storage. void resize(int count) {
fStorage.resize(count);
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.