Rogue Wave banner
Previous fileTop of documentContentsIndexNext file

RWTPtrSet<T,C>

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

Synopsis

#include <rw/tpset.h> 
RWTPtrSet<T,C> s;

Standard C++ Library Dependent!


RWTPtrSet requires the Standard C++ Library.


Description

This class maintains a pointer-based collection of values, which are ordered according to a comparison object of type C. Class T is the type pointed to by the items in the collection. C must induce a total ordering on elements of type T via a public member

bool operator()(const T& x, const T& y)

which returns true if x should precede y within the collection. The structure less<T> from the C++-standard header file <functional> is an example. Note that items in the collection will be dereferenced before being compared.

RWTPtrSet<T,C> will not accept an item that compares equal to an item already in the collection. (RWTPtrMultiSet<T,C> may contain multiple items that compare equal to each other.) Equality is based on the comparison object and not on the == operator. Given a comparison object comp, items a and b are equal if

           !comp(a,b) && !comp(b,a).

The value type must have operator== and operator< defined. This requirement is imposed by the Standard C++ Library.

Persistence

Isomorphic.

Examples

In this example, a pointer-based set of RWCStrings is exercised.

//
//tpset.cpp
//
#include <rw/tpset.h>
#include <rw/cstring.h>
#include <iostream.h>
#include <function.h>

main(){
  RWTPtrSet<RWCString, less<RWCString> > set;

  set.insert(new RWCString("one"));
  set.insert(new RWCString("two"));
  set.insert(new RWCString("three"));
  set.insert(new RWCString("one"));  // Rejected: duplicate entry

  cout << set.entries() << endl;   // Prints "3"

  set.clearAndDestroy();
  cout << set.entries() << endl;   // Prints "0"

  return 0;
}

Related Classes

Class RWTPtrMultiSet<T,C> offers the same interface to a pointer-based collection that accepts multiple items that compare equal to each other. RWTPtrMap<K,T,C> is a pointer-based collection of key-value pairs.

Class set<T*,rw_deref_compare<C,T>,allocator> is the C++-standard collection that serves as the underlying implementation for RWTPtrSet<T,C>.

Public Typedefs

typedef rw_deref_compare<C,T>                  container_comp; 
typedef set<T*, container_comp,allocator>      container_type; 
typedef container_type::size_type              size_type; 
typedef container_type::difference_type        difference_type; 
typedef container_type::iterator               iterator; 
typedef container_type::const_iterator         const_iterator; 
typedef T*                                     value_type; 
typedef T*const&                               reference; 
typedef T*const&                               const_reference; 

Public Constructors

RWTPtrSet<T,C>(const container_comp& comp = container_comp());
RWTPtrSet<T,C>(const RWTPtrSet<T,C>& rws); 
RWTPtrSet<T,C>(const container_type& s);
RWTPtrSet<T,C>(T* const* first,T* const* last,const container_comp& comp = container_comp());

Public Member Operators

RWTPtrSet<T,C>&
operator=(const container_type& s); 
RWTPtrSet<T,C>&
operator=(const RWTPtrSet<T,C>& s);
bool
operator<(const RWTPtrSet<T,C>& s); 
bool
operator==(const RWTPtrSet<T,C>& s); 

Public Member Functions

void
apply(void (*fn)(const T*,void*), void* d) const; 
iterator
begin();
const_iterator
begin() const;
void
clear();
void
clearAndDestroy();
bool
contains(const T* a) const; 
bool
contains(bool (*fn)(const T*,void*), void* d) const;
void
difference(const RWTPtrSet<T,C>& s); 
iterator
end();
const_iterator
end() const;
size_type
entries() const; 
const T*
find(const T* a) const; 
const T*
find(bool (*fn)(const T*,void*), void* d) const;
bool
insert(T* a); 
void
intersection(const RWTPtrSet<T,C>& s); 
bool
isEmpty() const; 
bool
isEquivalent(const RWTPtrSet<T,C>& s) const; 
bool
isProperSubsetOf(const RWTPtrSet<T,C>& s) const; 
bool
isSubsetOf(const RWTPtrSet<T,C>& s) const; 
size_type
occurrencesOf(const T* a) const; 
size_type
occurrencesOf(bool (*fn)(T*,void*), void* d);
size_type
occurrencesOf(bool (*fn)(const T*,void*), void* d) const;
T*
remove(const T* a); 
T*
remove(bool (*fn)(const T*,void*), void* d);
size_type
removeAll(const T* a); 
size_type
removeAll(bool (*fn)(const T*,void*), void* d); 
set<T*, container_comp,allocator>&
std();
const set<T*, container_comp,allocator>&
std() const;
void
symmetricDifference(const RWTPtrSet<T,C>& s); 
void
Union(const RWTPtrSet<T,C>& s); 

Related Global Operators

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


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