Chapter 9. RWTValHashTableIterator - RWWString

RWTValHashTableIterator

Synopsis

#define RWTValHashTableIterator RWTValHashMultiSetIterator


Note: If you have the Standard C++ Library, refer to the reference for this class under its new name: RWTValHashMultiSetIterator. Although the old name (RWTValHashTableIterator) is still supported, we recommend that you use the new name when coding your applications. If you do not have the Standard C++ Library, refer to the description of RWTValHashTableIterator in Appendix A: Alternate Template Class Interfaces.


RWTValMap<K,T,C>

Synopsis

#include <rw/tvmap.h> 
RWTValMap<K,T,C> m;

Standard C++ Library Dependent!


Note: RWTValMap requires the Standard C++ Library.


Description

This class maintains a collection of keys, each with an associated item of type T. Order is determined by the key according to a comparison object of type C. C must induce a total ordering on elements of type K via a public member

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

which returns true if x and its partner should precede y and its partner within the collection. The structure less<T> from the C++-standard header file <functional> is an example.

RWTValMap<K,T,C> will not accept a key that compares equal to any key already in the collection. (RWTValMultiMap<K,T,C> may contain multiple keys that compare equal to each other.) Equality is based on the comparison object and not on the == operator. Given a comparison object comp, keys a and b are equal if

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

Persistence

Isomorphic.

Examples

In this example, a map of RWCStrings and RWDates is exercised.

//
// tvmbday.cpp
//
#include <rw/tvmap.h>
#include <rw/cstring.h>
#include <rw/rwdate.h>
#include <iostream.h>
 
main(){
  RWTValMap<RWCString, RWDate, less<RWCString> > birthdays;
 
  birthdays.insert("John", RWDate(12, "April",1975));
  birthdays.insert("Ivan", RWDate(2, "Nov", 1980));
 
  // Alternative syntax:
  birthdays["Susan"] = RWDate(30, "June", 1955);
  birthdays["Gene"] = RWDate(5, "Jan", 1981);
 
  // Print a birthday:
  cout << birthdays["John"] << endl;
  return 0;
}

Program Output:

04/12/75

Related Classes

Class RWTValMultiMap<K,T,C> offers the same interface to a collection that accepts multiple keys that compare equal to each other. RWTValSet<T,C> maintains a collection of keys without the associated values.

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

Public Typedefs

typedef map<K,T,C,allocator>                   container_type;
typedef container_type::iterator               iterator;
typedef container_type::const_iterator         const_iterator;
typedef container_type::size_type              size_type;
typedef pair <const K,T>                       value_type;
typedef pair <const K,T>&                      reference;
typedef const pair <const K,T>&                const_reference;

Public Constructors

RWTValMap<K,T,C>(const C& comp = C());

Constructs an empty map with comparator comp.

RWTValMap<K,T,C>(const container_type& m);

Constructs a map by copying all elements of m.

RWTValMap<K,T,C>(const RWTValMap<K,T,C>& rwm);

Copy constructor.

RWTValMap<K,T,C>(const value_type* first, const value_type* last,const C& comp = C());

Constructs a map by copying elements from the array of value_type pairs pointed to by first, up to, but not including, the pair pointed to by last.

Public Member Operators

RWTValMap<K,T,C>& operator=(const RWTValMap<K,T,C>& m); RWTValMap<K,T,C>& operator=(const container_type& m);

Destroys all elements of self and replaces them by copying all associations from m.

bool operator<(const RWTValMap<K,T,C>& m) const; bool operator<(const container_type & m) const;

Returns true if self compares lexicographically less than m, otherwise returns false. Assumes that type K has well-defined less-than semantics (T::operator<(const K&) or equivalent).

bool operator==(const RWTValMap<K,T,C>& m) const; bool operator==(const container_type & m) const;

Returns true if self compares equal to m, otherwise returns false. Two collections are equal if both have the same number of entries, and iterating through both collections produces, in turn, individual pairs that compare equal to each other.

T& operator[](const K& key);

Looks up key and returns a reference to its associated item. If the key is not in the dictionary, then it will be added with an associated item provided by the default constructor for type T.

Public Member Functions

void apply(void (*fn)(const K&, T&, void*),void* d); void apply(void (*fn)(const K&, const T&, void*), void* d) const;

Applies the user-defined function pointed to by fn to every association in the collection. This function must have one of the prototypes:

void yourfun(const K& key, T& a, void* d);

void yourfun(const K& key, const T& a,void* d);

Client data may be passed through parameter d.

void applyToKeyAndValue(void (*fn)(const K&, T&, void*),void* d); void applyToKeyAndValue(void (*fn)(const K&, const T&, void*), void* d) const;

This is a deprecated version of the apply member above. It behaves exactly the same as apply.

iterator begin(); const_iterator begin() const;

Returns an iterator positioned at the first pair in self.

void clear();

Clears the collection by removing all items from self. Each key and its associated item will have its destructor called.

bool contains(const K& key) const;

Returns true if there exists a key j in self that compares equal to key, otherwise returns false.

bool contains(bool (*fn)(const_reference,void*), void* d) const;

Returns true if there exists an association a in self such that the expression ((*fn)(a,d)) is true, otherwise returns false. fn points to a user-defined tester function which must have prototype:

bool yourTester(const_reference a, void* d);

Client data may be passed through parameter d.

iterator end(); const_iterator end() const;

Returns an iterator positioned "just past" the last association in self.

size_type entries() const;

Returns the number of associations in self.

bool find(const K& key, Key& r) const;

If there exists a key j in self that compares equal to key, assigns j to r and returns true. Otherwise, returns false and leaves the value of r unchanged.

bool find(bool (*fn)(const_reference,void*), void* d, pair<K,T>& r) const;

If there exists an association a in self such that the expression ((*fn)(a,d)) is true, assigns a to r and returns true. Otherwise, returns false and leaves the value of k unchanged. fn points to a user-defined tester function which must have prototype:

bool yourTester(const_reference a, void* d);

Client data may be passed through parameter d.

bool findValue(const K& key, T& r) const;

If there exists a key j in self that compares equal to key, assigns the item associated with j to r and returns true. Otherwise, returns false and leaves the value of r unchanged.

bool findKeyValue(const K& key, K& kr, T& tr) const;

If there exists a key j in self that compares equal to key, assigns j to kr, assigns the item associated with j to tr, and returns true. Otherwise, returns false and leaves the values of kr and tr unchanged.

bool insert(const K& key, const T& a);

Adds key with associated item a to the collection. Returns true if the insertion is successful, otherwise returns false. The function will return true unless the collection already holds an association with the equivalent key.

bool insertKeyAndValue(const K& key, const T& a);

This is a deprecated version of the insert member above. It behaves exactly the same as insert.

bool isEmpty() const;

Returns true if there are no items in the collection, false otherwise.

size_type occurrencesOf(const K& key) const;

Returns the number of keys j in self that compare equal to key.

size_type occurrencesOf (bool (*fn)(const_reference&,void*),void* d) const;

Returns the number of associations a in self such that the expression((*fn)(a,d)) is true. fn points to a user-defined tester function which must have prototype:

bool yourTester(const_reference& a, void* d);

Client data may be passed through parameter d.

bool remove(const K& key);

Removes the first association with key j in self such that j compares equal to key and returns true. Returns false if there is no such association.

bool remove(bool (*fn)(const_reference,void*), void* d);

Removes the first association a in self such that the expression ((*fn)(a,d)) is true and returns true. Returns false if there is no such element. fn points to a user-defined tester function which must have prototype:

bool yourTester(const_reference a, void* d);

Client data may be passed through parameter d.

size_type removeAll(const K& key);

Removes all associations with key j in self such that j compares equal to key. Returns the number of items removed.

size_type removeAll(bool (*fn)(const_reference,void*), void* d);

Removes all associations a in self such that the expression ((*fn)(a,d))is true. Returns the number of items removed. fn points to a user-defined tester function which must have prototype:

bool yourTester(const_reference a, void* d);

Client data may be passed through parameter d.

map<K,T,C,allocator>& std(); const map<K,T,C,allocator>& std() const;

Returns a reference to the underlying C++-standard collection that serves as the implementation for self. This reference may be used freely, providing access to the C++-standard interface as well as interoperability with other software components that make use of the C++-standard collections.

Related Global Operators

RWvostream& operator<<(RWvostream& strm, const RWTValMap<K,T,C>& coll); RWFile& operator<<(RWFile& strm, const RWTValMap<K,T,C>& coll);

Saves the collection coll onto the output stream strm, or a reference to it if it has already been saved.

RWvistream& operator>>(RWvistream& strm, RWTValMap<K,T,C>& coll); RWFile& operator>>(RWFile& strm, RWTValMap<K,T,C>& coll);

Restores the contents of the collection coll from the input stream strm.

RWvistream& operator>>(RWvistream& strm, RWTValMap<K,T,C>*& p); RWFile& operator>>(RWFile& strm, RWTValMap<K,T,C>*& p);

Looks at the next object on the input stream strm and either creates a new collection off the heap and sets p to point to it, or sets p to point to a previously read instance. If a collection is created off the heap, then you are responsible for deleting it.

RWTValMapIterator<K,T,C>

Synopsis

#include<rw/tvmap.h>
RWTValMap<K,T,C> vm;
RWTValMapIterator<K,T,C> itr(vm);

Standard C++ Library Dependent!


Note: RWTValMapIterator requires the Standard C++ Library.


Description

RWTValMapIterator is supplied with Tools.h++ 7 to provide an iterator interface to RWTValMapIterator that is backward compatable with the container iterators provided in Tools.h++ 6.x.

The order of iteration over an RWTValMap is dependent on the comparator object supplied as applied to the key values of the stored associations.

The current item referenced by this iterator is undefined after construction or after a call to reset(). The iterator becomes valid after being advanced with either a preincrement or operator().

For both operator++ and operator(), iterating past the last element will return a value equivalent to boolean false. Continued increments will return a value equivalent to false until reset() is called.

Persistence

None

Examples

#include<rw/tvmap.h>
#include<iostream.h>
#include<rw/cstring.h>
 
int main(){
   RWTValMap<RWCString,int,greater<RWCString> > age;
   RWTValMapIterator<RWCString,int,greater<RWCString> > itr(age);
 
   age.insert("John", 30);
   age.insert("Steve",17);
   age.insert("Mark",24);
 
//Insertion is rejected, no duplicates allowed
   age.insert("Steve",24);
 
   for(;itr();)
     cout << itr.key() << "\'s age is " << itr.value() << endl;
 
   return 0;
}

Program Output:

Steve's age is 17
Mark's age is 24
John's age is 30

Public Constructors

RWTValMapIterator<K,T,C>(RWTValMap<K,T,C>&h);

Creates an iterator for the map h. The iterator begins in an undefined state and must be advanced before the first association will be accessible.

Public Member Operators

RWBoolean operator()();

Advances self to the next element. If the iterator has advanced past the last element in the collection, false will be returned. Otherwise, true will be returned.

RWBoolean operator++();

Advances self to the next element. If the iterator has been reset or just created self will now reference the first element. If, before iteration, self pointed to the last association in the map, self will now reference an undefined value and false will be returned. Otherwise, true is returned. Note: no postincrement operator is provided.

Public Member Functions

RWTValMap<K,T,C>* container() const;

Returns a pointer to the collection being iterated over.

K key() const;

Returns the key portion of the association currently referenced by self.

void reset(); void reset(RWTValMap<K,T,C>& h);

Resets the iterator so that after being advanced it will reference the first element of the collection. Using reset() with no argument will reset the iterator on the current container. Supplying a RWTValMap with reset() will reset the iterator on that container.

T value();

Returns the value portion of the association referenced by self.

RWTValMultiMap<K,T,C>

Synopsis

#include <rw/tvmmap.h> 
RWTValMultiMap<K,T,C> m;

Standard C++ Library Dependent!


Note: RWTValMultiMap requires the Standard C++ Library.


Description

This class maintains a collection of keys, each with an associated item of type T. Order is determined by the key according to a comparison object of type C. C must induce a total ordering on elements of type K via a public member

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

which returns true if x and its partner should precede y and its partner within the collection. The structure less<T> from the C++-standard header file <functional> is an example.

RWTValMultiMap<K,T,C> may contain multiple keys that compare equal to each other. (RWTValMap<K,T,C> will not accept a key that compares equal to any key already in the collection.) Equality is based on the comparison object and not on the == operator. Given a comparison object comp, keys a and b are equal if
!comp(a,b) && !comp(b,a).

Persistence

Isomorphic.

Examples

In this example, a map of RWCStrings and RWDates is exercised.

//
// tvmmbday.cpp
//
#include <rw/tvmmap.h>
#include <rw/cstring.h>
#include <rw/rwdate.h>
#include <iostream.h>
#include <function.h>
 
main(){
  typedef RWTValMultiMap<RWCString, RWDate, less<RWCString> >
     RWMMap;
  RWMMap birthdays;
 
  birthdays.insert("John", RWDate(12, "April",1975));
  birthdays.insert("Ivan", RWDate(2, "Nov", 1980));
  birthdays.insert("Mary", RWDate(22, "Oct", 1987));
  birthdays.insert("Ivan", RWDate(19, "June", 1971));
  birthdays.insert("Sally",RWDate(15, "March",1976));
  birthdays.insert("Ivan",  RWDate(6, "July", 1950));
 
  // How many "Ivan"s?
  RWMMap::size_type n = birthdays.occurrencesOf("Ivan");
  RWMMap::size_type idx = 0;
  cout << "There are " << n << " Ivans:" << endl;
  RWMMap::iterator iter = birthdays.std().lower_bound("Ivan");
  while (++idx <= n) 
    cout << idx << ".  " << (*iter++).second << endl; 
  return 0;
}

Program Output:

There are 3 Ivans:
1.  11/02/80
2.  06/19/71
3.  07/06/50

Related Classes

Class RWTValMap<K,T,C> offers the same interface to a collection that will not accept multiple keys that compare equal to each other. RWTValMultiSet<T,C> maintains a collection of keys without the associated values.

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

Public Typedefs

typedef multimap<K,T,C,allocator>             container_type;
typedef container_type::iterator              iterator;
typedef container_type::const_iterator        const_iterator;
typedef container_type::size_type             size_type;
typedef pair <const K,T>                       value_type;
typedef pair <const K,T>&                      reference;
typedef const pair <const K,T>&                const_reference;

Public Constructors

RWTValMultiMap<K,T,C>(const C& comp = C());

Constructs an empty map with comparator comp.

RWTValMultiMap<K,T,C>(const container_type& m);

Constructs a map by copying all elements of m.

RWTValMultiMap<K,T,C>(const RWTValMultiMap<K,T,C>& rwm);

Copy constructor.

RWTValMultiMap<K,T,C>(const value_type* first, const value_type* last, const C& comp = C());

Constructs a map by copying elements from the array of Ts pointed to by first, up to, but not including, the element pointed to by last.

Public Member Operators

RWTValMultiMap<K,T,C>& operator=(const RWTValMultiMap<K,T,C>& m); RWTValMultiMap<K,T,C>& operator=(const container_type& m) const;

Destroys all elements of self and replaces them by copying all associations from m.

bool operator<(const RWTValMultiMap<K,T,C>& m); bool operator<(const container_type& m) const;

Returns true if self compares lexicographically less than m, otherwise returns false. Assumes that type K has well-defined less-than semantics (T::operator<(const K&) or equivalent).

bool operator==(const RWTValMultiMap<K,T,C>& m) const; bool operator==(const container_type& m) const;

Returns true if self compares equal to m, otherwise returns false. Two collections are equal if both have the same number of entries, and iterating through both collections produces, in turn, individual pairs that compare equal to each other.

Public Member Functions

void apply(void (*fn)(const K&, T&, void*),void* d); void apply(void (*fn)(const K&, const T&, void*),void* d) const;

Applies the user-defined function pointed to by fn to every association in the collection. This function must have one of the prototypes:

void yourfun(const K& key, T& a, void* d);

void yourfun(const K& key, const T& a,void* d);

Client data may be passed through parameter d.

void applyToKeyAndValue(void (*fn)(const K&, T&, void*),void* d); void applyToKeyAndValue (void (*fn)(const K&, const T&, void*),void* d) const;

This is a deprecated version of the apply member above. It behaves exactly the same as apply.

iterator begin(); const_iterator begin() const;

Returns an iterator positioned at the first pair in self.

void clear();

Clears the collection by removing all items from self. Each key and its associated item will have its destructor called.

bool contains(const K& key) const;

Returns true if there exists a key j in self that compares equal to key, otherwise returns false.

