Main Page   Class Hierarchy   Compound List   File List   Compound Members   File Members   Related Pages   Examples  

type_allocator Template Class Reference

A list of objects. More...

#include <type_allocator.h>

Inheritance diagram for type_allocator:

BlockingCurveList BlockingEdgeList collection hash_link hashtable RFBocoList RFFileSet stack List of all members.

Public Types

typedef T* iterator
 An iterator is just a pointer to the object.

typedef const T* const_iterator
 An iterator is just a pointer to the object.

typedef T& reference
 A reference is a reference to the object.

typedef const T& const_reference
 A reference is a reference to the object.

typedef size_t difference_type
 The distance between two entries in the list is the longest possible unsigned integer on the platform.


Public Methods

iterator begin ()
 Beginning of elements. More...

const_iterator begin () const
 Beginning of elements. More...

iterator end ()
 One past end of elements. More...

const_iterator end () const
 One past end of elements. More...

iterator last ()
 Last entry in list. More...

const_iterator last () const
 Last entry in list. More...

difference_type distance_ta (const_iterator f, const_iterator s) const
 Distance between two operands. More...

difference_type distance_ta (const_iterator p) const
 Index of entry p in list. More...

size_t curAllocation () const
 Return current number of allocated slots. More...

void erase (iterator s, iterator e)
 Erase from s to and including e-1. More...

void erase (iterator p)
 Erase specified entry. More...

void uninitialized_copy (const_iterator s, const_iterator e, iterator d)
 Not a full implementation. More...

void deleteElements ()
 Free the elements. More...

void set_exp_alloc ()
 Use the exponential allocator. More...

void set_block_alloc ()
 Use the block allocator. More...

void set_justsize_alloc ()
 Size the allocation just to fit. More...

void reAllocation (T *newElements, size_t nextAlloc, size_t nNext)
 Reset the element storage to specified values. More...

void reserve (size_t n)
 Make sure we have enough storage to hold specified number of elements. More...

void reserveArray (size_t n)
 Array reservation. More...

 type_allocator ()
 Empty list. More...

 type_allocator (const type_allocator<T, defAlloc>& fl)
 Copy specified list.

type_allocator<T, defAlloc>& operator= (const type_allocator<T, defAlloc>& fl)
 Simply copy operand into list. More...

 ~type_allocator ()
 Delete element storage. More...

void destroy_obj ()
 So can put type allocators in type allocator lists on machines with compilers that do not understand ~T();.

int empty () const
 Is the list empty? More...

size_t size () const
 Return number of elements in list. More...

void setNElements (size_t n)
 Set the number of elements to specified value. More...

iterator find (const T& id)
 Find given object in list. More...

iterator find (iterator s, iterator e, const T& id)
 Find given object in list within given range. More...

const_iterator find (const T& id) const
 Find given object in list. More...

const_iterator find (const_iterator s, const_iterator e, const T& id) const
 Find given object in list within given range. More...

size_t nextAllocation (size_t n) const
 Compute the next allocation size that will fit requested allocation if requested size is greater than current allocation. More...

iterator insert (const T& id)
 Insert object at end of list. More...

iterator add (const T& id)
iterator insert (iterator position, const T& id)
 Insert object at specified position. More...

int sortBy (int (*comparison)(const void *a, const void *b))
 Sort the entire list by the comparison function using qsort. More...

int sortBy (const_iterator s, const_iterator e, int (*comparison)(const void *a, const void *b))
 Sort list between given start and end by the comparison function using qsort. More...

int makeuniq (int (*comparison)(const void *a, const void *b))
 Make the entries in type_allocator unique by sorting the list then removing duplicate entires. More...

int makeuniq (iterator s, iterator e, int (*comparison)(const void *a, const void *b))
 Make the entries in type_allocator unique by sorting the list then removing duplicate entires. More...

T& operator[] (size_t i)
 Return reference to object at specified index. More...

const T& operator[] (size_t i) const
 Return reference to object at specified index. More...


Friends

int operator== (const type_allocator<T, defAlloc>& iA, const type_allocator<T, defAlloc>& iB)
 So that type allocator lists can be part of other lists.


Detailed Description

template<class T, size_t defAlloc> template class type_allocator

