Rogue Wave banner
Previous fileTop of DocumentContentsIndex pageNext file
Essential Tools Module User's Guide
Rogue Wave web site:  Home Page  |  Main Documentation Page

6.9 Essential Tools Module Templates and C++ Standard Library Containers

Most of the Essential Tools Module collection class templates use the C++ Standard Library for their underlying implementation. The collection classes of the C++ Standard Library, called containers, act as an engine under the hood of the Essential Tools Module templates.

For example, the Essential Tools Module's value-based, double-ended queue RWTValDeque<T,A> has a member of type deque<T> from the C++ Standard Library. This member serves as the implementation of the collection. Like an engine, it does the bulk of the work of adding and removing elements, and so on. RWTValDeque<T,A> is a wrapper class, like the hood protecting the engine. More than cosmetic, it functions as a simpler, object-oriented interface to the deque class, making it easier and more pleasant to deal with.

Thanks to inlining and the lack of any extra level of indirection, this wrapping incurs few, if any, performance penalties. If you need direct access to the implementation, the wrapper classes offer the member function std(), which returns a reference to the implementation. In addition, because the Rogue Wave template collections supply standard iterators, you can use them with the C++ Standard Library algorithms as if they were C++ Standard Library collections themselves.

6.9.1 The C++ Standard Library Containers

There are seven C++ Standard Library containers: deque, list, vector, set, multiset, map, and multimap. The Essential Tools Module extends these with five additional containers: rw_slist<T,A>, rw_hashset<T,H,EQ,A>, rw_hashmultiset<T,H,EQ,A>, rw_hashmap<K,T,H,EQ,A>, and rw_hashmultimap<K,T,H,EQ,A>. Each of these has value-based and pointer-based Rogue Wave wrapper templates. The Essential Tools Module also offers always-sorted versions, both value-based and pointer-based, of the doubly-linked list and vector collections. The total: 28 new or re-engineered collection class templates, all based on the C++ Standard Library! These are summarized in Table 15.

Table 15: Essential Tools Module Standard Library-Based Templates

Division // Notes Value-based Pointer-based Standard Library Req?
Sequence-based //External ordering, access by index RWTValDlist<T,A> RWTPtrDlist<T,A> No
RWTValDeque<T,A> RWTPtrDeque<T,A> Yes
RWTValOrderedVector<T,A> RWTPtrOrderedVector<T,A> No
RWTValSlist<T,A> RWTPtrSlist<T,A> No
Sorted sequence-based //Internal ordering, access by index RWTValSortedDlist<T,C,A> RWTPtrSortedDlist<T,C,A> Yes
RWTValSortedVector<T,A> RWTPtrSortedVector<T,C,A> No
Associative container-based //Internal ordering, access by key RWTValSet<T,C,A> RWTPtrSet<T,C,A> Yes
(set-based) RWTValMultiSet<T,C,A> RWTPtrMultiSet<T,C,A> Yes
(map-based) RWTValMap<K,T,C,A> RWTPtrMap<K,T,C,A> Yes
RWTValMultiMap<K,T,C,A> RWTPtrMultiMap<K,T,C,A> Yes
Associative hash-based //No ordering, access by key RWTValHashSet<T,H,EQ,A> RWTPtrHashSet<T,H,EQ,A> No
(set-based) RWTValHashMultiSet<T,H,EQ,A> RWTPtrHashMultiSet<T,H,EQ,A> No
(map-based) RWTValHashMap<K,T,H,EQ,A> RWTPtrHashMap<K,T,H,EQ,A> No
RWTValHashMultiMap<K,T,H,EQ,A> RWTPtrHashMap<K,T,H,EQ,A> Yes

6.9.2 Commonality of Interface

To keep things simple and allow you to program with more flexibility, we have implemented common interfaces within the various divisions of standard-library based collection class templates. For example, the RWTPtrSet<T,C,A> and RWTPtrMultiSet<T,C,A> templates have interfaces identical to their value-based cousins; so do the map-based collection classes. All of the Sequence-based collections have nearly identical interfaces within the value and pointer-based subgroups. (An exception here is the set of deque-based classes, which contain push and pop member functions designed to enhance their abstraction of the queue data structure.)

There are advantages and disadvantages to this approach. The disadvantage is that it puts slightly more of the burden on you, the developer, to choose the appropriate collection class. Had we chosen not to provide the insertAt(size_type index) member function for class RWTValOrderedVector<T,A>, we could have enforced the idea that vector-based templates are not a good choice for inserting into the middle of a collection class. Instead, it is up to you to be aware of your choices and use such member functions carefully.

The advantages are that the common interface lowers the learning curve, that it allows flexibility in experimenting with different collections, and that it provides the capability of dealing with the Rogue Wave templates polymorphically via genericity. For a discussion of genericity versus inheritance, see Meyer (1988).

Real-life programming is seldom as neat as the exercises in a data structures textbook. You may find yourself in a situation where it is difficult to balance the trade-offs and determine just which collection class to use. With the common interface, you can easily benchmark code that uses an RWTValDeque<T,A> and later benchmark it again, substituting an RWTValOrderedVector<T,A> or RWTValDlist<T,A>. You can also write class and function templates that are parameterized on the collection class type. For example:

Thanks to the common interface, the above function template will work when instantiated with any of the Rogue Wave Sequence-based templates.



Previous fileTop of DocumentContentsNo linkNext file

Copyright © Rogue Wave Software, Inc. All Rights Reserved.

The Rogue Wave name and logo, and SourcePro, are registered trademarks of Rogue Wave Software. All other trademarks are the property of their respective owners.
Provide feedback to Rogue Wave about its documentation.