bool contains (bool (*fn)(const_reference,void*),void* d) const;

Returns true if there exists an association a in self such that the expression ((*fn)(a,d)) is true, otherwise returns false. fn points to a user-defined tester function which must have prototype:

bool yourTester(const_reference a, void* d);

Client data may be passed through parameter d.

iterator end(); const_iterator end() const;

Returns an iterator positioned "just past" the last association in self.

size_type entries() const;

Returns the number of associations in self.

bool find(const K& key, Key& r) const;

If there exists a key j in self that compares equal to key, assigns j to r and returns true. Otherwise, returns false and leaves the value of r unchanged.

bool find(bool (*fn)(const_reference,void*),void* d, pair<K,T>& r) const;

If there exists an association a in self such that the expression ((*fn)(a,d)) is true, assigns a to r and returns true. Otherwise, returns false and leaves the value of k unchanged. fn points to a user-defined tester function which must have prototype:

bool yourTester(const_reference a, void* d);

Client data may be passed through parameter d.

bool findValue(const K& key, T& r) const;

If there exists a key j in self that compares equal to key, assigns the item associated with j to r and returns true. Otherwise, returns false and leaves the value of r unchanged.

bool findKeyValue(const K& key, K& kr, T& tr) const;

If there exists a key j in self that compares equal to key, assigns j to kr, assigns the item associated with j to tr, and returns true. Otherwise, returns false and leaves the values of kr and tr unchanged.

bool insert(const K& key, const T& a);

Adds key with associated item a to the collection. Returns true.

bool insertKeyAndValue(const K& key, const T& a);

This is a deprecated version of the insert member above. It behaves exactly the same as insert.

bool isEmpty() const;

Returns true if there are no items in the collection, false otherwise.

size_type occurrencesOf(const K& key) const;

Returns the number of keys j in self that compare equal to key.

size_type occurrencesOf(bool (*fn)(const_reference,void*), void* d) const;

Returns the number of associations a in self such that the expression((*fn)(a,d)) is true. fn points to a user-defined tester function which must have prototype:

bool yourTester(const_reference a, void* d);

Client data may be passed through parameter d.

bool remove(const K& key);

Removes the first association with key j in self where j compares equal to key and returns true. Returns false if there is no such association.

bool remove(bool (*fn)(const_reference,void*), void* d);

Removes the first association a in self such that the expression ((*fn)(a,d)) is true and returns true. Returns false if there is no such element. fn points to a user-defined tester function which must have prototype:

bool yourTester(const_reference a, void* d);

Client data may be passed through parameter d.

size_type removeAll(const K& key);

Removes all associations in self that have a key j that compares equal to key. Returns the number of items removed.

size_type removeAll(bool (*fn)(const_reference,void*), void* d);

Removes all associations a in self such that the expression ((*fn)(a,d))is true. Returns the number of items removed. fn points to a user-defined tester function which must have prototype:

bool yourTester(const_reference a, void* d);

Client data may be passed through parameter d.

multimap<K,T,C,allocator>& std(); const multimap<K,T,C,allocator>& std() const;

Returns a reference to the underlying C++-standard collection that serves as the implementation for self. This reference may be used freely, providing access to the C++-standard interface as well as interoperability with other software components that make use of the C++-standard collections.

Related Global Operators

RWvostream& operator<<(RWvostream& strm, const RWTValMultiMap<K,T,C>& coll); RWFile& operator<<(RWFile& strm, const RWTValMultiMap<K,T,C>& coll);

Saves the collection coll onto the output stream strm, or a reference to it if it has already been saved.

RWvistream& operator>>(RWvistream& strm, RWTValMultiMap<K,T,C>& coll); RWFile& operator>>(RWFile& strm, RWTValMultiMap<K,T,C>& coll);

Restores the contents of the collection coll from the input stream strm.

RWvistream& operator>>(RWvistream& strm, RWTValMultiMap<K,T,C>*& p); RWFile& operator>>(RWFile& strm, RWTValMultiMap<K,T,C>*& p);

Looks at the next object on the input stream strm and either creates a new collection off the heap and sets p to point to it, or sets p to point to a previously read instance. If a collection is created off the heap, then you are responsible for deleting it.

RWTValMultiMapIterator<K,T,C>

Synopsis

#include<rw/tvmmap.h>
RWTValMultiMap<K,T,C> vm;
RWTValMultiMapIterator<K,T,C> itr(vm);

Standard C++ Library Dependent!


Note: RWTValMultiMapIterator requires the Standard C++ Library.


Description

RWTValMultiMapIterator is supplied with Tools.h++ 7 to provide an iterator interface for class RWTValMultiMap that has backward compatibility with the container iterators provided in Tools.h++ 6.x.

The order of iteration for an RWTValMultiMap is dependent upon the comparator object as applied to the keys of the stored associations.

The current item referenced by this iterator is undefined after construction or after a call to reset(). The iterator becomes valid after being advanced with either a preincrement or operator().

For both operator++ and operator(), iterating past the last element will return a value equivalent to boolean false. Continued increments will return a value equivalent to false until reset() is called.

Persistence

None

Examples

#include<rw/tvmmap.h>
 
#include<iostream.h>
#include<rw/cstring.h>
 
int main(){
   RWTValMultiMap<RWCString,int,greater<RWCString> > a;
   RWTValMultiMapIterator
      <RWCString,int,greater<RWCString> > itr(a);
 
   a.insert("John", 30);
   a.insert("Steve",17);
   a.insert("Mark",24);
   a.insert("Steve",24);
 
   for(;itr();)
     cout << itr.key() << "\'s age is " << itr.value() << endl;
 
   return 0;
}

Program Output:

Steve's age is 17
Steve's age is 24
Mark's age is 24
John's age is 30

Public Constructors

RWTValMultiMapIterator<K,T,C>(RWTValMultiMap<K,T,C>&m);

Creates an iterator for the multi-map m. The iterator begins in an undefined state and must be advanced before the first association will be accessible.

Public Member Operators

RWBoolean operator()();

Advances self to the next element. If the iterator has advanced past the last item in the collection, returns false. Otherwise, returns true.

RWBoolean operator++();

Advances self to the next element. If the iterator has been reset or just created self will now reference the first element. If, before iteration, self referenced the last association in the multi-map, self will now reference an undefined value and false will be returned. Otherwise, true is returned. Note: no postincrement operation is provided.

Public Member Functions

RWTValMultiMap<K,T,C>* container() const;

Returns a pointer to the collection being iterated over.

K key() const;

Returns the key portion of the association currently referenced by self.

void reset(); void reset(RWTValMultiMap<K,T,C>& h);

Resets the iterator so that after being advanced it will reference the first element of the collection. Using reset() with no argument will reset the iterator on the current container. Supplying a RWTValMultiMap to reset() will reset the iterator on the new container.

T value();

Returns the value portion of the association referenced by self.

RWTValMultiSet<T,C>

Synopsis

#include <rw/tvmset.h>
RWTValMultiSet<T,C>

Standard C++ Library Dependent!


Note: RWTPtrMultiSet requires the Standard C++ Library.


Description

This class maintains a collection of values, which are ordered according to a comparison object of type C. C must induce a total ordering on elements of type T via a public member

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

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.

RWTValMultiSet<T,C> may contain multiple items that compare equal to each other. (RWTValSet<T,C> will not accept an item that compares equal to an item already in the collection.)

Persistence

Isomorphic.

Examples

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

//
 
// tvmsstr.cpp
//
#include <rw/tvmset.h>
#include <rw/cstring.h>
#include <iostream.h>
 
main(){
 RWTValMultiSet<RWCString,less<RWCString> > set;
 
  set.insert("one");
  set.insert("two");
  set.insert("three");
  set.insert("one");               // OK, duplicates allowed
 
  cout << set.entries() << endl;   // Prints "4"
  return 0;
}

Related Classes

Class RWTValSet<T,C> offers the same interface to a collection that will not accept multiple items that compare equal to each other. RWTValMultiMap<K,T,C> maintains a collection of key-value pairs.

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

Public Typedefs

typedef multiset<T,C,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 const T&                               const_reference;

Public Constructors

RWTValMultiSet<T,C>(const C& cmp = C());

Constructs an empty set.

RWTValMultiSet<T,C>(const container_type& s);

Constructs a set by copying all elements of s.

RWTValMultiSet<T,C>(const RWTValMultiSet<T,C>& rws);

Copy constructor.

RWTValMultiSet<T,C>(const T* first,const T* last,const C& cmp = C());

Constructs a set by copying elements from the array of Ts pointed to by first, up to, but not including, the element pointed to by last.

Public Member Operators

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

Destroys all elements of self and replaces them by copying all elements of s.

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

Returns true if self compares lexicographically less than s, otherwise returns false. Assumes that type T has well-defined less-than semantics (T::operator<(const T&) or equivalent).

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

Returns true if self compares equal to s, otherwise returns false. Two collections are equal if both have the same number of entries, and iterating through both collections produces, in turn, individual elements that compare equal to each other.

Public Member Functions

void apply(void (*fn)(const_reference,void*), void* d) const;

Applies the user-defined function pointed to by fn to every item in the collection. This function must have prototype:

void yourfun(const_reference a, void* d);

Client data may be passed through parameter d.

iterator begin(); const_iterator begin() const;

Returns an iterator positioned at the first element of self.

void clear();

Clears the collection by removing all items from self. Each item will have its destructor called.

bool contains(const_reference a) const;

Returns true if there exists an element t in self that compares equal to a, otherwise returns false.

bool contains(bool (*fn)(const_reference, void*), void* d) const;

Returns true if there exists an element t in self such that the expression ((*fn)(t,d)) is true, otherwise returns false. fn points to a user-defined tester function which must have prototype:

bool yourTester(const_reference a, void* d);

Client data may be passed through parameter d.

void difference(const RWTValMultiSet<T,C>& s); void difference(const container_type& s);

Sets self to the set-theoretic difference given by (self - s).

iterator end(); const_iterator end() const;

Returns an iterator positioned "just past" the last element in self.

size_type entries() const;

Returns the number of items in self.

bool find(const_reference a, T& k) const;

If there exists an element t in self that compares equal to a, assigns t to k and returns true. Otherwise, returns false and leaves the value of k unchanged.

bool find(bool (*fn)(const_reference,void*), void* d, T& k) const;

If there exists an element t in self such that the expression ((*fn)(t,d)) is true, assigns t to k and returns true. Otherwise, returns false and leaves the value of k unchanged. fn points to a user-defined tester function which must have prototype:

bool yourTester(const_reference a, void* d);

Client data may be passed through parameter d.

void intersection(const RWTValMultiSet<T,C>& s); void intersection(const container_type& s);

Sets self to the intersection of self and s.

bool insert(const_reference a);

Adds the item a to the collection. Returns true.

bool isEmpty() const;

Returns true if there are no items in the collection, false otherwise.

bool isEquivalent(const RWTValMultiSet<T,C>& s) const;

Returns true if there is set equivalence between self and s, and returns false otherwise.

bool isProperSubsetOf(const RWTValMultiSet<T,C>& s) const;

Returns true if self is a proper subset of s, and returns false otherwise.

bool isSubsetOf(const RWTValMultiSet<T,C>& s) const;

Returns true if self is a subset of s or if self is set equivalent to rhs, false otherwise.

size_type occurrencesOf(const_reference a) const;

Returns the number of elements t in self that compare equal to a.

size_type occurrencesOf(bool (*fn)(const_reference,void*),void* d) const;

Returns the number of elements t in self such that the expression((*fn)(t,d)) is true. fn points to a user-defined tester function which must have prototype:

bool yourTester(const_reference a, void* d);

Client data may be passed through parameter d.

bool remove(const_reference a);

Removes the first element t in self that compares equal to a and returns true. Returns false if there is no such element.

bool remove(bool (*fn)(const_reference,void*), void* d);

Removes the first element t in self such that the expression ((*fn)(t,d)) is true and returns true. Returns false if there is no such element. fn points to a user-defined tester function which must have prototype:

bool yourTester(const_reference a, void* d);

Client data may be passed through parameter d.

size_type removeAll(const_reference a);

Removes all elements t in self that compare equal to a. Returns the number of items removed.

size_type removeAll(bool (*fn)(const_reference,void*), void* d);

Removes all elements t in self such that the expression ((*fn)(t,d))is true. Returns the number of items removed. fn points to a user-defined tester function which must have prototype:

bool yourTester(const_reference a, void* d);

Client data may be passed through parameter d.

multiset<T,C,allocator>& std(); const multiset<T,C,allocator>& std() const;

Returns a reference to the underlying C++-standard collection that serves as the implementation for self. This reference may be used freely, providing access to the C++-standard interface as well as interoperability with other software components that make use of the C++-standard collections.

void symmetricDifference(const RWTValMultiSet<T,C>& s); void symmetricDifference(const container_type& s);

Sets self to the symmetric difference of self and s.

void Union(const RWTValMultiSet<T,C>& s); void Union(const container_type& s);

Sets self to the union of self and s. Note the use of the uppercase "U"in Union to avoid conflict with the C++ reserved word.

Related Global Operators

RWvostream& operator<<(RWvostream& strm, const RWTValMultiSet<T,C>& coll); RWFile& operator<<(RWFile& strm, const RWTValMultiSet<T,C>& coll);

Saves the collection coll onto the output stream strm, or a reference to it if it has already been saved.

RWvistream& operator>>(RWvistream& strm, RWTValMultiSet<T,C>& coll); RWFile& operator>>(RWFile& strm, RWTValMultiSet<T,C>& coll);

Restores the contents of the collection coll from the input stream strm.

RWvistream& operator>>(RWvistream& strm, RWTValMultiSet<T,C>*& p); RWFile& operator>>(RWFile& strm, RWTValMultiSet<T,C>*& p);

Looks at the next object on the input stream strm and either creates a new collection off the heap and sets p to point to it, or sets p to point to a previously read instance. If a collection is created off the heap, then you are responsible for deleting it.

RWTValMultiSetIterator<T,C>

Synopsis

#include<rw/tvmset.h>
 
RWTValMultiSet< T,C> vs;
RWTValMultiSetIterator< T,C> itr(vs);

Standard C++ Library Dependent!


Note: RWTValMultiSetIterator requires the Standard C++ Library.


Description

RWTValMultiSetIterator is supplied with Tools.h++ 7 to provide an iterator interface for class RWTValMultiSetIterator that has backward compatibility with the container iterators provided in Tools.h++ 6.x.

The order of iteration over an RWTValMultiSet is dependent on the supplied comparator object parameter C as applied to the values stored in the container.

The current item referenced by this iterator is undefined after construction or after a call to reset(). The iterator becomes valid after being advanced with either a preincrement or operator().

For both operator++ and operator(), iterating past the last element will return a value equivalent to boolean false. Continued increments will return a value equivalent to false until reset() is called.

Persistence

None

Examples

#include<rw/tvmset.h>
 
#include<iostream.h>
#include<rw/cstring.h>
 
int main(){
   RWTValMultiSet<RWCString,greater<RWCString> > a;
   RWTValMultiSetIterator<RWCString,greater<RWCString> > itr(a);
   a.insert("John");
   a.insert("Steve");
   a.insert("Mark");
   a.insert("Steve");
 
   for(;itr();)
     cout << itr.key() << endl;
 
   return 0;
}

Program Output:

Steve
Steve
Mark
John

Public Constructors

RWTValMultiSetIterator<T,C>(RWTValMultiSet< T,C> &h);

Creates an iterator for the multi-set h. The iterator begins in an undefined state and must be advanced before the first element will be accessible

Public Member Operators

RWBoolean operator()();

Advances self to the next element. If the iterator has advanced past the last element in the collection, false will be returned. Otherwise, true will be returned.

RWBoolean operator++();

Advances self to the next element. If the iterator has been reset or just created self will now reference the first element. If, before iteration, self referenced the last association in the multi-set, self will now reference an undefined value and false will be returned. Otherwise, true is returned. Note: no postincrement operator is provided.

Public Member Functions

RWTValMultiSet<T,C>* container() const;

Returns a pointer to the collection being iterated over.

T key();

Returns the value pointed to by self.

void reset(); void reset(RWTValMultiSet<T,C>& h);

Resets the iterator so that after being advanced it will point to the first element of the collection. Using reset() with no argument will reset the iterator on the current container. Supplying a RWTValMultiSet to reset() will reset the iterator on that container.

RWTValOrderedVector<T>

Synopsis

#include <rw/tvordvec.h> 
RWTValOrderedVector<T> ordvec;


