Modernized GAlib  3.0.0 current
Public Member Functions | Protected Member Functions | Protected Attributes | Friends | List of all members
GAList< T > Class Template Reference

Container for nodes that have a list structure. More...

#include <GAList.hpp>

Inheritance diagram for GAList< T >:
[legend]
Collaboration diagram for GAList< T >:
[legend]

Public Member Functions

 GAList (const T &t)
 
 GAList (const GAList< T > &orig)
 
GAList< T > & operator= (const GAList< T > &orig)
 
GAList< T > * clone (unsigned int i=0) const
 Make a copy of a list and return the pointer to the new list. More...
 
void copy (const GAList< T > &orig)
 Make a complete copy of the list and return a pointer to the new list. More...
 
int destroy ()
 Remove the current node from the list and free the memory it was using. More...
 
int swap (unsigned int a, unsigned int b)
 Swap two nodes in the list. More...
 
T * remove ()
 Remove the current node from the list. More...
 
int insert (GAList< T > *t, GAListBASE::Location where=GAListBASE::AFTER)
 Inserts the contents of list in to the current list and removes it from the original list. More...
 
int insert (const T &t, GAListBASE::Location where=GAListBASE::AFTER)
 Insert the object into the list at the specified place relative to the current location of the embedded iterator. More...
 
T * head ()
 
T * tail ()
 
T * current ()
 
T * next ()
 
T * prev ()
 
T * warp (unsigned int i)
 
T * warp (const GAListIter< T > &i)
 
T * operator[] (unsigned int i)
 
- Public Member Functions inherited from GAListBASE
 GAListBASE (GANodeBASE *n)
 
int size () const
 

Protected Member Functions

int insert (GANode< T > *n, GANode< T > *idx, GAListBASE::Location where=GAListBASE::AFTER)
 
- Protected Member Functions inherited from GAListBASE
GANodeBASEremove (GANodeBASE *n)
 
int insert (GANodeBASE *n, GANodeBASE *idx, Location where=AFTER)
 
int swapnode (GANodeBASE *a, GANodeBASE *b)
 

Protected Attributes

GAListIter< T > iter
 
- Protected Attributes inherited from GAListBASE
int sz
 
int csz
 
GANodeBASEhd
 

Friends

class GAListIter< T >
 

Additional Inherited Members

- Public Types inherited from GAListBASE
enum  Location { HEAD = 0 , TAIL , BEFORE , AFTER }
 
enum  { NO_ERR = 0 , ERR = -1 }
 

Detailed Description

template<class T>
class GAList< T >

Container for nodes that have a list structure.

The base list object is responsible for maintaining the list heirarchy. This object is responsible for doing the memory management (allocating and de-allocating the nodes in the list). We insulate the user entirely from nodes - when you use a list, you don't get nodes back, you get the contents of nodes (ie the user doesn't have to think about the list parts of a node, they can simply assume that their data is organized into a list structure). We include an iterator in this object so that you can navigate through the list. You can create another iterator and assign it to your list so you can have multiple iterators. All of the actions take place relative to the current location of the embedded iterator. None of the iterators change the state of the list. Be careful so that you don't end up with an iterator dangling with a pointer to a part of a list that no longer exists (I would need some kind of reference counting and/or message passing to take care of this at a lower level, and I'm not ready to implement that at this point). For now we allocate nodes on the fly. Eventually I would like to do some better memory management (arrays perhaps?) so we don't have to do so much alloc and dealloc and recursion. We depend on the template-ized GAListIter routine, thus the declaration.

current, head, tail, next, prev, warp These iterator methods are defined as access to the embedded iterator of the list. Use these methods to move the insertion point and to traverse the list. You can also create other iterators for this list, but they won't affect the contents.

Template Parameters
T

Member Function Documentation

◆ clone()

template<class T >
GAList<T>* GAList< T >::clone ( unsigned int  i = 0) const
inline

Make a copy of a list and return the pointer to the new list.

The cloning is based on the value passed to this routine. This routine has no effect on the iterator in the original list.

Parameters
i0: will clone entire list; other values will clone the list from the index to the end of the list.
Returns
GAList<T>*

◆ copy()

template<class T >
void GAList< T >::copy ( const GAList< T > &  orig)
inline

Make a complete copy of the list and return a pointer to the new list.

Parameters
orig

◆ destroy()

template<class T >
int GAList< T >::destroy ( )
inline

Remove the current node from the list and free the memory it was using.

Returns
int

◆ insert() [1/2]

template<class T >
int GAList< T >::insert ( const T &  t,
GAListBASE::Location  where = GAListBASE::AFTER 
)
inline

Insert the object into the list at the specified place relative to the current location of the embedded iterator.

Parameters
tObject to be inserted into list
whereInsert location (default: AFTER)
Returns
Error code
Return values
0No error
-1Error occurred

◆ insert() [2/2]

template<class T >
int GAList< T >::insert ( GAList< T > *  t,
GAListBASE::Location  where = GAListBASE::AFTER 
)
inline

Inserts the contents of list in to the current list and removes it from the original list.

Does NOT delete the original list, but DOES assume responsibility for the memory used by the contents of the original list.

Parameters
tList to be inserted
whereLocation where list is to be inserted (default: AFTER)
Returns
Error code
Return values
0No Error
-1Error occurred

◆ remove()

template<class T >
T* GAList< T >::remove ( )
inline

Remove the current node from the list.

The iterator gets set to the next node toward the head of the list. This routine makes a copy of the node contents using the copy initializer of the T object, so the copy initializer MUST be defined and accessible. We return a pointer to the contents rather than the contenst for the same reason we return a pointer from all the iter routines - we don't want to pass big objects around.

Returns
T* pointer to the contents of the node that was removed. The node itself is destroyed

◆ swap()

template<class T >
int GAList< T >::swap ( unsigned int  a,
unsigned int  b 
)
inline

Swap two nodes in the list.

This has no effect on the size or the iterator. If either index is out of bounds then we don't do anything.

Parameters
a
b
Returns
int

The documentation for this class was generated from the following file: