partly working mac build settings from last update
[feisty_meow.git] / nucleus / library / structures / amorph.h
index d2104c700e26179087bd2787f80dcbda6a996c79..69cf27b1831a953037ad4da9ba38ced7d5a4afe9 100644 (file)
@@ -29,7 +29,7 @@
 
   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
 
   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.
   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.
@@ -55,7 +55,7 @@
 namespace structures {
 
 template <class contents>
 namespace structures {
 
 template <class contents>
-class amorph : private basis::array<contents *>
+class amorph : protected basis::array<contents *>
 {
 public:
   amorph(int elements = 0);
 {
 public:
   amorph(int elements = 0);
@@ -67,7 +67,7 @@ public:
     //!< the maximum number of elements currently allowed in this amorph.
 
   int valid_fields() const { return _fields_used; }
     //!< 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);
     /*!< This might be different from the number of total elements. */
 
   void adjust(int new_max);
@@ -76,12 +76,15 @@ public:
     index "new_maximum" and upwards are thrown away.  existing fields are
     kept. */
 
     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.
 
     //!< 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.
   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
     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
@@ -96,11 +99,11 @@ public:
     //!< a synonym for append.
 
   //! Returns a constant pointer to the information at the index "field".
     //!< 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".
   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);
 
   pointer; it is still owned by the amorph. */
   contents *borrow(int field);
 
@@ -150,7 +153,7 @@ public:
   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
   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);
     returned. */
 
   int find(const contents *to_locate, basis::outcome &o);
@@ -173,14 +176,14 @@ private:
     /*!< This is only used for the debugging version. */
 
   void set_nil(int start, int end);
     /*!< 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
     /*!< 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.
 
   // 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.
 };
   amorph &operator = (const amorph &to_copy) { return *this; }
     //!< not to be used.
 };
@@ -242,7 +245,7 @@ int amorph_packed_size(const amorph<contents> &to_pack);
 
 template <class contents>
 amorph<contents>::amorph(int elements)
 
 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)
 {
       | basis::array<contents *>::EXPONE | basis::array<contents *>::FLUSH_INVISIBLE),
   _fields_used(0)
 {
@@ -263,7 +266,7 @@ template <class contents>
 void amorph<contents>::set_nil(int start, int end)
 {
   for (int i = start; i <= end; i++)
 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>
@@ -280,7 +283,7 @@ void amorph<contents>::check_fields(const char *where) const
 }
 
 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("reset");
   CHECK_FIELDS;
@@ -310,7 +313,7 @@ const contents *amorph<contents>::get(int field) const
 {
   FUNCDEF("get");
   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];
 }
 
   return basis::array<contents *>::observe()[field];
 }
 
@@ -334,7 +337,7 @@ void amorph<contents>::adjust(int new_maximum)
 
   basis::array<contents *>::insert(old_max, new_fields);
   for (int i = old_max; i < new_maximum; i++) {
 
   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);
   }
 }
 
   }
 }
 
@@ -370,7 +373,7 @@ basis::outcome amorph<contents>::put(int field, const contents *data)
   CHECK_FIELDS;
   bounds_return(field, 0, elements() - 1, basis::common::OUT_OF_RANGE);
   contents *to_whack = acquire(field);
   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++; 
   if (data) {
     basis::array<contents *>::access()[field] = (contents *)data;
     _fields_used++; 
@@ -395,13 +398,13 @@ const contents *amorph<contents>::next_valid(int &field) const
 {
   FUNCDEF("next_valid");
   CHECK_FIELDS;
 {
   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);
     }
   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>
 }
 
 template <class contents>
@@ -409,7 +412,7 @@ basis::outcome amorph<contents>::clear(int field)
 {
   FUNCDEF("clear");
   CHECK_FIELDS;
 {
   FUNCDEF("clear");
   CHECK_FIELDS;
-  return this->put(field, NIL);
+  return this->put(field, NULL_POINTER);
 }
 
 template <class contents>
 }
 
 template <class contents>
@@ -420,7 +423,7 @@ contents *amorph<contents>::acquire(int field)
   contents *to_return = borrow(field);
   if (to_return) {
     _fields_used--;
   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;
 }
   }
   return to_return;
 }
@@ -446,7 +449,7 @@ contents *amorph<contents>::borrow(int field)
 {
   FUNCDEF("borrow");
   CHECK_FIELDS;
 {
   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];
 }
 
   return basis::array<contents *>::access()[field];
 }
 
@@ -508,7 +511,7 @@ void amorph_assign(amorph<contents> &to_assign,
   }
   for (int i = 0; i < to_assign.elements(); i++) {
     if (to_copy.get(i)) to_assign.put(i, new contents(*to_copy.get(i)));
   }
   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);
   }
 }
 
   }
 }