Note: If you have the Standard C++ Library, use the interface described here. Otherwise, use the restricted interface to RWTValOrderedVector described in Appendix A: Alternate Template Class Interfaces.


Description

This class maintains a collection of values, implemented as a vector.

Persistence

Isomorphic

Example

In this example, a vector of type double is exercised.

//
 
// tvordvec.cpp
//
#include <rw/tvordvec.h>
#include <iostream.h>
 
main() {
  RWTValOrderedVector<double> vec;
 
  vec.insert(22.0);
  vec.insert(5.3);
  vec.insert(-102.5);
  vec.insert(15.0);
  vec.insert(5.3);
 
  cout << vec.entries() << " entries\n" << endl;  // Prints "5"
  for (int i=0; i<vec.length(); i++)
    cout << vec[i] << endl;
 
  return 0;
}

Program Output:

5 entries
 
22
5.3
-102.5
15
5.3

Related Classes

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

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

Public Typedefs

typedef vector<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

RWTValOrderedVector<T>();

Constructs an empty vector.

RWTValOrderedVector<T>(const vector<T,allocator>& vec);

Constructs a vector by copying all elements of vec.

RWTValOrderedVector<T>(const RWTValOrderedVector<T>& rwvec);

Copy constructor.

RWTValOrderedVector<T>(size_type n, const T& val);

Constructs a vector with n elements, each initialized to val.

RWTValOrderedVector<T>(size_type n);

Constructs an empty vector with a capacity of n elements.

RWTValOrderedVector<T>(const T* first, const T* last);

Constructs a vector by copying elements from the array of Ts pointed to by first, up to, but not including, the element pointed to by last.

Public Member Operators

RWTValOrderedVector<T>& operator=(const RWTValOrderedVector<T>& vec); RWTValOrderedVector<T>& operator=(const vector<T,allocator>& vec);

Calls the destructor on all elements of self and replaces them by copying all elements of vec.

bool operator<(const RWTValOrderedVector<T>& vec); bool operator<(const vector<T>& vec);

Returns true if self compares lexicographically less than vec, otherwise returns false. Type T must have well-defined less-than semantics (T::operator<(const T&) or equivalent).

bool operator==(const RWTValOrderedVector<T>& vec) const; bool operator==(const vector<T>& vec) const;

Returns true if self compares equal to vec, otherwise returns false. Two collections are equal if both have the same number of entries, and iterating through both collections produces, in turn, individual elements that compare equal to each other.

T& operator()(size_type i); const T& operator()(size_type i) const;

Returns a reference to the ith element of self. Index i should be between 0 and one less then the number of entries, otherwise the results are undefined—no bounds checking is performed.

T& operator[](size_type i); const T& operator[](size_type i) const;

Returns a reference to the ith element of self. Index i must be between 0 and one less then the number of entries in self, otherwise the function throws an exception of type RWBoundsErr.

Public Member Functions

void append(const_reference a);

Adds the item a to the end of the collection.

void apply(void (*fn)(reference,void*), void* d); void apply(void (*fn)(const_reference,void*), void* d) const;

Applies the user-defined function pointed to by fn to every item in the collection. This function must have one of the prototypes:

void yourfun(const_reference a, void* d);

void yourfun(reference a, void* d);

Client data may be passed through parameter d.

reference at(size_type i); const_reference at(size_type i) const;

Returns a reference to the ith element of self. Index i must be between 0 and one less then the number of entries in self, otherwise the function throws an exception of type RWBoundsErr.

iterator begin(); const_iterator begin() const;

Returns an iterator positioned at the first element of self.

void clear();

Clears the collection by removing all items from self. Each item will have its destructor called.

bool contains(const_reference a) const;

Returns true if there exists an element t in self such that the expression(t == a) is true, otherwise returns false.

bool contains(bool (*fn)(const_reference,void*), void* d) const;

Returns true if there exists an element t in self such that the expression ((*fn)(t,d)) is true, otherwise returns false. fn points to a user-defined tester function which must have prototype:

bool yourTester(const_reference a, void* d);

Client data may be passed through parameter d.

const T* data() const;

Returns a pointer to the first element of the vector.

iterator end(); const_iterator end() const;

Returns a past-the-end valued iterator of self.

size_type entries() const;

Returns the number of elements in self.

bool find(const_reference a, value_type& k) const;

If there exists an element t in self such that the expression (t == a) is true, assigns t to k and returns true. Otherwise, returns false and leaves the value of k unchanged.

bool find(bool (*fn)(const_reference,void*), void* d, value_type& k) const;

If there exists an element t in self such that the expression ((*fn)(t,d)) is true, assigns t to k and returns true. Otherwise, returns false and leaves the value of k unchanged. fn points to a user-defined tester function which must have prototype:

bool yourTester(const T& a, void* d);

Client data may be passed through parameter d.

reference first(); const_reference first() const;

Returns a reference to the first element of self.

size_type index(const_reference a) const;

Returns the position of the first item t in self such that (t == a), or returns the static member npos if no such item exists.

size_type index(bool (*fn)(const_reference,void*), void* d) const;

Returns the position of the first item t in self such that((*fn)(t,d)) is true, or returns the static member npos if no such item exists. fn points to a user-defined tester function which must have prototype:

bool yourTester(const_reference a, void* d);

Client data may be passed through parameter d.

bool insert(const_reference a);

Adds the item a to the end of the collection. Returns true.

void insertAt(size_type i, const_reference a);

Inserts the item a in front of the item at position i in self. This position must be between 0 and the number of entries in the collection, otherwise the function throws an exception of type RWBoundsErr.

bool isEmpty() const;

Returns true if there are no items in the collection, false otherwise.

reference last(); const_reference last() const;

Returns a reference to the last item in the collection.

size_type length() const;

Returns the number of elements in self.

reference maxElement(); const_reference maxElement() const; reference minElement(); const_reference minElement() const;

Returns a reference to the minimum or maximum element in the collection. Type T must have well-defined less-than semantics (T::operator<(const T&) or equivalent).

size_type occurrencesOf(const_reference a) const;

Returns the number of elements t in self such that the expression (t == a) is true.

size_type occurrencesOf (bool (*fn)(const_reference,void*), void* d) const;

Returns the number of elements t in self such that the expression((*fn)(t,d)) is true. fn points to a user-defined tester function which must have prototype:

bool yourTester(const_reference a, void* d);

Client data may be passed through parameter d.

void prepend(const_reference a);

Adds the item a to the beginning of the collection.

bool remove(const_reference a);

Removes the first element t in self such that the expression (t == a) is true and returns true. Returns false if there is no such element.

bool remove(bool (*fn)(const_reference,void*), void* d);

Removes the first element t in self such that the expression ((*fn)(t,d)) is true and returns true. Returns false if there is no such element. fn points to a user-defined tester function which must have prototype:

bool yourTester(const_reference a, void* d);

Client data may be passed through parameter d.

size_type removeAll(const_reference a);

Removes all elements t in self such that the expression (t == a) is true. Returns the number of items removed.

size_type removeAll(bool (*fn)(const_reference,void*), void* d);

Removes all elements t in self such that the expression ((*fn)(t,d))is true. Returns the number of items removed. fn points to a user-defined tester function which must have prototype:

bool yourTester(const_reference a, void* d);

Client data may be passed through parameter d.

value_type removeAt(size_type i);

Removes and returns the item at position i in self. This position must be between 0 and one less then the number of entries in the collection, otherwise the function throws an exception of type RWBoundsErr.

value_type removeFirst();

Removes and returns the first item in the collection.

value_type removeLast();

Removes and returns the first item in the collection.

size_type replaceAll(const_reference oldVal, const_reference newVal);

Replaces all elements t in self such that the expression (t == oldVal) is true with newVal. Returns the number of items replaced.

size_type replaceAll(bool (*fn)(const_reference,void*), void* d, const T& newval);

Replaces all elements t in self such that the expression ((*fn)(t,d))is true. Returns the number of items replaced. fn points to a user-defined tester function which must have prototype:

bool yourTester(const_reference a, void* d);

Client data may be passed through parameter d.

void resize(size_type n);

Modify the capacity of the vector to be at least as large as n. The function has no effect if the capacity is already as large as n.

void sort();

Sorts the collection using the less-than operator to compare elements.

vector<T,allocator>& std(); const vector<T,allocator>& std() const;

Returns a reference to the underlying C++-standard collection that serves as the implementation for self. This reference may be used freely, providing access to the C++-standard interface as well as interoperability with other software components that make use of the C++-standard collections.

Static Public Data Member

const size_type npos;

This is the value returned by member functions such as index to indicate a non-position. The value is equal to ~(size_type)0.

Related Global Operators

RWvostream& operator<<(RWvostream& strm, const RWTValOrderedVector<T>& coll); RWFile& operator<<(RWFile& strm, const RWTValOrderedVector<T>& coll);

Saves the collection coll onto the output stream strm, or a reference to it if it has already been saved.

RWvistream& operator>>(RWvistream& strm, RWTValOrderedVector<T>& coll); RWFile& operator>>(RWFile& strm, RWTValOrderedVector<T>& coll);

Restores the contents of the collection coll from the input stream strm.

RWvistream& operator>>(RWvistream& strm, RWTValOrderedVector<T>*& p); RWFile& operator>>(RWFile& strm, RWTValOrderedVector<T>*& p);

Looks at the next object on the input stream strm and either creates a new collection off the heap and sets p to point to it, or sets p to point to a previously read instance. If a collection is created off the heap, then you are responsible for deleting it.

RWTValSet<T,C>

Synopsis

#include <rw/tvset.h> 
RWTValSet<T,C> s;

Standard C++ Library Dependent!

RWTValSet requires the Standard C++ Library.

Description

This class maintains a collection of values, which are ordered according to a comparison object of type C. C must induce a total ordering on elements of type T via a public member

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

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.

RWTValSet<T,C> will not accept an item that compares equal to an item already in the collection. (RWTValMultiSet<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).

Persistence

Isomorphic.

Examples

In this example, a set of RWCStrings is exercised.

//
 
// tvsstr.cpp
//
#include <rw/tvset.h>
#include <rw/cstring.h>
#include <iostream.h>
#include <function.h>
 
main(){
  RWTValSet<RWCString,less<RWCString> > set;
 
  set.insert("one");
  set.insert("two");
  set.insert("three");
  set.insert("one");     // Rejected: already in collection
 
  cout << set.entries() << endl;     // Prints "3"
  return 0;
}

Related Classes

Class RWTValMultiSet<T,C> offers the same interface to a collection that accepts multiple items that compare equal to each other. RWTValMap<K,T,C> maintains a collection of key-value pairs.

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

Public Typedefs

typedef set<T,C,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 const T&                               const_reference;

Public Constructors

RWTValSet<T,C>(const C& comp = C());

Constructs an empty set.

RWTValSet<T,C>(const container_type& s);

Constructs a set by copying all elements of s.

RWTValSet<T,C>(const RWTValSet<T,C>& rws);

Copy constructor.

RWTValSet<T,C>(const T* first,const T* last,const C& comp = C());

Constructs a set by copying elements from the array of Ts pointed to by first, up to, but not including, the element pointed to by last.

Public Member Operators

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

Destroys all elements of self and replaces them by copying all elements of s.

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

Returns true if self compares lexicographically less than s, otherwise returns false. Assumes that type T has well-defined less-than semantics (T::operator<(const T&) or equivalent).

bool operator==(const RWTValSet<T,C>& s) const; bool operator==(const set<T,C>& s) const;

Returns true if self compares equal to s, otherwise returns false. Two collections are equal if both have the same number of entries, and iterating through both collections produces, in turn, individual elements that compare equal to each other.

Public Member Functions

void apply(void (*fn)(const_reference,void*), void* d) const;

Applies the user-defined function pointed to by fn to every item in the collection. This function must have prototype:

void yourfun(const_reference a, void* d);

Client data may be passed through parameter d.

iterator begin(); const_iterator begin() const;

Returns an iterator positioned at the first element of self.

void clear();

Clears the collection by removing all items from self. Each item will have its destructor called.

bool contains(const_reference a) const;

Returns true if there exists an element t in self that compares equal to a, otherwise returns false.

bool contains(bool (*fn)(const_reference,void*), void* d) const;

Returns true if there exists an element t in self such that the expression ((*fn)(t,d)) is true, otherwise returns false. fn points to a user-defined tester function which must have prototype:

bool yourTester(const_reference a, void* d);

Client data may be passed through parameter d.

void difference(const RWTValSet<T,C>& s); void difference(const container_type& s);

Sets self to the set-theoretic difference given by (self - s).

iterator end(); const_iterator end() const;

Returns an iterator positioned "just past" the last element in self.

size_type entries() const;

Returns the number of items in self.

bool find(const_reference a, T& k) const;

If there exists an element t in self that compares equal to a, assigns t to k and returns true. Otherwise, returns false and leaves the value of k unchanged.

bool find(bool (*fn)(const_reference,void*), void* d, T& k) const;

If there exists an element t in self such that the expression ((*fn)(t,d)) is true, assigns t to k and returns true. Otherwise, returns false and leaves the value of k unchanged. fn points to a user-defined tester function which must have prototype:

bool yourTester(const_reference a, void* d);

Client data may be passed through parameter d.

bool insert(const_reference a);

Adds the item a to the collection. Returns true if the insertion is successful, otherwise returns false. The function will return true unless the collection already holds an element with the equivalent key.

void intersection(const RWTValSet<T,C>& s); void intersection(const container_type& s);

Sets self to the intersection of self and s.

bool isEmpty() const;

Returns true if there are no items in the collection, false otherwise.

bool isEquivalent(const RWTValSet<T,C>& s) const;

Returns true if there is set equivalence between self and s, and returns false otherwise.

bool isProperSubsetOf(const RWTValSet<T,C>& s) const;

Returns true if self is a proper subset of s, and returns false otherwise.

bool isSubsetOf(const RWTValSet<T,C>& s) const;

Returns true if self is a subset of s; false otherwise.

size_type occurrencesOf(const_reference a) const;

Returns the number of elements t in self that compare equal to a.

size_type occurrencesOf(bool (*fn)(const T&,void*),void* d) const;

Returns the number of elements t in self such that the expression((*fn)(t,d)) is true. fn points to a user-defined tester function which must have prototype:

bool yourTester(const_reference a, void* d);

Client data may be passed through parameter d.

bool remove(const_reference a);

Removes the first element t in self that compares equal to a and returns true. Returns false if there is no such element.

bool remove(bool (*fn)(const_reference,void*), void* d);

Removes the first element t in self such that the expression ((*fn)(t,d)) is true and returns true. Returns false if there is no such element. fn points to a user-defined tester function which must have prototype:

bool yourTester(const_reference a, void* d);

Client data may be passed through parameter d.

size_type removeAll(const_reference a);

Removes all elements t in self that compare equal to a. Returns the number of items removed.

size_type removeAll(bool (*fn)(const_reference,void*), void* d);

Removes all elements t in self such that the expression ((*fn)(t,d))is true. Returns the number of items removed. fn points to a user-defined tester function which must have prototype:

bool yourTester(const_reference a, void* d);

Client data may be passed through parameter d.

set<T,C,allocator>& std(); const set<T,C,allocator>& std() const;

Returns a reference to the underlying C++-standard collection that serves as the implementation for self. This reference may be used freely, providing access to the C++-standard interface as well as interoperability with other software components that make use of the C++-standard collections.

void symmetricDifference(const RWTValSet<T,C>& s); void symmetricDifference(const container_type& s);

Sets self to the symmetric difference of self and s.

void Union(const RWTValSet<T,C>& s); void Union(const container_type& s);

Sets self to the union of self and s. Note the use of the uppercase "U"in Union to avoid conflict with the C++ reserved word.

Related Global Operators

RWvostream& operator<<(RWvostream& strm, const RWTValSet<T,C>& coll); RWFile& operator<<(RWFile& strm, const RWTValSet<T,C>& coll);

Saves the collection coll onto the output stream strm, or a reference to it if it has already been saved.

RWvistream& operator>>(RWvistream& strm, RWTValSet<T,C>& coll); RWFile& operator>>(RWFile& strm, RWTValSet<T,C>& coll);

Restores the contents of the collection coll from the input stream strm.

RWvistream& operator>>(RWvistream& strm, RWTValSet<T,C>*& p); RWFile& operator>>(RWFile& strm, RWTValSet<T,C>*& p);

Looks at the next object on the input stream strm and either creates a new collection off the heap and sets p to point to it, or sets p to point to a previously read instance. If a collection is created off the heap, then you are responsible for deleting it.

