An amorph has a specified number of fields at any one time, but the number
can be changed with "zap", "insert" and "adjust". Fields in the amorph
- are either full or empty, where an empty field in the amorph has NIL as
+ are either full or empty, where an empty field in the amorph has NULL_POINTER as
its content. "put" adds a new field to the amorph. "get" retrieves the
contents of a field as a constant. "acquire" is used to check a field
out of the amorph, meaning that the amorph no longer possesses that field.
//!< the maximum number of elements currently allowed in this amorph.
int valid_fields() const { return _fields_used; }
- //!< Returns the number of fields that have non-NIL contents.
+ //!< Returns the number of fields that have non-null contents.
/*!< This might be different from the number of total elements. */
void adjust(int new_max);
index "new_maximum" and upwards are thrown away. existing fields are
kept. */
- void reset(int new_maximum = 0);
+ void resize(int new_maximum = 0);
//!< like adjust but doesn't keep existing contents.
+ void reset() { this->resize(0); }
+ //!< cleans out all of the contents.
+
basis::outcome put(int field, const contents *data);
//!< Enters an object into the field at index "field" in the amorph.
- /*!< If "data" is NIL, then the field is cleared. The amorph considers the
+ /*!< If "data" is NULL_POINTER, then the field is cleared. The amorph considers the
pointer "data" to be its own property after put is invoked; "data"
should not be destructed since the amorph will automatically do so.
This restriction does not hold if the object is checked back out of
//!< a synonym for append.
//! Returns a constant pointer to the information at the index "field".
- /*! If no information is stored or the field is out range, then NIL is
+ /*! If no information is stored or the field is out range, then NULL_POINTER is
returned. */
const contents *get(int field) const;
//! Returns a pointer to the information at the index "field".
- /*! Also returns NIL for invalid indexes. DO NOT destroy the returned
+ /*! Also returns NULL_POINTER for invalid indexes. DO NOT destroy the returned
pointer; it is still owned by the amorph. */
contents *borrow(int field);
const contents *next_valid(int &field) const;
//!< Returns the contents of the next valid element at or after "field".
/*!< "field" is set to the location where an entry was found, if one was
- actually found. If none exists at "field" or after it, then NIL is
+ actually found. If none exists at "field" or after it, then NULL_POINTER is
returned. */
int find(const contents *to_locate, basis::outcome &o);
/*!< This is only used for the debugging version. */
void set_nil(int start, int end);
- // Puts NIL in the indices between start and end.
+ // Puts NULL_POINTER in the indices between start and end.
/*!< Does not delete whatever used to reside there; it just sets the
- pointers to NIL. */
+ pointers to NULL_POINTER. */
// not to be used: amorphs should not be copied because it is intended that
// they support storing heavyweight objects that either have no copy
// constructors or have high-cost copy constructors.
- amorph(const amorph &to_copy) {} //!< not to be used.
+ amorph(const amorph &to_copy) {_fields_used = 0;} //!< not to be used.
amorph &operator = (const amorph &to_copy) { return *this; }
//!< not to be used.
};
template <class contents>
amorph<contents>::amorph(int elements)
-: basis::array<contents *>(elements, NIL, basis::array<contents *>::SIMPLE_COPY
+: basis::array<contents *>(elements, NULL_POINTER, basis::array<contents *>::SIMPLE_COPY
| basis::array<contents *>::EXPONE | basis::array<contents *>::FLUSH_INVISIBLE),
_fields_used(0)
{
void amorph<contents>::set_nil(int start, int end)
{
for (int i = start; i <= end; i++)
- basis::array<contents *>::put(i, (contents *)NIL);
+ basis::array<contents *>::put(i, (contents *)NULL_POINTER);
}
template <class contents>
}
template <class contents>
-void amorph<contents>::reset(int new_maximum)
+void amorph<contents>::resize(int new_maximum)
{
FUNCDEF("reset");
CHECK_FIELDS;
{
FUNCDEF("get");
CHECK_FIELDS;
- bounds_return(field, 0, elements() - 1, NIL);
+ bounds_return(field, 0, elements() - 1, NULL_POINTER);
return basis::array<contents *>::observe()[field];
}
basis::array<contents *>::insert(old_max, new_fields);
for (int i = old_max; i < new_maximum; i++) {
- basis::array<contents *>::put(i, NIL);
+ basis::array<contents *>::put(i, NULL_POINTER);
}
}
CHECK_FIELDS;
bounds_return(field, 0, elements() - 1, basis::common::OUT_OF_RANGE);
contents *to_whack = acquire(field);
- WHACK(to_whack);
+ delete to_whack;
if (data) {
basis::array<contents *>::access()[field] = (contents *)data;
_fields_used++;
{
FUNCDEF("next_valid");
CHECK_FIELDS;
- bounds_return(field, 0, elements() - 1, NIL);
+ bounds_return(field, 0, elements() - 1, NULL_POINTER);
for (int i = field; i < elements(); i++)
if (basis::array<contents *>::get(i)) {
field = i;
return basis::array<contents *>::get(i);
}
- return NIL;
+ return NULL_POINTER;
}
template <class contents>
{
FUNCDEF("clear");
CHECK_FIELDS;
- return this->put(field, NIL);
+ return this->put(field, NULL_POINTER);
}
template <class contents>
contents *to_return = borrow(field);
if (to_return) {
_fields_used--;
- basis::array<contents *>::access()[field] = NIL;
+ basis::array<contents *>::access()[field] = NULL_POINTER;
}
return to_return;
}
{
FUNCDEF("borrow");
CHECK_FIELDS;
- bounds_return(field, 0, elements() - 1, NIL);
+ bounds_return(field, 0, elements() - 1, NULL_POINTER);
return basis::array<contents *>::access()[field];
}
}
for (int i = 0; i < to_assign.elements(); i++) {
if (to_copy.get(i)) to_assign.put(i, new contents(*to_copy.get(i)));
- else to_assign.put(i, (contents *)NIL);
+ else to_assign.put(i, (contents *)NULL_POINTER);
}
}