Rogue Wave banner
Previous fileTop of documentContentsIndexNext file

RWTPtrSortedVector<T,C>

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

Synopsis

#include <rw/tpsrtvec.h> 
RWTPtrSortedVector<T,C> srtvec;

Please Note!


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


Description

This class maintains an always-sorted pointer-based collection of values, implemented as a vector. Items 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.

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

Persistence

Isomorphic.

Example

In this example, a sorted vector of RWDates is exercised.

//
// tpsrtvec.cpp
//
#include <rw/rwdate.h>
#include <rw/tpsrtvec.h>
#include <iostream.h>

main(){
  RWTPtrSortedVector<RWDate, greater<RWDate> > vec;

  vec.insert(new RWDate(10, "Aug", 1991));
  vec.insert(new RWDate(9, "Aug", 1991));
  vec.insert(new RWDate(1, "Sep", 1991));
  vec.insert(new RWDate(14, "May", 1990));
  vec.insert(new RWDate(1, "Sep", 1991));   // Add a duplicate
  vec.insert(new RWDate(2, "June", 1991));

  for (int i=0; i<vec.entries(); i++)
    cout << *vec[i] << endl;

  vec.clearAndDestroy();

  return 0;
}
Program Output:
09/01/91
09/01/91
08/10/91
08/09/91
06/02/91
05/14/90

Related Classes

RWTPtrSortedDlist<T,C> is an alternative always-sorted pointer-based collection. RWTPtrOrderedVector<T> is an unsorted pointer-based vector.

Class vector<T*,allocator> is the Standard C++ Library collection that serves as the underlying implementation for this class.

Public Typedefs

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

Public Constructors

RWTPtrSortedVector<T,C>();
RWTPtrSortedVector<T,C>(const vector<T*,allocator>& vec); 
RWTPtrSortedVector<T,C>(const RWTPtrSortedVector<T,C>& rwvec);
RWTPtrSortedVector<T,C>(size_type n, T* p);
RWTPtrSortedVector<T,C>(size_type n);
RWTPtrSortedVector<T,C>(T** first,T** last);

Public Member Operators

bool
operator<(const RWTPtrSortedVector<T,C>& vec) const; 
bool
operator==(const RWTPtrSortedVector<T,C>& vec) 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
apply(void (*fn)(T*,void*), void* d); 
void
apply(void (*fn)(T*&,void*), void* d);
void
apply(void (*fn)(const T*,void*), void* d) const;
reference
at(size_type i); 
const_reference
at(size_type i) 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;
T* const*
data() const; 
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; 
reference
first();
const_reference
first() const;
size_type
index(const T* a) const; 
size_type
index(bool (*fn)(const T*,void*), void* d) const;
bool
insert(T* a); 
size_type
insert(const vector<T*,allocator>& a);
bool
isEmpty() const; 
bool
isSorted() const; 
T*&
last();
T* const&
last() const;
size_type
length() const; 
size_type
merge(const RWTPtrSortedVector<T,C>& vec);
size_type
occurrencesOf(const T* a) const; 
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); 
T*
removeAt(size_type i); 
T*
removeFirst();
T*
removeLast();
void
resize(size_type n); 
const vector<T*,allocator>&
std() const; 

Static Public Data Member

const size_type  npos;

Related Global Operators

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


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