RWTValSetIterator<T,C>

Synopsis

#include<rw/tvset.h>
RWTValSet<T,C> vs;
RWTValSetIterator<T,C> itr(vs);

Standard C++ Library Dependent!


Note: RWTValSetIterator requires the Standard C++ Library.


Description

RWTValSetIterator is supplied with Tools.h++ 7 to provide an iterator interface for class RWTValSetIterator that is backward compatable with the container iterators provided in Tools.h++ 6.x.

The order of iteration over an RWTValSet is dependent on the supplied comparator object parameter C as applied to the values stored in the container.

The current item referenced by this iterator is undefined after construction or after a call to reset(). The iterator becomes valid after being advanced with either a preincrement or operator().

For both operator++ and operator(), iterating past the last element will return a value equivalent to boolean false. Continued increments will return a value equivalent to false until reset() is called.

Persistence

None

Examples

#include<rw/tvset.h>
 
#include<iostream.h>
#include<rw/cstring.h>
 
int main(){
   RWTValSet<RWCString,greater<RWCString> > a;
   RWTValSetIterator<RWCString,greater<RWCString> > itr(a);
 
   a.insert("John");
   a.insert("Steve");
   a.insert("Mark");
 
//Rejected, duplicates are not allowed
   a.insert("Steve");
 
   for(;itr();)
     cout << itr.key() << endl;
 
   return 0;
}

Program Output:

Steve
Mark
John

Public Constructors

RWTValSetIterator<T,C>(RWTValSet<T,C>&s);

Creates an iterator for the set s. The iterator begins in an undefined state and must be advanced before the first element will be accessible

Public Member Operators

RWBoolean operator()();

Advances self to the next element. If the iterator has advanced past the last element in the collection, false will be returned. Otherwise, true will be returned.

RWBoolean operator++();

Advances self to the next element. If the iterator has been reset or just created self will now reference the first element. If, before iteration, self referenced the last association in the set, self will now reference an undefined value and false will be returned. Otherwise, true is returned. Note: no postincrement operator is provided.

Public Member Functions

RWTValSet<T,C>* container() const;

Returns a pointer to the collection being iterated over.

T key() const;

Returns the value referenced by self.

void reset(); void reset(RWTValSet<T,C>& s);

Resets the iterator so that after being advanced it will reference the first element of the collection. Using reset() with no argument will reset the iterator on the current container. Supplying a RWTValSet to reset() will reset the iterator on that container.

RWTValSlist<T>

Synopsis

#include <rw/tvslist.h> 
RWTValSlist<T> lst;


Note: If you have the Standard C++ Library, use the interface described here. Otherwise, use the restricted interface to RWTValSlist described in Appendix A: Alternate Template Class Interfaces.


Description

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

Persistence

Isomorphic

Example

In this example, a singly-linked list of RWDates is exercised.

//
 
// tvslint.cpp
//
#include<rw/tvslist.h>
#include<iostream.h>
 
void div5(int& x, void *y){x = x/5;}
 
int main()
{
  const int vec[10] = {45,10,5,15,25,30,35,20,40,50};
 
  RWTValSlist<int> lst(vec, vec+10);
  RWTValSlistIterator<int> itr(lst);
 
  lst.apply(div5, 0);
  lst.sort();
 
for(;itr();)
     cout << itr.key() << "  ";
  cout << endl;
 
  return 0;
}

Program Output:

1 2 3 4 5 6 7 8 9 10

Related Classes

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

The Rogue Wave supplied, standard-compliant class rw_slist<T> is the collection that serves as the underlying implementation for this class.

Public Typedefs

typedef rw_slist<T>                            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

RWTValSlist<T>();

Constructs an empty, singly-linked list.

RWTValSlist<T>(const rw_slist<T>& lst);

Constructs a singly-linked list by copying all elements of lst.

RWTValSlist<T>(const RWTValSlist<T>& rwlst);

Copy constructor.

RWTValSlist<T>(size_type n, const T& val = T());

Constructs a singly-linked list with n elements, each initialized to val.

RWTValSlist<T>(const T* first, const T* last);

Constructs a singly-linked list by copying elements from the array of Ts pointed to by first, up to, but not including, the element pointed to by last.

Public Member Operators

RWTValSlist<T>& operator=(const RWTValSlist<T>& lst); RWTValSlist<T>& operator=(const rw_slist<T>& lst);

Calls the destructor on all elements of self and replaces them by copying all elements of lst.

bool operator<(const RWTValSlist<T>& lst) const; bool operator<(const rw_slist<T>& lst) const;

Returns true if self compares lexicographically less than lst, otherwise returns false. Type T must have well-defined less-than semantics (T::operator<(const T&) or equivalent).

bool operator==(const RWTValSlist<T>& lst) const; bool operator==(const rw_slist<T>& lst) const;

Returns true if self compares equal to lst, otherwise returns false. Two collections are equal if both have the same number of entries, and iterating through both collections produces, in turn, individual elements that compare equal to each other.

reference operator()(size_type i); const_reference operator()(size_type i) const;

Returns a reference to the ith element of self. Index i should be between 0 and one less then the number of entries, otherwise the results are undefined—no bounds checking is performed.

reference operator[](size_type i); const_reference operator[](size_type i) const;

Returns a reference to the ith element of self. Index i must be between 0 and one less then the number of entries in self, otherwise the function throws an exception of type RWBoundsErr.

Public Member Functions

void append(const_reference a);

Adds the item a to the end of the collection.

void apply(void (*fn)(reference,void*), void* d); void apply(void (*fn)(const_reference,void*), void* d) const;

Applies the user-defined function pointed to by fn to every item in the collection. This function must have one of the prototypes:

void yourfun(const_reference a, void* d);

void yourfun(reference a, void* d);

Client data may be passed through parameter d.

reference at(size_type i); const_reference at(size_type i) const;

Returns a reference to the ith element of self. Index i must be between 0 and one less then the number of entries in self, otherwise the function throws an exception of type RWBoundsErr.

iterator begin(); const_iterator begin() const;

Returns an iterator positioned at the first element of self.

void clear();

Clears the collection by removing all items from self. Each item will have its destructor called.

bool contains(const T& a) const;

Returns true if there exists an element t in self such that the expression(t == a) is true, otherwise returns false.

bool contains(bool (*fn)(const T&,void*), void* d) const;

Returns true if there exists an element t in self such that the expression ((*fn)(t,d)) is true, otherwise returns false. fn points to a user-defined tester function which must have prototype:

bool yourTester(const T& a, void* d);

Client data may be passed through parameter d.

iterator end(); const_iterator end() const;

Returns a past-the-end valued iterator of self.

size_type entries() const;

Returns the number of elements in self.

bool find(const_reference a,reference k) const;

If there exists an element t in self such that the expression (t == a) is true, assigns t to k and returns true. Otherwise, returns false and leaves the value of k unchanged.

bool find (bool (*fn)(const_reference,void*),void* d,reference k) const;

If there exists an element t in self such that the expression ((*fn)(t,d)) is true, assigns t to k and returns true. Otherwise, returns false and leaves the value of k unchanged. fn points to a user-defined tester function which must have prototype:

bool yourTester(const_reference a, void* d);

Client data may be passed through parameter d.

reference first(); const_reference first() const;

Returns a reference to the first element of self.

T* get();

Removes and returns the first element in the collection. This method is identical to removeFirst and is included to provide compatibility with previous versions.

size_type index(const_reference a) const;

Returns the position of the first item t in self such that (t == a), or returns the static member npos if no such item exists.

size_type index(bool (*fn)(const_reference,void*), void* d) const;

Returns the position of the first item t in self such that((*fn)(t,d)) is true, or returns the static member npos if no such item exists. fn points to a user-defined tester function which must have prototype:

bool yourTester(const_reference a, void* d);

Client data may be passed through parameter d.

bool insert(const_reference a);

Adds the item a to the end of the collection. Returns true.

void insertAt(size_type i, const T& a);

Inserts the item a in front of the item at position i in self. This position must be between 0 and the number of entries in the collection, otherwise the function throws an exception of type RWBoundsErr.

bool isEmpty() const;

Returns true if there are no items in the collection, false otherwise.

T last() const;

Returns a reference to the last item in the collection.

reference maxElement(); const_reference maxElement() const; reference minElement(); const_reference minElement() const;

Returns a reference to the minimum or maximum element in the collection. Type T must have well-defined less-than semantics (T::operator<(const T&) or equivalent).

size_type occurrencesOf(const_reference a) const;

Returns the number of elements t in self such that the expression (t == a) is true.

size_type occurrencesOf(bool (*fn)(const_reference,void*),void* d) const;

Returns the number of elements t in self such that the expression((*fn)(t,d)) is true. fn points to a user-defined tester function which must have prototype:

bool yourTester(const_reference a, void* d);

Client data may be passed through parameter d.

void prepend(const_reference a);

Adds the item a to the beginning of the collection.

bool remove(const_reference a);

Removes the first element t in self such that the expression (t == a) is true and returns true. Returns false if there is no such element.

bool remove(bool (*fn)(const_reference,void*), void* d);

Removes the first element t in self such that the expression ((*fn)(t,d)) is true and returns true. Returns false if there is no such element. fn points to a user-defined tester function which must have prototype:

bool yourTester(const_reference a, void* d);

Client data may be passed through parameter d.

size_type removeAll(const_reference a);

Removes all elements t in self such that the expression (t == a) is true. Returns the number of items removed.

size_type removeAll(bool (*fn)(const_reference,void*), void* d);

Removes all elements t in self such that the expression ((*fn)(t,d))is true. Returns the number of items removed. fn points to a user-defined tester function which must have prototype:

bool yourTester(const_reference a, void* d);

Client data may be passed through parameter d.

T removeAt(size_type i);

Removes and returns the item at position i in self. This position must be between 0 and one less then the number of entries in the collection, otherwise the function throws an exception of type RWBoundsErr.

T removeFirst();

Removes and returns the first item in the collection.

T removeLast();

Removes and returns the first item in the collection.

size_type replaceAll(const_reference oldVal,const_reference newVal);

Replaces all elements t in self such that the expression (t == oldVal) is true with newVal. Returns the number of items replaced.

size_type replaceAll(bool (*fn)(const_reference,void*), void* d,const_reference nv);

Replaces all elements t in self such that the expression ((*fn)(t,d))is true with the value nv. Returns the number of items replaced. fn points to a user-defined tester function which must have prototype:

bool yourTester(const_reference a, void* d);

Client data may be passed through parameter d.

void sort();

Sorts the collection using the less-than operator to compare elements.

rw_slist<T>& std(); const rw_slist<T>& std() const;

Returns a reference to the underlying C++-standard collection that serves as the implementation for self. This reference may be used freely, providing access to the C++-standard interface as well as interoperability with other software components that make use of the C++-standard collections.

Static Public Data Member

const size_type npos;

This is the value returned by member functions such as index to indicate a non-position. The value is equal to ~(size_type)0.

Related Global Operators

RWvostream& operator<<(RWvostream& strm, const RWTValSlist<T>& coll); RWFile& operator<<(RWFile& strm, const RWTValSlist<T>& coll);

Saves the collection coll onto the output stream strm, or a reference to it if it has already been saved.

RWvistream& operator>>(RWvistream& strm, RWTValSlist<T>& coll); RWFile& operator>>(RWFile& strm, RWTValSlist<T>& coll);

Restores the contents of the collection coll from the input stream strm.

RWvistream& operator>>(RWvistream& strm, RWTValSlist<T>*& p); RWFile& operator>>(RWFile& strm, RWTValSlist<T>*& p);

Looks at the next object on the input stream strm and either creates a new collection off the heap and sets p to point to it, or sets p to point to a previously read instance. If a collection is created off the heap, then you are responsible for deleting it.

RWTValSlistIterator<T>

Synopsis

#include<rw/tvslist.h>
 
RWTValSlist<T> dl;
RWTValSlistIterator<T> itr(dl);


Note: If you have the Standard C++ Library, use the interface described here. Otherwise, use the restricted interface to RWTValSlistIterator described in Appendix A: Alternate Template Class Interfaces.


Description

RWTValSlistIterator is supplied with Tools.h++ 7 to provide an iterator interface for class RWTValSlistIterator that is backward compatible with the container iterators provided in Tools.h++ 6.x.

The order of iteration over an RWTValSlist is dependent on the order of insertion of the values into the container.

The current item referenced by this iterator is undefined after construction or after a call to reset(). The iterator becomes valid after being advanced with either a preincrement or operator().

For both operator++ and operator(), iterating past the last element will return a value equivalent to boolean false. Continued increments will return a value equal to false until reset() is called.

Persistence

None

Examples

#include<rw/tvslist.h>
 
#include<iostream.h>
#include<rw/cstring.h>
 
int main(){
 
   RWTValSlist<RWCString> a;
   RWTValSlistIterator<RWCString> itr(a);
  
a.insert("John");
 
   a.insert("Steve");
   a.insert("Mark");
   a.insert("Steve");
 
   for(;itr();)
 
     cout << itr.key() << endl;
 
   return 0;
}

Program Output:

John
Steve
Mark
Steve

Public Constructors

RWTValSlistIterator<T>(RWTValSlist<T>& s);

Creates an iterator for the singly linked list s. The iterator begins in an undefined state and must be advanced before the first element will be accessible

Public Member Operators

RWBoolean operator()();

Advances self to the next element. If the iterator has advanced past the last element in the collection, false will be returned. Otherwise, true will be returned.

RWBoolean operator++();

Advances self to the next element. If the iterator has been reset or just created, self will reference the first element. If, before iteration, self referenced the last value in the list, self will now reference an undefined value distinct from the reset value and false will be returned. Otherwise, true is returned. Note: no postincrement operator is provided.

RWBoolean operator+=(size_type n);

Behaves as if the operator++ member function had been applied n times

RWBoolean operator--();

Moves self back to the immediately previous element. If the iterator has been reset or just created, this operator will return false, otherwise it will return true. If self references the the first element, it will now be in the reset state. If self has been iterated past the last value in the list, it will now reference the last item in the list. Note: no postdecrement operator is provided.

RWBoolean operator-=(size_type n);

Behaves as if the operator-- member function had been applied n times

Public Member Functions

RWTValSlist<T>* container() const;

Returns a pointer to the collection being iterated over.

RWBoolean findNext(const_reference a);

Advances self to the first element t encountered by iterating forward, such that the expression (t == a) is true. Returns true if an element was found, returns false otherwise.

RWBoolean findNext(RWBoolean(*fn)(const_reference, void*), void* d);

Advances self to the first element t encountered by iterating forward such that the expression((*fn)(t,d)) is true. fn points to a user-defined tester function which must have prototype:

bool yourTester(const_reference a, void* d);

Client data may be passed through parameter d. Returns true if an element was found, returns false otherwise.

void insertAfterPoint(T* p);

Inserts the pointer p into the container directly after the element referenced by self.

T key();

Returns the stored value referenced by self.

RWBoolean remove();

Removes the value referenced by self from the collection. true is returned if the removal is successful, false is returned otherwise.

RWBoolean removeNext(const T);

Removes the first element t, encountered by iterating self forward, such that the expression (t == a) is true. Returns true if an element was found and removed, returns false otherwise.

RWBoolean removeNext(RWBoolean(*fn)(T, void*), void* d);

Removes the first element t, encountered by iterating self forward, such that the expression((*fn)(t,d)) is true. fn points to a user-defined tester function which must have prototype:

bool yourTester(const T a, void* d);

Client data may be passed through parameter d. Returns true if an element was found and removed, returns false otherwise.

void reset(); void reset(RWTValSlist<T>& l);

Resets the iterator so that after being advanced it will reference the first element of the collection. Using reset() with no argument will reset the iterator on the current container. Supplying a RWTValSlist to reset() will reset the iterator on the new container.

RWTValSortedDlist<T,C>

Synopsis

#include <rw/tvsrtdli.h>

RWTValSortedDlist<T,C> srtdlist;

Standard C++ Library Dependent!


Note: RWTValSortedDlist requires the Standard C++ Library.


Description

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

Persistence

Isomorphic.

Example

In this example, a sorted doubly-linked list of RWDates is exercised.

//
// tvsdldat.cpp
//
#include <rw/tvsrtdli.h>
#include <rw/rwdate.h>
#include <iostream.h>
#include <function.h>
 
