Rogue Wave banner
Previous fileTop of documentContentsIndexNext file

RWTIsvSlist<T>

Data Type and Member Function Indexes
(exclusive of constructors and destructors)

Synopsis

#include <rw/tislist.h>
RWTIsvSlist<T> list;

Descripton

Class RWTIsvSlist<T> is a class that implements intrusive singly-linked lists.

An intrusive list is one where the member of the list must inherit from a common base class, in this case RWIsvSlink. The advantage of such a list is that memory and space requirements are kept to a minimum. The disadvantage is that the inheritance hierarchy is inflexible, making it slightly more difficult to use with an existing class. Class RWTValSlist<T> is offered as an alternative, non-intrusive, linked list.

See Stroustrup (1991; Section 8.3.1) for more information about intrusive lists.


Note that when you insert an item into an intrusive list, the actual item (not a copy) is inserted. Because each item carries only one link field, the same item cannot be inserted into more than one list, nor can it be inserted into the same list more than once.


Example

#include <rw/tislist.h>
#include <rw/rstream.h>
#include <string.h>
struct Symbol : public RWIsvSlink
{ char name[10];
  Symbol( const char* cs)
   { strncpy(name, cs, sizeof(name)); name[9] = '\0'; }
};
void printem(Symbol* s, void*) { cout << s->name << endl; }
main(){
  RWTIsvSlist<Symbol> list;
  list.insert( new Symbol("one") );
  list.insert( new Symbol("two") );
  list.prepend( new Symbol("zero") );
  list.apply(printem, 0);
  list.clearAndDestroy();  // Deletes the items inserted into 
                           // the list
  return 0;
}

Program Output:

zero
one
two

Public Constructors

RWTIsvSlist();
RWTIsvSlist(T* a);

Public Member Functions

void
append(T* a);
void
apply(void (*applyFun)(T*, void*), void* d);
T*
at(size_t i) const;
void
clear();
void
clearAndDestroy();
RWBoolean
contains(RWBoolean (*testFun)(const T*, void*), void* d) 
         const;
RWBoolean
containsReference(const T* a) const; 
size_t
entries() const; 
T*
find(RWBoolean (*testFun)(const T*, void*),void* d) const; 
T*
first() const; 
T*
get();
size_t
index(RWBoolean (*testFun)(const T*, void*),void* d) const; 
void
insert(T* a); 
void
insertAt(size_t i, T* a); 
RWBoolean
isEmpty() const; 
T*
last() const; 
size_t
occurrencesOf(RWBoolean (*testFun)(const T*, void*),void* d) 
              const; 
size_t
occurrencesOfReference(const T* a) const; 
void
prepend(T* a); 
T*
remove(RWBoolean (*testFun)(const T*, void*),void* d); 
T*
removeAt(size_t i); 
T*
removeFirst();
T*
removeLast();
T*
removeReference(T* a); 


Previous fileTop of documentContentsIndexNext file
©Copyright 1999, Rogue Wave Software, Inc.
Send mail to report errors or comment on the documentation.