A list of objects.

Template class must include type for list to hold and the number of elements to be held on the stack. Once users add more objects than the default initial size, the storage is dynamically created to hold the members. Any object that implements a default constructor, a copy constructor, and equal operator, a destructor, and an equality operator can be put into type_allocator lists. Note that since C++ constructs default constructors, only the equal operator and the equality operator are required. A small note: There are a number of methods that are duplicates of one another except one has the signature of const and the other does not. The code needs to be replicated because casts from non-const arguments to const arguments (or visa versa) is not symantically correct and certain compilers might make incorrect assumptions in compiling the code.

Examples:

example_uns_ftn.f, exmesh_impl.cxx, exuns_impl.cxx, nodetonode.cxx, OpenGateway.C, OpenGatewayBase.C, readexuns_ftn.f, test_blk.C, test_blkinter.C, vector1.cxx, vector2.cxx, and vector3.cxx.


Constructor & Destructor Documentation

template<classT, size_tdefAlloc>
type_allocator<T, defAlloc>::type_allocator<T, defAlloc> ( )
 

Empty list.

By default use exponential allocator.

template<classT, size_tdefAlloc>
type_allocator<T, defAlloc>::~type_allocator<T, defAlloc> ( ) [inline]
 

Delete element storage.

DO NOT make virtual because this is a template class. All subclasses that use a list as parent class must explicitly carry out destructor by invoking it explicitly.

See also:
deleteElements().


Member Function Documentation

template<classT, size_tdefAlloc>
iterator type_allocator<T, defAlloc>::begin ( ) [inline]
 

Beginning of elements.

Returns:
iterator at start of list.

template<classT, size_tdefAlloc>
const_iterator type_allocator<T, defAlloc>::begin ( ) const [inline]
 

Beginning of elements.

Returns:
iterator at start of list.
Examples:
OpenGateway.C, and vector3.cxx.

template<classT, size_tdefAlloc>
iterator type_allocator<T, defAlloc>::end ( ) [inline]
 

One past end of elements.

Returns:
one past last valid entry.

template<classT, size_tdefAlloc>
const_iterator type_allocator<T, defAlloc>::end ( ) const [inline]
 

One past end of elements.

Returns:
one past last valid entry.
Examples:
OpenGateway.C, vector1.cxx, and vector3.cxx.

template<classT, size_tdefAlloc>
iterator type_allocator<T, defAlloc>::last ( ) [inline]
 

Last entry in list.

Returns:
iterator to last valid entry.

template<classT, size_tdefAlloc>
const_iterator type_allocator<T, defAlloc>::last ( ) const [inline]
 

Last entry in list.

Returns:
iterator to last valid entry.

template<classT, size_tdefAlloc>
difference_type type_allocator<T, defAlloc>::distance_ta ( const_iterator f,
const_iterator s ) const [inline]
 

Distance between two operands.

Parameters:
f   iterator for entry.
s   iterator for start (entry >= start)
Returns:
number of entries between given entry and starting entry.

template<classT, size_tdefAlloc>
difference_type type_allocator<T, defAlloc>::distance_ta ( const_iterator p ) const [inline]
 

Index of entry p in list.

Invokes distance_ts(const_iterator, const_iterator) with starting entry specified as the beginning of the list.

See also:
begin().

template<classT, size_tdefAlloc>
size_t type_allocator<T, defAlloc>::curAllocation ( ) const [inline]
 

Return current number of allocated slots.

Returns:
number of allocated slots.

template<classT, size_tdefAlloc>
void type_allocator<T, defAlloc>::erase ( iterator s,
iterator e ) [inline]
 

Erase from s to and including e-1.

Parameters:
s   iterator for start.
e   one past last entry to erase.

Reimplemented in hashtable.

template<classT, size_tdefAlloc>
void type_allocator<T, defAlloc>::erase ( iterator s ) [inline]
 

Erase specified entry.

Parameters:
p   iterator to entry to erase.

Reimplemented in hashtable.

template<classT, size_tdefAlloc>
void type_allocator<T, defAlloc>::uninitialized_copy ( const_iterator s,
const_iterator e,
iterator d ) [inline]
 

Not a full implementation.