main(){
  RWTValSortedDList<RWDate, less<RWDate> > lst;
 
  lst.insert(RWDate(10, "Aug", 1991));
  lst.insert(RWDate(9, "Aug", 1991));
  lst.insert(RWDate(1, "Sep", 1991));
  lst.insert(RWDate(14, "May", 1990));
  lst.insert(RWDate(1, "Sep", 1991));   // Add a duplicate
  lst.insert(RWDate(2, "June", 1991));
 
  for (int i=0; i<lst.entries(); i++)
    cout << lst[i] << endl;
  return 0;
}

Program Output:

05/14/90
06/02/91
08/09/91
08/10/91
09/01/91
09/01/91

Related Classes

RWTValSortedVector<T> is an alternative always-sorted collections. RWTValDlist<T> is an unsorted doubly-linked list of values.

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::const_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

RWTValSortedDlist<T,C>();

Constructs an empty doubly-linked list.

RWTValSortedDlist<T,C>(const list<T,allocator>& lst);

Constructs a doubly-linked list by copying and sorting all elements of lst.

RWTValSortedDlist<T,C>(const RWTValSortedDlist<T,C>& rwlst);

Copy constructor.

RWTValSortedDlist<T,C>(size_type n, const T& val = T());

Constructs a doubly-linked list with n elements, each initialized to val.

RWTValSortedDlist<T,C>(const T* first, const T* last);

Constructs a doubly-linked list by copying and sorting elements from the array of Ts pointed to by first, up to, but not including, the element pointed to by last.

Public Member Operators

RWTValSortedDlist<T,C>& operator=(const RWTValSortedDlist<T,C>& lst); RWTValSortedDlist<T,C>& operator=(const list<T,allocator>& lst);

Destroys all elements of self and replaces them by copying (and sorting, if necessary) all elements of lst.

bool operator<(const RWTValSortedDlist<T,C>& lst) const; bool operator<(const list<T,allocator>& lst) const;

Returns true if self compares lexicographically less than lst, otherwise returns false. Assumes that type T has well-defined less-than semantics (T::operator<(const T&) or equivalent).

bool operator==(const RWTValSortedDlist<T,C>& lst) const; bool operator==(const list<T>& lst) const;

Returns true if self compares equal to lst, otherwise returns false. Two collections are equal if both have the same number of entries, and iterating through both collections produces, in turn, individual elements that compare equal to each other.

const_reference operator()(size_type i) const;

Returns a reference to the ith element of self. Index i should be between 0 and one less then the number of entries, otherwise the results are undefined—no bounds checking is performed.

const_reference operator[](size_type i) const;

Returns a reference to the ith element of self. Index i must be between 0 and one less then the number of entries in self, otherwise the function throws an exception of type RWBoundsErr.

Public Member Functions

void apply(void (*fn)(const_reference,void*), void* d) const;

Applies the user-defined function pointed to by fn to every item in the collection. This function must have prototype:

void yourfun(const_reference a, void* d);

Client data may be passed through parameter d.

const_reference at(size_type i) const;

Returns a reference to the ith element of self. Index i must be between 0 and one less then the number of entries in self, otherwise the function throws an exception of type RWBoundsErr.

iterator begin(); const_iterator begin() const;

Returns an iterator positioned at the first element of self.

void clear();

Clears the collection by removing all items from self. Each item will have its destructor called.

bool contains(const_reference a) const;

Returns true if there exists an element t in self such that the expression(t==a) is true, otherwise returns false.

bool contains(bool (*fn)(const_reference,void*), void* d) const;

Returns true if there exists an element t in self such that the expression ((*fn)(t,d)) is true, otherwise returns false. fn points to a user-defined tester function which must have prototype:

bool yourTester(const_reference a, void* d);

Client data may be passed through parameter d.

iterator end(); const_iterator end() const;

Returns an iterator positioned "just past" the last element in self.

size_type entries() const;

Returns the number of items in self.

bool find(const_reference a, value_type& k) const;

If there exists an element t in self such that the expression (t == a) is true, assigns t to k and returns true. Otherwise, returns false and leaves the value of k unchanged.

bool find(bool (*fn)(const_reference,void*), void* d, value_type& k) const;

If there exists an element t in self such that the expression ((*fn)(t,d)) is true, assigns t to k and returns true. Otherwise, returns false and leaves the value of k unchanged. fn points to a user-defined tester function which must have prototype:

bool yourTester(const_reference a, void* d);

Client data may be passed through parameter d.

reference first(); const_reference first() const;

Returns a reference to the first element of self.

size_type index(const_reference a) const;

Returns the position of the first item t in self such that (t == a), or returns the static member npos if no such item exists.

size_type index(bool (*fn)(const_reference,void*), void* d) const;

Returns the position of the first item t in self such that((*fn)(t,d)) is true, or returns the static member npos if no such item exists. fn points to a user-defined tester function which must have prototype:

bool yourTester(const_reference a, void* d);

Client data may be passed through parameter d.

size_type insert(const list<T,allocator>& a);

Adds the items from a to self in an order preserving manner. Returns the number of items inserted into self.

bool insert(const_reference a);

Adds the item a to self. The collection remains sorted. Returns true.

bool isEmpty() const;

Returns true if there are no items in the collection, false otherwise.

bool isSorted() const;

Returns true if the collection is sorted relative to the supplied comparator object, false otherwise.

const_reference last() const;

Returns a reference to the last item in the collection.

size_type merge(const RWTValSortedDlist&<T,C> dl);

Inserts all elements of dl into self, preserving sorted order.

size_type occurrencesOf(const_reference) const;

Returns the number of elements t in self such that the expression (t == a) is true.

size_type occurrencesOf(bool (*fn)(const_reference,void*), void* d) const;

Returns the number of elements t in self such that the expression((*fn)(t,d)) is true. fn points to a user-defined tester function which must have prototype:

bool yourTester(const_reference a, void* d);

Client data may be passed through parameter d.

bool remove(const_reference a);

Removes the first element t in self such that the expression (t == a) is true and returns true. Returns false if there is no such element.

bool remove(bool (*fn)(const_reference,void*), void* d);

Removes the first element t in self such that the expression ((*fn)(t,d)) is true and returns true. Returns false if there is no such element. fn points to a user-defined tester function which must have prototype:

bool yourTester(const_reference a, void* d);

Client data may be passed through parameter d.

size_type removeAll(const_reference a);

Removes all elements t in self such that the expression (t == a) is true. Returns the number of items removed.

size_type removeAll(bool (*fn)(const_reference,void*), void* d);

Removes all elements t in self such that the expression ((*fn)(t,d))is true. Returns the number of items removed. fn points to a user-defined tester function which must have prototype:

bool yourTester(const_reference a, void* d);

Client data may be passed through parameter d.

T removeAt(size_type i);

Removes and returns the item at position i in self. This position must be between zero and one less then the number of entries in the collection, otherwise the function throws an exception of type RWBoundsErr.

T removeFirst();

Removes and returns the first item in the collection.

T removeLast();

Removes and returns the first item in the collection.

list<T,allocator>& std(); const list<T,allocator>& std() const;

Returns a reference to the underlying C++-standard collection that serves as the implementation for self. It is your responsibility not to violate the ordering of the elements within the collection.

Static Public Data Member

const size_type npos;

This is the value returned by member functions such as index to indicate a non-position. The value is equal to ~(size_type)0.

Related Global Operators

RWvostream& operator<<(RWvostream& strm, const RWTValSortedDlist<T,C>& coll); RWFile& operator<<(RWFile& strm, const RWTValSortedDlist<T,C>& coll);

Saves the collection coll onto the output stream strm, or a reference to it if it has already been saved.

RWvistream& operator>>(RWvistream& strm, RWTValSortedDlist<T,C>& coll); RWFile& operator>>(RWFile& strm, RWTValSortedDlist<T,C>& coll);

Restores the contents of the collection coll from the input stream strm.

RWvistream& operator>>(RWvistream& strm, RWTValSortedDlist<T,C>*& p); RWFile& operator>>(RWFile& strm, RWTValSortedDlist<T,C>*& p);

Looks at the next object on the input stream strm and either creates a new collection off the heap and sets p to point to it, or sets p to point to a previously read instance. If a collection is created off the heap, then you are responsible for deleting it.

RWTValSortedDlistIterator<T,C>

Synopsis

#include<rw/tvsrtdli.h>
RWTValSortedDlist<T,C> dl;
RWTValSortedDlistIterator<T,C> itr(dl);

Standard C++ Library Dependent!

RWTValSortedDlistIterator requires the Standard C++ Library.

Description

RWTValSortedDlistIterator is supplied with Tools.h++ 7 to provide an iterator interface to RWTValSortedDlistIterator that is backward compatable with the container iterators provided in Tools.h++ 6.x.

The order of iteration over an RWTValSortedDlist is dependent on the supplied comparator object supplied as applied to the values stored in the container.

The current item referenced by this iterator is undefined after construction or after a call to reset(). The iterator becomes valid after being advanced with either a preincrement or operator().

For both operator++ and operator(), iterating past the last element will return a value equivalent to boolean false. Continued increments will return a value equivalent to false until reset() is called.

Persistence

None

Examples

#include<rw/tvsrtdli.h>
#include<iostream.h>
#include<rw/cstring.h>
int main(){
   RWTValSortedDlist<RWCString, less<RWCString> > a;
   RWTValSortedDlistIterator<RWCString, less<RWCString> > itr(a);
   a.insert("John");
   a.insert("Steve");
   a.insert("Mark");
   a.insert("Steve");
   for(;itr();)
     cout << itr.key() << endl;
   return 0;
}

Program Output:

John
Mark
Steve
Steve

Public Constructors

RWTValSortedDlistIterator<T,C>(RWTValSortedDlist<T,C>&s);

Creates an iterator for the sorted dlist s. The iterator begins in an undefined state and must be advanced before the first element will be accessible.

Public Member Operators

RWBoolean operator()();

Advances self to the next element. If the iterator has advanced past the last item in the container, the element returned will be a nil pointer equivalent to boolean false.

RWBoolean operator++();

Advances self to the next element. If the iterator has been reset or just created, self will reference the first element. If, before iteration, self referenced the last value in the list, self will now point to an undefined value distinct from the reset value and false will be returned. Otherwise, true is returned. Note: no postincrement operator is provided.

RWBoolean operator+=(size_type n);

Behaves as if the operator++ member function had been applied n times

RWBoolean operator--();

Moves self back to the immediately previous element. If the iterator has been reset or just created, this operator will return false, otherwise it will return true. If self references the the first element, it will now be in the reset state. If self has been iterated past the last value in the list, it will now point to the last item in the list. Note: no postdecrement operator is provided.

RWBoolean operator-=(size_type n);

Behaves as if the operator-- member function had been applied n times

Public Member Functions

RWTValSortedDlist<T,C>* container() const;

Returns a pointer to the collection being iterated over.

RWBoolean findNext(const T a);

Advances self to the first element t encountered by iterating forward, such that the expression (t == a) is true. Returns true if such an element if found, false otherwise.

RWBoolean findNext(RWBoolean(*fn)(T, void*), void* d);

Advances self to the first element t encountered by iterating forward, such that the expression((*fn)(t,d)) is true. fn points to a user-defined tester function which must have prototype:

bool yourTester(const T a, void* d);

Client data may be passed through parameter d. Returns true if such an element if found, false otherwise.

T key();

Returns the stored value referenced by self.

RWBoolean remove();

Removes the stored value referenced by self from the collection. Returns true if the value was successfully removed, false otherwise.

RWBoolean removeNext(const T);

Removes the first element t, encountered by iterating self forward, such that the expression (t == a) is true. Returns true if such an element is successfully removed, false otherwise.

RWBoolean removeNext(RWBoolean(*fn)(T, void*), void* d);

Removes the first element t, encountered by iterating self forward, such that the expression((*fn)(t,d)) is true. fn points to a user-defined tester function which must have prototype:

bool yourTester(const T a, void* d);

Client data may be passed through parameter d. Returns true if such an element is successfully removed, false otherwise.

void reset(); void reset(RWTValSortedDlist<T,C>& l);

Resets the iterator so that after being advanced it will reference the first element of the collection. Using reset() with no argument will reset the iterator on the current container. Supplying a RWTValSortedDlist to reset() will reset the iterator on the new container.

RWTValSortedVector<T,C>

Synopsis

#include <rw/tvsrtvec.h> 
RWTValSortedVector<T,C> srtvec;


Note: If you have the Standard C++ Library, use the interface described here. Otherwise, use the restricted interface to RWTValSortedVector described in Appendix A: Alternate Template Class Interfaces.


Description

This class maintains an always-sorted collection of values, implemented as a vector.

Persistence

Isomorphic

Example

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

//
// tvsvcdat.cpp
//
#include <rw/tvsrtvec.h>
#include <rw/rwdate.h>
#include <iostream.h>
 
main(){
  RWTValSortedVector<RWDate, less<RWDate> > vec;
 
  vec.insert(RWDate(10, "Aug", 1991));
  vec.insert(RWDate(9, "Aug", 1991));
  vec.insert(RWDate(1, "Sep", 1991));
  vec.insert(RWDate(14, "May", 1990));
  vec.insert(RWDate(1, "Sep", 1991));   // Add a duplicate
  vec.insert(RWDate(2, "June", 1991));
 
  for (int i=0; i<vec.entries(); i++)
    cout << vec[i] << endl;
  return 0;
}

Program Output:

05/14/90
06/02/91
08/09/91
08/10/91
09/01/91
09/01/91

Related Classes

RWTValSortedDlist<T,C> is an alternative always-sorted collection. RWTValOrderedVector<T> is an unsorted vector of values.

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

Public Typedefs

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

Public Constructors

RWTValSortedVector<T,C>();

Constructs an empty vector.

RWTValSortedVector<T,C>(const vector<T,allocator>& vec);

Constructs a vector by copying and sorting all elements of vec.

RWTValSortedVector<T,C>(const RWTValSortedVector<T,C>& rwvec);

Copy constructor.

RWTValSortedVector<T,C>(size_type n, const T& val);

Constructs a vector with n elements, each initialized to val.

RWTValSortedVector<T,C>(size_type n);

Constructs an empty vector with a capacity of n elements.

RWTValSortedVector<T,C>(const T* first, const T* last);

Constructs a vector by copying and sorting elements from the array of Ts pointed to by first, up to, but not including, the element pointed to by last.

Public Member Operators

bool operator<(const RWTValSortedVector<T,C>& vec) const; bool operator<(const vector<T,allocator>& vec) const;

Returns true if self compares lexicographically less than vec, otherwise returns false. Assumes that type T has well-defined less-than semantics (T::operator<(const T&) or equivalent).

bool operator==(const RWTValSortedVector<T,C>& vec) const; bool operator==(const vector<T,allocator>& vec) const;

Returns true if self compares equal to vec, otherwise returns false. Two collections are equal if both have the same number of entries, and iterating through both collections produces, in turn, individual elements that compare equal to each other.

reference operator()(size_type i); const_reference operator()(size_type i) const;

Returns a reference to the ith element of self. Index i should be between 0 and one less then the number of entries, otherwise the results are undefined—no bounds checking is performed.

reference operator[](size_type i); const_reference operator[](size_type i) const;

Returns a reference to the ith element of self. Index i must be between 0 and one less then the number of entries in self, otherwise the function throws an exception of type RWBoundsErr.

Public Member Functions

void apply(void (*fn)(const_reference,void*), void* d) const;

Applies the user-defined function pointed to by fn to every item in the collection. This function must have the prototype:

void yourfun(const_reference a, void* d);

Client data may be passed through parameter d.

reference at(size_type i); const_reference at(size_type i) const;

Returns a reference to the ith element of self. Index i must be between 0 and one less then the number of entries in self, otherwise the function throws an exception of type RWBoundsErr.

iterator begin(); const_iterator begin() const;

Returns an iterator positioned at the first element of self.

void clear();

Clears the collection by removing all items from self. Each item will have its destructor called.

bool contains(const_reference a) const;

Returns true if there exists an element t in self such that the expression(t==a) is true, otherwise returns false.

bool contains(bool (*fn)(const_reference,void*), void* d) const;

Returns true if there exists an element t in self such that the expression ((*fn)(t,d)) is true, otherwise returns false. fn points to a user-defined tester function which must have prototype:

bool yourTester(const_reference a, void* d);

Client data may be passed through parameter d.

const T* data();

Returns a pointer to the first element of the vector.

iterator end(); const_iterator end() const;

Returns an iterator positioned "just past" the last element in self.

size_type entries() const;

Returns the number of items in self.

bool find(const_reference a, value_type& k) const;

If there exists an element t in self such that the expression (t == a) is true, assigns t to k and returns true. Otherwise, returns false and leaves the value of k unchanged.

