#define VECTOR_H
typedef enum vector_error_e {
- Vector_ReadOnly,
Vector_PreAllocated,
Vector_ItemNotFound
} vector_error_t;
template <typename Type>
class CVector {
private:
- bool m_ReadOnly; /**< indicates whether the list is read-only */
mutable Type *m_List; /**< the actual list */
int m_Count; /**< the number of items in the list */
int m_AllocCount; /**< the number of allocated items */
m_List = NULL;
m_Count = 0;
m_AllocCount = 0;
- m_ReadOnly = false;
}
/**
RESULT<bool> Insert(Type Item) {
Type *NewList;
- if (m_ReadOnly) {
- THROW(bool, Vector_ReadOnly, "Vector is read-only.");
- }
-
if (m_AllocCount == 0) {
NewList = (Type *)realloc(m_List, sizeof(Type) * ++m_Count);
RESULT<bool> Remove(int Index) {
Type *NewList;
- if (m_ReadOnly) {
- THROW(bool, Vector_ReadOnly, "Vector is read-only.");
- }
-
if (m_AllocCount != 0) {
THROW(bool, Vector_PreAllocated, "Vector is pre-allocated.");
}
memcpy(m_List, List, sizeof(Type) * Count);
m_Count = Count;
- m_ReadOnly = false;
RETURN(bool, true);
}