#include "guards.h"
#include "outcome.h"
+#include <string.h>
+
#define DEBUG_ARRAY
// uncomment for the noisier debugging version.
that's in use and we want NEW_AT_END, then the existing contents are
jammed up into the front end of the array. */
- array(int number = 0, const contents *init = NIL,
+ array(int number = 0, const contents *init = NULL_POINTER,
int flags = EXPONENTIAL_GROWTH | FLUSH_INVISIBLE);
//!< Constructs an array with room for "number" objects.
- /*!< The initial contents are copied from "init" unless NIL is passed in
- instead. If "init" is not NIL, then it must point to an array of objects
+ /*!< The initial contents are copied from "init" unless NULL_POINTER is passed in
+ instead. If "init" is not NULL_POINTER, then it must point to an array of objects
that contains at least "number". The "flags" are a value based on the
special flags being added bit-wise. If "flags" contains SIMPLE_COPY, then
memmove() is used rather than using the C++ object's assignment operator.
virtual ~array(); //!< destroys the memory allocated for the objects.
- void reset(int number = 0, const contents *initial_contents = NIL);
+ void reset(int number = 0, const contents *initial_contents = NULL_POINTER);
//!< Resizes this array and sets the contents from an array of contents.
- /*< If "initial_contents" is not NIL, then it must contain an array of
- "contents" with at least "number" objects in it. If it is NIL, then
+ /*< If "initial_contents" is not NULL_POINTER, then it must contain an array of
+ "contents" with at least "number" objects in it. If it is NULL_POINTER, then
the size of the array is changed but the contents are not. note that
any pre-existing elements that were previously out of range might still
have their prior contents; the newly available elements are not necessarily
class double_array : public array<double>
{
public:
- double_array(int len = 0, double *data = NIL)
+ double_array(int len = 0, double *data = NULL_POINTER)
: root_object(),
array<double>(len, data, SIMPLE_COPY | EXPONE) {}
double_array(const array<double> &to_copy) : array<double>(to_copy) {}
template <class contents>
array<contents>::array(int num, const contents *init, int flags)
-: root_object(), c_active_length(0), c_real_length(0), c_mem_block(NIL), c_offset(NIL), c_flags(flags)
+: root_object(), c_active_length(0), c_real_length(0), c_mem_block(NULL_POINTER), c_offset(NULL_POINTER), c_flags(flags)
{
if (c_flags > 7) {
#ifdef DEBUG_ARRAY
template <class contents>
array<contents>::array(const array<contents> &cf)
-: root_object(), c_active_length(0), c_real_length(0), c_mem_block(NIL), c_offset(NIL), c_flags(cf.c_flags)
+: root_object(), c_active_length(0), c_real_length(0), c_mem_block(NULL_POINTER), c_offset(NULL_POINTER), c_flags(cf.c_flags)
{
allocator_reset(cf.c_active_length, 1); // get some space.
operator = (cf); // assignment operator does the rest.
template <class contents>
array<contents>::~array()
{
- c_offset = NIL;
+ c_offset = NULL_POINTER;
if (c_mem_block) delete [] c_mem_block;
- c_mem_block = NIL;
+ c_mem_block = NULL_POINTER;
c_active_length = 0;
c_real_length = 0;
}
array<contents> array<contents>::concatenation(const array &s1) const
{
// tailor the return array to the new size needed.
- array<contents> to_return(this->length() + s1.length(), NIL, s1.c_flags);
+ array<contents> to_return(this->length() + s1.length(), NULL_POINTER, s1.c_flags);
to_return.overwrite(0, *this); // put the first part into the new array.
to_return.overwrite(this->length(), s1); // add the second segment.
return to_return;
template <class contents>
array<contents> array<contents>::concatenation(const contents &s1) const
{
- array<contents> to_return(this->length() + 1, NIL, c_flags);
+ array<contents> to_return(this->length() + 1, NULL_POINTER, c_flags);
to_return.overwrite(0, *this);
if (!this->simple())
to_return.access()[to_return.last()] = s1;
template <class contents>
array<contents> array<contents>::subarray(int start, int end) const
{
- bounds_return(start, 0, this->last(), array<contents>(0, NIL, c_flags));
- bounds_return(end, 0, this->last(), array<contents>(0, NIL, c_flags));
- if (start > end) return array<contents>(0, NIL, c_flags);
+ bounds_return(start, 0, this->last(), array<contents>(0, NULL_POINTER, c_flags));
+ bounds_return(end, 0, this->last(), array<contents>(0, NULL_POINTER, c_flags));
+ if (start > end) return array<contents>(0, NULL_POINTER, c_flags);
return array<contents>(end - start + 1, &(this->observe()[start]), c_flags);
}
if (c_mem_block) {
// remove old contents.
delete [] c_mem_block;
- c_mem_block = NIL;
- c_offset = NIL;
+ c_mem_block = NULL_POINTER;
+ c_offset = NULL_POINTER;
}
c_active_length = initial; // reset the length to the reporting size.
c_real_length = initial + blocking; // compute the real length.
if (c_real_length < new_size) {
// there's really not enough space overall, no fooling. we now will
// create a new block.
- c_mem_block = NIL; // zero out the pointer so reset doesn't delete it.
+ c_mem_block = NULL_POINTER; // zero out the pointer so reset doesn't delete it.
delete_old = true;
int blocking = 1;
if (exponential()) blocking = new_size + 1;
class char_star_array : public array<char *>
{
public:
- char_star_array() : array<char *>(0, NIL, SIMPLE_COPY | EXPONE
+ char_star_array() : array<char *>(0, NULL_POINTER, SIMPLE_COPY | EXPONE
| FLUSH_INVISIBLE) {}
~char_star_array() {
// clean up all the memory we're holding.