bool find(bool (*fn)(const_reference,void*), void* d, value_type& k) const;

If there exists an element t in self such that the expression ((*fn)(t,d)) is true, assigns t to k and returns true. Otherwise, returns false and leaves the value of k unchanged. fn points to a user-defined tester function which must have prototype:

bool yourTester(const_reference a, void* d);

Client data may be passed through parameter d.

reference first(); const_reference first() const;

Returns a reference to the first element of self.

size_type index(const_reference a) const;

Returns the position of the first item t in self such that (t == a), or returns the static member npos if no such item exists.

size_type index(bool (*fn)(const_reference,void*), void* d) const;

Returns the position of the first item t in self such that((*fn)(t,d)) is true, or returns the static member npos if no such item exists. fn points to a user-defined tester function which must have prototype:

bool yourTester(const_reference a, void* d);

Client data may be passed through parameter d.

bool insert(const_reference a);

Adds the item a to self. The collection remains sorted. Returns true.

size_type insert(const vector<T,allocator>& a);

Inserts all elements of a into self. The collection remains sorted. Returns the number of items inserted.

bool isEmpty() const;

Returns true if there are no items in the collection, false otherwise.

bool isSorted() const;

Returns true if the collection is sorted relative to the supplied comparator object, false otherwise.

const_reference last() const;

Returns a reference to the last item in the collection.

size_type length() const;

Returns the maximum number of elements which can be stored in self without first resizing.

size_type merge(const RWTValSortedVector<T,C>& dl);

Inserts all elements of dl into self, preserving sorted order.

size_type occurrencesOf(const_reference a) const;

Returns the number of elements t in self such that the expression (t == a) is true.

size_type occurrencesOf(bool (*fn)(const_reference,void*), void* d) const;

Returns the number of elements t in self such that the expression((*fn)(t,d)) is true. fn points to a user-defined tester function which must have prototype:

bool yourTester(const_reference a, void* d);

Client data may be passed through parameter d.

bool remove(const_reference a);

Removes the first element t in self such that the expression (t == a) is true and returns true. Returns false if there is no such element.

bool remove(bool (*fn)(const_reference,void*), void* d);

Removes the first element t in self such that the expression ((*fn)(t,d)) is true and returns true. Returns false if there is no such element. fn points to a user-defined tester function which must have prototype:

bool yourTester(const_reference a, void* d);

Client data may be passed through parameter d.

size_type removeAll(const_reference a);

Removes all elements t in self such that the expression (t == a) is true. Returns the number of items removed.

size_type removeAll(bool (*fn)(const_reference,void*), void* d);

Removes all elements t in self such that the expression ((*fn)(t,d))is true. Returns the number of items removed. fn points to a user-defined tester function which must have prototype:

bool yourTester(const_reference a, void* d);

Client data may be passed through parameter d.

value_type removeAt(size_type i);

Removes and returns the item at position i in self. This position must be between zero and one less then the number of entries in the collection, otherwise the function throws an exception of type RWBoundsErr.

value_type removeFirst();

Removes and returns the first item in the collection.

value_type removeLast();

Removes and returns the first item in the collection.

void resize(size_type n);

Modify, if necessary, the capacity of the vector to be at least as large as n.

vector<T,allocator>& std(); const vector<T,allocator>& std() const;

Returns a reference to the underlying C++-standard collection that serves as the implementation for self. It is your responsibility not to violate the ordering of the elements within the collection.

Static Public Data Member

const size_type npos;

This is the value returned by member functions such as index to indicate a non-position. The value is equal to ~(size_type)0.

Related Global Operators

RWvostream& operator<<(RWvostream& strm, const RWTValSortedVector<T,C>& coll); RWFile& operator<<(RWFile& strm, const RWTValSortedVector<T,C>& coll);

Saves the collection coll onto the output stream strm, or a reference to it if it has already been saved.

RWvistream& operator>>(RWvistream& strm, RWTValSortedVector<T,C>& coll); RWFile& operator>>(RWFile& strm, RWTValSortedVector<T,C>& coll);

Restores the contents of the collection coll from the input stream strm.

RWvistream& operator>>(RWvistream& strm, RWTValSortedVector<T,C>*& p); RWFile& operator>>(RWFile& strm, RWTValSortedVector<T,C>*& p);

Looks at the next object on the input stream strm and either creates a new collection off the heap and sets p to point to it, or sets p to point to a previously read instance. If a collection is created off the heap, then you are responsible for deleting it.

RWTValVector<T>

Synopsis

#include <rw/tvvector.h>
RWTValVector<T> vec;

Descripton

Class RWTValVector<T> is a simple parameterized vector of objects of type T. It is most useful when you know precisely how many objects have to be held in the collection. If the intention is to "insert" an unknown number of objects into a collection, then class RWTValOrderedVector<T> may be a better choice.

The class T must have:

  • well-defined copy semantics (T::T(const T&) or equiv.);

  • well-defined assignment semantics (T::operator=(const T&) or equiv.);

  • a default constructor.

Persistence

Isomorphic

Example

#include <rw/tvvector.h>
#include <rw/rwdate.h>
#include <rw/rstream.h>
 
main()  {
  RWTValVector<RWDate> week(7);
 
  RWDate begin;   // Today's date
 
  for (int i=0; i<7; i++)
    week[i] = begin++;
 
  for (i=0; i<7; i++)
    cout << week[i] << endl;
 
  return 0;
}

Program Output:

March 16, 1996
March 17, 1996
March 18, 1996
March 19, 1996
March 20, 1996
March 21, 1996
March 22, 1996

Public Constructors

RWTValVector<T>();

Constructs an empty vector of length zero.

RWTValVector<T>(size_t n);

Constructs a vector of length n. The values of the elements will be set by the default constructor of class T. For a built in type this can (and probably will) be garbage.

RWTValVector<T>(size_t n, const T& ival);

Constructs a vector of length n, with each element initialized to the value ival.

RWTValVector<T>(const RWTValVector& v);

Constructs self as a copy of v. Each element in v will be copied into self.

~RWTValVector<T>();

Calls the destructor for every element in self.

Public Operators

RWTValVector<T>& operator=(const RWTValVector<T>& v);

Sets self to the same length as v and then copies all elements of v into self.

RWTValVector<T>& operator=(const T& ival);

Sets all elements in self to the value ival.

const T& operator()(size_t i) const; T& operator()(size_t i);

Returns a reference to the ith value in the vector. The index i must be between 0 and the length of the vector less one. No bounds checking is performed.

const T& operator[](size_t i) const; T& operator[](size_t i);

Returns a reference to the ith value in the vector. The index i must be between 0 and the length of the vector less one. Bounds checking will be performed.

Public Member Functions

const T* data() const;

Returns a pointer to the raw data of self. Should be used with care.

size_t length() const;

Returns the length of the vector.

void reshape(size_t N);

Changes the length of the vector to N. If this results in the vector being lengthened, then the initial value of the additional elements is set by the default constructor of T.

RWTValVirtualArray<T>

Synopsis

#include <rw/tvrtarry.h>
RWVirtualPageHeap* heap;
RWTValVirtualArray<T> array(1000L, heap);

Description

This class represents a virtual array of elements of type T of almost any length. Individual elements are brought into physical memory as needed basis. If an element is updated it is automatically marked as "dirty" and will be rewritten to the swapping medium.

The swap space is provided by an abstract page heap which is specified by the constructor. Any number of virtual arrays can use the same abstract page heap. You must take care that the destructor of the abstract page heap is not called before all virtual arrays built from it have been destroyed.

The class supports reference counting using a copy-on-write technique, so (for example) returning a virtual array by value from a function is as efficient as it can be. Be aware, however, that if the copy-on-write machinery finds that a copy must ultimately be made, then for large arrays this could take quite a bit of time.

For efficiency, more than one element can (and should) be put on a page. The actual number of elements is equal to the page size divided by the element size, rounded downwards. Example: for a page size of 512 bytes, and an element size of 8, then 64 elements would be put on a page.

The indexing operator (operator[](long)) actually returns an object of type RWTVirtualElement<T>. Consider this example:

double d = vec[j];
vec[i] = 22.0;

Assume that vec is of type RWTValVirtualArray<double>. The expression vec[j] will return an object of type RWTVirtualElement<double>, which will contain a reference to the element being addressed. In the first line, this expression is being used to initialize a double. The class RWTVirtualElement<T> contains a type conversion operator to convert itself to a T, in this case a double. The compiler uses this to initialize d in the first line. In the second line, the expression vec[i] is being used as an lvalue. In this case, the compiler uses the assignment operator for RWTVirtualElement<T>. This assignment operator recognizes that the expression is being used as an lvalue and automatically marks the appropriate page as "dirty," thus guaranteeing that it will be written back out to the swapping medium.

Slices, as well as individual elements, can also be addressed. These should be used wherever possible as they are much more efficient because they allow a page to be locked and used multiple times before unlocking.

The class T must have:

  • well-defined copy semantics (T::T(const T&) or equiv.);

  • well-defined assignment semantics (T::operator=(const T&) or equiv.).

In addition, you must never take the address of an element.

Persistence

None

Example

In this example, a virtual vector of objects of type ErsatzInt is exercised. A disk-based page heap is used for swapping space.

#include <rw/tvrtarry.h>
#include <rw/rstream.h>
#include <rw/diskpage.h>
#include <stdlib.h>
#include <stdio.h>
 
struct ErsatzInt {
  char  buf[8];
  ErsatzInt(int i) { sprintf(buf, "%d", i); }
  friend ostream& operator<<(ostream& str, ErsatzInt& i)
    { str << atoi(i.buf); return str; }
};
 
main() {
  RWDiskPageHeap heap;
  RWTValVirtualArray<ErsatzInt> vec1(10000L, &heap);
 
  for (long i=0; i<10000L; i++)
    vec1[i] = i; // Some compilers may need a cast here
 
  cout << vec1[100] << endl; // Prints "100"
  cout << vec1[300] << endl; // Prints "300"
 
  RWTValVirtualArray<ErsatzInt> vec2 = vec1.slice(5000L, 500L);
  cout << vec2.length() << endl; // Prints "500"
  cout << vec2[0] << endl; // Prints "5000";
 
  return 0;
}

Program Output:

100
300
500
5000

Public Constructors

RWTValVirtualArray<T>(long size, RWVirtualPageHeap* heap);

Construct a vector of length size. The pages for the vector will be allocated from the page heap given by heap which can be of any type.

RWTValVirtualArray<T>(const RWTValVirtualArray<T>& v);

Constructs a vector as a copy of v. The resultant vector will use the same heap and have the same length as v. The actual copy will not be made until a write, minimizing the amount of heap allocations and copying that must be done.

RWTValVirtualArray<T>(const RWTVirtualSlice<T>& sl);

Constructs a vector from a slice of another vector. The resultant vector will use the same heap as the vector whose slice is being taken. Its length will be given by the length of the slice. The copy will be made immediately.

Public Destructor

~RWTValVirtualArray<T>();

Releases all pages allocated by the vector.

Public Operators

RWTValVirtualArray& operator=(const RWTValVirtualArray<T>& v);

Sets self to a copy of v. The resultant vector will use the same heap and have the same length as v. The actual copy will not be made until a write, minimizing the amount of heap allocations and copying that must be done.

void operator=(const RWTVirtualSlice<T>& sl);

Sets self equal to a slice of another vector. The resultant vector will use the same heap as the vector whose slice is being taken. Its length will be given by the length of the slice. The copy will be made immediately.

T operator=(const T& val);

Sets all elements in self equal to val. This operator is actually quite efficient because it can work with many elements on a single page at once. A copy of val is returned.

T operator[](long i) const;

Returns a copy of the value at index i. The index i must be between zero and the length of the vector less one or an exception of type TOOL_LONGINDEX will occur.

RWTVirtualElement<T> operator[](long);

Returns a reference to the value at index i. The results can be used as an lvalue. The index i must be between zero and the length of the vector less one or an exception of type TOOL_LONGINDEX will occur.

Public Member Functions

long length() const;

Returns the length of the vector.

T val(long i) const;

Returns a copy of the value at index i. The index i must be between zero and the length of the vector less one or an exception of type TOOL_LONGINDEX will occur.

void set(long i, const T& v);

Sets the value at the index i to v. The index i must be between zero and the length of the vector less one or an exception of type TOOL_LONGINDEX will occur.

RWTVirtualSlice<T> slice(long start, long length);

Returns a reference to a slice of self. The value start is the starting index of the slice, the value length its extent. The results can be used as an lvalue.

void reshape(long newLength);

Change the length of the vector to newLength. If this results in the vector being lengthened then the value of the new elements is undefined.

RWVirtualPageHeap* heap() const;

Returns a pointer to the heap from which the vector is getting its pages.

RWVirtualPageHeap

Synopsis

#include <rw/vpage.h>
 
(Abstract base class) 

Description

This is an abstract base class representing an abstract page heap of fixed sized pages. The following describes the model by which specializing classes of this class are expected to work.

You allocate a page off the abstract heap by calling member function allocate() which will return a memory "handle," an object of type RWHandle. This handle logically represents the page.

In order to use the page it must first be "locked" by calling member function lock() with the handle as an argument. It is the job of the specializing class of RWVirtualPageHeap to make whatever arrangements are necessary to swap in the page associated with the handle and bring it into physical memory. The actual swapping medium could be disk, expanded or extended memory, or a machine someplace on a network. Upon return, lock() returns a pointer to the page, now residing in memory.

Once a page is in memory, you are free to do anything you want with it although if you change the contents, you must call member function dirty() before unlocking the page.

Locked pages use up memory. In fact, some specializing classes may have only a fixed number of buffers in which to do their swapping. If you are not using the page, you should call unlock(). After calling unlock() the original address returned by lock() is no longer valid — to use the page again, it must be locked again with lock().

When you are completely done with the page then call deallocate() to return it to the abstract heap.

In practice, managing this locking and unlocking and the inevitable type casts can be difficult. It is usually easier to design a class that can work with an abstract heap to bring things in and out of memory automatically. Indeed, this is what has been done with class RWTValVirtualArray<T>, which represents a virtual array of elements of type T. Elements are automatically swapped in as necessary as they are addressed.

Persistence

None

Example

This example illustrates adding N nodes to a linked list. In this linked list, a "pointer" to the next node is actually a handle.

#include <rw/vpage.h>
 
struct Node {
  int  key;
  RWHandle  next;
};
RWHandle head = 0;
void addNodes(RWVirtualPageHeap& heap, unsigned N) {
  for (unsigned i=0; i<N; i++){
    RWHandle h = heap.allocate();
    Node* newNode = (Node*)heap.lock(h);
    newNode->key  = i;
    newNode->next = head;
    head = h;
    heap.dirty(h);
    heap.unlock(h);
  }
}

Public Constructor

RWVirtualPageHeap(unsigned pgsize);

Sets the size of a page.

Public Destructor

virtual ~RWVirtualPageHeap();

The destructor has been made virtual to give specializing classes a chance to deallocate any resources that they may have allocated.

Public Member Functions

unsigned pageSize() const;

Returns the page size for this abstract page heap.

Public Pure Virtual Functions

virtual RWHandle allocate() = 0

Allocates a page off the abstract heap and returns a handle for it. If the specializing class is unable to honor the request, then it should return a zero handle.

virtual void deallocate(RWHandle h) = 0;

Deallocate the page associated with handle h. It is not an error to deallocate a zero handle.

virtual void dirty(RWHandle h) = 0;

Declare the page associated with handle h to be "dirty." That is, it has changed since it was last locked. The page must be locked before calling this function.

virtual void* lock(RWHandle h) = 0;

Lock the page, swapping it into physical memory, and return an address for it. A nil pointer will be returned if the specializing class is unable to honor the lock. The returned pointer should be regarded as pointing to a buffer of the page size.

virtual void unlock(RWHandle h) = 0;

Unlock a page. A page must be locked before calling this function. After calling this function the address returned by lock() is no longer valid.

RWvios

Synopsis

#include <vstream.h>

(abstract base class)

Description

RWvios is an abstract base class. It defines an interface similar to the C++ streams class ios. However, unlike ios, it offers the advantage of not necessarily being associated with a streambuf.

This is useful for classes that cannot use a streambuf in their implementation. An example of such a class is RWXDRistream, where the XDR model does not permit streambuf functionality.

Specializing classes that do use streambufs in their implementation (e.g., RWpistream) can usually just return the corresponding ios function.

Persistence

None

Public Member Functions

virtual int eof() = 0;

Returns a nonzero integer if an EOF has been encountered.

virtual int fail() = 0;