Uses equality operator instead of new operator with specified space and copy constructor.

Parameters:
s   iterator for start.
e   one past last entry to initialize.
d   source of initialization data.

template<classT, size_tdefAlloc>
void type_allocator<T, defAlloc>::deleteElements ( ) [inline]
 

Free the elements.

If not on stack, then delete all dynamically allocated elements and set storage to stack. If in stack, then just erase all elements.

template<classT, size_tdefAlloc>
void type_allocator<T, defAlloc>::set_exp_alloc ( ) [inline]
 

Use the exponential allocator.

At least a factor of two more memory than required will be allocated for the list on any resize request.

Examples:
OpenGatewayBase.C.

template<classT, size_tdefAlloc>
void type_allocator<T, defAlloc>::set_block_alloc ( ) [inline]
 

Use the block allocator.

Allocate block in multiples of the stack allocation if the list needs more memory.

Examples:
vector1.cxx, and vector2.cxx.

template<classT, size_tdefAlloc>
void type_allocator<T, defAlloc>::set_justsize_alloc ( ) [inline]
 

Size the allocation just to fit.

The list will be sized to hold only the amount of memory requested. Further inserts into the list imply resizing the list once the stack size has been exhausted.

template<classT, size_tdefAlloc>
void type_allocator<T, defAlloc>::reAllocation ( T * newElements,
size_t nextAlloc,
size_t nNext ) [inline]
 

Reset the element storage to specified values.

Parameters:
newElements   new element storage.
nextAlloc   how much storage allocated in newElements.
nNext   how many elements are in newElements.

template<classT, size_tdefAlloc>
void type_allocator<T, defAlloc>::reserve ( size_t n ) [inline]
 

Make sure we have enough storage to hold specified number of elements.

Parameters:
n   list must be sized to hold this number of elements. Number of elements unchanged.
See also:
nextAllocation().

template<classT, size_tdefAlloc>
void type_allocator<T, defAlloc>::reserveArray ( size_t n ) [inline]
 

Array reservation.

In addition to reserving the space, also sets the number of elements to specified allocation size.

See also:
reserve().
Parameters:
n   array size.
Examples:
OpenGateway.C.

template<classT, size_tdefAlloc>
type_allocator< T,defAlloc >& type_allocator<T, defAlloc>::operator= ( const type_allocator< T,defAlloc >& fl ) [inline]
 

Simply copy operand into list.

Note on HP compilers, need to do copy by hand due to compiler bug.

See also:
unitialized_copy.
Parameters:
fl   operand.
Returns:
reference to this.

template<classT, size_tdefAlloc>
int type_allocator<T, defAlloc>::empty ( ) const [inline]
 

Is the list empty?

Returns:
1 if list is empty.

template<classT, size_tdefAlloc>
size_t type_allocator<T, defAlloc>::size ( ) const [inline]
 

Return number of elements in list.

Returns:
nElements.
Examples:
exuns_impl.cxx, hashtable.cxx, and OpenGateway.C.

template<classT, size_tdefAlloc>
void type_allocator<T, defAlloc>::setNElements ( size_t n ) [inline]
 

Set the number of elements to specified value.

Parameters:
n   number of elements.

template<classT, size_tdefAlloc>
iterator type_allocator<T, defAlloc>::find ( const T & next ) [inline]
 

Find given object in list.

If not found, return end().

Parameters:
id   object to find.
Returns:
iterator to position object found. If not found, return end().

Reimplemented in hashtable.

Examples:
vector1.cxx, and vector3.cxx.

template<classT, size_tdefAlloc>
iterator type_allocator<T, defAlloc>::find ( iterator s,
iterator e,
const T & id ) [inline]
 

Find given object in list within given range.

If not found, return e.

Parameters:
s   start of range to look for object.
e   end of range (not inclusive) to look for object.
id   object to find.
Returns:
iterator to position object found. Return e if not found.

template<classT, size_tdefAlloc>
const_iterator type_allocator<T, defAlloc>::find ( const T & next ) const [inline]
 

Find given object in list.

If not found, return end().

Parameters:
id   object to find.
Returns:
iterator to position object found. If not found, return end().

Reimplemented in hashtable.

