Chapter 7. RWTPtrMap<K,T,C> - RWTPtrVector<T>

RWTPtrMap<K,T,C>

Synopsis

#include <rw/tpmap.h> 
RWTPtrMap<K,T,C> m;

Standard C++ Library Dependent!


Note: RWTPtrMap requires the Standard C++ Library.


Description

This class maintains a pointer-based collection of associations of type pair<K* const, T*>. The first part of the association is a key of type K*, the second is its 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)

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. Note that keys will be dereferenced before being compared.

RWTPtrMap<K,T,C> will not accept a key that compares equal to any key already in the collection. (RWTPtrMultiMap<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.

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

Program Output:

04/12/75

Related Classes

Class RWTPtrMultiMap<K,T,C> offers the same interface to a pointer-based collection that accepts multiple keys that compare equal to each other. RWTPtrSet<T,C> maintains a pointer-based collection of keys without the associated items.

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

Public Typedefs

typedef rw_deref_compare<C,K>                  container_comp;
typedef map<K*,T*,container_comp, allocator>   container_type;
typedef container_type::size_type              size_type;
typedef container_type::difference_type        difference_type;
typedef container_type::iterator               iterator;
typedef container_type::const_iterator         const_iterator;
typedef pair <K* const, T*>                    value_type;
typedef pair <K* const, T*>&                   reference;
typedef const pair <K* const, T*>&             const_reference;
typedef K*                                     value_type_key;
typedef T*                                     value_type_data;
typedef K*&                                    reference_key;
typedef T*&                                    reference_data;
typedef const K*const&                   const_reference_key;
typedef const T*const&                   const_reference_data;

Public Constructors

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

Constructs an empty map with comparator comp.

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

Copy constructor.

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

Constructs a map by copying all elements from m.

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

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

Public Member Operators

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

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

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

Returns true if self compares lexicographically less than m, otherwise returns false. Keys in each collection are dereferenced before being compared. Assumes that type K has well-defined less-than semantics.

bool operator==(const RWTPtrMap<K,T,C>& 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 keys that compare equal to each other. Keys are dereferenced before being compared.

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 uninitialized pointer of type T*. Because of this, if there is a possibility that a key will not be in the dictionary, then this operator should only be used as an lvalue.

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.

void clearAndDestroy();

Removes all associations from the collection and uses operator delete to destroy the objects pointed to by the keys and their associated items. Do not use this method if multiple pointers to the same object are stored. (This could happen even if keys all compare different, since items are not considered during comparison.)

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)(value_type,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(value_type 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.

const K* find(const K* key) const;

If there exists a key j in self that compares equal to *key, then j is returned. Otherwise, returns rwnil.

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

If there exists an association a in self such that the expression ((*fn)(a,d)) is true, then returns a. Otherwise, returns pair<rwnil,rwnil>. fn points to a user-defined tester function which must have prototype:

bool yourTester(value_type a, void* d);

Client data may be passed through parameter d.

T* findValue(const K* key); const T* findValue(const K* key) const;

If there exists a key j in self that compares equal to *key, returns the item associated with j. Otherwise, returns rwnil.

const K* findKeyAndValue(const K* key, T*& tr); const K* findKeyAndValue(const K* key, const T*& tr) const;

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

bool insert(K* key, 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(K* key, 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)(value_type,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(value_type a, void* d);

Client data may be passed through parameter d.

K* remove(const K* key);

Removes the first association with key j in self that compare euqal to *key and returns j. Returns rwnil if there is no such association.

K* remove(bool (*fn)(value_type,void*), void* d);

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

bool yourTester(value_type 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 that compare equal to *key. Returns the number of associations removed.

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

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

bool yourTester(value_type a, void* d);

Client data may be passed through parameter d.

container_type std(); const container_type std() const;

Returns a reference to the underlying C++-standard collection that serves as the implementation for self.

Related Global Operations

RWvostream& operator<<(RWvostream& strm, const RWTPtrMap<K,T,C>& coll); RWFile& operator<<(RWFile& strm, const RWTPtrMap<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, RWTPtrMap<K,T,C>& coll); RWFile& operator>>(RWFile& strm, RWTPtrMap<K,T,C>& coll);

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

RWvistream& operator>>(RWvistream& strm, RWTPtrMap<K,T,C>*& p); RWFile& operator>>(RWFile& strm, RWTPtrMap<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.

RWTPtrMapIterator<K,T,C>

Synopsis

#include<rw/tpmap.h>
RWTPMap<K,T,C> map;
RWTPMapIterator<K,T,C> itr(map);

Standard C++ Library Dependent!


Note: RWTPtrMapIterator requires the Standard C++ Library.


Description

RWTPrtMapIterator is supplied with Tools 7 to provide an iterator interface to the new Standard Library based collections that has backward compatibility with the container iterators provided in Tools 6.

The order of iteration over an RWTPtrMap 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/tpmap.h>
#include<iostream.h>
#include<rw/cstring.h>
 
int main(){
   RWTPtrMap<RWCString,int,less<RWCString> > age;
   RWTPtrMapIterator<RWCString,int,less<RWCString> > itr(age);
age.insert(new RWCString("John") ,new int(30));
   age.insert(new RWCString("Steve"),new int(17));
   age.insert(new RWCString("Mark") ,new int(24));
//Insertion is rejected, no duplicates allowed
   age.insert(new RWCString("Steve"),new int(24));
for(;itr();)
     cout << *itr.key() << "\'s age is " << *itr.value() << endl;
   return 0;
}

Program Output

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

Public Constructors

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

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

Public Member Operators

K* operator()();

Advances self to the next element, dereferences the resulting iterator and returns its key. 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 now reference the first element. If, before iteration, self referenced the last association in the multimap, self will now point to an undefined value and a value equivalent to false will be returned. Otherwise, a value equivalent to true is returned.


Note: No post-increment operator is provided.


Public Member Functions

RWTPtrMap<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. Undefined if self is not referencing a value within the map.

void reset(); void reset(RWTPtrMap<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 RWTPtrMap to reset() will reset the iterator on that container.

T* value();

Returns the value portion of the association pointed to by self. Undefined if self is not referencing a value within the map.

RWTPtrMultiMap<K,T,C>

Synopsis

#include <rw/tpmmap.h> 
RWTPtrMultiMap<K,T,C> m;

Standard C++ Library Dependent!


Note: RWTPtrMultiMap requires the Standard C++ Library.


Description

This class maintains a pointer-based collection of associations of type pair<K*, const T*>. The first part of the association is a key of type K*, the second is its 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)

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. Note that keys will be dereferenced before being compared.

RWTPtrMultiMap<K,T,C> may contain multiple keys that compare equal to each other. (RWTPtrMap<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 multimap of RWCStrings and RWDates is exercised.

//
 
// tpmmap.cpp
//
#include <rw/tpmmap.h>
#include <rw/cstring.h>
#include <rw/rwdate.h>
#include <iostream.h>
 
main(){
  typedef RWTPtrMultiMap<RWCString, RWDate, less<RWCString> > 
   RWMMap;
  RWMMap birthdays;
 
  birthdays.insert(new RWCString("John"),
                              new RWDate(12, "April", 1975));
  birthdays.insert(new RWCString("Ivan"),
                              new RWDate(2, "Nov", 1980));
  birthdays.insert(new RWCString("Mary"),
                              new RWDate(22, "Oct", 1987));
  birthdays.insert(new RWCString("Ivan"),
                              new RWDate(19, "June", 1971));
  birthdays.insert(new RWCString("Sally"),
                              new RWDate(15, "March", 1976));
  birthdays.insert(new RWCString("Ivan"),
                              new RWDate(6, "July", 1950));
 
// How many "Ivan"s?
 
  RWCString ivanstr("Ivan");
  RWMMap::size_type n = birthdays.occurrencesOf(&ivanstr);
  RWMMap::size_type idx = 0;
  cout << "There are " << n << " Ivans:" << endl;
  RWMMap::const_iterator iter = 
                             birthdays.std().lower_bound(&ivanstr);
  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 RWTPtrMap<K,T,C> offers the same interface to a pointer-based collection that will not accept multiple keys that compare equal to each other. RWTPtrMultiSet<T,C> maintains a pointer-based collection of keys without the associated values.

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

Public Typedefs

typedef rw_deref_compare<C,K>             container_comp;
typedef multimap<K*,T*,container_comp,allocator>
                container_type;
typedef container_type::size_type         size_type;
typedef container_type::difference_type   difference_type;
typedef container_type::iterator          iterator;
typedef container_type::const_iterator    const_iterator;
typedef pair<K* const, T*>                value_type;
typedef pair<K* const, T*>                reference;
typedef const pair<K* const, T*>&         const_reference;
typedef K*                                value_type_key;
typedef T*                                value_type_data;
typedef K*&                               reference_key;
typedef T*&                               reference_data;
typedef const K*const&                    const_reference_key;
typedef const T*const&                    const_reference_data;

Public Constructors

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

Constructs an empty map with comparator comp.

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

Constructs a multimap by copying all element from m.

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

Copy constructor.

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

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

Public Member Operators

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

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

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

Returns true if self compares lexicographically less than m, otherwise returns false. Keys in each collection are dereferenced before being compared. Assumes that type K has well-defined less-than semantics.

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

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 keys that compare equal to each other. Keys are dereferenced before being compared.

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.

void clearAndDestroy();

Removes all associations from the collection and uses operator delete to destroy the objects pointed to by the keys and their associated items. Do not use this method if multiple pointers to the same object are stored.

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)(value_type,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(value_type 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.

const K* find(const K* key) const;

If there exists a key j in self that compares equal to *key, then j is returned. Otherwise, returns rwnil.

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

If there exists an association a in self such that the expression ((*fn)(a,d)) is true, then returns a. Otherwise, returns pair<rwnil,rwnil>. fn points to a user-defined tester function which must have prototype:

bool yourTester(value_type a, void* d);

Client data may be passed through parameter d.

T* findValue(const K* key); const T* findValue(const K* key) const;

If there exists a key j in self such that the expression (*j == *key) is true, returns the item associated with j. Otherwise, returns rwnil.

const K* findKeyAndValue(const K* key, T*& tr); const K* findKeyAndValue(const K* key, const T*& tr) const;

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

bool insert(K* key, T* a);

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

bool insertKeyAndValue(K* key, 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)(value_type,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(value_type a, void* d);

Client data may be passed through parameter d.

K* remove(const K* key);

Removes the first association with key j in self such that the expression (*j == *key) is true and returns j. Returns rwnil if there is no such association.

K* remove(bool (*fn)(value_type,void*), void* d);

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

bool yourTester(value_type 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 that compare equal to *key. Returns the number of associations removed.

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

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

bool yourTester(value_type a, void* d);

Client data may be passed through parameter d.

container_type& std(); const container_type& std() const;

Returns a reference to the underlying C++-standard collection that serves as the implementation for self.

Related Global Operators

RWvostream& operator<<(RWvostream& strm, const RWTPtrMultiMap<K,T,C>& coll); RWFile& operator<<(RWFile& strm, const RWTPtrMultiMap<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, RWTPtrMultiMap<K,T,C>& coll); RWFile& operator>>(RWFile& strm, RWTPtrMultiMap<K,T,C>& coll);

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

RWvistream& operator>>(RWvistream& strm, RWTPtrMultiMap<K,T,C>*& p); RWFile& operator>>(RWFile& strm, RWTPtrMultiMap<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.

RWTPtrMultiMapIterator<K,T,C>

Synopsis

#include<rw/tpmmap.h>
 
RWTPtrMultiMap<K,T,C> map;
RWTPtrMultiMapIterator<K,T,C> itr(map);

Standard C++ Library Dependent!


Note: RWTPtrMultiMapIterator requires the Standard C++ Library.


Description

RWTPtrMultiMapIterator is supplied with Tools 7 to provide an iterator interface to the new Standard Library based collections with backward compatibility to the Tools 6 container iterators.

The order of iteration over an RWTPtrMultiMap is dependent on the comparator object of the container 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/tpmmap.h>
 
#include<iostream.h>
#include<rw/cstring.h>
#include<utility>
 
int main(){
 
   RWTPtrMultiMap<RWCString,int,less<RWCString> > age;
   RWTPtrMultiMapIterator<RWCString,int,less<RWCString> > itr(age);
 
   age.insert(new RWCString("John"), new int(30));
 
   age.insert(new RWCString("Steve"),new int(17));
   age.insert(new RWCString("Mark"), new int(24));
   age.insert(new RWCString("Steve"),new int(24));
 
   for(;itr();)
 
     cout << *itr.key() << "\'s age is " << *itr.value() << endl;
 
   return 0;
 
}

Program Output:

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

Public Constructors

RWTPtrMultiMapIterator<K,T,C>(const RWTPtrMultiMap<K,T,C>& m);

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

Public Member Operators

K* operator()();

Advances self to the next element, dereferences the resulting iterator and returns its key. 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 now reference the first element. If, before iteration, self referenced the last association in the multimap, self will now point to an undefined value and a value equivalent to false will be returned. Otherwise, a value equivalent to true is returned.


Note: No post-increment operator is provided.


Public Member Functions

RWTPtrMultiMap<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. Undefined if self is not referencing a value within the multimap.

void reset(); void reset(RWTPtrMultiMap<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 RWTPtrMultiMap to reset() will reset the iterator on that container.

T* value();

Returns the value portion of the association referenced by self. Undefined if self is not referencing a value within the multimap.

RWTPtrMultiSet<T,C>

Synopsis

#include <rw/tpmset.h>
 
RWTPtrMultiSet<T,C> s;

Standard C++ Library Dependent!


Note: RWTPtrMultiSet requires the Standard C++ Library.


Description

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

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

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

RWTPtrMultiSet<T,C> may contain multiple items that compare equal to each other. (RWTPtrSet<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.

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

Related Classes

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

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

Public Typedefs

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

Public Constructors

RWTPtrMultiSet<T,C>(const container_comp& = container_comp());

Constructs an empty set.

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

Copy constructor.

RWTPtrMultiSet<T,C>(const container_type>& ms);

Constructs a multimap by copying all elements from ms.

RWTPtrMultiSet<T,C>(T* const* first,T* const* last,const container_comp& = container_comp());

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

Public Member Operators

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

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

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

Returns true if self compares lexicographically less than s, otherwise returns false. Items in each collection are dereferenced before being compared. Assumes that type T has well-defined less-than semantics.

bool operator==(const RWTPtrMultiSet<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. Elements are dereferenced before being compared.

Public Member Functions

void apply(void (*fn)(const T*,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 T* 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.

void clearAndDestroy();

Removes all items from the collection and uses operator delete to destroy the objects pointed to by those items. Do not use this method if multiple pointers to the same object are stored.

bool contains(const T* 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 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.

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

Sets self to the set-theoretic difference given by (self - s). Elements from each set are dereferenced before being compared.

iterator end(); const_iterator end() const;

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

size_type entries();

Returns the number of items in self.

const T* find(const T* a) const;

If there exists an element t in self such that the expression (*t == *a) is true, returns t. Otherwise, returns rwnil.

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

If there exists an element t in self such that the expression ((*fn)(t,d)) is true, returns t. Otherwise, returns rwnil. 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.

bool insert(T* a);

Adds the item a to the collection. Returns true.

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

Sets self to the intersection of self and s. Elements from each set are dereferenced before being compared.

bool isEmpty() const;

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

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

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

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

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

bool isSubsetOf(const RWTPtrMultiSet<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 T* 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 T* a, void* d);

Client data may be passed through parameter d.

T* remove(const T* a);

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

T* remove(bool (*fn)(const T*,void*), void* d);

Removes and returns the first element t in self such that the expression ((*fn)(t,d)) is true. Returns rwnil if there is no such element. 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.

size_type removeAll(const T* a);

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

size_type removeAll(bool (*fn)(const T*,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 T* a, void* d);

Client data may be passed through parameter d.

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

Returns a reference to the underlying C++-standard collection that serves as the implementation for self.

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

Sets self to the symmetric difference of self and s. Elements from each set are dereferenced before being compared.

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

Sets self to the union of self and s. Elements from each set are dereferenced before being compared. Note the uppercase "U" in Union to avoid conflict with the C++ reserved word.

Related Global Operators

RWvostream& operator<<(RWvostream& strm, const RWTPtrMultiSet<T,C>& coll); RWFile& operator<<(RWFile& strm, const RWTPtrMultiSet<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, RWTPtrMultiSet<T,C>& coll); RWFile& operator>>(RWFile& strm, RWTPtrMultiSet<T,C>& coll);

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

RWvistream& operator>>(RWvistream& strm, RWTPtrMultiSet<T,C>*& p); RWFile& operator>>(RWFile& strm, RWTPtrMultiSet<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.

RWTPtrMultiSetIterator<T,C>

Synopsis

#include<rw/tpmset.h>
 
RWTPtrMultiSet<T,C> set;
RWTPtrMultiSetIterator<T,C> itr(set);

Standard C++ Library Dependent!


Note: RWTPtrMultiSetIterator requires the Standard C++ Library.


Description

RWTPtrMultiSetIterator is supplied with Tools 7 to provide an iterator interface to the new Standard Library based collections that has backward compatibility with the container iterators provided in Tools 6.

The order of iteration over an RWTPtrMultiSet is dependent upon the 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/tpmset.h>
 
#include<iostream.h>
#include<rw/cstring.h>
 
int main(){
 
   RWTPtrMultiSet<RWCString, less<RWCString> > a;
   RWTPtrMultiSetIterator<RWCString, less<RWCString> > itr(a);
 
   a.insert(new RWCString("John"));
 
   a.insert(new RWCString("Steve"));
   a.insert(new RWCString("Mark"));
   a.insert(new RWCString("Steve"));
 
   for(;itr();)
 
     cout << *itr.key() <<endl;
 
   return 0;
 
}
 

Program Output:

John
Mark
Steve
Steve

Public Constructors

RWTPtrMultiSetIterator<T,C>(const RWTPtrMultiSet<T,C>& m);

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

Public Member Operators

T* operator()();

Advances self to the next element, dereferences the resulting iterator and returns its value. 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 now reference the first element. If, before iteration, self referenced the last association in the multi-set, self will now point to an undefined value and a value equivalent to false will be returned. Otherwise, a value equivalent to true is returned.


Note: No post-increment operator is provided.


Public Member Functions

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

Returns a pointer to the collection being iterated over.

T* key();

Returns the stored value referenced by self. Undefined if self is not referencing a value within the list.

void reset(); void reset(RWTPtrMultiSet<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 RWTPtrMultiSet with reset() will reset the iterator on that container.

RWTPtrOrderedVector<T>

Synopsis

#include <rw/tpordvec.h> 
RWTPtrOrderedVector<T> ordvec;


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


Description

This class maintains a pointer-based collection of values, implemented as a vector. Class T is the type pointed to by the items in the collection

Persistence

Isomorphic

Example

In this example, a pointer-based vector of type RWDate is exercised.

//
 
// tporddat.cpp
//
#include <rw/tpordvec.h>
#include <rw/rwdate.h>
#include <iostream.h>
 
main(){
  RWTPtrOrderedVector<RWDate> week(7);
 
  RWDate begin;  // Today's date
 
  for (int i=0; i<7; i++)
    week.insert(new RWDate(begin++));
 
  for (i=0; i<7; i++)
    cout << *week[i] << endl;
 
  return 0;
}

Program Output:

05/31/95
06/01/95
06/02/95
06/03/95
06/04/95
06/05/95
06/06/95

Related Classes

Classes RWTPtrDeque<T>, RWTPtrSlist<T>, and RWTPtrDlist<T> also provide a Rogue Wave pointer-based 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 container_type::difference_type     difference_type;
typedef T*                                  value_type;
typedef T*&                                 reference;
typedef T* const&                           const_reference;

Public Constructors

RWTPtrOrderedVector<T>();

Constructs an empty vector.

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

Copy constructor.

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

Constructs an ordered vector by copying all elements of vec.

RWTPtrOrderedVector<T>(size_type n, T* a);

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

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

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

Public Member Operators

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

Clears all elements of self and replaces them by copying all elements of vec.

bool operator<(const RWTPtrOrderedVector<T>& vec) const;

Returns true if self compares lexicographically less than vec, otherwise returns false. Items in each collection are dereferenced before being compared.

bool operator==(const RWTPtrOrderedVector<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. Elements are dereferenced before being compared.

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(T* a);

Adds the item a to the end of the collection.

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

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(reference a, void* d);

void yourfun(T* a, void* d);

void yourfun(const T* 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.

void clearAndDestroy();

Removes all items from the collection and uses operator delete to destroy the objects pointed to by those items. Do not use this method if multiple pointers to the same object are stored.

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)(T*,void*), void* d) const; 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 one of the prototypes:

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

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

Client data may be passed through parameter d.

T*const* data() const;

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();

Returns the number of items in self.

T* find(const T* a) const;

If there exists an element t in self such that the expression (*t == *a) is true, returns t. Otherwise, returns rwnil.

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

If there exists an element t in self such that the expression ((*fn)(t,d)) is true, returns t. Otherwise, returns rwnil. fn points to a user-defined tester function which must have one of the prototypes:

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

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 T* 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)(T*,void*), void* d) const; size_type index(bool (*fn)(const T*,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 one of the prototypes:

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

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

Client data may be passed through parameter d.

bool insert(T* a);

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

void insertAt(size_type i, T* a);

Inserts the item a in front of the item at position i in self. This position must be between zero 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(); T*const& last() const;

Returns a reference to the last item in the collection.

size_type length() const;

Returns the number of items in self.

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

Returns a reference to the maximum or minimum element in self.

size_type occurrencesOf(const T* a) const;

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

size_type occurrencesOf(bool (*fn)(T*,void*),void* d) const; 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 one of the prototypes:

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

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

Client data may be passed through parameter d.

void prepend(T* a);

Adds the item a to the beginning of the collection.

T* remove(const T* a);

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

T* remove(bool (*fn)( T*,void*), void* d); T* remove(bool (*fn)(const T*,void*), void* d);

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

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

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

Client data may be passed through parameter d.

size_type removeAll(const T* 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)(T*,void*), void* d); size_type removeAll(bool (*fn)(const T*,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 one of the prototypes:

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

bool yourTester(const T* 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.

size_type replaceAll(const T* oldVal, T* newVal);

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

size_type replaceAll(bool (*fn)(T*, void*),void* x,T* newVal); size_type replaceAll(bool (*fn)(const T*, void*),void* x,T* newVal);

Replaces with newVal 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 one of the prototypes:

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

bool yourTester(const T* 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. Elements are dereferenced before being compared.

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.

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 RWTPtrOrderedVector<T>& coll); RWFile& operator<<(RWFile& strm, const RWTPtrOrderedVector<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, RWTPtrOrderedVector<T>& coll); RWFile& operator>>(RWFile& strm, RWTPtrOrderedVector<T>& coll);

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

RWvistream& operator>>(RWvistream& strm, RWTPtrOrderedVector<T>*& p); RWFile& operator>>(RWFile& strm, RWTPtrOrderedVector<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.

RWTPtrSet<T,C>

Synopsis

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

Standard C++ Library Dependent!


Note: RWTPtrSet requires the Standard C++ Library.


Description

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

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

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

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

Persistence

Isomorphic.

Examples

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

//
 
//tpset.cpp
//
#include <rw/tpset.h>
#include <rw/cstring.h>
#include <iostream.h>
#include <function.h>
 
main(){
  RWTPtrSet<RWCString, less<RWCString> > set;
 
  set.insert(new RWCString("one"));
  set.insert(new RWCString("two"));
  set.insert(new RWCString("three"));
  set.insert(new RWCString("one"));  // Rejected: duplicate entry
 
  cout << set.entries() << endl;   // Prints "3"
 
  set.clearAndDestroy();
  cout << set.entries() << endl;   // Prints "0"
 
  return 0;
}

Related Classes

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

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

Public Typedefs

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

Public Constructors

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

Constructs an empty set.

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

Copy constructor.

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

Creates a pointer based set by copying all elements from s.

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

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

Public Member Operators

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

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

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

Returns true if self compares lexicographically less than s, otherwise returns false. Items in each collection are dereferenced before being compared. Assumes that type T has well-defined less-than semantics.

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

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. Elements are dereferenced before being compared.

Public Member Functions

void apply(void (*fn)(const T*,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 T* 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.

void clearAndDestroy();

Removes all items from the collection and uses operator delete to destroy the objects pointed to by those items.

bool contains(const T* a) const;

Returns true if there exists an element t in self that compares equal with *a, 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.

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

Sets self to the set-theoretic difference given by (self - s). Elements from each set are dereferenced before being compared.

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.

const T* find(const T* a) const;

If there exists an element t in self that compares equal with *a, returns t. Otherwise, returns rwnil.

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

If there exists an element t in self such that the expression ((*fn)(t,d)) is true, returns t. Otherwise, returns rwnil. 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.

bool insert(T* 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 an equivalent key.

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

Sets self to the intersection of self and s. Elements from each set are dereferenced before being compared.

bool isEmpty() const;

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

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

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

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

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

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

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

size_type occurrencesOf(const T* a) const;

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

size_type occurrencesOf(bool (*fn)(T*,void*), void* d); 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 T* a, void* d);

Client data may be passed through parameter d.

T* remove(const T* a);

Removes and returns the first element t in self that compares equal with *a. Returns rwnil if there is no such element.

T* remove(bool (*fn)(const T*,void*), void* d);

Removes and returns the first element t in self such that the expression ((*fn)(t,d)) is true. Returns rwnil if there is no such element. 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 parámeter d.

size_type removeAll(const T* a);

Removes all elements t in self that compares equal with *a. Returns the number of items removed.

size_type removeAll(bool (*fn)(const T*,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 T* a, void* d);

Client data may be passed through parameter d.

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

Returns a reference to the underlying C++-standard collection that serves as the implementation for self.

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

Sets self to the symmetric difference of self and s. Elements from each set are dereferenced before being compared.

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

Sets self to the union of self and s. Elements from each set are dereferenced before being compared. Note the uppercase "U" in Union to avoid conflict with the C++ reserved word.

Related Global Operators

RWvostream& operator<<(RWvostream& strm, const RWTPtrSet<T,C>& coll); RWFile& operator<<(RWFile& strm, const RWTPtrSet<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, RWTPtrSet<T,C>& coll); RWFile& operator>>(RWFile& strm, RWTPtrSet<T,C>& coll); Restores the contents of the collection coll from the input stream strm. RWvistream& operator>>(RWvistream& strm, RWTPtrSet<T,C>*& p); RWFile& operator>>(RWFile& strm, RWTPtrSet<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.

RWTPtrSetIterator<T,C>

Synopsis

#include<rw/tpset.h>
 
RWTPtrSet<T,C> set;
RWTPtrSetIterator<T,C> itr(set);

Standard C++ Library Dependent!


Note: RWTPtrSetIterator requires the Standard C++ Library.


Description

RWTPtrSetIterator is supplied with Tools 7 to provide an iterator interface to the new Standard Library based collections that has backward compatibility with the container iterators provided in Tools 6.

The order of iteration over an RWTPtrSet is dependent on the 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/tpset.h>
 
#include<iostream.h>
#include<rw/cstring.h>
 
int main(){
 
   RWTPtrSet<RWCString,less<RWCString> > a;
   RWTPtrSetIterator<RWCString,less<RWCString> > itr(a);
 
   a.insert(new RWCString("John"));
 
   a.insert(new RWCString("Steve"));
   a.insert(new RWCString("Mark"));
 
//Rejected, duplicate insertions not allowed
 
   a.insert(new RWCString("Steve"));
 
   for(;itr();)
 
     cout << *itr.key() <<endl;
 
   return 0;
 
}

Program Output:

John
Mark
Steve

Public Constructors

RWTPtrSetIterator<T,C>(const RWTPtrSet<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

T* operator()();

Advances self to the next element, dereferences the resulting iterator and returns its value. 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 now reference the first element. If, before iteration, self referenced the last association in the set, self will now reference an undefined value and a value equivalent to false will be returned. Otherwise, a value equivalent to true is returned.


Note: No post-increment operator is provided.


Public Member Functions

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

Returns a pointer to the collection being iterated over.

T* key() const;

Returns the stored value pointed to by self. Undefined if self is not referencing a value within the set.

void reset(); void reset(RWTPtrSet<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 RWTPtrSet to reset() will reset the iterator on the new container.

RWTPtrSlist<T>

Synopsis

#include <rw/tpslist.h> 
RWTPtrSlist<T> slist;


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


Description

This class maintains a pointer-based collection of values, implemented as a singly-linked list. Class T is the type pointed to by the items in the collection.

Persistence

Isomorphic

Example

//
 
// tpsldat.cpp
//
#include <rw/tpslist.h>
#include <rw/rwdate.h>
#include <iostream.h>
 
main(){
  RWTPtrSlist<RWDate> dates;
  dates.insert(new RWDate(2, "June", 52));      // 6/2/52
  dates.insert(new RWDate(30, "March", 46));    // 3/30/46
  dates.insert(new RWDate(1, "April", 90));     // 4/1/90
 
  // Now look for one of the dates:
  RWDate * ret = dates.find(new RWDate(2,"June",52));
  if (ret){
    cout << "Found date " << ret << endl;
  }
 
  // Remove in reverse order:
  while (!dates.isEmpty())
    cout << *dates.removeLast() << endl;
 
  return 0;
}

Program Output:

Found date
4/01/90
3/30/46
6/02/52

Related Classes

Classes RWTPtrDlist<T>, RWTPtrDeque<T>, and RWTPtrOrderedVector<T> also provide a Rogue Wave pointer-based interface to C++-standard sequence collections.

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

Public Typedefs

typedef rw_slist<T*>                           container_type;
typedef container_type::size_type              size_type;
typedef container_type::difference_type        difference_type;
typedef container_type::iterator               iterator;
typedef container_type::const_iterator         const_iterator;
typedef T*                                     value_type;
typedef T*&                                    reference;
typedef T*const&                               const_reference;

Public Constructors

RWTPtrSlist<T>();

Constructs an empty, singly-linked list.

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

Copy constructor.

RWTPtrSlist<T>(const rw_slist<T*>& lst);

Construct a singly linked list by copying all elements of lst.

RWTPtrSlist<T>(size_type n, const T* a=0);

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

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

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

Public Member Operators

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

Empties self then inserts all elements of lst.

bool operator<(const RWTPtrSlist<T>& lst) const;

Returns true if self compares lexicographically less than lst, otherwise returns false. Items in each collection are dereferenced before being compared.

bool operator==(const RWTPtrSlist<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. Elements are dereferenced before being compared.

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, 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(T* a);

Adds the item a to the end of the collection.

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

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(T* a, void* d);

void yourfun(reference a, void* d);

void yourfun(const T* 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.

void clearAndDestroy();

Removes all items from the collection and uses operator delete to destroy the objects pointed to by those items. Do not use this method if multiple pointers to the same object are stored.

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)(T*,void*), void* d) const; 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 one of the prototypes:

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

bool yourTester(const T* 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.

T* find(const T* a) const;

If there exists an element t in self such that the expression (*t == *a) is true, returns t. Otherwise, returns rwnil.

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

If there exists an element t in self such that the expression ((*fn)(t,d)) is true, returns t. Otherwise, returns rwnil. fn points to a user-defined tester function which must have one of the prototypes:

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

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.

T* get();

Removes and returns the first element in the collection.

size_type index(const T* 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)(T*,void*), void* d) const; size_type index(bool (*fn)(const T*,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 one of the prototypes:

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

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

Client data may be passed through parameter d.

bool insert(T* a);

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

void insertAt(size_type i, T* a);

Inserts the item a in front of the item at position i in self. This position must be between zero 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(); T*const& 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 maximum or minimum element in self.

size_type occurrencesOf(const T* a) const;

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

size_type occurrencesOf(bool (*fn)(T*,void*), void* d) const; 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 one of the prototypes:

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

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

Client data may be passed through parameter d.

void prepend(T* a);

Adds the item a to the beginning of the collection.

T* remove(const T* a);

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

T* remove(bool (*fn)(T*,void*), void* d); T* remove(bool (*fn)(const T*,void*), void* d);

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

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

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

Client data may be passed through parameter d.

size_type removeAll(const T* 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)(T*,void*), void* d); size_type removeAll(bool (*fn)(const T*,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 one of the prototypes:

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

bool yourTester(const T* 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.

size_type replaceAll(const T* oldVal,T* newVal);

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

size_type replaceAll(bool (*fn)(T*, void*),void* x,T* newVal); size_type replaceAll(bool (*fn)(const T*, void*),void* x,T* newVal);

Replaces with newVal 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 one of the prototypes:

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

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

Client data may be passed through parameter d.

void sort();

Sorts the collection using the less-than operator to compare elements. Elements are dereferenced before being compared.

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.

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 RWTPtrSlist<T>& coll); RWFile& operator<<(RWFile& strm, const RWTPtrSlist<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, RWTPtrSlist<T>& coll); RWFile& operator>>(RWFile& strm, RWTPtrSlist<T>& coll);

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

RWvistream& operator>>(RWvistream& strm, RWTPtrSlist<T>*& p); RWFile& operator>>(RWFile& strm, RWTPtrSlist<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.

RWTPtrSlistIterator<T>

Synopsis

#include<rw/tpslist.h>
 
RWTPtrSlist<T> dl;
RWTPtrSlistIterator<T> itr(dl);


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


Description

RWTPtrSlistIterator is supplied with Tools 7 to provide an iterator interface to the new Standard Library based collections that has backward compatibility with the container iterators provided in Tools 6.

The order of iteration over an RWTPtrSlist is dependent upon the order of insertion of items 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 equivalent to false until reset() is called.

Persistence

None

Examples

#include<rw/tpslist.h>
 
#include<iostream.h>
#include<rw/cstring.h>
 
int main(){
 
   RWTPtrSlist<RWCString> a;
   RWTPtrSlistIterator<RWCString> itr(a);
   a.insert(new RWCString("John"));
   a.insert(new RWCString("Steve"));
   a.insert(new RWCString("Mark"));
   a.insert(new RWCString("Steve"));
 
   for(;itr();)
 
     cout << *itr.key() <<endl;
 
   return 0;
}

Program Output:

John
Steve
Mark
Steve

Public Constructors

RWTPtrSlistIterator<T>(RWTPtrSlist<T>& lst);

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

Public Member Operators

T* operator()();

Advances self to the next element, dereferences the resulting iterator and returns its value. 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 now reference the first element. If, before iteration, self referenced the last association in the list, self will now reference an undefined value distinct from the reset value and a value equivalent to false will be returned. Otherwise, a value equivalent to true is returned.


Note: No post-increment operator is provided.


RWBoolean operator+=(size_type n);

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

Public Member Functions

RWTPtrSlist<T>* container() const;

Returns a pointer to the collection being iterated over.

T* findNext(const T* a);

Returns the first element t encountered by iterating self forward, such that the expression (*t == *a) is true. If no such element is found, returns nil. Leaves self referencing the found item or "off the end."

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

Returns 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.

void insertAfterPoint(T* p);

Inserts the pointer p into the container directly after the element pointed to by self. Leaves self referencing the prior item, or in reset condition.

T* key();

Returns the stored value pointed to by self. Undefined if self is not referencing a value within the list.

T* remove();

Returns the stored value pointed to by self. and removes it from the collection. Undefined if self is not referencing a value within the list. Leaves self referencing the prior item, or in reset condition.

T* removeNext(const T*);

Returns and removes the first element t, encountered by iterating self forward, such that the expression (*t == *a) is true. Leaves self referencing the prior item, or in reset condition.

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

Returns and 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. Leaves self referencing the prior item, or in reset condition.

void reset(); void reset(RWTPtrSlist<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 RWTPtrSlist to reset() will reset the iterator on the new container.

RWTPtrSortedDlist<T,C>

Synopsis

#include <rw/tpsrtdli.h> 
RWTPtrSortedDlist<T,C> srtdlist;

Standard C++ Library Dependent!


Note: RWTPtrSortedDlist requires the Standard C++ Library.


Description

This class maintains an always-sorted pointer-based collection of values, implemented as a doubly-linked list. Items are ordered according to a comparison object of type C. Class T is the type pointed to by the items in the collection. C must induce a total ordering on elements of type T via a public member

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

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

Persistence

Isomorphic.

Example

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

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

Program Output:

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

Related Classes

Class RWTPtrSortedVector<T> is an alternative always-sorted pointer-based collection. RWTPtrDlist<T> is an unsorted pointer-based doubly-linked list.

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

Public Typedefs

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

Public Constructors

RWTPtrSortedDlist<T,C>();

Constructs an empty doubly-linked list.

RWTPtrSortedDlist<T,C>(const RWTPtrSortedDlist<T,C>& lst);

Copy constructor.

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

Constructs a doubly-linked list by iterating over all elements in lst and performing an order preserving insertion on self for each.

RWTPtrSortedDlist<T,C>(size_type n, T* p);

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

RWTPtrSortedDlist<T,C>(T** first,T** last);

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

Public Member Operators

bool operator<(const RWTPtrSortedDlist<T,C>& lst) const;

Returns true if self compares lexicographically less than lst, otherwise returns false. Items in each collection are dereferenced before being compared.

bool operator==(const RWTPtrSortedDlist<T,C>& 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. Elements are dereferenced before being compared.

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)(T*&,void*), void* d); void apply(void (*fn)(T*,void*), void* d); void apply(void (*fn)(const T*,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 T* a, void* d);

void yourfun(T* a, void* d);

void yourfun(T* &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.

void clearAndDestroy();

Removes all items from the collection and uses operator delete to destroy the objects pointed to by those items. Do not use this method if multiple pointers to the same object are stored.

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 an iterator positioned "just past" the last element in self.

size_type entries() const;

Returns the number of items in self.

const T* find(const T* a) const;

If there exists an element t in self such that the expression (*t == *a) is true, returns t. Otherwise, returns rwnil.

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

If there exists an element t in self such that the expression ((*fn)(t,d)) is true, returns t. Otherwise, returns rwnil. 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 T* 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 T*,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 T* 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 way. Returns the number of items inserted.

bool insert(T* 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.

T*& last(); T* const& last() const;

Returns a reference to the last item in the collection.

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

Inserts all elements of dl into self, preserving sorted order. Returns the number of items inserted.

size_type occurrencesOf(const T* a) const;

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

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 T* a, void* d);

Client data may be passed through parameter d.

T* remove(const T* a);

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

T* remove(bool (*fn)(const T*,void*), void* d);

Removes and returns the first element t in self such that the expression ((*fn)(t,d)) is true. Returns rwnil if there is no such element. 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.

size_type removeAll(const T* 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 T*,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 T* 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.

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

Returns a reference to the underlying C++-standard collection that serves as the implementation for self.

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 RWTPtrSortedDlist<T,C>& coll); RWFile& operator<<(RWFile& strm, const RWTPtrSortedDlist<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, RWTPtrSortedDlist<T,C>& coll); RWFile& operator>>(RWFile& strm, RWTPtrSortedDlist<T,C>& coll); Restores the contents of the collection coll from the input stream strm. RWvistream& operator>>(RWvistream& strm, RWTPtrSortedDlist<T,C>*& p); RWFile& operator>>(RWFile& strm, RWTPtrSortedDlist<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.

RWTPtrSortedDlistIterator<T,C>

Synopsis

#include<rw/tpsrtdli.h>
 
RWTPtrSortedDlist<T,C> dl;
RWTPtrSortedDlistIterator<T,C> itr(dl);

Standard C++ Library Dependent!


Note: RWTPtrSortedDlistIterator requires the Standard C++ Library.


Description

RWTPtrSortedDlistIterator is supplied with Tools.h++ 7.x to provide an iterator interface to the new Standard Library based collections that has backward compatibility with the container iterators provided in Tools.h++ 6.x.

The order of iteration over an RWTPtrSortedDlist is dependent on the 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/tpsrtdli.h>
 
#include<iostream.h>
#include<rw/cstring.h>
 
int main(){
   RWTPtrSortedDlist<RWCString,less<RWCString> > a;
   RWTPtrSortedDlistIterator<RWCString,less<RWCString> > itr(a);
   a.insert(new RWCString("John"));
   a.insert(new RWCString("Steve"));
   a.insert(new RWCString("Mark"));
   a.insert(new RWCString("Steve"));
 
   for(;itr();)
     cout << *itr.key() <<endl;
 
   return 0;
}

Program Output:

John
Mark
Steve
Steve

Public Constructors

RWTPtrSortedDlistIterator<T,C>(RWTPtrSortedDlist<T,C>& l);

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

Public Member Operators

T* operator()();

Advances self to the next element, dereferences the resulting iterator and returns its value. 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 now reference the first element. If, before iteration, self referenced the last association in the list, self will now point to an undefined value and a value equivalent to false will be returned. Otherwise, a value equivalent to true is returned.


Note: No post-increment operator is provided.


RWBoolean operator+=(size_type n);

Behaves as if operator++() 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 post-decrement operator is provided.


RWBoolean operator-=(size_type n);

Behaves as if operator--() had been applied n times

Public Member Functions

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

Returns a pointer to the collection being iterated over.

T* findNext(const T* a);

Returns the first element t encountered by iterating self forward, such that the expression (*t == *a) is true. Otherwise returns nil. Leaves self referencing found item or "off the end."

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

Returns 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. Otherwise returns nil. Leaves self referencing found item or "off the end."

T* key();

Returns the stored value pointed to by self. Undefined if self is not referencing a value within the list.

T* remove();

Returns the stored value pointed to by self. and removes it from the collection. Undefined if self is not referencing a value within the list. Leaves self referencing prior item or in reset state.

T* removeNext(const T*);

Returns and removes the first element t, encountered by iterating self forward, such that the expression (*t == *a) is true. Otherwise returns nil. Leaves self referencing prior item or in reset state.

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

Returns and 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. Otherwise returns nil. Leaves self referencing prior item or in reset state.

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

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 RWTPtrSortedDlist to reset() will reset the iterator on the new container.

RWTPtrSortedVector<T,C>

Synopsis

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


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


Description

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

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

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

Persistence

Isomorphic.

Example

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

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

Program Output:

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

Related Classes

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

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

Public Typedefs

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

Public Constructors

RWTPtrSortedVector<T,C>();

Constructs an empty vector.

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

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

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

Copy constructor.

RWTPtrSortedVector<T,C>(size_type n, T* p);

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

RWTPtrSortedVector<T,C>(size_type n);

Constructs an empty vector with a capacity of n elements.

RWTPtrSortedVector<T,C>(T** first,T** last);

Constructs a vector by copying and sorted elements from the array of T*s pointed to by first, up to, but not including, the element pointed to by last.

Public Member Operators

bool operator<(const RWTPtrSortedVector<T,C>& vec) const;

Returns true if self compares lexicographically less than vec, otherwise returns false. Items in each collection are dereferenced before being compared.

bool operator==(const RWTPtrSortedVector<T,C>& 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. Elements are dereferenced before being compared.

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, 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)(T*,void*), void* d); void apply(void (*fn)(T*&,void*), void* d); void apply(void (*fn)(const T*,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(T* a, void* d);

void yourfun(T*& a, void* d);

void yourfun(const T* 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.

void clearAndDestroy();

Removes all items from the collection and uses operator delete to destroy the objects pointed to by those items. Do not use this method if multiple pointers to the same object are stored.

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.

T* const* data() const;

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.

const T* find(const T* a) const;

If there exists an element t in self such that the expression (*t == *a) is true, returns t. Otherwise, returns rwnil.

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

If there exists an element t in self such that the expression ((*fn)(t,d)) is true, returns t. Otherwise, returns rwnil. 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. If the collection is empty, the function throws an exception of type RWBoundsErr.

size_type index(const T* 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 T*,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 T* a, void* d);

Client data may be passed through parameter d.

bool insert(T* 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.

T*& last(); T* const& last() const;

Returns a reference to the last item in the collection. If the collection is empty, the function throws an exception of type RWBoundsErr.

size_type length() const;

Returns the number of elements in self.

size_type merge(const RWTPtrSortedVector<T,C>& vec);

Inserts all elements of vec into self, preserving sorted order. Returns the number of items inserted.

size_type occurrencesOf(const T* a) const;

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

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 T* a, void* d);

Client data may be passed through parameter d.

T* remove(const T* a);

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

T* remove(bool (*fn)(const T*,void*), void* d);

Removes and returns the first element t in self such that the expression ((*fn)(t,d)) is true. Returns rwnil if there is no such element. 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.

size_type removeAll(const T* 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 T*,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 T* 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. If the collection is empty, the function throws an exception of type RWBoundsErr.

T* 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.

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

Returns a reference to the underlying C++-standard collection that serves as the implementation for self.

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 RWTPtrSortedVector<T,C>& coll); RWFile& operator<<(RWFile& strm, const RWTPtrSortedVector<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, RWTPtrSortedVector<T,C>& coll); RWFile& operator>>(RWFile& strm, RWTPtrSortedVector<T,C>& coll);

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

RWvistream& operator>>(RWvistream& strm, RWTPtrSortedVector<T,C>*& p); RWFile& operator>>(RWFile& strm, RWTPtrSortedVector<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.

RWTPtrVector<T>

Synopsis

#include <rw/tpvector.h>
 
RWTPtrVector<T> vec;

Descripton

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

The class T can be of any type.

Persistence

Isomorphic

Example

#include <rw/tpvector.h>
#include <rw/rwdate.h>
#include <rw/rstream.h>
 
main()  {
  RWTPtrVector<RWDate> week(7);
 
  RWDate begin;   // Today's date
 
  for (int i=0; i<7; i++)
    week[i] = new RWDate(begin++);
 
  for (i=0; i<7; i++)
  {
    cout << *week[i] << endl;
    delete week[i];
  }
 
  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

RWTPtrVector<T>();

Constructs an empty vector of length zero.

RWTPtrVector<T>(size_t n);

Constructs a vector of length n. The initial values of the elements are undefined. Hence, they can (and probably will) be garbage.

RWTPtrVector<T>(size_t n, T* ival);

Constructs a vector of length n, with each element pointing to the item *ival.

RWTPtrVector<T>(const RWTPtrVector& v);

Constructs self as a shallow copy of v. After construction, pointers held by the two vectors point to the same items.

Public operators

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

Sets self to a shallow copy of v. Afterwards, the two vectors will have the same length and pointersheld by the two vectors will point to the same items.

RWTPtrVector<T>& operator=(T* p);

Sets all elements in self to point to the item *p.

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

Returns the ith value in the vector. The first variant can be used as an l-value, the second cannot. The index i must be between zero and the length of the vector, less one. No bounds checking is performed.

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

Returns the ith value in the vector. The first variant can be used as an lvalue, the second cannot. The index i must be between zero and the length of the vector, less one; or an exception of type TOOL_INDEX will be thrown.

Public Member Functions

T* const * data() const;

Returns a pointer to the raw data of the vector. 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 undefined.

void resize(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 to nil.