Rogue Wave banner
No previous fileTop of documentContentsIndexNext file

RWTPtrDlist<T>

Alternative interface: no Standard C++ Library

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

Synopsis

#include <rw/tpdlist.h>
RWTPtrDlist<T> list;

Please Note!


If you do not have the Standard C++ Library, use the interface described here. Otherwise, use the interface to RWTPtrDlist described in the Class Reference.


Description

This class maintains a collection of pointers to type T, implemented as a doubly linked list. This is a pointer based list: pointers to objects are copied in and out of the links that make up the list.

Parameter T represents the type of object to be inserted into the list, either a class or fundamental type. The class T must have:

Persistence

Isomorphic

Example

In this example, a doubly-linked list of pointers to the user type Dog is exercised. Contrast this approach with the example given under RWTValDlist<T>.

#include <rw/tpdlist.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:
  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; }

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

main()  {
  RWTPtrDlist<Dog> terriers;
  terriers.insert(new Dog("Cairn Terrier"));
  terriers.insert(new Dog("Irish Terrier"));
  terriers.insert(new Dog("Schnauzer"));

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

  Dog key2("Irish Terrier");
  terriers.insertAt(
      terriers.index(&key2),
      new Dog("Fox Terrier")
    );

  Dog* d;
  while (!terriers.isEmpty()) {
    d = terriers.get();
    cout << *d << endl;
    delete d;
  }

  return 0;
}
 

Program output:

The list does contain a Schnauzer
Cairn Terrier
Fox Terrier
Irish Terrier
Schnauzer

Public Constructors

RWTPtrDlist<T>();
RWTPtrDlist<T>(const RWTPtrDlist<T>& c);

Public Operators

RWTPtrDlist&
operator=(const RWTPtrDlist<T>& c);
T*&
operator[](size_t i);
T* const&
operator[](size_t i) const;

Public Member Functions

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

Related Global Operators

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


No previous fileTop of documentContentsIndexNext file
Return to the main class reference
©Copyright 1999, Rogue Wave Software, Inc.
Send mail to report errors or comment on the documentation.