19
19
#ifndef __array_h__
20
20
#define __array_h__
23
* Variable length array implementation. */
22
25
#include <assert.h>
30
/** \class Array Array.h Puma/Array.h
31
* Variable length array implementation. */
26
32
template <class Item>
35
/** Default array size. */
29
36
static const long default_init_size = 5;
37
/** Default array size increment. */
30
38
static const long default_increment = 5;
42
* \param is The default size of the array.
43
* \param incr The default increment value. */
33
44
Array (long is = default_init_size, long incr = default_increment);
46
* \param array The array to copy. */
34
47
Array (const Array<Item>& array);
35
Array<Item>& operator =(const Array<Item>&);
48
/** Assignment operator.
49
* \param copy The array to copy. */
50
Array<Item>& operator =(const Array<Item>& copy);
51
/** Destructor. Destroys the array. */
53
/** Append an item to the array.
54
* \param item The item to append. */
37
55
void append (const Item& item);
56
/** Insert an item at the given array index.
57
* \param index The array index.
58
* \param item The item to insert. */
38
59
void insert (long index, const Item& item);
61
* \param item The item to prepend. */
39
62
void prepend (const Item& item);
63
/** Remove the array item at the given array index.
64
* \param index The array index. */
40
65
void remove (long index);
66
/** Reset the array. Destroys the current array. */
68
/** Get a reference to the array item at the given
69
* array index. If the index exceeds the array
70
* bounds, then the array is reallocated accordingly.
71
* \param index The array index. */
42
72
Item& get (long index);
73
/** Get a reference to the array item at the given
74
* array index. If the index exceeds the array
75
* bounds, then the array is reallocated accordingly.
76
* \param index The array index. */
43
77
Item& operator[] (long index);
78
/** Get the array item at the given array index.
79
* Does not return a reference, thus the item may
80
* be implicitely copied.
81
* \warning Does not validate the index!
82
* \param index The array index. */
44
83
Item fetch (long index) const;
84
/** Get a reference to the array item at the given
86
* \warning Does not validate the index!
87
* \param index The array index. */
45
88
Item& lookup (long index) const;
89
/** Get the number of items in the array. */
46
90
long length () const;