template<classT, size_tdefAlloc>
const_iterator type_allocator<T, defAlloc>::find ( const_iterator s,
const_iterator e,
const T & id ) const [inline]
 

Find given object in list within given range.

If not found, return e.

Parameters:
s   start of range to look for object.
e   end of range (not inclusive) to look for object.
id   object to find.
Returns:
iterator to position object found. Return e if not found.

template<classT, size_tdefAlloc>
size_t type_allocator<T, defAlloc>::nextAllocation ( size_t n ) const [inline]
 

Compute the next allocation size that will fit requested allocation if requested size is greater than current allocation.

If exponential allocator, then we will at least double the current allocation by defAlloc blocks of storage. Block allocation just uses nearest multiple of defAlloc to size requested. Just to fit simply uses the requested size.

Parameters:
n   requested size.
Returns:
actual next size of allocation.

template<classT, size_tdefAlloc>
iterator type_allocator<T, defAlloc>::insert ( const T & next ) [inline]
 

Insert object at end of list.

See also:
insert(interator, const T&).
Parameters:
id   object to insert.
Returns:
iterator to inserted object.

Reimplemented in hash_link, and hashtable.

Examples:
exuns_impl.cxx, OpenGatewayBase.C, vector1.cxx, vector2.cxx, and vector3.cxx.

template<classT, size_tdefAlloc>
iterator type_allocator<T, defAlloc>::insert ( iterator position,
const T & id ) [inline]
 

Insert object at specified position.

Parameters:
position   position to insert object.
id   object to insert.
Returns:
iterator to inserted object.

template<classT, size_tdefAlloc>
int type_allocator<T, defAlloc>::sortBy ( int(* comparison)(const void *a,const void *b) ) [inline]
 

Sort the entire list by the comparison function using qsort.

Warning: Objects can only hold POD (plain old data). Does not properly carry out equal operation when moving data around because uses qsort directly. Proper qsort implementation for objects for future.

Parameters:
comparison   comparison functions that compares two objects in list.
Returns:
1 if list has any members.
Examples:
vector1.cxx.

template<classT, size_tdefAlloc>
int type_allocator<T, defAlloc>::sortBy ( const_iterator s,
const_iterator e,
int(* comparison)(const void *a,const void *b) ) [inline]
 

Sort list between given start and end by the comparison function using qsort.

Warning: Objects can only hold POD (plain old data). Does not properly carry out equal operation when moving data around because uses qsort directly. Proper qsort implementation for objects for future.

Parameters:
s   start of portion of list to sort.
e   one past end of portion of list to sort.
comparison   comparison functions that compares two objects in list.
Returns:
1 if list has any members.

template<classT, size_tdefAlloc>
int type_allocator<T, defAlloc>::makeuniq ( int(* comparison)(const void *a,const void *b) ) [inline]
 

Make the entries in type_allocator unique by sorting the list then removing duplicate entires.

See sortBy() for restrictions on the type of objects that can be in the list.

Parameters:
comparison   comparison functions that compares two objects in list.
Returns:
1 if list has any members.
Examples:
vector2.cxx.

template<classT, size_tdefAlloc>
int type_allocator<T, defAlloc>::makeuniq ( iterator s,
iterator e,
int(* comparison)(const void *a,const void *b) ) [inline]
 

Make the entries in type_allocator unique by sorting the list then removing duplicate entires.

See sortBy() for restrictions on the type of objects that can be in the list.

Parameters:
s   start of portion of list to sort.
e   one past end of portion of list to sort.
comparison   comparison functions that compares two objects in list.
Returns:
1 if list has any members.

template<classT, size_tdefAlloc>
T & type_allocator<T, defAlloc>::operator[] ( size_t i ) [inline]
 

Return reference to object at specified index.

Parameters:
i   index.
Returns:
reference to entry at that index.

template<classT, size_tdefAlloc>
const T & type_allocator<T, defAlloc>::operator[] ( size_t i ) const [inline]
 

Return reference to object at specified index.

Parameters:
i   index.
Returns:
reference to entry at that index.


The documentation for this class was generated from the following file:
Generated at Wed Mar 2 11:19:02 2005 for Result Library by doxygen1.2.0 written by Dimitri van Heesch, © 1997-2000