/*
....[@@@..[@@@..............[@.................. MUD++ is a written from
....[@..[@..[@..[@..[@..[@@@@@....[@......[@.... scratch multi-user swords and
....[@..[@..[@..[@..[@..[@..[@..[@@@@@..[@@@@@.. sorcery game written in C++.
....[@......[@..[@..[@..[@..[@....[@......[@.... This server is an ongoing
....[@......[@..[@@@@@..[@@@@@.................. development project. All
................................................ contributions are welcome.
....Copyright(C).1995.Melvin.Smith.............. Enjoy.
------------------------------------------------------------------------------
Melvin Smith (aka Fusion) msmith@hom.net
MUD++ development mailing list mudpp@van.ml.org
------------------------------------------------------------------------------
llist.h
*/
#ifndef _LLIST_H
#define _LLIST_H
class Node
{
public:
static int getFreeCount();
static int allocated_nodes;
#ifdef _ARRAY_H
static void * operator new( size_t );
static void operator delete( void * );
#endif
Node *next;
void *obj;
Node()
: next(0), obj(0)
{
}
Node( void * x )
: next(0), obj(x)
{
}
~Node()
{
}
};
#define RDONLY 1
template < class T >
class LList
{
private:
Node * head;
Node * current;
unsigned char flags;
public:
LList()
: head(0), current(0), flags(0)
{
}
// Does node by node copy. This is so constructed objects
// that have list data will copy correctly.
LList( const LList & x );
~LList() { destroyList(); }
void destroyList();
// For creating a temp list to iterate with.
const LList & operator = ( const LList & );
// true copy, not read-only like assign operator
void copy( const LList & );
// Of course these members change the state of the object but
// for practical purposes they don't and we need const because
// iterating through a list is common thing to do for a const
// object. For example writing an object and its inventory to a
// file doesn't change object but you must iterate through
// inventory. This would not be required if I implemented LList
// iterators instead of my method off read-only copying of lists.
void next() const;
// *YAWN* Solaris C++ 4.0.1 doesn't support const_cast<> yet
void reset() const { ((LList< T > *)this)->current = head; }
void add( T * );
void addTop( T * );
void addAfterCurrent( T * );
T* remove( T * );
T *remove();
T *peek() const;
T *peekNext() const;
};
#define for_each( x, y ) for( x.reset(); ( ( y = x.peek() ) ); x.next() )
#endif