RWTPtrMultiSet(3C++)

RWTPtrMultiSet<T,C> - Rogue Wave library class

As shipped in IRIX 6.5.15. Unchanged since IRIX 6.5.

Name
     RWTPtrMultiSet<T,C> - Rogue Wave library class

Synopsis
              #include <rw/tpmset.h>



              RWTPtrMultiSet<T,C> s;

Standard C++ Library Dependent!
     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 allowd


                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.