Collection Class Referencean abstract structure to build related data structures
More...
#include <Collection.h>
Inheritance diagram for Collection:
[legend]List of all members.
|
Public Member Functions |
| | Collection () |
| | Set up an empty Collection.
|
| virtual | ~Collection () |
| | Delete all elements of Collection which are not aliased.
|
| int | entries () const |
| | Return the number of entries in the collection.
|
| Boolean | static_size () const |
| | Is the size of the collection static?
|
| void | fix_size () |
| | Make the size constant.
|
| void | unfix_size () |
| | Make the size variable.
|
| const Listable & | operator[] (int sub) const |
| virtual Listable & | operator[] (int sub) |
| | return object corresponding to subth element where the first element is indexed as 0
|
| const Listable * | first_ref () const |
| Listable * | first_ref () |
| | Return the first element of the collection or NULL.
|
| const Listable * | last_ref () const |
| Listable * | last_ref () |
| | Return the last element of the collection or NULL.
|
| virtual void | clear () |
| | Delete all elements of the collection.
|
| virtual void | del (int loc)=0 |
| | Delete the Node in position loc where 0 <= loc <= entries()-1.
|
| virtual Boolean | member (const Listable &el) const |
| | Check to see if node 'el' is a member of the collection.
|
| virtual int | index (const Listable &el) const |
| | Check to see if node 'el' is a member of the collection.
|
| Boolean | aliased (const Listable &el) const |
| | Return true if el is aliased by 1 or more structures--i.e., there are structures refering to el in addition to the owner-structure.
|
| Boolean | valid (const int loc) const |
| | is the locth element valid?
|
| Boolean | valid (const Listable &l) const |
| | Is l a valid element owned by the collection? This raises an error if l is not in the Collection, valid or otherwise.
|
| virtual void | print (ostream &out, char *sep) const |
| | print Collection seperated by sep.
|
| LiveWrapper * | get_wrapper (const Listable &obj) const |
| | Return obj\'s wrapper.
|
| virtual int | structures_OK () const |
| | Check the structure of the data for errors or inconsistency Return 0 and print error message if problems found, otherwise return 1 without message.
|
Protected Member Functions |
| void | _check_subscript (int sub, int validlo, int valid_hi, char *method_name) const |
| void | _subscript_error (int sub, int valid_lo, int valid_hi, char *method_name) const |
| void | _unlink_wrapper (Listable *element) |
| | Remove element\'s wrapper from it\'s list and adjust _first and _last if necessary.
|
| void | _unlink_wrapper (Wrapper *wrap) |
| | Remove wrap from it's list as above.
|
Protected Attributes |
| Wrapper * | _first |
| | First and last elements of the list.
|
| Wrapper * | _last |
| int | _entries |
| | Number of entries in the list.
|
| Boolean | _static |
| | Is the size constant?
|
Friends |
| class | BaseIter |
| ostream & | operator<< (ostream &o, const Collection &c) |
Detailed Description
an abstract structure to build related data structures
Polaris C++ VDL - See also:
- Collection.h
Collection.h
Collection.cc
This describes the Collection class which can be used as the base for more specific template collections of data. The Collection class can not be used on it's own.
The Collection class is the upper-most class in the Collection hierarchy which includes a wide variety of data structures.
These structures each exist in two forms: ownership and reference. An ownership structure takes control of---and responsibility for---all objects which are inserted into it. Ownership structures insure, through reference counting, that, for instance, objects are not prematurely deleted and that memory is properly deallocated when an object is deleted. Once an object has been placed in an ownership collection, the collection is responsible for its maintenance. An object can only be ``owned'' by one collection. If a collection is required to contain elements already owned by other structures, a reference structure is used. Reference structures do not take ownership of objects and, in fact, require that inserted objects are already owned.
Essentially all of the classes used in Polaris are derived from the class Listable which contributes information necessary to indicate ownership of an object and allows the object to be placed in any collection. However, all of the Collection classes, including the reference collections, are class templates. This templatization allows additional type-checking.
Collections maintain inserted objects through Wrappers. The Wrappers provide all of the functionality needed to manipulate objects, perform all necessary operations and reference counting and allow iterators to function properly. Since the Collection class is the most general, it contains only a list of generic Wrappers. The actual instantiated classes would eventually be further specified as either Live or Reference structures and would contain LiveWrappers or RefWrappers accordingly.
Collections also keep track of invalid elements. An invalid element (sometimes ghost nodes or zombies as they are 'partially alive Listable objects') exists when an element is deleted but there are still references to it. Attempts to access these "ghosts" of old elements result in errors. It is not an error for ghost nodes to exist within a Collection and they can be dealt with by checking an element's validity (ghost nodes return false). However, continued presence of ghost-nodes is usually indicative of poorly designed code or the continued presence of data-structures which should have been deallocated.
The Collection class specifies some of the general principles which are maintained by all Collection classes. For example, Collection specifies the abillity of a derived class to be made static, that Collection classes are intended to be indexed begining with 0 and specifies a number of functions which will be used by all derived classes.
Specific collections do not actually inherit from Collection. Instead base collections inherit from Collection and these are contained in specific classes. The hierarchy can be represented by:
Listable, Wrapper, Iterator, TypedCollection, Zombie
Definition at line 138 of file Collection.h.
Constructor & Destructor Documentation
| Collection::Collection |
( |
|
) |
[inline] |
|
|
|
Delete all elements of Collection which are not aliased.
May be virtual and overrided by derived classes.
Definition at line 21 of file Collection.cc.
References _static, and clear(). |
Member Function Documentation
| void Collection::_check_subscript |
( |
int |
sub, |
|
|
int |
validlo, |
|
|
int |
valid_hi, |
|
|
char * |
method_name |
|
) |
const [inline, protected] |
|
|
|
Definition at line 256 of file Collection.h.
References _subscript_error(), and sub().
Referenced by BaseList::assign(), BaseRefList::del(), BaseList::del(), BaseList::grab(), BaseRefList::ins(), BaseList::ins(), BaseList::modify(), operator[](), BaseList::pull(), and valid(). |
| void Collection::_subscript_error |
( |
int |
sub, |
|
|
int |
valid_lo, |
|
|
int |
valid_hi, |
|
|
char * |
method_name |
|
) |
const [protected] |
|
| void Collection::_unlink_wrapper |
( |
Listable * |
element |
) |
[protected] |
|
| void Collection::_unlink_wrapper |
( |
Wrapper * |
wrap |
) |
[protected] |
|
| int Collection::entries |
( |
|
) |
const [inline] |
|
|
|
Return the number of entries in the collection.
Definition at line 274 of file Collection.h.
References _entries.
Referenced by RefSet< T >::any_valid(), Set< T >::empty(), RefSet< T >::empty(), Set< T >::entries(), RefSet< T >::entries(), RefList< T >::entries(), List< T >::entries(), Set< T >::grab(), RefSet< T >::grab(), Set< T >::ins(), RefSet< T >::ins(), RefList< T >::ins_last(), List< T >::ins_last(), and Set< T >::modify(). |
| Boolean Collection::static_size |
( |
|
) |
const [inline] |
|
| void Collection::fix_size |
( |
|
) |
[inline] |
|
| void Collection::unfix_size |
( |
|
) |
[inline] |
|
| const Listable & Collection::operator[] |
( |
int |
sub |
) |
const [inline] |
|
| Listable & Collection::operator[] |
( |
int |
sub |
) |
[virtual] |
|
| const Listable * Collection::first_ref |
( |
|
) |
const [inline] |
|
| Listable * Collection::first_ref |
( |
|
) |
[inline] |
|
| const Listable * Collection::last_ref |
( |
|
) |
const [inline] |
|
| Listable * Collection::last_ref |
( |
|
) |
[inline] |
|
| void Collection::clear |
( |
|
) |
[virtual] |
|
|
|
Delete all elements of the collection.
... delete (or null) _ptr
... remove object
Definition at line 28 of file Collection.cc.
References _entries, _first, _last, _static, _unlink_wrapper(), Wrapper::delete_object(), Wrapper::is_live_wrapper(), Wrapper::next_ref(), ProtoWrapper::object_address(), Wrapper::ref_dec(), and ProtoWrapper::valid().
Referenced by Set< T >::clear(), RefSet< T >::clear(), RefList< T >::clear(), List< T >::clear(), BaseList::make_static_list(), BaseRefList::operator=(), BaseList::operator=(), and ~Collection(). |
| virtual void Collection::del |
( |
int |
loc |
) |
[pure virtual] |
|
| int Collection::index |
( |
const Listable & |
el |
) |
const [virtual] |
|
|
|
Check to see if node 'el' is a member of the collection.
Return -1 if the element was not found, else return the index of the element. Collections are indexed beginning with 0.
Definition at line 71 of file Collection.cc.
References _first, Wrapper::next_ref(), and ProtoWrapper::object_address().
Referenced by Set< T >::_member(), RefSet< T >::_member(), Set< T >::del(), RefSet< T >::del(), RefList< T >::index(), List< T >::index(), Set< T >::ins(), RefSet< T >::ins(), and member(). |
|
|
Return true if el is aliased by 1 or more structures--i.e., there are structures refering to el in addition to the owner-structure.
Note that this says nothing about whether or not \'el\' is owned by *this collection.
Definition at line 328 of file Collection.h. |
| Boolean Collection::valid |
( |
const int |
loc |
) |
const |
|
| void Collection::print |
( |
ostream & |
out, |
|
|
char * |
sep |
|
) |
const [virtual] |
|
| int Collection::structures_OK |
( |
|
) |
const [virtual] |
|
|
|
Check the structure of the data for errors or inconsistency Return 0 and print error message if problems found, otherwise return 1 without message.
- Note:
- invalid nodes in a Collection is NOT considered to be a problem--it's just a part of life.
Definition at line 217 of file Collection.cc.
References _entries, _first, _last, Wrapper::next_ref(), Wrapper::object(), Wrapper::prev_ref(), Listable::print(), ProtoWrapper::structures_OK(), and ProtoWrapper::valid().
Referenced by StmtList::structures_OK(), Set< T >::structures_OK(), RefSet< T >::structures_OK(), RefList< T >::structures_OK(), and List< T >::structures_OK(). |
Friends And Related Function Documentation
| ostream& operator<< |
( |
ostream & |
o, |
|
|
const Collection & |
c |
|
) |
[friend] |
|
Member Data Documentation
|
|
First and last elements of the list.
Definition at line 143 of file Collection.h.
Referenced by BaseMap::_insert_before(), BaseRefMap::_list_insert(), BaseMap::_list_insert(), _unlink_wrapper(), clear(), Collection(), first_ref(), index(), operator[](), BaseIter::reset(), structures_OK(), and valid(). |
|
|
Number of entries in the list.
Definition at line 146 of file Collection.h.
Referenced by BaseMap::_insert_after(), BaseMap::_insert_before(), BaseRefMap::_list_insert(), BaseMap::_list_insert(), _subscript_error(), _unlink_wrapper(), clear(), Collection(), entries(), operator[](), structures_OK(), and valid(). |
The documentation for this class was generated from the following files:
|