libnative-utilities/include/array/GrowableArray.hpp
2024-08-15 18:40:30 +08:00

75 lines
1.5 KiB
C++

#ifndef GROWABLEARRAY_HPP
#define GROWABLEARRAY_HPP
class GrowableArray{
public:
static const unsigned int TYPE_BOOLEAN;
static const unsigned int TYPE_BYTE;
static const unsigned int TYPE_SHORT;
static const unsigned int TYPE_INT;
static const unsigned int TYPE_FLOAT;
static const unsigned int TYPE_DOUBLE;
static const unsigned int TYPE_LONG;
static const unsigned int TYPE_VOIDPTR;
GrowableArray(unsigned int type, unsigned int initSize);
~GrowableArray();
void* getArrayData();
unsigned int capacity();
const unsigned int& length=arrlen;
const unsigned int& element_size=elementSize;
void put(const void* e);
void set(unsigned index, const void* e);
void copyFrom(const void* data, unsigned int count);
void copyFrom(const void* data, unsigned int index, unsigned int count);
void copyFrom(const void* data, unsigned int index, unsigned int bufferOffset, unsigned int count);
void* get(unsigned int index);
void remove(unsigned int index);
void gc();
void clear();
private:
unsigned int arrlen;
unsigned int arrayCapacity;
unsigned int elementSize;
unsigned int init_cap;
void* array;
void grow(unsigned int count);
void decrease(unsigned int count);
void checkIndex(unsigned int index);
};
#endif // GROWABLEARRAY_HPP