NList Class Template Reference

NList class implements a double-linked list. More...

Inheritance diagram for NList:

NSortedList

List of all members.

Public Types

typedef const iterator const_iterator
 Const iterator for NList objects.

Public Member Functions

 NList (void)
 Constructs an empty NList object.
 NList (const T &val)
 Constructs a NList class with item val as its first item.
 NList (const NList< T > &other)
 Copy constructor.
virtual ~NList (void)
 Destroys a NList object freeing the resources allocataded by this class.
nuint64 count (void) const
 Gets the count of itens in the list.
nuint64 count (const T &obj) const
 Gets the count of itens in the list that are equal to a given object.
nuint64 size (void) const
 Gets the current number of itens in the class.
bool isEmpty (void) const
 Checks if the list is empty.
NList< T > & append (const T &val)
 Inserts an item at the end of the list.
NList< T > & insert (const T &val, nuint64 pos)
 Inserts an item at a given position in the list.
NList< T > & removeAt (nuint64 pos)
 Removes item at a given position.
const T & at (nuint64 pos) const
 Returns the item at a given position in the list.
value (nuint64 pos) const
 Returns the value at a given position.
T & first (void)
 Returns the first item on the list.
T & last (void)
 Returns the last item on the list.
takeFirst (void)
 Removes the first item on the list and returns it.
takeLast (void)
 Removes the last item on the list and returns it.
takeAt (nuint64 pos)
 Removes the a item with a given position on the list and returns it.
void clear (void)
 Removes all the items on the list.
NList< T > & copy (const NList< T > &other)
 Copies one list to another.
bool hasNext (void) const
 Returns whether there is a next item in the list.
bool hasPrevious (void) const
 Returns whether there is a previous item in the list.
bool contains (const T &val) const
 Returns whether there is an item equal to val.
NList< T > & operator= (const NList< T > &rhs)
 Copies other list to this list.
iterator begin (void)
 Returns an iterator pointing to the first item in the list.
const_iterator constBegin (void) const
 Returns a const_iterator pointing to the first item in the list.
iterator end (void)
 Returns an iterator pointing to the last item in the list.
const_iterator constEnd (void) const
 Returns a const_iterator pointing to the last item in the list.

Protected Member Functions

void gotoFirst () const
 Goes to the first node.
void gotoPos (nuint64 pos) const
 Goes to a position on the list.

Protected Attributes

NListNode< T > * m_first
NListNode< T > * m_node
nuint64 m_count

Classes

class  iterator
 NList::iterator iterates through a NList object. More...


Detailed Description

template<typename T>
class NList< T >

NList class implements a double-linked list.

Note:
To add itens to a NList class, they must overload the operator=
Examples:

ex_ndir.cpp, ex_ngetopt.cpp, ex_nlist.cpp, ex_nmap.cpp, ex_nregex.cpp, and ex_nsortedlist.cpp.

Definition at line 36 of file nlist.hpp.


Member Function Documentation

nuint64 count ( void   )  const [inline]

Gets the count of itens in the list.

Returns:
The count of itens in the list

Definition at line 303 of file nlist.hpp.

References m_count.

Referenced by removeAt(), and size().

nuint64 count ( const T &  obj  )  const [inline]

Gets the count of itens in the list that are equal to a given object.

Parameters:
obj An object to count against
Returns:
The count of itens in the list that are equal to a given object
Note:
Note that the object must implement operator==

Definition at line 308 of file nlist.hpp.

References at(), gotoFirst(), and size().

nuint64 size ( void   )  const [inline]

Gets the current number of itens in the class.

Returns:
The current number of itens in the class
Note:
See count()

Definition at line 323 of file nlist.hpp.

References count().

Referenced by clear(), contains(), copy(), count(), NMySql::getFirst(), NMySql::getNext(), gotoPos(), last(), and takeLast().

bool isEmpty ( void   )  const [inline]

Checks if the list is empty.

Returns:
True if the list is empty and false otherwise

Definition at line 293 of file nlist.hpp.

References m_count.

Referenced by append(), and insert().

NList< T > & append ( const T &  val  )  [inline]

Inserts an item at the end of the list.

Parameters:
val The item to be inserted
Returns:
A reference to this

Definition at line 329 of file nlist.hpp.

References NListNode::data, isEmpty(), m_count, m_first, m_node, and NListNode::previous.

Referenced by NGetOpt::add(), NHostAddress::addresses(), NOpt::addValue(), NHostAddress::aliases(), copy(), NMap::keys(), NList(), NGetOpt::proccess(), NString::split(), and NMap::values().

NList< T > & insert ( const T &  val,
nuint64  pos 
) [inline]

Inserts an item at a given position in the list.

Parameters:
val The item to be inserted
pos Position where to insert the item
Returns:
A reference to this
Note:
Pos must be valid in the list (pos >= 0 && pos <= size() -1)

Definition at line 370 of file nlist.hpp.

References NListNode::data, gotoPos(), isEmpty(), m_count, m_node, NListNode::next, and NListNode::previous.

NList< T > & removeAt ( nuint64  pos  )  [inline]

Removes item at a given position.

Parameters:
pos Position of the item to be removed
Returns:
A reference to this
Note:
Pos must be valid in the list (pos >= 0 && pos <= size() -1)

Definition at line 396 of file nlist.hpp.

References count(), gotoPos(), m_count, m_first, m_node, NListNode::next, and NListNode::previous.

Referenced by clear(), and takeAt().