Returns a nonzero integer if the fail or bad bit has been set. Normally, this indicates that some storage or retrieval has failed but that the stream is still in a usable state.

virtual int bad() = 0;

Returns a nonzero integer if the bad bit has been set. Normally this indicates that a severe error has occurred from which recovery is probably impossible.

virtual int good() = 0;

Returns a nonzero integer if no error bits have been set.

virtual int rdstate() = 0;

Returns the current error state.

virtual void clear(int v=0) = 0;

Sets the current error state to v. If v is zero, then this clears the error state.

operator void*();

If fail() then return 0 else return self.

RWvistream

RWvistream ->- RWvios 

Synopsis

#include <rw/vstream.h>

Description

Class RWvistream is an abstract base class. It provides an interface for format-independent retrieval of fundamental types and arrays of fundamental types. Its counterpart, RWvostream, provides a complementary interface for the storage of the fundamental types.

Because the interface of RWvistream and RWvostream is independent of formatting, the user of these classes need not be concerned with how variables will actually be stored or restored. That will be up to the derived class to decide. It might be done using an operating-system independent ASCII format (classes RWpistream and RWpostream), a binary format (classes RWbistream and RWbostream), or the user could define his or her own format (e.g., an interface to a network). Note that because it is an abstract base class, there is no way to actually enforce these goals — the description here is merely the model of how a class derived from RWvistream and RWvostream should act.

See class RWvostream for additional explanations and examples of format-independent stream storage.

Persistence

None

Example

#include <rw/vstream.h>
void restoreStuff( RWvistream& str) {
   int i;
   double d;
   char string[80];
   str >> i;  // Restore an int
   str >> d;  // Restore a double
   // Restore a character string, up to 80 characters long:
   str.getString(string, sizeof(string));
 
   if(str.fail()) cerr << "Oh, oh, bad news.\n";
}

Public Destructor

virtual ~RWvistream();

This virtual destructor allows specializing classes to deallocate any resources that they may have allocated.

Public Operators

virtual RWvistream& operator>>(char& c) = 0;

Get the next char from the input stream and store it in c.

virtual RWvistream& operator>>(wchar_t& wc) = 0;

Get the next wchar_t from the input stream and store it in wc.

virtual RWvistream& operator>>(double& d) = 0;

Get the next double from the input stream and store it in d.

virtual RWvistream& operator>>(float& f) = 0;

Get the next float from the input stream and store it in f.

virtual RWvistream& operator>>(int& i) = 0;

Get the next int from the input stream and store it in i.

virtual RWvistream& operator>>(long& l) = 0;

Get the next long from the input stream and store it in l.

virtual RWvistream& operator>>(short& s) = 0;

Get the next short from the input stream and store it in s.

virtual RWvistream& operator>>(unsigned char& c) = 0;

Get the next unsigned char from the input stream and store it in c.

virtual RWvistream& operator>>(unsigned short& s) = 0;

Get the next unsigned short from the input stream and store it in s.

virtual RWvistream& operator>>(unsigned int& i) = 0;

Get the next unsigned int from the input stream and store it in i.

virtual RWvistream& operator>>(unsigned long& l) = 0;

Get the next unsigned long from the input stream and store it in l.

operator void*();

Inherited from RWvios.

Public Member Functions

virtual int get() = 0;

Get and return the next byte from the input stream, returning its value. Returns EOF if end of file is encountered.

virtual RWvistream& get(char& c) = 0;

Get the next char from the input stream, returning its value in c.

virtual RWvistream& get(wchar_t& wc) = 0;

Get the next wchar_t from the input stream, returning its value in wc.

virtual RWvistream& get(unsigned char& c) = 0;

Get the next unsignedchar from the input stream, returning its value in c.

virtual RWvistream& get(char* v, size_t N) = 0;

Get a vector of chars and store them in the array beginning at v. If the restore operation stops prematurely because there are no more data available on the stream, because an exception is thrown, or for some other reason, get stores what has already been retrieved from the stream into v, and sets the failbit. Note that get retrieves raw characters and does not perform any conversions on speical characters such as "\n".

virtual RWvistream& get(wchar_t* v, size_t N) = 0;

Get a vector of wide characterss and store them in the array beginning at v. If the restore operation stops prematurely because there are no more data available on the stream, because an exception is thrown, or for some other reason, get stores what has already been retrieved from the stream into v, and sets the failbit. Note that get retrieves raw characters and does not perform any conversions on speical characters such as "\n".

virtual RWvistream& get(double* v, size_t N) = 0;

Get a vector of Ndoubles and store them in the array beginning at v. If the restore operation stops prematurely because there are no more data available on the stream, because an exception is thrown, or for some other reason, get stores what has already been retrieved from the stream into v, and sets the failbit.

virtual RWvistream& get(float* v, size_t N) = 0;

Get a vector of Nfloats and store them in the array beginning at v. If the restore operation stops prematurely because there are no more data available on the stream, because an exception is thrown, or for some other reason, get stores what has already been retrieved from the stream into v, and sets the failbit.

virtual RWvistream& get(int* v, size_t N) = 0;

Get a vector of Nints and store them in the array beginning at v. If the restore operation stops prematurely because there are no more data available on the stream, because an exception is thrown, or for some other reason, get stores what has already been retrieved from the stream into v, and sets the failbit.

virtual RWvistream& get(long* v, size_t N) = 0;

Get a vector of Nlongs and store them in the array beginning at v. If the restore operation stops prematurely because there are no more data available on the stream, because an exception is thrown, or for some other reason,get stores what has already been retrieved from the stream into v, and sets the failbit.

virtual RWvistream& get(short* v, size_t N) = 0;

Get a vector of Nshorts and store them in the array beginning at v. If the restore operation stops prematurely because there are no more data available on the stream, because an exception is thrown, or for some other reason,get stores what has already been retrieved from the stream into v, and sets the failbit.

virtual RWvistream& get(unsigned char* v, size_t N) = 0;

Get a vector of Nunsigned chars and store them in the array beginning at v. If the restore operation stops prematurely because there are no more data available on the stream, because an exception is thrown, or for some other reason, get stores what has already been retrieved from the stream into v, and sets the failbit. Note that this member preserves ASCII numerical codes, not their corresponding character values. If you wish to restore a character string, use the function getString(char*, size_t).

virtual RWvistream& get(unsigned short* v, size_t N) = 0;

Get a vector of Nunsigned shorts and store them in the array beginning at v. If the restore operation stops prematurely because there are no more data available on the stream, because an exception is thrown, or for some other reason, get stores what has already been retrieved from the stream into v, and sets the failbit.

virtual RWvistream& get(unsigned int* v, size_t N) = 0;

Get a vector of Nunsigned ints and store them in the array beginning at v. If the restore operation stops prematurely because there are no more data available on the stream, because an exception is thrown, or for some other reason, get stores what has already been retrieved from the stream into v, and sets the failbit.

virtual RWvistream& get(unsigned long* v, size_t N) = 0;

Get a vector of N unsigned longs and store them in the array beginning at v. If the restore operation stops prematurely because there are no more data available on the stream, because an exception is thrown, or for some other reason, get stores what has already been retrieved from the stream into v, and sets the failbit.

virtual RWvistream& getString(char* s, size_t N) = 0;

Restores a character string from the input stream that was stored to the output stream with RWvostream::putstring and stores it in the array beginning at s. The function stops reading at the end of the string or after N-1 characters, whichever comes first. If N-1 characters have been read and the Nth character is not the string terminator, then the failbit of the stream will be set. In either case, the string will be terminated with a null byte.

virtual RWvistream& getString(wchar_t* ws, size_t N) = 0;

Restores a wide character string from the input stream that was stored to the output stream with RWvostream::putstring and stores it in the array beginning at ws. The function stops reading at the end of the string or after N-1 characters, whichever comes first. If N-1 characters have been read and the Nth character is not the string terminator, then the failbit of the stream will be set. In either case, the string will be terminated with a null byte.

RWvostream

RWvostream ->- RWvios 

Synopsis

#include <rw/vstream.h>

Description

Class RWvostream is an abstract base class. It provides an interface for format-independent storage of fundamental types and arrays of fundamental types. Its counterpart, RWvistream, provides a complementary interface for the retrieval of variables of the fundamental types.

Because the interface of RWvistream and RWvostream is independent of formatting, the user of these classes need not be concerned with how variables will actually be stored or restored. That will be up to the derived class to decide. It might be done using an operating-system independent ASCII format (classes RWpistream and RWpostream), a binary format (classes RWbistream and RWbostream), or the user could define his or her own format (e.g., an interface to a network). Note that because it is an abstract base class, there is no way to actually enforce these goals — the description here is merely the model of how a class derived from RWvistream and RWvostream should act.

Note that there is no need to separate variables with whitespace. It is the responsibility of the derived class to delineate variables with whitespace, packet breaks, or whatever might be appropriate for the final output sink. The model is one where variables are inserted into the output stream, either individually or as homogeneous vectors, to be restored in the same order using RWvistream.

Storage and retrieval of characters requires some explanation. Characters can be thought of as either representing some alphanumeric or control character, or as the literal number. Generally, the overloaded insertion (<<) and extraction (>>) operators seek to store and restore characters preserving their symbolic meaning. That is, storage of a newline should be restored as a newline, regardless of its representation on the target machine. By contrast, member functions get() and put() should treat the character as a literal number, whose value is to be preserved. See also class RWpostream.

Persistence

None

Example

#include <rw/vstream.h>
void storeStuff( RWvostream& str) {
   int i = 5;
   double d = 22.5;
   char string[] = "A string with \t tabs and a newline\n";
   str << i;        // Store an int
   str << d;        // Store a double
   str << string;   // Store a string
 
   if(str.fail()) cerr << "Oh, oh, bad news.\n";
}

Public Destructor

virtual ~RWvostream();

This virtual destructor allows specializing classes to deallocate any resources that they may have allocated.

Public Operators

virtual RWvostream& operator<<(const char* s) = 0;

Store the character string starting at s to the output stream. The character string is expected to be null terminated.

virtual RWvostream& operator<<(const wchar_t* ws) = 0;

Store the wide character string starting at ws to the output stream. The character string is expected to be null terminated.

virtual RWvostream& operator<<(char c) = 0;

Store the charc to the output stream. Note that c is treated as a character, not a number.

virtual RWvostream& operator<<(wchar_t wc) = 0;

Store the wchar_t wc to the output stream. Note that wc is treated as a character, not a number.

virtual RWvostream& operator<<(unsigned char c) = 0;

Store the unsignedcharc to the output stream. Note that c is treated as a character, not a number.

virtual RWvostream& operator<<(double d) = 0;

Store the doubled to the output stream.

virtual RWvostream& operator<<(float f) = 0;

Store the floatf to the output stream.

virtual RWvostream& operator<<(int i) = 0;

Store the inti to the output stream.

virtual RWvostream& operator<<(unsigned int i) = 0;

Store the unsigned inti to the output stream.

virtual RWvostream& operator<<(long l) = 0;

Store the longl to the output stream.

virtual RWvostream& operator<<(unsigned long l) = 0;

Store the unsigned long l to the output stream.

virtual RWvostream& operator<<(short s) = 0;

Store the shorts to the output stream.

virtual RWvostream& operator<<(unsigned short s) = 0;

Store the unsigned short s to the output stream.

operator void*();

Inherited from RWvios.

Public Member Functions

virtual RWvostream& flush();

Send the contents of the stream buffer to output immediately.

virtual RWvostream& put(char c) = 0;

Store the charc to the output stream, preserving its value.

virtual RWvostream& put(wchar_t wc) = 0;

Store the wchar_t wc to the output stream, preserving its value.

virtual RWvostream& put(unsigned char c) = 0;

Store the charc to the output stream, preserving its value.

virtual RWvostream& put(const char* p, size_t N) = 0;

Store the vector of N chars starting at p to the output stream. The chars should be treated as literal numbers (i.e., not as a character string).

virtual RWvostream& put(const wchar_t* p, size_t N) = 0;

Store the vector of Nwchar_ts starting at p to the output stream. The chars should be treated as literal numbers (i.e., not as a character string).

virtual RWvostream& put(const unsigned char* p, size_t N) = 0;

Store the vector of Nunsigned chars starting at p to the output stream. The chars should be treated as literal numbers (i.e., not as a character string).

virtual RWvostream& put(const short* p, size_t N) = 0;

Store the vector of Nshorts starting at p to the output stream.

virtual RWvostream& put(const unsigned short* p, size_t N) = 0;

Store the vector of Nunsigned shorts starting at p to the output stream.

virtual RWvostream& put(const int* p, size_t N) = 0;

Store the vector of Nints starting at p to the output stream.

virtual RWvostream& put(const unsigned int* p, size_t N) = 0;

Store the vector of Nunsigned ints starting at p to the output stream.

virtual RWvostream& put(const long* p, size_t N) = 0;

Store the vector of Nlongs starting at p to the output stream.

virtual RWvostream& put(const unsigned long* p, size_t N) = 0;

Store the vector of Nunsigned longs starting at p to the output stream.

virtual RWvostream& put(const float* p, size_t N) = 0;

Store the vector of Nfloats starting at p to the output stream.

virtual RWvostream& put(const double* p, size_t N) = 0;

Store the vector of Ndoubles starting at p to the output stream.

virtual RWvostream& putString(const char*s, size_t N);

Store the character string, including embedded nulls, starting at s to the output string.

RWWString

Synopsis

#include <rw/wstring.h>
RWWString a;

Description

Class RWWString offers very powerful and convenient facilities for manipulating wide character strings.

This string class manipulates wide characters of the fundamental type wchar_t. These characters are generally two or four bytes, and can be used to encode richer code sets than the classic "char" type. Because wchar_t characters are all the same size, indexing is fast.

Conversion to and from multibyte and ASCII forms are provided by the RWWString constructors, and by the RWWString member functions isAscii(), toAscii(), and toMultiByte().

Stream operations implicitly translate to and from the multibyte stream representation. That is, on output, wide character strings are converted into multibyte strings, while on input they are converted back into wide character strings. Hence, the external representation of wide character strings is usually as multibyte character strings, saving storage space and making interfaces with devices (which usually expect multibyte strings) easier.

RWWStrings tolerate embedded nulls.

Parameters of type "constwchar_t*" must not be passed a value of zero. This is detected in the debug version of the library.

The class is implemented using a technique called copy on write. With this technique, the copy constructor and assignment operators still reference the old object and hence are very fast. An actual copy is made only when a "write" is performed, that is if the object is about to be changed. The net result is excellent performance, but with easy-to-understand copy semantics.

A separate RWWSubString class supports substring extraction and modification operations.

Persistence

Simple

Example

#include <rw/rstream.h>
#include <rw/wstring.h>
 
main(){
 RWWString a(L"There is no joy in Beantown");
 a.subString(L"Beantown") = L"Redmond";
 cout << a << endl;
 return 0;
}

Program Output:

There is no joy in Redmond.

Enumerations

enum RWWString::caseCompare { exact, ignoreCase };

Used to specify whether comparisons, searches, and hashing functions should use case sensitive (exact) or case-insensitive (ignoreCase) semantics..

enum RWWString::multiByte_ { multiByte };

Allow conversion from multibyte character strings to wide character strings. See constructor below.

enum RWWString::ascii_ {ascii };

Allow conversion from ASCII character strings to wide character strings. See constructor below.

Public Constructors

RWWString();

Creates a string of length zero (the null string).

RWWString(const wchar_t* cs);

Creates a string from the wide character string cs. The created string will copy the data pointed to by cs, up to the first terminating null.

RWWString(const wchar_t* cs, size_t N);

Constructs a string from the character string cs. The created string will copy the data pointed to by cs. Exactly N characters are copied, including any embedded nulls. Hence, the buffer pointed to by cs must be at least N* sizeof(wchar_t) bytes or N wide characters long.

RWWString(RWSize_T ic);

Creates a string of length zero (the null string). The string's capacity (that is, the size it can grow to without resizing) is given by the parameter ic.

RWWString(const RWWString& str);

Copy constructor. The created string will copystr's data.

RWWString(const RWWSubString& ss);

Conversion from sub-string. The created string will copy the substring represented by ss.

RWWString(char c);

Constructs a string containing the single character c.

RWWString(char c, size_t N);

Constructs a string containing the character c repeated N times.

RWWString(const char* mbcs, multiByte_ mb);

Construct a wide character string from the multibyte character string contained in mbcs. The conversion is done using the Standard C library function ::mbstowcs(). This constructor can be used as follows:

RWWString a("\306\374\315\313\306\374", multiByte);

