Click on the banner to return to the Class Reference home page.

©Copyright 1996 Rogue Wave Software

RWTValDlist<T>

Synopsis

#include <rw/tvdlist.h> 
RWTValDlist<T> dlist;

Please Note!


If you have the Standard C++ Library, use the interface described here. Otherwise, use the restricted interface to RWTValDlist described in Appendix A.


Description

This class maintains a collection of values, implemented as a doubly-linked list.

Persistence

Isomorphic

Example

In this example, a doubly-linked list of user type Dog is exercised.

//
// tvdldog.cpp
//
#include <rw/tvdlist.h>
#include <iostream.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:
  Dog(const Dog& dog) {
   name = new char[strlen(dog.name)+1];
   strcpy(name, dog.name); }

  // Define an assignment operator:
  void operator=(const Dog& dog) {
   if (this!=&dog) {
     delete name;
     name = new char[strlen(dog.name)+1];
     strcpy(name, dog.name);
   }
  }

  // Define an equality test operator:
  int operator==(const Dog& dog) const {
   return strcmp(name, dog.name)==0; }

  // order alphabetically:
  int operator<(const Dog& dog) const {
   return strcmp(name, dog.name) < 0; }

  friend ostream& operator<<(ostream& str, const Dog& dog){
    str << dog.name;
    return str;}
};

main(){
  RWTValDlist<Dog> terriers;
  terriers.insert("Cairn Terrier");  // NB: type conversion occurs
  terriers.insert("Irish Terrier");
  terriers.insert("Schnauzer");

  cout << "The list " <<
    (terriers.contains("Schnauzer") ? "does " : "does not ") <<
    "contain a Schnauzer\n";

  terriers.insertAt(
      terriers.index("Irish Terrier"),
      "Fox Terrier"
    );

  while (!terriers.isEmpty())
    cout << terriers.get() << endl;

  return 0;
}
Program Output:
   The list does contain a Schnauzer
   Cairn Terrier
   Fox Terrier
   Irish Terrier
   Schnauzer

Related Classes

Classes RWTValDeque<T>, RWTValSlist<T>, and RWTValOrderedVector<T> also provide a Rogue Wave interface to C++-standard sequence collections.

Class list<T,allocator> is the C++-standard collection that serves as the underlying implementation for this class.

Public Typedefs

typedef list<T,allocator>                      container_type;
typedef container_type::iterator               iterator;
typedef container_type::const_iterator         const_iterator;
typedef container_type::size_type              size_type;
typedef T                                      value_type;
typedef T&                                     reference;
typedef const T&                               const_reference;

Public Constructors

RWTValDlist<T>();
RWTValDlist<T>(const list<T,allocator>& lst);
RWTValDlist<T>(const RWTValDlist<T>& rwlst);
RWTValDlist<T>(size_type n, const T& val = T());
RWTValDlist<T>(const T* first, const T* last);

Public Member Operators

RWTValDlist<T>&
operator=(const RWTValDlist<T>& lst);
RWTValDlist<T>&
operator=(const list<T,allocator>& lst);
bool
operator<(const RWTValDlist<T>& lst) const;
bool
operator<(const list<T,allocator>& lst) const;
bool
operator==(const RWTValDlist<T>& lst) const;
bool
operator==(const list<T,allocator>& lst) const;
reference
operator()(size_type i);
const_reference
operator()(size_type i) const;
reference
operator[](size_type i);
const_reference
operator[](size_type i) const;

Public Member Functions

void
append(const_reference a);
void
apply(void (*fn)(reference,void*), void* d);
void
apply(void (*fn)(const_reference,void*), void* d) const;
reference
at(size_type i);
const_reference
at(size_type i) const;
iterator
begin();
const_iterator
begin() const;
void
clear();
bool
contains(const_reference a) const;
bool
contains(bool (*fn)(const_reference,void*), void* d) const;
iterator
end();
const_iterator
end() const;
size_type
entries() const;
bool
find(const_reference a, T& k) const;
bool
find(bool (*fn)(const_reference,void*), void* d, T& k) const;
reference
first();
const_reference
first() const;
T
get();
size_type
index(const_reference a) const;
size_type
index(bool (*fn)(const_reference,void*), void* d) const;
bool
insert(const_reference a);
void
insertAt(size_type i,const_reference a);
bool
isEmpty() const;
reference
last();
const_reference
last() const;
reference
maxElement();
const_reference
maxElement() const;
reference
minElement();
const_reference
minElement() const;
size_type 
occurrencesOf(const_reference a) const;
size_type
occurrencesOf(bool (*fn)(const_reference,void*),void* d) const;
void
prepend(const_reference a);
bool
remove(const_reference a);
bool
remove(bool (*fn)(const_reference,void*), void* d);
size_type
removeAll(const_reference a);
size_type
removeAll(bool (*fn)(const_reference,void*), void* d);
T
removeAt(size_type i);
T
removeFirst();
T
removeLast();
size_type
replaceAll(const_reference oldVal, const_reference newVal);
size_type
replaceAll(bool (*fn)(const_reference,void*), void* d,
           const value_type& newval);
void
sort();
list<T,allocator>&
std();
const list<T>&
std() const;

Static Public Data Member

const size_type  npos;

Related Global Operators

RWvostream&
operator<<(RWvostream& strm, const RWTValDlist<T>& coll);
RWFile&
operator<<(RWFile& strm, const RWTValDlist<T>& coll);
RWvistream&
operator>>(RWvistream& strm, RWTValDlist<T>& coll);
RWFile&
operator>>(RWFile& strm, RWTValDlist<T>& coll);
RWvistream&
operator>>(RWvistream& strm, RWTValDlist<T>*& p);
RWFile&
operator>>(RWFile& strm, RWTValDlist<T>*& p);