#include <amorph.h>
Inheritance diagram for amorph< contents >:


Public Member Functions | |
| amorph (int elements=0) | |
| constructs an amorph capable of holding "elements" pointers. | |
| ~amorph () | |
| int | elements () const |
| the maximum number of elements currently allowed in this amorph. | |
| int | valid_fields () const |
| Returns the number of fields that have non-NIL contents. | |
| void | adjust (int new_max) |
| Changes the maximum number of elements for this amorph. | |
| void | reset (int new_maximum=0) |
| like adjust but doesn't keep existing contents. | |
| outcome | put (int field, const contents *data) |
| Enters an object into the field at index "field" in the amorph. | |
| outcome | append (const contents *data) |
| puts "data" on the end of this amorph. | |
| outcome | operator+= (const contents *data) |
| a synonym for append. | |
| const contents * | get (int field) const |
| Returns a constant pointer to the information at the index "field". | |
| contents * | borrow (int field) |
| Returns a pointer to the information at the index "field". | |
| const contents * | operator[] (int field) const |
| synonym for get. | |
| contents * | operator[] (int field) |
| synonym for borrow. | |
| contents * | acquire (int field) |
| Retrieves a "field" from the amorph, taking responsibility for it back. | |
| outcome | clear (int field) |
| Clears the contents of the field specified. | |
| void | clear_all () |
| Clears every field in the amorph. | |
| outcome | zap (int start, int end) |
| Removes a range of indices from the amorph. | |
| outcome | insert (int position, int lines_to_add) |
| Adds "lines_to_add" indices to the amorph at the index "position". | |
| int | find_empty (outcome &outcome) const |
| Returns the index of a free field if there are any. | |
| const contents * | next_valid (int &field) const |
| Returns the contents of the next valid element at or after "field". | |
| int | find (const contents *to_locate, outcome &outcome) |
| Searches the amorph for the contents specified. | |
| void | swap_contents (amorph< contents > &other) |
| Exchanges the contents of "this" and "other". | |
The object is considered owned by the amorph unless re-acquired from it, and will be deleted when the amorph is destroyed.
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 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 legal range of indices in an amorph is from 0 through "elements() - 1". In general, a range violation for an index is treated as an invalid request and is ignored (although BAD_INDEX is returned by functions with compatible return values).
Model:
The policy followed in amorph is that once an object is checked in with "put" or "append", then the amorph owns that object. The object must not be destroyed externally, because the amorph will automatically destroy the object when either: 1) the amorph itself is destroyed, or 2) another object is entered into the same field. If the stored object must be destroyed externally, then it should be checked out of the amorph with "acquire"; after that, the pointer may be deleted. "get" and "borrow" return a pointer to the stored item while leaving it checked in to the amorph. it is safe to modify what was "borrow"ed or to look at what one "get"s, but do not destroy the pointers returned from either method.
Definition at line 51 of file amorph.h.
constructs an amorph capable of holding "elements" pointers.
Definition at line 45 of file amorph.cpp.
References CHECK_FIELDS, and FUNCDEF.
Definition at line 56 of file amorph.cpp.
References CHECK_FIELDS, amorph< contents >::clear_all(), and FUNCDEF.
| int amorph< contents >::elements | ( | ) | const [inline] |
the maximum number of elements currently allowed in this amorph.
Definition at line 59 of file amorph.h.
Referenced by amorph< contents >::adjust(), advance(), amorph_assign(), amorph_pack(), amorph< contents >::append(), amorph< contents >::borrow(), heavy_file_operations::buffer_files(), amorph< contents >::clear_all(), compare(), directory_tree::compare_trees(), canvas::elements(), fake_pack(), amorph< contents >::find(), amorph< contents >::find_empty(), amorph< contents >::get(), amorph< contents >::insert(), main(), amorph< contents >::next_valid(), filename_list::operator=(), amorph< contents >::put(), test_bogon_amorph(), test_byte_array_amorph(), timer_driver_private_handler(), picture::update(), and amorph< contents >::zap().
| int amorph< contents >::valid_fields | ( | ) | const [inline] |
| void amorph< contents >::adjust | ( | int | new_max | ) |
Changes the maximum number of elements for this amorph.
If the new number is smaller than the original, then the fields at index "new_maximum" and upwards are thrown away. existing fields are kept.
Definition at line 118 of file amorph.cpp.
References CHECK_FIELDS, amorph< contents >::elements(), FUNCDEF, array< contents >::insert(), NIL, and amorph< contents >::zap().
Referenced by amorph< contents >::append(), amorph< contents >::reset(), test_bogon_amorph(), and test_byte_array_amorph().
| void amorph< contents >::reset | ( | int | new_maximum = 0 |
) |
like adjust but doesn't keep existing contents.
Definition at line 83 of file amorph.cpp.
References amorph< contents >::adjust(), CHECK_FIELDS, amorph< contents >::clear_all(), and FUNCDEF.
Referenced by amorph_unpack(), directory_tree::compare_trees(), directory_tree::current(), file_transfer_tentacle::get_differences(), main(), mat_morph< contents >::redimension(), mat_morph< contents >::reset(), and filename_tree::~filename_tree().
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 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 the amorph with acquire().
Definition at line 167 of file amorph.cpp.
References array< contents >::access(), amorph< contents >::acquire(), bounds_return, CHECK_FIELDS, amorph< contents >::elements(), FUNCDEF, common::OKAY, common::OUT_OF_RANGE, and WHACK().
Referenced by amorph_assign(), amorph< contents >::append(), amorph< contents >::clear(), mat_morph< contents >::put(), test_bogon_amorph(), test_byte_array_amorph(), and picture::update().
puts "data" on the end of this amorph.
adds an element to the end of the amorph by increasing the amorph size (with "adjust") and putting the element into the new spot (with "put").
Definition at line 100 of file amorph.cpp.
References amorph< contents >::adjust(), CHECK_FIELDS, amorph< contents >::elements(), FUNCDEF, and amorph< contents >::put().
Referenced by menu::add(), amorph_unpack(), wp_menu_item::connect(), main(), and test_byte_array_amorph().
| const contents * amorph< contents >::get | ( | int | field | ) | const |
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 returned.
Reimplemented from array< contents * >.
Reimplemented in picture.
Definition at line 109 of file amorph.cpp.
References bounds_return, CHECK_FIELDS, amorph< contents >::elements(), FUNCDEF, NIL, and array< contents >::observe().
Referenced by advance(), amorph_assign(), amorph_pack(), heavy_file_operations::buffer_files(), compare(), fake_pack(), mat_morph< contents >::get(), picture::get(), filename_list::operator=(), test_byte_array_amorph(), and picture::update().
| contents * amorph< contents >::borrow | ( | int | field | ) |
Returns a pointer to the information at the index "field".
Also returns NIL for invalid indexes. DO NOT destroy the returned pointer; it is still owned by the amorph.
Definition at line 245 of file amorph.cpp.
References array< contents >::access(), bounds_return, CHECK_FIELDS, amorph< contents >::elements(), FUNCDEF, and NIL.
Referenced by amorph< contents >::acquire(), main(), and timer_driver_private_handler().
| const contents* amorph< contents >::operator[] | ( | int | field | ) | const [inline] |
synonym for get.
Reimplemented from array< contents * >.
Definition at line 100 of file amorph.h.
Referenced by mat_morph< contents >::get().
| contents* amorph< contents >::operator[] | ( | int | field | ) | [inline] |
| contents * amorph< contents >::acquire | ( | int | field | ) |
Retrieves a "field" from the amorph, taking responsibility for it back.
This function is similar to get, except that the contents are pulled out of the amorph. The contents will no longer be destroyed when the amorph is destroyed. To store the modified contents again, use put, and then the amorph will take over management of the contents again. Note that the index is not zapped with this function; the acquired "field" will simply hold a null pointer.
Reimplemented in picture.
Definition at line 216 of file amorph.cpp.
References array< contents >::access(), amorph< contents >::borrow(), CHECK_FIELDS, FUNCDEF, and NIL.
Referenced by mat_morph< contents >::acquire(), picture::acquire(), amorph< contents >::put(), and picture::update().
Clears the contents of the field specified.
Clearing an empty field has no effect. Clearing an invalid field has no effect. NOTE: clearing the contents means that the contents are destroyed, not just disconnected.
Definition at line 208 of file amorph.cpp.
References CHECK_FIELDS, FUNCDEF, NIL, and amorph< contents >::put().
Referenced by amorph< contents >::clear_all(), test_bogon_amorph(), test_byte_array_amorph(), and amorph< contents >::zap().
| void amorph< contents >::clear_all | ( | ) |
Clears every field in the amorph.
Definition at line 92 of file amorph.cpp.
References CHECK_FIELDS, amorph< contents >::clear(), amorph< contents >::elements(), and FUNCDEF.
Referenced by amorph_assign(), mat_morph< contents >::reset(), amorph< contents >::reset(), test_bogon_amorph(), test_byte_array_amorph(), and amorph< contents >::~amorph().
Removes a range of indices from the amorph.
This does not just clear the field associated with the specified index as "clear" does, it actually changes the number of total elements by removing the indices from the amorph. The new amorph contains the old elements up to just before the "start" and from the "end" + 1 through the end of the amorph. AMORPH_BAD_INDEX is returned if either index is out of range. If the zap succeeds, then AMORPH_OKAY is returned, even if the "end" is less than the "start".
Reimplemented from array< contents * >.
Definition at line 154 of file amorph.cpp.
References bounds_return, CHECK_FIELDS, amorph< contents >::clear(), amorph< contents >::elements(), FUNCDEF, common::OKAY, common::OUT_OF_RANGE, and array< contents >::zap().
Referenced by amorph< contents >::adjust(), amorph_assign(), directory_tree::remove_path(), test_bogon_amorph(), test_byte_array_amorph(), mat_morph< contents >::zap_column(), and mat_morph< contents >::zap_row().
Adds "lines_to_add" indices to the amorph at the index "position".
If "lines_to_add" is non-positive, the request is ignored. Inserting at a position beyond the bounds of the array is ignored, but a position AT elements() is allowed (it is an append...).
Reimplemented from array< contents * >.
Definition at line 142 of file amorph.cpp.
References bounds_return, CHECK_FIELDS, amorph< contents >::elements(), FUNCDEF, array< contents >::insert(), common::OKAY, and common::OUT_OF_RANGE.
Referenced by amorph_assign(), and mat_morph< contents >::insert_row().
Returns the index of a free field if there are any.
The returned index is invalid if the "outcome" is IS_FULL.
Definition at line 182 of file amorph.cpp.
References AMO_ALERT, CHECK_FIELDS, amorph< contents >::elements(), FUNCDEF, common::IS_FULL, and common::OKAY.
| const contents * amorph< 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 returned.
Definition at line 194 of file amorph.cpp.
References bounds_return, CHECK_FIELDS, amorph< contents >::elements(), FUNCDEF, array< contents >::get(), and NIL.
| int amorph< contents >::find | ( | const contents * | to_locate, | |
| outcome & | outcome | |||
| ) |
Searches the amorph for the contents specified.
Since only pointers to the contents are maintained, the search is based on finding a pointer in the amorph that is identical to "to_locate". if "outcome" is OKAY, then the index of the entry is returned. If "outcome" is NOT_FOUND, then the contents are not present.
Definition at line 229 of file amorph.cpp.
References CHECK_FIELDS, amorph< contents >::elements(), FUNCDEF, common::NOT_FOUND, and common::OKAY.
Exchanges the contents of "this" and "other".
No validation is performed but this should always succeed given amorphs that are constructed properly.
Definition at line 254 of file amorph.cpp.
References amorph< contents >::_fields_used, CHECK_FIELDS, FUNCDEF, and array< contents >::swap_contents().
1.5.1