improved array list a bit
This commit is contained in:
parent
813e82415a
commit
38676308e3
@ -1,5 +1,5 @@
|
|||||||
#ifndef ARRAYLIST_H_
|
#ifndef FRAMEWORK_CONTAINER_ARRAYLIST_H_
|
||||||
#define ARRAYLIST_H_
|
#define FRAMEWORK_CONTAINER_ARRAYLIST_H_
|
||||||
|
|
||||||
#include <framework/returnvalues/HasReturnvaluesIF.h>
|
#include <framework/returnvalues/HasReturnvaluesIF.h>
|
||||||
#include <framework/serialize/SerializeAdapter.h>
|
#include <framework/serialize/SerializeAdapter.h>
|
||||||
@ -7,8 +7,9 @@
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief A List that stores its values in an array.
|
* @brief A List that stores its values in an array.
|
||||||
* @details The backend is an array that can be allocated
|
* @details
|
||||||
* by the class itself or supplied via ctor.
|
* The underlying storage is an array that can be allocated by the class
|
||||||
|
* itself or supplied via ctor.
|
||||||
*
|
*
|
||||||
* @ingroup container
|
* @ingroup container
|
||||||
*/
|
*/
|
||||||
@ -19,6 +20,53 @@ public:
|
|||||||
static const uint8_t INTERFACE_ID = CLASS_ID::ARRAY_LIST;
|
static const uint8_t INTERFACE_ID = CLASS_ID::ARRAY_LIST;
|
||||||
static const ReturnValue_t FULL = MAKE_RETURN_CODE(0x01);
|
static const ReturnValue_t FULL = MAKE_RETURN_CODE(0x01);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Copying is forbiden by declaring copy ctor and copy assignment deleted
|
||||||
|
* It is too ambigous in this case.
|
||||||
|
* (Allocate a new backend? Use the same? What to do in an modifying call?)
|
||||||
|
*/
|
||||||
|
ArrayList(const ArrayList& other) = delete;
|
||||||
|
const ArrayList& operator=(const ArrayList& other) = delete;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Number of Elements stored in this List
|
||||||
|
*/
|
||||||
|
count_t size;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This is the allocating constructor;
|
||||||
|
*
|
||||||
|
* It allocates an array of the specified size.
|
||||||
|
*
|
||||||
|
* @param maxSize
|
||||||
|
*/
|
||||||
|
ArrayList(count_t maxSize) :
|
||||||
|
size(0), maxSize_(maxSize), allocated(true) {
|
||||||
|
entries = new T[maxSize];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This is the non-allocating constructor
|
||||||
|
*
|
||||||
|
* It expects a pointer to an array of a certain size and initializes itself to it.
|
||||||
|
*
|
||||||
|
* @param storage the array to use as backend
|
||||||
|
* @param maxSize size of storage
|
||||||
|
* @param size size of data already present in storage
|
||||||
|
*/
|
||||||
|
ArrayList(T *storage, count_t maxSize, count_t size = 0) :
|
||||||
|
size(size), entries(storage), maxSize_(maxSize), allocated(false) {
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Destructor, if the allocating constructor was used, it deletes the array.
|
||||||
|
*/
|
||||||
|
virtual ~ArrayList() {
|
||||||
|
if (allocated) {
|
||||||
|
delete[] entries;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An Iterator to go trough an ArrayList
|
* An Iterator to go trough an ArrayList
|
||||||
*
|
*
|
||||||
@ -30,10 +78,7 @@ public:
|
|||||||
/**
|
/**
|
||||||
* Empty ctor, points to NULL
|
* Empty ctor, points to NULL
|
||||||
*/
|
*/
|
||||||
Iterator() :
|
Iterator(): value(0) {}
|
||||||
value(0) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initializes the Iterator to point to an element
|
* Initializes the Iterator to point to an element
|
||||||
@ -92,47 +137,7 @@ public:
|
|||||||
bool operator!=(const typename ArrayList<T, count_t>::Iterator& other) const {
|
bool operator!=(const typename ArrayList<T, count_t>::Iterator& other) const {
|
||||||
return !(*this == other);
|
return !(*this == other);
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Number of Elements stored in this List
|
|
||||||
*/
|
|
||||||
count_t size;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This is the allocating constructor;
|
|
||||||
*
|
|
||||||
* It allocates an array of the specified size.
|
|
||||||
*
|
|
||||||
* @param maxSize
|
|
||||||
*/
|
|
||||||
ArrayList(count_t maxSize) :
|
|
||||||
size(0), maxSize_(maxSize), allocated(true) {
|
|
||||||
entries = new T[maxSize];
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This is the non-allocating constructor
|
|
||||||
*
|
|
||||||
* It expects a pointer to an array of a certain size and initializes itself to it.
|
|
||||||
*
|
|
||||||
* @param storage the array to use as backend
|
|
||||||
* @param maxSize size of storage
|
|
||||||
* @param size size of data already present in storage
|
|
||||||
*/
|
|
||||||
ArrayList(T *storage, count_t maxSize, count_t size = 0) :
|
|
||||||
size(size), entries(storage), maxSize_(maxSize), allocated(false) {
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Destructor, if the allocating constructor was used, it deletes the array.
|
|
||||||
*/
|
|
||||||
virtual ~ArrayList() {
|
|
||||||
if (allocated) {
|
|
||||||
delete[] entries;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Iterator pointing to the first stored elmement
|
* Iterator pointing to the first stored elmement
|
||||||
@ -223,19 +228,6 @@ public:
|
|||||||
return (maxSize_ - size);
|
return (maxSize_ - size);
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
|
||||||
/**
|
|
||||||
* This is the copy constructor
|
|
||||||
*
|
|
||||||
* It is private, as copying is too ambigous in this case. (Allocate a new backend? Use the same?
|
|
||||||
* What to do in an modifying call?)
|
|
||||||
*
|
|
||||||
* @param other
|
|
||||||
*/
|
|
||||||
ArrayList(const ArrayList& other) :
|
|
||||||
size(other.size), entries(other.entries), maxSize_(other.maxSize_),
|
|
||||||
allocated(false) {}
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
/**
|
/**
|
||||||
* pointer to the array in which the entries are stored
|
* pointer to the array in which the entries are stored
|
||||||
|
Loading…
Reference in New Issue
Block a user