Rogue Wave banner
Previous fileTop of documentContentsIndexNext file

RWTIsvDlist<T>

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

Synopsis

#include <rw/tidlist.h>
RWTIsvDlist<T> list;

Descripton

Class RWTIsvDlist<T> is a class that implements intrusive doubly-linked lists.

An intrusive list is one where the member of the list must inherit from a common base class, in this case RWIsvDlink. 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 RWTValDlist<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/tidlist.h>
#include <rw/rstream.h>
#include <string.h>
struct Symbol : public RWIsvDlink {
  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()  {
  RWTIsvDlist<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

RWTIsvDlist();
RWTIsvDlist(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.