X-Git-Url: https://feistymeow.org/gitweb/?a=blobdiff_plain;f=nucleus%2Flibrary%2Fstructures%2Famorph.h;h=69cf27b1831a953037ad4da9ba38ced7d5a4afe9;hb=2b52b91229de41f97a44e775fe0069efe7bb4d48;hp=d2104c700e26179087bd2787f80dcbda6a996c79;hpb=3ea085ec301ed1399dfa1e9f3a240312dc95410b;p=feisty_meow.git diff --git a/nucleus/library/structures/amorph.h b/nucleus/library/structures/amorph.h index d2104c70..69cf27b1 100644 --- a/nucleus/library/structures/amorph.h +++ b/nucleus/library/structures/amorph.h @@ -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 - 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. @@ -55,7 +55,7 @@ namespace structures { template -class amorph : private basis::array +class amorph : protected basis::array { 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; } - //!< 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); @@ -76,12 +76,15 @@ public: 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 @@ -96,11 +99,11 @@ public: //!< 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); @@ -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 - 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); @@ -173,14 +176,14 @@ private: /*!< 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. }; @@ -242,7 +245,7 @@ int amorph_packed_size(const amorph &to_pack); template amorph::amorph(int elements) -: basis::array(elements, NIL, basis::array::SIMPLE_COPY +: basis::array(elements, NULL_POINTER, basis::array::SIMPLE_COPY | basis::array::EXPONE | basis::array::FLUSH_INVISIBLE), _fields_used(0) { @@ -263,7 +266,7 @@ template void amorph::set_nil(int start, int end) { for (int i = start; i <= end; i++) - basis::array::put(i, (contents *)NIL); + basis::array::put(i, (contents *)NULL_POINTER); } template @@ -280,7 +283,7 @@ void amorph::check_fields(const char *where) const } template -void amorph::reset(int new_maximum) +void amorph::resize(int new_maximum) { FUNCDEF("reset"); CHECK_FIELDS; @@ -310,7 +313,7 @@ const contents *amorph::get(int field) const { FUNCDEF("get"); CHECK_FIELDS; - bounds_return(field, 0, elements() - 1, NIL); + bounds_return(field, 0, elements() - 1, NULL_POINTER); return basis::array::observe()[field]; } @@ -334,7 +337,7 @@ void amorph::adjust(int new_maximum) basis::array::insert(old_max, new_fields); for (int i = old_max; i < new_maximum; i++) { - basis::array::put(i, NIL); + basis::array::put(i, NULL_POINTER); } } @@ -370,7 +373,7 @@ basis::outcome amorph::put(int field, const contents *data) 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::access()[field] = (contents *)data; _fields_used++; @@ -395,13 +398,13 @@ const contents *amorph::next_valid(int &field) const { 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::get(i)) { field = i; return basis::array::get(i); } - return NIL; + return NULL_POINTER; } template @@ -409,7 +412,7 @@ basis::outcome amorph::clear(int field) { FUNCDEF("clear"); CHECK_FIELDS; - return this->put(field, NIL); + return this->put(field, NULL_POINTER); } template @@ -420,7 +423,7 @@ contents *amorph::acquire(int field) contents *to_return = borrow(field); if (to_return) { _fields_used--; - basis::array::access()[field] = NIL; + basis::array::access()[field] = NULL_POINTER; } return to_return; } @@ -446,7 +449,7 @@ contents *amorph::borrow(int field) { FUNCDEF("borrow"); CHECK_FIELDS; - bounds_return(field, 0, elements() - 1, NIL); + bounds_return(field, 0, elements() - 1, NULL_POINTER); return basis::array::access()[field]; } @@ -508,7 +511,7 @@ void amorph_assign(amorph &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))); - else to_assign.put(i, (contents *)NIL); + else to_assign.put(i, (contents *)NULL_POINTER); } }