RWTValMultiSet(3C++) RWTValMultiSet(3C++)
Name
RWTValMultiSet<T,C> - Rogue Wave library class
Synopsis
#include <rw/tvmset.h>
RWTValMultiSet<T,C>
Standard C++ Library Dependent!RWTValMultiSet requires the Standard C++ Library.
Description
This class maintains a collection of values, which are ordered according
to a comparison object of type C. C must induce a total ordering on
elements of type T via a public member
bool operator()(const T& x, const T& y) const which returns true if
x should precede y within the collection. The structure less<T> from the
C++-standard header file <functional> is an example. RWTValMultiSet<T,C>
may contain multiple items that compare equal to each other.
(RWTValSet<T,C> will not accept an item that compares equal to an item
already in the collection.)
Persistence
Isomorphic.
Examples
In this example, a multi-set of RWCStrings is exercised.
//
// tvmsstr.cpp
//
#include <rw/tvmset.h>
#include <rw/cstring.h>
#include <iostream.h>
main(){
RWTValMultiSet<RWCString,less<RWCString> > set;
set.insert("one");
set.insert("two");
set.insert("three");
set.insert("one"); // OK, duplicates allowed
cout << set.entries() << endl; // Prints "4"
return 0;
}
Page 1
RWTValMultiSet(3C++) RWTValMultiSet(3C++)
Related Classes
Class RWTValSet<T,C> offers the same interface to a collection that will
not accept multiple items that compare equal to each other.
RWTValMultiMap<K,T,C> maintains a collection of key-value pairs. Class
multiset<T,C,allocator> is the C++-standard collection that serves as the
underlying implementation for RWTValMultiSet<T,C>.
Public Typedefs
typedef multiset<T,C,allocator> container_type;
typedef container_type::iterator iterator;
typedef container_type::const_iterator const_iterator;
typedef container_type::size_type size_type;
typedef T value_type;
typedef const T& const_reference;
Public Constructors
RWTValMultiSet<T,C>(const C& cmp = C());
Constructs an empty set.
RWTValMultiSet<T,C>(const container_type& s);
Constructs a set by copying all elements of s.
RWTValMultiSet<T,C>(const RWTValMultiSet<T,C>& rws);
Copy constructor.
RWTValMultiSet<T,C>
(const T* first,const T* last,const C& cmp = C());
Constructs a set by copying elements from the array of Ts pointed to by
first, up to, but not including, the element pointed to by last.
Public Member Operators
RWTValMultiSet<T,C>&
operator=(const RWTValMultiSet<T,C>& s);
RWTValMultiSet<T,C>&
operator=(const container_type& s);
Destroys all elements of self and replaces them by copying all elements
of s.
Page 2
RWTValMultiSet(3C++) RWTValMultiSet(3C++)
bool
operator<(const RWTValMultiSet<T,C>& s) const;
bool
operator<(const container_type& s) const;
Returns true if self compares lexicographically less than s, otherwise
returns false. Assumes that type T has well-defined less-than semantics
(T::operator<(const T&) or equivalent).
bool
operator==(const RWTValMultiSet<T,C>& s) const;
bool
operator==(const container_type& s) const;
Returns true if self compares equal to s, otherwise returns false. Two
collections are equal if both have the same number of entries, and
iterating through both collections produces, in turn, individual elements
that compare equal to each other.
Public Member Functions
void
apply(void (*fn)(const_reference,void*), void* d) const;
Applies the user-defined function pointed to by fn to every item in the
collection. This function must have prototype:
void yourfun(const_reference a, void* d);
Client data may be passed through parameter d.
iterator
begin();
const_iterator
begin() const;
Returns an iterator positioned at the first element of self.
void
clear();
Page 3
RWTValMultiSet(3C++) RWTValMultiSet(3C++)
Clears the collection by removing all items from self. Each item will
have its destructor called.
bool
contains(const_reference a) const;
Returns true if there exists an element t in self that compares equal to
a, otherwise returns false.
bool
contains(bool (*fn)(const_reference, void*), void* d) const;
Returns true if there exists an element t in self such that the
expression ((*fn)(t,d)) is true, otherwise returns false. fn points to a
user-defined tester function which must have prototype:
bool yourTester(const_reference a, void* d);
Client data may be passed through parameter d.
void
difference(const RWTValMultiSet<T,C>& s);
void
difference(const container_type& s);
Sets self to the set-theoretic difference given by (self - s).
iterator
end();
const_iterator
end() const;
Returns an iterator positioned "just past" the last element in self.
size_type
entries() const;
Returns the number of items in self.
bool
find(const_reference a, T& k) const;
Page 4
RWTValMultiSet(3C++) RWTValMultiSet(3C++)
If there exists an element t in self that compares equal to a, assigns t
to k and returns true. Otherwise, returns false and leaves the value of
k unchanged.
bool
find(bool (*fn)(const_reference,void*), void* d, T& k) const;
If there exists an element t in self such that the expression
((*fn)(t,d)) is true, assigns t to k and returns true. Otherwise,
returns false and leaves the value of k unchanged. fn points to a user-
defined tester function which must have prototype:
bool yourTester(const_reference a, void* d);
Client data may be passed through parameter d.
void
intersection(const RWTValMultiSet<T,C>& s);
void
intersection(const container_type& s);
Sets self to the intersection of self and s.
bool
insert(const_reference a);
Adds the item a to the collection. Returns true.
bool
isEmpty() const;
Returns true if there are no items in the collection, false otherwise.
bool
isEquivalent(const RWTValMultiSet<T,C>& s) const;
Returns true if there is set equivalence between self and s, and returns
false otherwise.
bool
isProperSubsetOf(const RWTValMultiSet<T,C>& s) const;
Page 5
RWTValMultiSet(3C++) RWTValMultiSet(3C++)
Returns true if self is a proper subset of s, and returns false
otherwise.
bool
isSubsetOf(const RWTValMultiSet<T,C>& s) const;
Returns true if self is a subset of s or if self is set equivalent to
rhs, false otherwise.
size_type
occurrencesOf(const_reference a) const;
Returns the number of elements t in self that compare equal to a.
size_type
occurrencesOf(bool (*fn)(const_reference,void*),void* d) const;
Returns the number of elements t in self such that the
expression((*fn)(t,d)) is true. fn points to a user-defined tester
function which must have prototype:
bool yourTester(const_reference a, void* d);
Client data may be passed through parameter d.
bool
remove(const_reference a);
Removes the first element t in self that compares equal to a and returns
true. Returns false if there is no such element.
bool
remove(bool (*fn)(const_reference,void*), void* d);
Removes the first element t in self such that the expression ((*fn)(t,d))
is true and returns true. Returns false if there is no such element. fn
points to a user-defined tester function which must have prototype:
Page 6
RWTValMultiSet(3C++) RWTValMultiSet(3C++)
bool yourTester(const_reference a, void* d);
Client data may be passed through parameter d.
size_type
removeAll(const_reference a);
Removes all elements t in self that compare equal to a. Returns the
number of items removed.
size_type
removeAll(bool (*fn)(const_reference,void*), void* d);
Removes all elements t in self such that the expression ((*fn)(t,d))is
true. Returns the number of items removed. fn points to a user-defined
tester function which must have prototype:
bool yourTester(const_reference a, void* d);
Client data may be passed through parameter d.
multiset<T,C,allocator>&
std();
const multiset<T,C,allocator>&
std() const;
Returns a reference to the underlying C++-standard collection that serves
as the implementation for self. This reference may be used freely,
providing access to the C++-standard interface as well as
interoperability with other software components that make use of the
C++-standard collections.
void
symmetricDifference(const RWTValMultiSet<T,C>& s);
void
symmetricDifference(const container_type& s);
Sets self to the symmetric difference of self and s.
void
Union(const RWTValMultiSet<T,C>& s);
void
Page 7
RWTValMultiSet(3C++) RWTValMultiSet(3C++)
Union(const container_type& s);
Sets self to the union of self and s. Note the use of the uppercase
"U"in Union to avoid conflict with the C++ reserved word.
Related Global Operators
RWvostream&
operator<<(RWvostream& strm, const RWTValMultiSet<T,C>& coll);
RWFile&
operator<<(RWFile& strm, const RWTValMultiSet<T,C>& coll);
Saves the collection coll onto the output stream strm, or a reference to
it if it has already been saved.
RWvistream&
operator>>(RWvistream& strm, RWTValMultiSet<T,C>& coll);
RWFile&
operator>>(RWFile& strm, RWTValMultiSet<T,C>& coll);
Restores the contents of the collection coll from the input stream strm.
RWvistream&
operator>>(RWvistream& strm, RWTValMultiSet<T,C>*& p);
RWFile&
operator>>(RWFile& strm, RWTValMultiSet<T,C>*& p);
Looks at the next object on the input stream strm and either creates a
new collection off the heap and sets p to point to it, or sets p to point
to a previously read instance. If a collection is created off the heap,
then you are responsible for deleting it.
Page 8