![]()
|
Top: Basic types: Lists: objlist: Manipulation #include <ptypes.h> int length(const objlist& s); void setlength(objlist& s, int newcount); void pack(objlist& s); void clear(objlist& s); void ins(objlist& s, int i, unknown* obj); int add(objlist& s, unknown* obj); void put(objlist& s, int i, unknown* obj); void del(objlist& s, int i); unknown* get(const objlist& s, int i); int indexof(const objlist& s, unknown* obj); int length(const objlist& s) returns the number of items in the given object list s. setlength(objlist& s, int newcount) sets the length of the dynamic array to newcount. If the new count is greater than the old number of items, all extra positions are filled with NULL pointers. If the new count is less than the old number and the list "owns" objects, all objects left out of the list are destroyed. pack(objlist& s) optimizes the memory usage for the objlist object. Useful when a big number of objects has been inserted and then deleted from the list. clear(objlist& s) clears all items of the list s. This function may also destroy all objects if the list "owns" objects. ins(objlist& s, int i, unknown* iobj) inserts object obj at the position i. The position is 0-based. Inserting a new item at the position equal to the number of items is not an error -- in this case the function ins() simply adds the object like add(). int add(objlist& s, unknown* obj) adds object obj to the list s and returns the actual position at which the item was inserted. put(objlist& s, int i, unknown* obj) assigns a new object value to the item i of the list s. The previous object may be destroyed depending on whether the list "owns" objects. del(objlist& s, int i) removes the item at the position i. The object associated with this item may be destroyed depending on whether the list "owns" objects. unknown* get(const objlist& s, int i) returns the object value at position i. Indexed access is also allowed through operator[]. Both get() and operator[] may generate an unrecoverable error if the index is out of bounds and if the library is compiled with either _DEBUG or DEBUG conditional symbol. In other words, the non-debugging version of the library never checks for index overlfows, thus making your program somewhat faster but less safe. int indexof(const objlist& s, unknown* obj) finds a pointer obj in the object list. If the pointer is not found in the list, this function returns -1, otherwise it returns the index of the item. See also: Constructors/destructors PTypes home |