const T & at ( nuint64  pos  )  const [inline]

Returns the item at a given position in the list.

Parameters:
pos Position of the item to be removed
Returns:
A reference to the item in the given pos.
Note:
Pos must be valid in the list (pos >= 0 && pos <= size() -1)

Definition at line 433 of file nlist.hpp.

References gotoPos(), and m_node.

Referenced by contains(), count(), NMySql::getFirst(), NMySql::getNext(), and NMySql::getPrevious().

T value ( nuint64  pos  )  const [inline]

Returns the value at a given position.

Parameters:
pos Position of the item to be removed
Returns:
The value at the position pos or a default constructed one if pos is invalid (ie.: item does not exists)

Definition at line 441 of file nlist.hpp.

References gotoPos(), and m_node.

Referenced by copy(), and takeAt().

T & first ( void   )  [inline]

Returns the first item on the list.

Returns:
A reference to the first item in the list

Definition at line 452 of file nlist.hpp.

References gotoPos(), and m_node.

T & last ( void   )  [inline]

Returns the last item on the list.

Returns:
A reference to the last item in the list

Definition at line 459 of file nlist.hpp.

References gotoPos(), m_node, and size().

Referenced by NMySql::getLast().

T takeFirst ( void   )  [inline]

Removes the first item on the list and returns it.

Returns:
The first item in the list or a default constructed value if it does not exists

Definition at line 506 of file nlist.hpp.

References takeAt().

T takeLast ( void   )  [inline]

Removes the last item on the list and returns it.

Returns:
The last item in the list or a default constructed value if it does not exists

Definition at line 512 of file nlist.hpp.

References size(), and takeAt().

T takeAt ( nuint64  pos  )  [inline]

Removes the a item with a given position on the list and returns it.

Returns:
The item in the list or a default constructed value if it does not exists

Definition at line 518 of file nlist.hpp.

References removeAt(), and value().

Referenced by takeFirst(), and takeLast().

NList< T > & copy ( const NList< T > &  other  )  [inline]

Copies one list to another.

Parameters:
other A NList object with items to be coppied

Definition at line 475 of file nlist.hpp.

References append(), clear(), size(), and value().

Referenced by NOpt::addValues(), NList(), NSortedList::NSortedList(), and operator=().

bool hasNext ( void   )  const [inline]

Returns whether there is a next item in the list.

Returns:
True if there is a next item or false otherwise

Definition at line 486 of file nlist.hpp.

References m_node.

bool hasPrevious ( void   )  const [inline]

Returns whether there is a previous item in the list.

Returns:
True if there is a previous item or false otherwise

Definition at line 496 of file nlist.hpp.

References m_node.

bool contains ( const T &  val  )  const [inline]

Returns whether there is an item equal to val.

Returns:
True if there is an item equal to val or false otherwise

Definition at line 534 of file nlist.hpp.

References at(), and size().

Referenced by NGetOpt::add(), and NSortedList::insert().

NList< T > & operator= ( const NList< T > &  rhs  )  [inline]

Copies other list to this list.

Parameters:
rhs The list to be copied
Returns:
A reference to this

Definition at line 528 of file nlist.hpp.

References copy().

NList< T >::iterator begin ( void   )  [inline]

Returns an iterator pointing to the first item in the list.

Returns:
An iterator pointing to the first item in the list

Definition at line 710 of file nlist.hpp.

References m_first.

Referenced by NGetOpt::proccess().

NLISTITERATOR_CONST constBegin ( void   )  const [inline]

Returns a const_iterator pointing to the first item in the list.

Returns:
A const_iterator pointing to the first item in the list

Definition at line 718 of file nlist.hpp.

References m_first.

NList< T >::iterator end ( void   )  [inline]

Returns an iterator pointing to the last item in the list.

Returns:
An iterator pointing to the last item in the list

Definition at line 726 of file nlist.hpp.

Referenced by NGetOpt::proccess().

NLISTITERATOR_CONST constEnd ( void   )  const [inline]

Returns a const_iterator pointing to the last item in the list.

Returns:
A const_iterator pointing to the last item in the list

Definition at line 733 of file nlist.hpp.

void gotoPos ( nuint64  pos  )  const [inline, protected]

Goes to a position on the list.

Parameters:
pos A valid (pos < size) position

Definition at line 356 of file nlist.hpp.

References gotoFirst(), m_node, and size().

Referenced by at(), first(), insert(), last(), removeAt(), and value().


Member Data Documentation

NListNode<T>* m_first [mutable, protected]

The first node of the list

Definition at line 239 of file nlist.hpp.

Referenced by append(), begin(), constBegin(), gotoFirst(), and removeAt().

NListNode<T>* m_node [mutable, protected]

The current node

Definition at line 240 of file nlist.hpp.

Referenced by append(), at(), first(), gotoFirst(), gotoPos(), hasNext(), hasPrevious(), insert(), NList::iterator::iterator(), last(), NList::iterator::operator *(), NList::iterator::operator!=(), NList::iterator::operator++(), NList::iterator::operator->(), NList::iterator::operator=(), NList::iterator::operator==(), removeAt(), and value().

nuint64 m_count [protected]

The number of the itens in the list

Definition at line 242 of file nlist.hpp.

Referenced by append(), count(), insert(), isEmpty(), and removeAt().


The documentation for this class was generated from the following file:
Generated on Wed Mar 5 23:10:36 2008 for NemesisUtilitiesSystem by  doxygen 1.5.4