Tools.h++ Manual
104011 Tandem Computers Incorporated 22-75
22
RWTValDlist<T>
Synopsis
#include <rw/tvdlist.h>
RWTValDlist<T> list;
Description This class maintains a collection of values, implemented as a doubly linked list.
This is a value based list: objects are copied in and out of the links that make up
the list. Unlike intrusive lists (see class
RWTIsvDlist<T>
), the objects need
not inherit from a link class. However, this makes the class slightly less
efficient than the intrusive lists because of the need to allocate a new link off
the heap with every insertion and to make a copy of the object in the newly
allocated link.
Parameter
T
represents the type of object to be inserted into the list, either a
class or built in type. The class
T
must have:
• A default constructor;
• well-defined copy semantics (
T::T(const T&)
or equiv.);
• well-defined assignment semantics (
T::operator=(const T&)
or equiv.);
• well-defined equality semantics (
T::operator==(const T&)
).
Example In this example, a doubly-linked list of user type Dog is exercised.
Code Example 22-6 (1 of 2)
#include <rw/tvdlist.h>
#include <rw/rstream.h>
#include <string.h>
class Dog {
char* name;
public:
Dog( const char* c = "") {
name = new char[strlen(c)+1];
strcpy(name, c); }
~Dog() { delete name; }
// Define a copy constructor: