Rogue Wave banner
Previous fileTop of DocumentContentsIndex pageNext file
Essential Tools Module User's Guide

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

Most of the Essential Tools Module collection class templates use the Standard C++ Library for their underlying implementation. The collection classes of the Standard C++ 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 Standard C++ 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 Standard C++ Library algorithms as if they were Standard C++ Library collections themselves.

6.9.1 The Standard C++ Library Containers

There are seven Standard C++ 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 Standard C++ Library! These are summarized in Table 14.

Table 14: Essential Tools Module Standard Library-Based Templates 

Division
// Notes
Value-based Pointer-based Standard Library Required?

Sequence-based
//External ordering, access by index

RWTValDlist<T,A>

RWTValDeque<T,A>

RWTValOrderedVector<T,A>

RWTValSlist<T,A>

RWTPtrDlist<T,A>

RWTPtrDeque<T,A>

RWTPtrOrderedVector<T,A>

RWTPtrSlist<T,A>

No

Yes

No

No

Sorted sequence-based
//Internal ordering, access by index

RWTValSortedDlist<T,C,A>

RWTValSortedVector<T,A>

RWTPtrSortedDlist<T,C,A>

RWTPtrSortedVector<T,C,A>

Yes

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>

RWTValMultiMap<K,T,C,A>

RWTPtrMap<K,T,C,A>

RWTPtrMultiMap<K,T,C,A>

Yes

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>

RWTValHashMultiMap<K,T,H,EQ,A>

RWTPtrHashMap<K,T,H,EQ,A>

RWTPtrHashMap<K,T,H,EQ,A>

No

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 DocumentContentsIndex pageNext file

©2004 Copyright Quovadx, Inc. All Rights Reserved.
Rogue Wave and SourcePro are registered trademarks of Quovadx, Inc. in the United States and other countries. All other trademarks are the property of their respective owners.
Contact Rogue Wave about documentation or support issues.