RWWString(const char* acs, ascii_ asc);

Construct a wide character string from the ASCII character string contained in acs. The conversion is done by simply stripping the high-order bit and, hence, is much faster than the more general constructor given immediately above. For this conversion to be successful, you must be certain that the string contains only ASCII characters. This can be confirmed (if necessary) using RWCString::isAscii(). This constructor can be used as follows:

RWWString a("An ASCII character string", ascii);

RWWString(const char* cs, size_t N, multiByte_ mb);

RWWString(const char* cs, size_t N, ascii__ asc);

These two constructors are similar to the two constructors immediately above except that they copy exactly N characters, including any embedded nulls. Hence, the buffer pointed to by cs must be at least N bytes long.

Type Conversion

operator constwchar_t*() const;

Access to the RWWString's data as a null terminated wide string. This datum is owned by the RWWString and may not be deleted or changed. If the RWWString object itself changes or goes out of scope, the pointer value previously returned will become invalid. While the string is null-terminated, note that its length is still given by the member function length(). That is, it may contain embedded nulls.

Assignment Operators

RWWString& operator=(const char* cs);

Assignment operator. Copies the null-terminated character string pointed to by cs into self. Returns a reference to self.

RWWString& operator=(const RWWString& str);

Assignment operator. The string will copystr's data. Returns a reference to self.

RWWString& operator=(const RWWSubString& sub);

Assignment operator. The string will copysub's data. Returns a reference to self.

RWWString& operator+=(const wchar_t* cs);

Append the null-terminated character string pointed to by cs to self. Returns a reference to self.

RWWString& operator+=(const RWWString& str);

Append the string str to self. Returns a reference to self.

Indexing Operators

wchar_t& operator[](size_t i); wchar_t operator[](size_t i) const;

Return the ith character. The first variant can be used as an lvalue. The index i must be between 0 and the length of the string less one. Bounds checking is performed — if the index is out of range then an exception of type RWBoundsErr will be thrown.

wchar_t& operator()(size_t i); wchar_t operator()(size_t i) const;

Return the ith character. The first variant can be used as an lvalue. The index i must be between 0 and the length of the string less one. Bounds checking is performed if the pre-processor macro RWBOUNDS_CHECK has been defined before including <rw/wstring.h>. In this case, if the index is out of range, then an exception of type RWBoundsErr will be thrown.

RWWSubString operator()(size_t start, size_t len); const RWWSubString operator()(size_t start, size_t len) const;

Substring operator. Returns an RWWSubString of self with length len, starting at index start. The first variant can be used as an lvalue. The sum of start plus len must be less than or equal to the string length. If the library was built using the RWDEBUG flag, and start and len are out of range, then an exception of type RWBoundsErr will be thrown.

Public Member Functions

RWWString& append(const wchar_t* cs);

Append a copy of the null-terminated wide character string pointed to by cs to self. Returns a reference to self.

RWWString& append(const wchar_t* cs, size_t N,);

Append a copy of the wide character string cs to self. Exactly N wide characters are copied, including any embedded nulls. Hence, the buffer pointed to by cs must be at least N*sizeof(wchar_t) bytes long. Returns a reference to self.

RWWString& append(const RWWString& cstr);

Append a copy of the string cstr to self. Returns a reference to self.

RWWString& append(const RWWString& cstr, size_t N);

Append the first N characters or the length of cstr (whichever is less) of cstr to self. Returns a reference to self.

size_t binaryStoreSize() const;

Returns the number of bytes necessary to store the object using the global function:

RWFile& operator<<(RWFile&, const RWWString&); size_t capacity() const;

Return the current capacity of self. This is the number of characters the string can hold without resizing.

size_t capacity(size_t capac);

Hint to the implementation to change the capacity of self to capac. Returns the actual capacity.

int collate(const RWWString& str) const; int collate(const wchar_t* str) const;

Returns an int less then, greater than, or equal to zero, according to the result of calling the POSIX function ::wscoll() on self and the argument str. This supports locale-dependent collation.

int compareTo(const RWWString& str, caseCompare = RWWString::exact) const; int compareTo(const wchar_t* str, caseCompare = RWWString::exact) const;

Returns an int less than, greater than, or equal to zero, according to the result of calling the Standard C library function ::memcmp() on self and the argument str. Case sensitivity is according to the caseCompare argument, and may be RWWString::exact or RWWString::ignoreCase.

RWBoolean contains(const RWWString& cs, caseCompare = RWWString::exact) const; RWBoolean contains(const wchar_t* str, caseCompare = RWWString::exact) const;

Pattern matching. Returns TRUE if cs occurs in self. Case sensitivity is according to the caseCompare argument, and may be RWWString::exact or RWWString::ignoreCase.

const wchar_t* data() const;

Access to the RWWString's data as a null terminated string. This datum is owned by the RWWString and may not be deleted or changed. If the RWWString object itself changes or goes out of scope, the pointer value previously returned will become invalid. While the string is null-terminated, note that its length is still given by the member function length(). That is, it may contain embedded nulls.

size_t first(wchar_t c) const;

Returns the index of the first occurrence of the wide character c in self. Returns RW_NPOS if there is no such character or if there is an embedded null prior to finding c.

size_t first(wchar_t c, size_t) const;

Returns the index of the first occurrence of the wide character c in self. Continues to search past embedded nulls. Returns RW_NPOS if there is no such character.

size_t first(const wchar_t* str) const;

Returns the index of the first occurrence in self of any character in str. Returns RW_NPOS if there is no match or if there is an embedded null prior to finding any character from str.

size_t first(const wchar_t* str, size_t N) const;

Returns the index of the first occurrence in self of any character in str. Exactly N characters in str are checked including any embedded nulls so str must point to a buffer containing at least N wide characters. Returns RW_NPOS if there is no match.

unsigned hash(caseCompare = RWWString::exact) const;

Returns a suitable hash value.

size_t index(const wchar_t* pat,size_t i=0, caseCompare = RWWString::exact) const; size_t index(const RWWString& pat,size_t i=0, caseCompare = RWWString::exact) const;

Pattern matching. Starting with index i, searches for the first occurrence of pat in self and returns the index of the start of the match. Returns RW_NPOS if there is no such pattern. Case sensitivity is according to the caseCompare argument; it defaults to RWWString::exact.

size_t index(const wchar_t* pat, size_t patlen,size_t i, caseCompare) const; size_t index(const RWWString& pat, size_t patlen,size_t i, caseCompare) const;

Pattern matching. Starting with index i, searches for the first occurrence of the first patlen characters from pat in self and returns the index of the start of the match. Returns RW_NPOS if there is no such pattern. Case sensitivity is according to the caseCompare argument.

RWWString& insert(size_t pos, const wchar_t* cs);

Insert a copy of the null-terminated string cs into self at position pos. Returns a reference to self.

RWWString& insert(size_t pos, const wchar_t* cs, size_t N);

Insert a copy of the first N wide characters of cs into self at position pos. Exactly N wide characters are copied, including any embedded nulls. Hence, the buffer pointed to by cs must be at least N*sizeof(wchar_t) bytes long. Returns a reference to self.

RWWString& insert(size_t pos, const RWWString& str);

Insert a copy of the string str into self at position pos. Returns a reference to self.

RWWString& insert(size_t pos, const RWWString& str, size_t N);

Insert a copy of the first N wide characters or the length of str (whichever is less) of str into self at position pos. Returns a reference to self.

RWBoolean isAscii() const;

Returns TRUE if it is safe to perform the conversion toAscii() (that is, if all characters of self are ASCII characters).

RWBoolean isNull() const;

Returns TRUE if this string has zero length (i.e., the null string).

size_t last(wchar_t c) const;

Returns the index of the last occurrence in the string of the wide character c. Returns RW_NPOS if there is no such character.

size_t length() const;

Return the number of characters in self.

RWWString& prepend(const wchar_t* cs);

Prepend a copy of the null-terminated wide character string pointed to by cs to self. Returns a reference to self.

RWWString& prepend(const wchar_t* cs, size_t N,);

Prepend a copy of the character string cs to self. Exactly N characters are copied, including any embedded nulls. Hence, the buffer pointed to by cs must be at least N*sizeof(wchart_t) bytes long. Returns a reference to self.

RWWString& prepend(const RWWString& str);

Prepends a copy of the string str to self. Returns a reference to self.

RWWString& prepend(const RWWString& cstr, size_t N);

Prepend the first N wide characters or the length of cstr (whichever is less) of cstr to self. Returns a reference to self.

istream& readFile(istream& s);

Reads characters from the input stream s, replacing the previous contents of self, until EOF is reached. The input stream is treated as a sequence of multibyte characters, each of which is converted to a wide character (using the Standard C library function mbtowc()) before storing. Null characters are treated the same as other characters.

istream& readLine(istream& s, RWBoolean skipWhite = TRUE);

Reads characters from the input stream s, replacing the previous contents of self, until a newline (or an EOF) is encountered. The newline is removed from the input stream but is not stored. The input stream is treated as a sequence of multibyte characters, each of which is converted to a wide character (using the Standard C library function mbtowc()) before storing. Null characters are treated the same as other characters. If the skipWhite argument is TRUE, then whitespace is skipped (using the iostream library manipulator ws) before saving characters.

istream& readString(istream& s);

Reads characters from the input stream s, replacing the previous contents of self, until an EOF or null terminator is encountered. The input stream is treated as a sequence of multibyte characters, each of which is converted to a wide character (using the Standard C library function mbtowc()) before storing.

istream& readToDelim(istream&, wchar_t delim=(wchar_t)'\n');

Reads characters from the input stream s, replacing the previous contents of self, until an EOF or the delimiting character delim is encountered. The delimiter is removed from the input stream but is not stored. The input stream is treated as a sequence of multibyte characters, each of which is converted to a wide character (using the Standard C library function mbtowc()) before storing. Null characters are treated the same as other characters.

istream& readToken(istream& s);

Whitespace is skipped before storing characters into wide string. Characters are then read from the input stream s, replacing previous contents of self, until trailing whitespace or an EOF is encountered. The trailing whitespace is left on the input stream. Only ASCII whitespace characters are recognized, as defined by the standard C library function isspace(). The input stream is treated as a sequence of multibyte characters, each of which is converted to a wide character (using the Standard C library function mbtowc()) before storing.

RWWString& remove(size_t pos);

Removes the characters from the position pos, which must be no greater than length(), to the end of string. Returns a reference to self.

RWWString& remove(size_t pos, size_t N);

Removes N wide characters or to the end of string (whichever comes first) starting at the position pos, which must be no greater than length(). Returns a reference to self.

RWWString& replace(size_t pos, size_t N, const wchar_t* cs);

Replaces N wide characters or to the end of string (whichever comes first) starting at position pos, which must be no greater than length(), with a copy of the null-terminated string cs. Returns a reference to self.

RWWString& replace(size_t pos, size_t N1,const wchar_t* cs, size_t N2);

Replaces N1 characters or to the end of string (whichever comes first) starting at position pos, which must be no greater than length(), with a copy of the string cs. Exactly N2 characters are copied, including any embedded nulls. Hence, the buffer pointed to by cs must be at least N2*sizeof(wchart_t) bytes long. Returns a reference to self.

RWWString& replace(size_t pos, size_t N, const RWWString& str);

Replaces N characters or to the end of string (whichever comes first) starting at position pos, which must be no greater than length(), with a copy of the string str. Returns a reference to self.

RWWString& replace(size_t pos, size_t N1, const RWWString& str, size_t N2);

Replaces N1 characters or to the end of string (whichever comes first) starting at position pos, which must be no greater than length(), with a copy of the first N2 characters, or the length of str (whichever is less), from str. Returns a reference to self.

void resize(size_t n);

Changes the length of self, adding blanks (i.e., L' ') or truncating as necessary.

RWWSubString strip(stripType s = RWWString::trailing, wchar_t c = L' '); const RWWSubString strip(stripType s = RWWString::trailing, wchar_t c = L' ') const;

Returns a substring of self where the character c has been stripped off the beginning, end, or both ends of the string. The first variant can be used as an lvalue. The enum stripType can take values:

Table 9-1. enum stripType values and meanings

stripType

Meaning

leading

Remove characters at beginning

trailing

Remove characters at end

both

Remove characters at both ends


RWWSubString subString(const wchar_t* cs, size_t start=0, caseCompare = RWWString::exact); const RWWSubString subString(const wchar_t* cs, size_t start=0, caseCompare = RWWString::exact) const;

Returns a substring representing the first occurrence of the null-terminated string pointed to by "cs". Case sensitivity is according to the caseCompare argument; it defaults to RWWString::exact. The first variant can be used as an lvalue.

RWCString toAscii() const;

Returns an RWCString object of the same length as self, containing only ASCII characters. Any non-ASCII characters in self simply have the high bits stripped off. Use isAscii() to determine whether this function is safe to use.

RWCString toMultiByte() const;

Returns an RWCString containing the result of applying the standard C library function wcstombs() to self. This function is always safe to use.

void toLower();

Changes all upper-case letters in self to lower-case. Uses the C library function towlower().

void toUpper();

Changes all lower-case letters in self to upper-case. Uses the C library function towupper().

Static Public Member Functions

static unsigned hash(const RWWString& wstr);

Returns the hash value of wstr as returned by wstr.hash(RWWString::exact).

static size_t initialCapacity(size_t ic = 15);

Sets the minimum initial capacity of an RWWString, and returns the old value. The initial setting is 15 wide characters. Larger values will use more memory, but result in fewer resizes when concatenating or reading strings. Smaller values will waste less memory, but result in more resizes.

static size_t maxWaste(size_t mw = 15);

Sets the maximum amount of unused space allowed in a wide string should it shrink, and returns the old value. The initial setting is 15 wide characters. If more than mw characters are wasted, then excess space will be reclaimed.

static size_t resizeIncrement(size_t ri = 16);

Sets the resize increment when more memory is needed to grow a wide string. Returns the old value. The initial setting is 16 wide characters.

Related Global Operators

RWBoolean operator==(const RWWString&, const wchar_t* ); RWBoolean operator==(const wchar_t*, const RWWString&); RWBoolean operator==(const RWWString&, const RWWString&); RWBoolean operator!=(const RWWString&, const wchar_t* ); RWBoolean operator!=(const wchar_t*, const RWWString&); RWBoolean operator!=(const RWWString&, const RWWString&);

Logical equality and inequality. Case sensitivity is exact.

RWBoolean operator< (const RWWString&, const wchar_t* ); RWBoolean operator< (const wchar_t*, const RWWString&); RWBoolean operator< (const RWWString&, const RWWString&); RWBoolean operator> (const RWWString&, const wchar_t* ); RWBoolean operator> (const wchar_t*, const RWWString&); RWBoolean operator> (const RWWString&, const RWWString&); RWBoolean operator<=(const RWWString&, const wchar_t* ); RWBoolean operator<=(const wchar_t*, const RWWString&); RWBoolean operator<=(const RWWString&, const RWWString&); RWBoolean operator>=(const RWWString&, const wchar_t* ); RWBoolean operator>=(const wchar_t*, const RWWString&); RWBoolean operator>=(const RWWString&, const RWWString&);

Comparisons are done lexicographically, byte by byte. Case sensitivity is exact. Use member collate() or strxfrm() for locale sensitivity.

RWWString operator+(const RWWString&, const RWWString&); RWWString operator+(const wchar_t*, const RWWString&); RWWString operator+(const RWWString&, const wchar_t* );

Concatenation operators.

ostream& operator<<(ostream& s, const RWWString& str);

Output an RWWString on ostream s. Each character of str is first converted to a multibyte character before being shifted out to s.

istream& operator>>(istream& s, RWWString& str);

Calls str.readToken(s). That is, a token is read from the input stream s.

RWvostream& operator<<(RWvostream&, const RWWString& str); RWFile& operator<<(RWFile&, const RWWString& str);

Saves string str to a virtual stream or RWFile, respectively.

RWvistream& operator>>(RWvistream&, RWWString& str); RWFile& operator>>(RWFile&, RWWString& str);

Restores a wide character string into str from a virtual stream or RWFile, respectively, replacing the previous contents of str.

Related Global Functions

RWWString strXForm(const RWWString&);

Returns a string transformed by ::wsxfrm(), to allow quicker collation than RWWString::collate().

RWWString toLower(const RWWString& str);

Returns a version of str where all upper-case characters have been replaced with lower-case characters. Uses the C library function towlower().

RWWString toUpper(const RWWString& str);

Returns a version of str where all lower-case characters have been replaced with upper-case characters. Uses the C library function towupper().