home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c221 / 2.ddi / DOC / TOOLS5.DOC < prev   
Encoding:
Text File  |  1992-04-01  |  174.9 KB  |  5,400 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7.  
  8.  
  9.  
  10.  
  11.  
  12.  
  13.  
  14.  
  15.                                   Tools.h++
  16.                                      V5.0
  17.                                   Supplement
  18.  
  19.  
  20.  
  21.  
  22.  
  23.  
  24.  
  25.                               License Agreement
  26.  
  27.           c Copyright Rogue Wave Associates, 1989, 1990, 1991, 1992.
  28.  
  29. This software  package and  its documentation  are subject  to  the following
  30. license agreement.  By opening the diskette package  seal, you are implicitly
  31. accepting these terms and conditions.
  32.  
  33. Permission is given to the buyer of this package to use  this software on one
  34. computer at a time,  make one backup copy,  and make one printed  copy of the
  35. source code.   You may  utilize and/or modify  this program  for use  in your
  36. projects.   You may  distribute and  sell any  executable which  results from
  37. using this code  in your  applications, except a  utility program  of similar
  38. nature to  this  product.   You  may  NOT  redistribute  the source  code  or
  39. resultant object modules or libraries of  object modules in any  form, put it
  40. on a bulletin  board system,  or sell  it.   You may  not use,  copy, modify,
  41. merge, or transfer the  program, or manual or  any portion of the  program or
  42. manual, except as expressly provided above in this agreement.
  43.  
  44. A multi-user license  may be purchased  to allow the  software to be  used on
  45. more than one  computer at  the same  time; including  a shared  disk system.
  46. Contact Rogue Wave for information on site licenses.
  47.  
  48. This material  is  sold  "as is".  Rogue  Wave  makes no  warranties,  either
  49. expressed or implied, regarding  the enclosed computer software  package, its
  50. merchantability, or its  fitness for any  particular purpose.  Information in
  51. this document is subject  to change without notice  and does not  represent a
  52. commitment on the part of Rogue Wave.   While every effort  is made to insure
  53. that the above mentioned product  and its documentation are  free of defects,
  54. Rogue Wave shall not be held responsible for any loss of  profit or any other
  55. commercial  damage,  including  but  not  limited   to  special,  incidental,
  56. consequential or other damages occasioned by the use of this product.
  57.  
  58. It is  assumed  that  purchasers of  this  product  are familiar  with  basic
  59. programming skills (e.g., setting  up a path with  MS-DOS). This is  a highly
  60. technical product,  offered in  a rapidly  evolving  programming environment.
  61. Rogue Wave  recognizes  this  fact,  and  will  provide  limited  support  to
  62. purchasers of this  product for 60  days after its  purchase (of  course, bug
  63. reports and  comments are  always welcome).   Questions  and comments  may be
  64. submitted either by  mail or  telephone.   Rogue Wave  reserves the  right to
  65. respond to questions or comments in writing or by telephone.
  66.  
  67. Rogue Wave acknowledges all trademarks found in this manual and in the source
  68. code documentation.  This acknowledgement includes, but is not limited to:
  69. AT&T/UNIX, Microsoft, MS-DOS, Zortech, Borland, Oregon Software, HCR,
  70. ParcPlace, Smalltalk-80, SCO, Free Software Foundation, Glockenspiel,
  71. Windows.
  72.  
  73.  
  74.  
  75.  
  76.  
  77.                               Table of Contents
  78.  
  79.      Templates.....................................................3
  80.      1.1 Introduction .............................................3
  81.           1.1.1 Enter templates ...................................3
  82.           1.1.2 What's the catch? .................................4
  83.           1.1.3 Factoring out commonality .........................4
  84.      1.2 Naming scheme ............................................5
  85.      1.3 Header files .............................................5
  86.      1.4 Types of templates .......................................6
  87.           1.4.1 Intrusive lists ...................................6
  88.           1.4.2 Value-based collections ...........................6
  89.           1.4.3 Pointer-based collections .........................7
  90.      1.5 An example ...............................................7
  91.      1.6 A more complicated example ...............................9
  92.  
  93.      Class Reference Guide........................................13
  94.      GOrderedVector(val)..........................................14
  95.      RWBench......................................................17
  96.      RWBufferedPageHeap...........................................22
  97.      RWCString....................................................24
  98.      RWDiskPageHeap...............................................32
  99.      RWModel......................................................36
  100.      RWTBitVec<size>..............................................37
  101.      RWTimer......................................................40
  102.      RWTIsvDlist<T>...............................................42
  103.      RWTIsvSlist<T>...............................................46
  104.      RWTQueue<T, C>...............................................50
  105.      RWTStack<T, C>...............................................52
  106.      RWTValDlist<T>...............................................54
  107.      RWTValHashDictionary<K,V>....................................60
  108.      RWTValHashSet<T>.............................................65
  109.      RWTValHashTable<T>...........................................66
  110.      RWTValOrderedVector<T>.......................................69
  111.      RWTValSlist<T>...............................................73
  112.      RWTValSortedVector<T>........................................79
  113.      RWTValVector<T>..............................................83
  114.      RWTValVirtualArray<T>........................................87
  115.      RWVirtualPageHeap............................................91
  116.  
  117.      Appendix A:      Upgrading from V4.0 ........................95
  118.      A.1 Include path has changed ................................95
  119.      A.2 Dropped compilers .......................................95
  120.      A.3 Borland library names changed ...........................95
  121.      A.4 Windows streambuf constructors have changed .............96
  122.      A.5 RWCString replaces RWString .............................96
  123.      A.6 GSortedVector(val) ......................................96
  124.  
  125.  
  126.  
  127.  
  128.  
  129.  
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136.  
  137.                                   Tools.h++
  138.                                      V5.0
  139.  
  140.                                   Supplement
  141.                                     to the
  142.                                   User Guide
  143.  
  144.  
  145.  
  146.  
  147.  
  148.  
  149.  
  150.  
  151.  
  152.  
  153.  
  154.  
  155.  
  156.                                                            S e c t i o n   1 
  157.  
  158.  
  159.                                                                      Templates
  160.                                                     (Source code version only)
  161.  
  162.  
  163.  
  164. 1.1  Introduction
  165.  
  166.  
  167. Ever since Version 2.0, Tools.h++ has traditionally offered two types of
  168. collection classes: the so-called "generic" collection classes and the
  169. Smalltalk-like collection classes.  Each had its advantages and
  170. disadvantages.  The Smalltalk-like classes offer a pleasant programming
  171. interface, code reuse, and a consistent interface.  However, they actually
  172. collect pointers to a common base class (RWCollectable), requiring that all
  173. collected objects inherit from this class -- the actual type of the class is
  174. unknown at runtime.  This requires the programmer to rely on some other kind
  175. of information, either the isA() function or some logical inference, to
  176. decide whether it is safe to "downcast" the pointer to an RWCollectable to a
  177. pointer to the derived class.  Future language extensions1 hold the promise
  178. that such downcasting can at least be standardized by the language.  However,
  179. the programmer will always have to remember to perform the check.  The check
  180. may also fail: an object's inheritance hierarchy may make the type cast
  181. impossible and the prudent programmer must be prepared for this.
  182.  
  183. 1.1.1 Enter templates
  184. Templates, or parameterized types, offer an elegant solution.  Over the next
  185. few years they promise to revolutionize the way we approach C++ programming.
  186. Indeed, 5 years from now the polymorphic collection approach may be just a
  187. footnote in the history of C++ design.
  188. Templates are extremely similar to the existing "generic.h" approach, used by
  189. Rogue Wave's present generic collection classes, which relies on preprocessor
  190. macros to define a family of classes parameterized on a type.  However, a
  191. macro does a lexical substitution in situ, that is at the site of invocation,
  192. making them extremely hard to debug (a single line may be expanded into
  193.  
  194.                     
  195.  
  196. 1 See, for example, Bjarne Stroustrup's article ``Runtime type
  197.   identification'' in the March 1992 issue of The C++ Report.
  198.  
  199.  
  200.  
  201.  
  202.  
  203.  
  204.  
  205.  
  206.                                                                Templates
  207.  
  208. thousands of tokens!).  They are also nasty to write, requiring as they do
  209. that all newlines be escaped with a backslash.
  210. Templates are logically a class declaration parameterized on a type.  They
  211. are a prescription for how a particular type of collection should behave.
  212. For example, a Vector template would describe such things as how to index an
  213. element, how long it is, how to resize, etc.  The actual type of the elements
  214. is independent of these larger, more general issues.
  215. Now if you procede to request a vector of a particular type, say a
  216. Vector<double>, that is, a vector of doubles, then the compiler goes back to
  217. the template declaration and fills it in for the type double.  The effect is
  218. as if you had hand written a class "VectorOfDoubles".  But, of course, you
  219. didn't.  Instead, the compiler automatically generated the logical equivalent
  220. of such a class.  The result is extreme source code reuse.
  221.  
  222. 1.1.2 What's the catch?
  223. Which brings us to the one disadvantage of templates.  It is the source code
  224. that is being reused, not the object code.  A declaration for Vector<double>
  225. gets compiled separately from Vector<int>.  Unless some provisions have been
  226. made by the class designer, the two declarations will generate totally
  227. independent object code, with the potential for bloat of the executable.
  228. Indeed, to some extent, this is unavoidable.  Still, the careful class
  229. designer will recognize points of commonality that do not depend on the
  230. actual type and factor them out.  These are put in a separate "type-
  231. independent" class which can be compiled once, resulting in more
  232. compact code.  A trivial example, one that builds on our discussion of
  233. vectors, might be the vector length.  We might want to declare a
  234. BaseVector class that holds the length of any vector.  We would then
  235. derive the template-based vectors Vector<T> from this.  Of course, the
  236. code required to return the length of a vector is trivial, and so it
  237. turns out that in practice it isn't worth doing this.
  238.  
  239. 1.1.3 Factoring out commonality
  240. For a more substantial example, take a look at the intrusive linked-list
  241. class RWTIsvSlist<T>.  This is a linked list of types T which are required to
  242. inherit from class RWIsvSlink.  This class contains a "next" field,
  243. consisting of a pointer to the next link.  A few moments reflection will
  244. convince you that we don't really need to know the derived type of the link
  245. to actually walk the list.  We need only know that it inherits from
  246. RWIsvSlink.  Furthermore, given an existing link, we don't even need to know
  247. its type to add or remove it from the list!
  248. Hence, all this code can be factored out, compiled once, and forgotten.
  249.  
  250.  
  251.  
  252.  
  253. Rogue Wave              Tools.h++   V 5.0   Supplement  4
  254.  
  255.  
  256.  
  257.  
  258.  
  259.  
  260.  
  261.  
  262.                                                                Templates
  263.  
  264.  
  265. 1.2  Naming scheme
  266.  
  267.  
  268. All of the template class names start with "RWT", followed by a three letter
  269. code:
  270.                Isv             Intrusive lists
  271.                Val             Value-based
  272.                Ptr             Pointer-based
  273.  
  274. Hence, RWTValOrderedVector<T> is a value-based template for an ordered vector
  275. of type T.
  276.  
  277. 1.3  Header files
  278.  
  279.  
  280.  
  281.  
  282.  
  283.  Template class          Description                           Header file
  284.  
  285.  RWTBitVec<size>         Bit vector of length size            <rw/tbitvec.h>
  286.  RWTIsvDlist<T>          Intrusive doubly-linked list of      <rw/tidlist.h>
  287.                          types T
  288.  RWTIsvDlistIterator<T   Iterator for RWTIsvDlist<T>          <rw/tidlist.h>
  289.  >
  290.  RWTIsvSlist<T>          Intrusive singly-linked list of      <rw/tislist.h>
  291.                          types T
  292.  RWTIsvSlistIterator<T   Iterator for RWTIsvSlist<T>          <rw/tislist.h>
  293.  >
  294.  RWTPtrVector<T>         Vector of pointers to T.              <rw/tpvector.h>
  295.  RWTQueue<T,C>           Queue of types T, implemented by     <rw/tqueue.h>
  296.                          class C
  297.  RWTStack<T,C>           Stack of types T, implemented by     <rw/tstack.h>
  298.                          class C
  299.  RWTValDlist<T>          Value-based doubly linked list of    <rw/tvdlist.h>
  300.                          types T.
  301.  RWTValDlistIterator<T   Iterator for RWTValDlist<T>          <rw/tvdlist.h>
  302.  >
  303.  RWTValHashDictionary<   Value-based hash dictionary of keys  <rw/tvhdict.h>
  304.  K,V>                    of type K and values of type V.
  305.  RWTValHashDictionaryI   Iterator for                         <rw/tvhdict.h>
  306.  terator<K,V>            RWTValHashDictionary<K,V>
  307.  
  308.  
  309. Rogue Wave              Tools.h++   V 5.0   Supplement  5
  310.  
  311.  
  312.  
  313.  
  314.  
  315.  
  316.  
  317.  
  318.                                                                Templates
  319.  
  320.  RWTValHashSet<T>        Value-based Set, implemented using   <rw/tvhset.h>
  321.                          a hashed table
  322.  RWTValHashTable<T>      Value-based Bag, implemented using   <rw/tvhasht.h>
  323.                          a hashed table
  324.  RWTValHashTableIterat   Iterator for RWTValHashTable<T>      <rw/tvhasht.h>
  325.  or<T>
  326.  RWTValOrderedVector<T   Ordered collection of types T,       <rw/tvordvec.h>
  327.  >                       implemented as a vector
  328.  RWTValSlist<T>          Value-based singly linked list of    <rw/tvslist.h>
  329.                          types T.
  330.  RWTValSlistIterator<T   Iterator for RWTValSlist<T>          <rw/tvslist.h>
  331.  >
  332.  RWTValSortedVector<T>   Sorted vector of types T,             <rw/tvsrtvec.h>
  333.                          implemented as a vector
  334.  RWTValVector<T>         Vector of types T.                    <rw/tvvector.h>
  335.  RWTValVirtualArray<T>   Virtual array of types T.             <rw/tvrtarry.h>
  336.  
  337.  
  338.  
  339.  
  340. 1.4  Types of templates
  341.  
  342.  
  343.  
  344. 1.4.1 Intrusive lists
  345. For a collection of type T, intrusive lists are lists where type T inherits
  346. directly from the link type itself2.  The results are optimal in space and
  347. time, but require you to honor the inheritance hierarchy.
  348.  
  349. 1.4.2 Value-based collections
  350. Value-based collections copy the object in and out of the collection.  A very
  351. familiar example of a value-based "collection" is the C array:
  352.             int v[100];  /* A 100 element array of ints */
  353.             int i = 7;
  354.             v[2] = i;
  355.  
  356. The statement "v[2] = i" copies the value of i into the array at index 2.
  357. What resides within the array is a distinct copy, separate from the original
  358. object i.
  359.  
  360.                     
  361.  
  362. 2 See Stroustrup, The C++ Programming Language, Second Edition,
  363.   Addison-Wesley, 1991, for a description of intrusive lists.
  364.  
  365. Rogue Wave              Tools.h++   V 5.0   Supplement  6
  366.  
  367.  
  368.  
  369.  
  370.  
  371.  
  372.  
  373.  
  374.                                                                Templates
  375.  
  376. Value-based collections can contain more complicated objects too.  Here's an
  377. example of a vector of RWCStrings:
  378.             /* A 100 element array of RWCStrings: */
  379.             RWTValVector<RWCString> v(100);
  380.             RWCString s("A string");
  381.             v[2] = s;
  382.  
  383. Just as with the array of ints, the statement "v[2] = s" copies the value of
  384. s into the vector at index 2.  The object that lies within the vector is
  385. distinct and separate from the original object s.
  386.  
  387. 1.4.3 Pointer-based collections
  388. The final type of collection, pointer-based, is similar to the Smalltalk-like
  389. collection classes.  The data that gets inserted into the collection is not
  390. the object itself, but rather its address.  That is, a pointer to the data is
  391. inserted.  Now the collection class refers to the original object:
  392.             /* A 100 element array of pointers to RWCStrings: */
  393.             RWTPtrVector<RWCString> v(100);
  394.             RWCString s("A string");
  395.             v[2] = &s;
  396.  
  397. Both the object s and the array element v[2] refer to the same object.
  398. Naturally, this approach requires some care: should the string be deleted the
  399. array element will be left pointing into nonsense.  You must take care that
  400. you are aware of who is responsible for the allocation and deallocation of
  401. objects collected this way.
  402. Neverthless, this type of collection can be appropriate for many situations.
  403. You may need to have the same group of objects referred to in many ways,
  404. requiring that each collection point to the target objects, rather than wholy
  405. contain them.  For example, a collection may refer to a set of "picked"
  406. objects that your graphical program has obtained from a user.  You need to
  407. know which ones must be highlighted.  You can probably think of many other
  408. such examples.
  409.  
  410. 1.5  An example
  411.  
  412.  
  413. It's time to look at an example.  Let's start with a simple one: a vector of
  414. doubles.
  415.             BEGIN FILE: exam1.cpp
  416.           #include <rw/tvvector.h>    // 1
  417.  
  418.           main() {
  419.  
  420.  
  421. Rogue Wave              Tools.h++   V 5.0   Supplement  7
  422.  
  423.  
  424.  
  425.  
  426.  
  427.  
  428.  
  429.  
  430.                                                                Templates
  431.  
  432.             RWTValVector<double> vec(20, 0.0);          // 2
  433.  
  434.             int i;
  435.             for (i=0; i<10; i++) vec[i] = 1.0;          // 3
  436.             for (i=11; i<20; i++) vec(i) = 2.0;         // 4
  437.  
  438.             vec.reshape(30);          // 5
  439.             for (i=21; i<30; i++) vec[i] = 3.0;         // 6
  440.             return 0;
  441.           }
  442.             END FILE
  443.  
  444. Each program line is detailed below.
  445.           1  This is where the template for RWTValVector<T> is defined.
  446.           2  A vector of doubles, 20 elements long and initialized to 0.0 is
  447.              defined.
  448.           3  The first 10 elements of the vector are set to 1.0.  Here,
  449.              RWValVector<double>::operator[](int) has been used.  This
  450.              operator always performs a bounds check on its argument.
  451.           4  The next 10 elements of the vector are set to 2.0.  In this case
  452.              RWValVector<double>::operator()(int) has been used.  This
  453.              operator generally does not perform a bounds check.
  454.  
  455.  
  456. For all Rogue Wave classes, operator[](int) always performs a bounds check on
  457. its argument.
  458.  
  459.  
  460. Some classes also support operator()(int).  Bounds checking is generally not
  461. performed for this operator unless you define RWBOUNDS_CHECK before including
  462. the header file.
  463.  
  464.  
  465.           5  Member function reshape(int) changes the length of the vector.
  466.  
  467.  
  468.  
  469.  
  470.  
  471.  
  472.  
  473.  
  474.  
  475.  
  476.  
  477. Rogue Wave              Tools.h++   V 5.0   Supplement  8
  478.  
  479.  
  480.  
  481.  
  482.  
  483.  
  484.  
  485.  
  486.                                                                Templates
  487.  
  488.  
  489.  
  490. If a vector is lengthened using reshape(int), then the values of the new
  491. elements are undefined.
  492.  
  493.  
  494. If a vector is lengthened using resize(int), then the new values are
  495. initialized to something sensible, generally zero or blanks.
  496.  
  497.  
  498. All Rogue Wave vectors work this way.
  499.  
  500.  
  501. 6    Finally, the last 10 elements are initialized to 3.0.
  502.  
  503. 1.6  A more complicated example
  504.  
  505.  
  506. Here's another example, this one involving a hashing dictionary.
  507.           BEGIN FILE: exam2.cpp
  508.           #include <rw/tvhdict.h>
  509.           #include <rw/cstring.h>
  510.           #include <iostream.h>
  511.           #include <iomanip.h>
  512.  
  513.           class Count {               // 1
  514.             int           N;
  515.           public:
  516.             Count() : N(0){ }         // 2
  517.             int           operator++()  { return ++N; } // 3
  518.             operator      int() { return N; }           // 4
  519.           };
  520.  
  521.           unsigned hashString ( const RWCString& str )  // 5
  522.             { return str.hash(); }
  523.  
  524.           main() {
  525.  
  526.             RWTValHashDictionary<RWCString,Count> map(hashString);    // 6
  527.  
  528.             RWCString token;
  529.             while ( cin >> token )    // 7
  530.               ++map[token];                             // 8
  531.  
  532.  
  533. Rogue Wave              Tools.h++   V 5.0   Supplement  9
  534.  
  535.  
  536.  
  537.  
  538.  
  539.  
  540.  
  541.  
  542.                                                                Templates
  543.  
  544.             RWTValHashDictionaryIterator<RWCString,Count> next(map);  // 9
  545.  
  546.             cout.setf(ios::left, ios::adjustfield);    // 10
  547.             while ( ++next )          // 11
  548.               cout << setw(20) << next.key()
  549.                 << " " << setw(10) << next.value() << endl;// 12
  550.  
  551.             return 0;
  552.           }
  553.           END FILE
  554.  
  555. Program input:
  556.           How much wood could a woodchuck chuck if a woodchuck could chuck
  557.           wood ?
  558.  
  559. Program output:
  560.           much                 1
  561.           wood                 2
  562.           a                    2
  563.           if                   1
  564.           woodchuck            2
  565.           could                2
  566.           chuck                2
  567.           How                  1
  568.           ?                    1
  569.  
  570. The problem is to read an input file, break it up into tokens separated
  571. by whitespace, count the number of occurences of each token and print
  572. the results.  The general approach is to use a dictionary to map each
  573. token to its respective count.  Here's a line-by-line description:
  574.           1  This is a class used as the value part of the dictionary.
  575.           2  A default constructor is supplied that zeroes out the count.
  576.           3  We supply a prefix increment operator.  This will be used to
  577.              increment the count in a convenient and pleasant way.
  578.           4  A conversion operator is supplied that allows Count to be
  579.              converted to an int.  This will be used to print the results.
  580.              Alternatively, we could have supplied an overloaded operator<<()
  581.              to teach a Count how to print itself, but this is easier.
  582.           5  This is a function that must be supplied to the dictionary
  583.              constructor.  Its job is to return a hash value given an
  584.              argument of the type of the key.
  585.           6  Here the dictionary is constructed.  Given a key, the dictionary
  586.              will be used to look up a value.  In this case, the key will be
  587.              of type RWCString, the value of type Count.  The constructor
  588.  
  589. Rogue Wave              Tools.h++   V 5.0   Supplement  10
  590.  
  591.  
  592.  
  593.  
  594.  
  595.  
  596.  
  597.  
  598.                                                                Templates
  599.  
  600.              requires a single argument: a pointer to a function that will
  601.              return a hash value, given a key.  This function was defined on
  602.              line 5 above.
  603.           7  Tokens are read from the input stream into a RWCString.  This
  604.              will continue until an EOF is encountered.  How does this work?
  605.              The expression "cin >> token" reads a single token and returns
  606.              an ostream&.  Class ostream has a type conversion operator to
  607.              void* which is what the while loop will actually be testing.
  608.              Operator void* returns "this" if the stream state is "good",
  609.              otherwise zero.  Because an EOF causes the stream state to turn
  610.              to "not good", the while loop will be broken when an EOF is
  611.              encountered.  See the RWCString entry in the class reference
  612.              guide and the ios entry in the class reference guide that comes
  613.              with your compiler for more details.
  614.           8  Here's where all the magic occurs.  Object map is the
  615.              dictionary.  It has an overloaded operator[] that takes an
  616.              argument of the type of the key and returns a reference to its
  617.              associated value.  Recall that the type of the value is a Count.
  618.              Hence, map[token] will be of type Count.  As we saw on line 3,
  619.              Count has an overloaded prefix increment operator.  This is
  620.              invoked on the Count, thereby increasing its value.
  621.              What if the key isn't in the dictionary?  Then the overloaded
  622.              operator[] will insert it, along with a brand new value built
  623.              using the default constructor of the value's class.  This was
  624.              defined on line 2 to initialize the count to zero.
  625.           9  Now it comes time to print the results.  We start by defining an
  626.              iterator that will sweep over the dictionary, returning each key
  627.              and value.
  628.           10 The "field width" of the output stream is adjusted to make
  629.              things pretty.
  630.           11 The iterator is advanced until it reaches the end of the
  631.              collection.  For all template iterators, the prefix increment
  632.              operator advances the iterator then tests whether it has gone
  633.              past the end of the collection.
  634.           12 The key and value at the position of the iterator are printed.
  635.  
  636.  
  637.  
  638.  
  639.  
  640.  
  641.  
  642.  
  643.  
  644.  
  645. Rogue Wave              Tools.h++   V 5.0   Supplement  11
  646.  
  647.  
  648.  
  649.  
  650.  
  651.  
  652.  
  653.  
  654.  
  655.  
  656.  
  657.  
  658.  
  659.  
  660.  
  661.  
  662.  
  663.                                   Tools.h++
  664.                                      V5.0
  665.  
  666.                                   Supplement
  667.                                     to the
  668.                             Class Reference Guide
  669.  
  670.  
  671.  
  672.  
  673.  
  674.  
  675.  
  676.  
  677.  
  678.  
  679. GOrderedVector(val)GOrderedVector(val)
  680.  
  681.  
  682.  
  683.  
  684.  
  685. Synopsis     #include <rw/gordvec.h>
  686.              declare(GVector,val)
  687.              declare(GOrderedVector,val)
  688.              implement(GVector,val)
  689.              implement(GOrderedVector,val)
  690.  
  691.              GOrderedVector(val) v; // Ordered vector of objects of type val.
  692.  
  693.  
  694. DescriptionClass GOrderedVector(val) represents an ordered collection of
  695.            objects of type val.  Objects are ordered by the order of
  696.            insertion and are accessible by index.  Duplicates are allowed.
  697.            GorderedVector(val) is implemented as a vector, using macros
  698.            defined in the standard C++ header file <generic.h>.
  699.            To use this class you must declare and implement its base class as
  700.            well as the class itself.  For example, here is how you declare and
  701.            implement an ordered collection of doubles:
  702.           declare(GVector,double)     // Declare base class
  703.           declare(GOrderedVector,double)// Declare ordered vector
  704.  
  705.           // In one and only one .cpp file you must put the following:
  706.           implement(GVector,double)   // Implement base class
  707.           implement(GOrderedVector,double)// Implement ordered vector
  708.  
  709.           For each type of GOrderedVector you must include one (and only
  710.           one) call to the macro implement somewhere in your code for
  711.           both the GOrderedVector itself and for its base class GVector.
  712. Example
  713.  
  714. Here's an example that uses an ordered vector of RWCStrings.
  715.           BEGIN FILE: gordvec.cpp
  716.           #include <rw/gordvec.h>
  717.           #include <rw/cstring.h>
  718.           #include <rw/rstream.h>
  719.  
  720.           declare(GVector,RWCString)
  721.           declare(GOrderedVector,RWCString)
  722.           implement(GVector,RWCString)
  723.           implement(GOrderedVector,RWCString)
  724.  
  725.  
  726.  
  727.  
  728.  
  729.  
  730.  
  731.  
  732.                                                      GOrderedVector(val)
  733.  
  734.  
  735.  
  736.           main()
  737.           {
  738.             GOrderedVector(RWCString) vec;
  739.  
  740.             RWCString one("First");
  741.             vec.insert(one);
  742.  
  743.             vec.insert("Second");// Automatic type conversion occurs
  744.             vec.insert("Last");// Automatic type conversion occurs
  745.  
  746.             for(int i=0; i<vec.length(); i++)  cout << vec[i] << NL;
  747.  
  748.             return 0;
  749.           }
  750.           END FILE
  751.  
  752. Program output:
  753.  
  754.           First
  755.           Second
  756.           Last
  757.  
  758. Public      GOrderedVector(val)(unsigned capac=RWDEFAULT_CAPACITY);
  759. constructors
  760.  
  761.  
  762.         Construct an ordered vector of elements of type val.  The initial
  763.         capacity of the vector will be capac whose default value is
  764.         RWDEFAULT_CAPACITY.  The capacity will be automatically increased as
  765.         necessary should too many items be inserted, a relatively expensive
  766.         process because each item must be copied into the new storage.
  767.  
  768. Public member  val               operator()(int i) const;
  769. functions      val&              operator()(int i);
  770.  
  771.  
  772.         Return the i'th value in the vector.  The index i must be between 0
  773.         and the length of the vector less one.  No bounds checking is
  774.         performed.
  775.  
  776.  
  777.  
  778.  
  779. Rogue Wave              Tools.h++   V 5.0   Supplement  15
  780.  
  781.  
  782.  
  783.  
  784.  
  785.  
  786.  
  787.  
  788.                                                      GOrderedVector(val)
  789.  
  790.  
  791.           val     operator[](int i) const;
  792.           val&    operator[](int i);
  793.        Return the i'th value in the vector.  The index i must be between 0
  794.        and the length of the vector less one.  Bounds checking will be
  795.        performed.
  796.           void    clear();
  797.        Remove all items from the collection.
  798.           unsignedentries() const;
  799.        Return the number of items currently in the collection.
  800.           int     index(val item) const;
  801.        Performs a linear search of the collection returning the index of the
  802.        first item that isEqual to the argument item.  If no item is found,
  803.        then it returns -1.
  804.           void    insert(val item);
  805.        Add the new value item to the end of the collection.
  806.           void    insertAt(int indx, val item);
  807.        Add the new value item to the collection at position indx.  The value
  808.        of indx must be between zero and length of the collection.  Old items
  809.        from index indx upwards will be shifted to higher indices.  E.g., the
  810.        old item at position indx will be moved to position indx+1, etc.
  811.           RWBoolean      isEmpty() const;
  812.        Return TRUE if the collection has no entries.  FALSE otherwise.
  813.           unsignedlength() const;
  814.        Return the number of items in the collection.
  815.           void    removeAt(int indx);
  816.        Remove the item at position indx from the collection.  The value of
  817.        indx must be between zero and the length of the collection less one.
  818.        Old items from index indx+1 will be shifted to lower indices.  E.g.,
  819.        the item at index indx+1 will be moved to position indx, etc.
  820.           void    resize(unsigned newCapacity);
  821.        Change the capacity of the collection to newCapacity, which must be at
  822.        least as large as the present number of items in the collection.  Note
  823.        that the actual number of items in the collection does not change,
  824.        just the capacity.
  825.  
  826.  
  827.  
  828.  
  829.  
  830.  
  831.  
  832.  
  833.  
  834.  
  835. Rogue Wave              Tools.h++   V 5.0   Supplement  16
  836.  
  837.  
  838.  
  839.  
  840.  
  841.  
  842.  
  843.  
  844.  
  845.  
  846.  
  847. RWBenchRWBench
  848.  
  849.  
  850. Synopsis  #include <rw/bench.h>
  851.           (Abstract base class)
  852.  
  853.  
  854. Descrip-  This is an abstract class that can automate the process of
  855.           benchmarking a piece of code.  To use it, derive a class from RWBench
  856. tion      including a definition for the virtual function doLoop(unsigned long
  857.           N).  This function should perform N operations of the type that you
  858.           are trying to benchmark.  RWBench will call doLoop() over and over
  859.           again until a preset amount of time has elapsed.  It will then sum
  860.           the total number of operations performed.
  861.          To run, construct an instance of your derived class and then call
  862.          go().  Then call report() to get a standard summary.  For many
  863.          compilers, this summary will automatically include the compiler type
  864.          and memory model.  You can call ops(), outerLoops(), etc. for more
  865.          detail.
  866.          If you wish to correct for overhead, then provide an idleLoop()
  867.          function which should do non-benchmark related calculations.
  868. Example   This example benchmarks the time required to return a hash
  869.           value for a Rogue Wave string versus a Borland string.
  870.  
  871.           BEGIN FILE: bench.cpp
  872.  
  873.           #define RWNO_STD_TYPEDEFS 1
  874.           #include <rw/bench.h>                                  /* Benchmark
  875.           software */
  876.           #include <rw/cstring.h>/* Rogue Wave string class */
  877.           #include <strng.h>      /* Borland string class */
  878.           #include <stdlib.h>
  879.  
  880.           // The string to be hashed:
  881.           const char* cs = "A 22 character string.";
  882.  
  883.           class TestBCCString : public RWBench {
  884.           public:
  885.             TestBCCString() { }
  886.             virtual void   doLoop(unsigned long n);
  887.             virtual void   idleLoop(unsigned long n);
  888.             virtual void   what(ostream& s) const
  889.               { s << "Borland hashing string \"" << cs << "\"\n"; }
  890.           };
  891.  
  892.  
  893.  
  894.  
  895.  
  896.  
  897.  
  898.  
  899.  
  900.                                                                  RWBench
  901.  
  902.  
  903.           class TestRWCString : public RWBench {
  904.           public:
  905.             TestRWCString() { }
  906.             virtual void   doLoop(unsigned long n);
  907.             virtual void   idleLoop(unsigned long n);
  908.             virtual void   what(ostream& s) const
  909.               { s << "Rogue Wave hashing string \"" << cs << "\"\n"; }
  910.           };
  911.  
  912.           main(int argc, char* argv[])
  913.           {
  914.             cout << "Testing string \"" << cs << "\"\n\n";
  915.  
  916.             // Test Borland strings:
  917.             TestBCCString bccstring;
  918.             bccstring.parse(argc, argv);
  919.             bccstring.go();
  920.             bccstring.report(cout);
  921.  
  922.             // Test RW Strings:
  923.             TestRWCString rwstring;
  924.             rwstring.parse(argc, argv);
  925.             rwstring.go();
  926.             rwstring.report(cout);
  927.  
  928.             return 0;
  929.           }
  930.  
  931.           void TestBCCString::doLoop(unsigned long n){
  932.             String string(cs);
  933.             hashValueType h;
  934.             while(n--){
  935.               h = string.hashValue();
  936.             }
  937.           }
  938.  
  939.           void TestRWCString::doLoop(unsigned long n){
  940.             RWCString string(cs);
  941.             unsigned h;
  942.             while(n--){
  943.               h = string.hash();
  944.             }
  945.           }
  946.  
  947.  
  948. Rogue Wave              Tools.h++   V 5.0   Supplement  18
  949.  
  950.  
  951.  
  952.  
  953.  
  954.  
  955.  
  956.  
  957.  
  958.                                                                  RWBench
  959.  
  960.  
  961.           void TestBCCString::idleLoop(unsigned long n){
  962.             String string(cs); // Subtract out constructor time
  963.             hashValueType h;
  964.             while(n--){ /* No-op */ }
  965.           }
  966.  
  967.           void TestRWCString::idleLoop(unsigned long n){
  968.             RWCString string(cs);// Subtract out constructor time
  969.             unsigned h;
  970.             while(n--){ /* No-op */ }
  971.           }
  972.           END FILE
  973.  
  974. Program output:
  975.  
  976.           Testing string "A 22 character string."
  977.  
  978.           Borland C++ V3.0 Large memory model.
  979.  
  980.           Borland hashing string "A 22 character string."
  981.  
  982.           Iterations:                 163
  983.           Inner loop operations:      1000
  984.           Total operations:           163000
  985.           Elapsed (user) time:        4.945055
  986.           Kilo-operations per second: 32.962222
  987.  
  988.           Borland C++ V3.0 Large memory model.
  989.  
  990.           Rogue Wave hashing string "A 22 character string."
  991.  
  992.           Iterations:                 417
  993.           Inner loop operations:      1000
  994.           Total operations:           417000
  995.           Elapsed (user) time:        4.835165
  996.           Kilo-operations per second: 86.243182
  997.  
  998. Public    RWBench(double duration = 5, unsigned long ILO=1000,
  999. constructors          const char* machine = 0);
  1000.  
  1001.  
  1002.  
  1003.  
  1004.  
  1005.  
  1006. Rogue Wave              Tools.h++   V 5.0   Supplement  19
  1007.  
  1008.  
  1009.  
  1010.  
  1011.  
  1012.  
  1013.  
  1014.  
  1015.  
  1016.                                                                  RWBench
  1017.  
  1018.  
  1019.           The parameter duration is the nominal amount of time that the
  1020.           benchmark should take in seconds.  The virtual function
  1021.           doLoop(unsigned long) will be called over and over again until at
  1022.           least this amount of time has elapsed.  The parameter ILO is the
  1023.           number of "inner loop operations" that should be performed.  This
  1024.           parameter will be passed in as parameter N to doLoop(N).
  1025.           Parameter machine is an optional zero terminated string that
  1026.           should describe the test environment (perhaps the hardware the
  1027.           benchmark is being run on ).
  1028.  
  1029. Public     virtual void      doLoop(unsigned long N)=0;
  1030. member
  1031. functions
  1032.  
  1033.  
  1034.        A pure virtual function whose actual definition should be supplied by
  1035.        the specializing class. This function will be repeatedly called until
  1036.        a time duration has elapsed.  It should perform the operation to be
  1037.        benchmarked N times.  See the example.
  1038.           double  duration() const;
  1039.        Return the current current setting for the benchmark test duration.
  1040.        This should not be confused with function time() which returns the
  1041.        actual test time.
  1042.           virtual void   go();
  1043.        Call this function to actually run the benchmark.
  1044.           virtual void   idleLoop(unsigned long N);
  1045.        This function can help to correct the benchmark for overhead.  The
  1046.        default definition merely executes a "for()" loop N times.  See the
  1047.        example.
  1048.           virtual void   parse(int argc, char* argv[]);
  1049.        This function allows an easy way to change the test duration, number
  1050.        of inner loops and machine description from the command line:
  1051.                Argument   Type              Description
  1052.  
  1053.                argv[1]    double            Duration (sec.)
  1054.                argv[2]    unsigned long     No. of inner loops
  1055.                argv[3]    const char*       Machine
  1056.  
  1057.           virtual void   report(ostream&) const;
  1058.        Calling this function provides an easy and convenient way of getting
  1059.        an overall summary of the results of a benchmark.
  1060.           double  setDuration(double t);
  1061.        Change the test duration to time t.
  1062.  
  1063.  
  1064. Rogue Wave              Tools.h++   V 5.0   Supplement  20
  1065.  
  1066.  
  1067.  
  1068.  
  1069.  
  1070.  
  1071.  
  1072.  
  1073.  
  1074.                                                                  RWBench
  1075.  
  1076.  
  1077.           unsigned long  setInnerLoops(unsigned long N);
  1078.        Change the number of "inner loop operations" to N.
  1079.           virtual void   what(ostream&) const;
  1080.        You can supply a specializing version of this virtual function that
  1081.        provides some detail of what is being benchmarked.  It is called by
  1082.        report() when generating a standard report.
  1083.           void    where(ostream&) const;
  1084.        This function will print information to the stream about the compiler
  1085.        and memory model that the code was compiled under.
  1086.           unsigned long  innerLoops() const;
  1087.        Returns the current setting for the number of inner loop operations
  1088.        that will be passed into function doLoop(unsigned long N) as parameter
  1089.        N.
  1090.           double  time() const;
  1091.        Returns the amount of time the benchmark took, corrected for overhead.
  1092.           unsigned long  outerLoops() const;
  1093.        Returns the number of times the function doLoop() was called.
  1094.           double  ops() const;
  1095.        Returns the total number of inner loop operations that were performed
  1096.        (the product of the number of times outerLoop() was called times the
  1097.        number of inner loop operations performed per call).
  1098.           double  opsRate() const;
  1099.        Returns the number of inner loop operations per second.
  1100.  
  1101.  
  1102.  
  1103.  
  1104.  
  1105.  
  1106.  
  1107.  
  1108.  
  1109.  
  1110.  
  1111.  
  1112.  
  1113.  
  1114.  
  1115.  
  1116.  
  1117.  
  1118.  
  1119.  
  1120.  
  1121.  
  1122. Rogue Wave              Tools.h++   V 5.0   Supplement  21
  1123.  
  1124.  
  1125.  
  1126.  
  1127.  
  1128.  
  1129.  
  1130.  
  1131.  
  1132.  
  1133. RWBufferedPageHeapRWBufferedPageHeap                       RWBufferedPageHeap
  1134.                                                                    |
  1135.                                                            RWVirtualPageHeap
  1136.  
  1137.  
  1138.  
  1139. Synopsis  #include <rw/bufpage.h>
  1140.           (Abstract base class)
  1141.  
  1142.  
  1143. Descripti This is an abstract base class that represents an abstract
  1144. on        page heap buffered through a set of memory buffers.  It
  1145.           inherits from the abstract base class RWVirtualPageHeap which
  1146.           represents an abstract page heap.
  1147.           RWBufferedPageHeap will supply and maintain a set of memory
  1148.           buffers.  Specializing classes should supply the actual
  1149.           physical mechanism to swap pages in and out of these buffers
  1150.           by supplying definitions for the pure virtual functions
  1151.           swapIn(RWHandle, void*) and swapOut(RWHandle, void*).
  1152.           The specializing class should also supply appropriate definitions
  1153.           for the public functions allocate() and deallocate(RWHandle).
  1154.          For a sample implementation of a specializing class, see class
  1155.          RWDiskPageHeap.
  1156. Public    RWBufferedPageHeap(unsigned pgsize, unsigned nbufs=10);
  1157. constructo
  1158. r
  1159.  
  1160.  
  1161.           Constructs a buffered page heap with page size pgsize.  The number
  1162.           of buffers (each of size pgsize) that will be allocated to the
  1163.           heap will be nbufs.  If there is insufficient memory to satisfy
  1164.           the request, then the state of the resultant object as returned by
  1165.           member function isValid() will be FALSE, otherwise, TRUE.
  1166.  
  1167. Protected virtual RWBoolean swapIn(RWHandle h, void* buf)  = 0;
  1168. member    virtual RWBoolean swapOut(RWHandle, h void* buf) = 0;
  1169. functions
  1170.  
  1171.  
  1172.           It is the responsibility of the specializing class to supply
  1173.           definitions for these two pure virtual functions.  Function
  1174.           swapOut() should copy the page with handle h from the buffer
  1175.           pointed to buf to the swapping medium.  Function swapIn() should
  1176.           copy the page with handle h into the buffer pointed to by buf.
  1177.  
  1178.  
  1179.  
  1180.  
  1181.  
  1182.  
  1183.  
  1184.  
  1185.                                                       RWBufferedPageHeap
  1186.  
  1187.  
  1188. Public    virtual RWHandle  allocate() = 0;
  1189. member
  1190. functions
  1191.  
  1192.  
  1193.           It is the responsibility of the specializing class to supply a
  1194.           definition for this pure virtual function.  The specializing class
  1195.           should allocate a page and return a unique handle for it.  It should
  1196.           return zero if it cannot satisfy the request.  The size of the page
  1197.           is set by the constructor.
  1198.           virtual ~RWBufferedPageHeap();
  1199.        Deallocates all internal buffers.
  1200.  
  1201.           RWBoolean      isValid();
  1202.        Returns TRUE if self is in a valid state.  A possible reason why the
  1203.        object might not be valid is insufficient memory to allocate the
  1204.        internal buffers.
  1205.  
  1206.           virtual void   deallocate(RWHandle h);
  1207.        Redefined from class RWVirtualPageHeap.  It is never an error to call
  1208.        this function with argument zero.  Even though this is not a pure
  1209.        virtual function, it is the responsibility of the specializing class
  1210.        to supply an appropriate definition for this function.  All this
  1211.        definition does is release any buffers associated with the handle h.
  1212.        Just as the actual page allocation is done by the specializing class
  1213.        through virtual function allocate(), so must the actual deallocation
  1214.        be done by overriding deallocate().
  1215.           virtual void   dirty(RWHandle h);
  1216.        Redefined from class RWVirtualPageHeap.
  1217.           virtual void*  lock(RWHandle h);
  1218.        Redefined from class RWVirtualPageHeap.
  1219.           virtual void   unlock(RWHandle h);
  1220.        Redefined from class RWVirtualPageHeap.
  1221.  
  1222.  
  1223.  
  1224.  
  1225.  
  1226.  
  1227.  
  1228.  
  1229.  
  1230.  
  1231.  
  1232. Rogue Wave              Tools.h++   V 5.0   Supplement  23
  1233.  
  1234.  
  1235.  
  1236.  
  1237.  
  1238.  
  1239.  
  1240.  
  1241.  
  1242.  
  1243. RWCStringRWCString
  1244.  
  1245.  
  1246.  
  1247.  
  1248.  
  1249. Synopsis  #include <cstring.h>
  1250.           RWCString a;
  1251.  
  1252.  
  1253. Description  Class RWCString replaces class RWString, used in previous
  1254.           versions of Tools.h++.  It is very similar, the only difference
  1255.           being that its copy constructor and assignment operator use copy
  1256.           semantics, rather than reference semantics.
  1257.           The class is implemented using a technique called copy on write.
  1258.           With this technique, the copy constructor and assignment operators
  1259.           still reference the old object and hence are very fast.  An actual
  1260.           copy is made only when a "write" is performed, that is if the object
  1261.           is about to be changed.  The net result is excellent performance,
  1262.           but with easy to understand copy semantics.
  1263.          A separate RWCSubString class supports substring extraction and
  1264.          modification operations.
  1265.           Note that if compilers implemented type conversion correctly, some
  1266.           of the operators below would not be necessary.  Experience has
  1267.           proven otherwise.
  1268.  
  1269. Example
  1270.  
  1271.           #include <rw/cstring.h>
  1272.           #include <rw/regexp.h>
  1273.           #include <rw/rstream.h>
  1274.  
  1275.           main()
  1276.           {
  1277.             RWCString a("There is no joy in Beantown.");
  1278.  
  1279.             RWRegexp re("[A-Z][a-z]*town");// Any capitalized "town"
  1280.             a(re) = "Redmond";
  1281.             cout << a << NL;
  1282.           }
  1283. Program output:
  1284.              There is no joy in Redmond.
  1285.  
  1286.  
  1287.  
  1288.  
  1289.  
  1290.  
  1291.  
  1292.  
  1293.                                                                RWCString
  1294.  
  1295.  
  1296. Public    RWCString();
  1297. construct
  1298. ors
  1299.  
  1300.  
  1301.           Constructs a RWCString with zero characters (the null string).
  1302.           RWCString(const char* cs);
  1303.        Conversion from  a null-terminated character string.  The created
  1304.        string will copy the data pointed to by cs.
  1305.           RWCString(const char* cs, int N);
  1306.        Constructs a string from the (possibly) null terminated character
  1307.        string cs.  The created string will copy the data pointed to by cs.
  1308.        At most N characters (not including the terminating null) will be
  1309.        copied.
  1310.           RWCString(const RWCString& str);
  1311.        Copy constructor.  The created string will copy str's data.
  1312.           RWCString(const RWCSubString& ss);
  1313.        Conversion from sub-string.  The created string will copy the
  1314.        substring represented by ss.
  1315.           RWCString(unsigned N, char c = ' ');
  1316.        Constructs a RWCString with N characters, all initialized to the
  1317.        character c (default blank).
  1318.  
  1319. Type      operator          const char*() const;
  1320. conversion
  1321.  
  1322.  
  1323.           Returns self as a null-terminated string.
  1324.  
  1325. AssignmentRWCString&        operator=(const RWCString& str);
  1326. operators
  1327.  
  1328.  
  1329.           Assignment operator.  The string will copy str's data.
  1330.           RWCString&     operator+=(const RWCString& str);
  1331.        Append the string str to self.
  1332.           RWCString&     operator+=(const char* cs);
  1333.        Append the character string pointed to by cs to self.
  1334.  
  1335. Indexing  char&             operator[](int i);
  1336. operators
  1337.  
  1338.  
  1339.  
  1340. Rogue Wave              Tools.h++   V 5.0   Supplement  25
  1341.  
  1342.  
  1343.  
  1344.  
  1345.  
  1346.  
  1347.  
  1348.  
  1349.                                                                RWCString
  1350.  
  1351.  
  1352.        Return the i'th character.  The result can be used as an lvalue.
  1353.        The index i must be between 0 and the length of the string less
  1354.        one.  Bounds checking is performed -- if the index is out of
  1355.        range then an exception with error TOOL_INDEX will occur.
  1356.           char    operator[](int i) const;
  1357.        Return the i'th character.  The index i must be between 0 and the
  1358.        length of the string less one.  Bounds checking is performed -- if the
  1359.        index is out of range then an exception with error TOOL_INDEX will
  1360.        occur.
  1361.           char&   operator()(int);
  1362.        Return the i'th character.  The result can be used as an lvalue.  The
  1363.        index i must be between 0 and the length of the string less one.
  1364.        Bounds checking is performed if the pre-processor macro BOUNDS_CHECK
  1365.        has been defined before including rwstring.h.  In this case, if the
  1366.        index is out of range, then an exception with error TOOL_INDEX will
  1367.        occur.
  1368.           char    operator()(int) const;
  1369.        Return the i'th character.  The index i must be between 0 and the
  1370.        length of the string less one.  Bounds checking is performed if the
  1371.        pre-processor macro BOUNDS_CHECK has been defined before including
  1372.        rwstring.h.  In this case, if the index is out of range, then an
  1373.        exception with error TOOL_INDEX will occur.
  1374.           RWCSubString   operator()(int start, unsigned len);
  1375.        Substring operator.  Returns a RWCSubString of self with length len,
  1376.        starting at index start.  The results can be used as an lvalue.  If
  1377.        the library was built using the DEBUG flag, and start and len are out
  1378.        of range, then an exception will occur with error TOOL_SUBSTRING.
  1379.           const RWCSubString  operator()(int start, unsigned len) const;
  1380.        Returns a RWCSubString of self with length len, starting at index
  1381.        start.  The results cannot be used as an lvalue.  If the library was
  1382.        built using the DEBUG flag, and start and len are out of range, then
  1383.        an exception will occur with error TOOL_SUBSTRING.
  1384.           RWCSubString   operator()(const RWRegexp& re, int start=0);
  1385.        Returns the first substring starting after index start that matches
  1386.        the regular expression re.  If there is no such substring, then the
  1387.        null substring is returned.  The results can be used as an lvalue.
  1388.           const RWCSubString  operator()(const RWRegexp& re, int start=0)
  1389.           const;
  1390.        Returns the first substring starting after index start that matches
  1391.        the regular expression re.  If there is no such substring, then the
  1392.        null substring is returned.  The results cannot be used as an lvalue.
  1393.  
  1394.  
  1395.  
  1396. Rogue Wave              Tools.h++   V 5.0   Supplement  26
  1397.  
  1398.  
  1399.  
  1400.  
  1401.  
  1402.  
  1403.  
  1404.  
  1405.                                                                RWCString
  1406.  
  1407.  
  1408.  
  1409. Logical   RWBoolean         operator==(const char*) const;
  1410. operators RWBoolean         operator!=(const char*) const;
  1411.           RWBoolean         operator==(const RWCString&) const;
  1412.           RWBoolean         operator!=(const RWCString&) const;
  1413.  
  1414.           Logical equality and inequality.  Case sensitivity is set by the
  1415.           static member function setCaseSensitive().
  1416.           RWBoolean      operator>(const char*) const;
  1417.           RWBoolean      operator<(const char*) const;
  1418.           RWBoolean      operator>=(const char*) const;
  1419.           RWBoolean      operator<=(const char*) const;
  1420.           RWBoolean      operator>(const RWCString&) const;
  1421.           RWBoolean      operator<(const RWCString&) const;
  1422.           RWBoolean      operator>=(const RWCString&) const;
  1423.           RWBoolean      operator<=(const RWCString&) const;
  1424.        Other logical operators.  Comparisons are done lexicographically.
  1425.        Case sensitivity is set by the static member function
  1426.        setCaseSensitive().
  1427.  
  1428. Public   RWCString&         append(const char* cs, unsigned N);
  1429. member
  1430. functions
  1431.  
  1432.  
  1433.        Append the (possibly) null terminated character string cs to self.  At
  1434.        most, the first N characters of the string (not including the
  1435.        terminating null) will be used.  A copy of cs will be made.
  1436.           unsignedbinaryStoreSize() const;
  1437.        Returns the number of bytes necessary to store the object using the
  1438.        function RWCString::saveOn(RWFile&).
  1439.           int     compareTo(const RWCString& str) const;
  1440.        Returns an int less than, greater than, or equal to zero depending on
  1441.        whether self is less than, greater than, or equal to the string str.
  1442.        The comparisons are done lexicographically.  Case sensitivity is set
  1443.        by the static member function setCaseSensitive().
  1444.           RWBoolean      contains(const char* cs) const;
  1445.        Pattern matching.  Returns TRUE if the string pointed to by cs occurs
  1446.        in self.  Case sensitivity is set by the static member function
  1447.        setCaseSensitive().
  1448.           RWBoolean      contains(const RWCString& str) const;
  1449.        Pattern matching.  Returns TRUE if str occurs in RWCString.  Case
  1450.        sensitivity is set by the static member function setCaseSensitive().
  1451.  
  1452. Rogue Wave              Tools.h++   V 5.0   Supplement  27
  1453.  
  1454.  
  1455.  
  1456.  
  1457.  
  1458.  
  1459.  
  1460.  
  1461.                                                                RWCString
  1462.  
  1463.  
  1464.           const char*    data() const;
  1465.        Access to the RWCString's data as a null terminated string.  Must be
  1466.        used with care.
  1467.           int     first(char c) const;
  1468.        Returns the index of the first occurence of the character c in self.
  1469.        Returns -1 if there is no such character.
  1470.           unsignedhash() const;
  1471.        Returns a suitable hash value.
  1472.           int     index(const char* cs, int i=0) const;
  1473.        Pattern matching.  Returns the index greater than or equal to i of the
  1474.        start of the first occurrence of the string pointed to by cs in self.
  1475.        Returns -1 if there is no such pattern.  Case sensitivity is set by
  1476.        the static member function setCaseSensitive().  The pattern matching
  1477.        is done by computing a hash value for the string pointed to by c using
  1478.        what is effectively a very large hash table and then comparing it
  1479.        against hash values computed from self.  The table is so large that it
  1480.        is very unlikely that two different patterns would hash to the same
  1481.        value.  Nevertheless, a final string comparison can be made by calling
  1482.        the static member function setParanoidCheck() with argument TRUE.
  1483.           int     index(const RWCString& str, int i=0) const;
  1484.        Pattern matching.  Returns the index greater than or equal to i of the
  1485.        start of the first occurrence of str in self.  Returns -1 if there is
  1486.        no such pattern.  Case sensitivity is set by the static member
  1487.        function setCaseSensitive().  See additional comments above on final
  1488.        string comparisons.
  1489.           int     index(const RWRegexp& re, int i=0) const;
  1490.        Regular expression matching.  Returns the index greater than or equal
  1491.        to i of the start of the first pattern that matches the regular
  1492.        expression re.  Returns -1 if there is no such pattern.
  1493.           int     index(const RWRegexp& re, int* ext, int i=0) const;
  1494.        Regular expression matching.  Returns the index greater than or equal
  1495.        to i of the start of the first pattern that matches the regular
  1496.        expression re.  Returns -1 if there is no such pattern.  The length of
  1497.        the matching pattern is returned in the integer pointed to by ext.
  1498.           RWBoolean      isNull() const;
  1499.        Returns TRUE if this is a zero lengthed string (i.e., the null
  1500.        string).
  1501.           int     last(char c) const;
  1502.        Returns the index of the last occurrence in the string of the
  1503.        character c.  Returns -1 if there is no such character.
  1504.           unsignedlength() const;
  1505.        Return the number of characters in self.
  1506.  
  1507.  
  1508. Rogue Wave              Tools.h++   V 5.0   Supplement  28
  1509.  
  1510.  
  1511.  
  1512.  
  1513.  
  1514.  
  1515.  
  1516.  
  1517.                                                                RWCString
  1518.  
  1519.  
  1520.           RWCString&     prepend(const char* cs);
  1521.        Prepend the string pointed to by cs to self.  A copy of cs will be
  1522.        made.
  1523.           RWCString&     prepend(const char* cs, unsigned N);
  1524.        Prepend the (possibly) null terminated character string cs to self.
  1525.        At most, the first N characters of the string (not including the
  1526.        terminating null) will be used.  A copy of cs will be made.
  1527.           RWCString&     prepend(const RWCString& str);
  1528.        Prepends the string str to self.
  1529.           istream&readFile(istream& s);
  1530.        Read an entire file into self from the input stream s, replacing the
  1531.        previous contents of self.  Read to an EOF or null terminator,
  1532.        whichever comes first.
  1533.           istream&readLine(istream& s);
  1534.        If skipWhitespace() is TRUE (the default), then whitespace is skipped
  1535.        before saving characters. Characters are then read from the input
  1536.        stream s until a newline (or an EOF) is encountered. The newline is
  1537.        removed from the input stream but is not stored.
  1538.           istream&readToDelim(istream&, char delim='\n');
  1539.        Reads up to an EOF or the delimiting character delim, whichever comes
  1540.        first.  The delimiter is not stored in the string, but is removed from
  1541.        the input stream.
  1542.  
  1543.           istream&readToken(istream& s);
  1544.        Whitespace is skipped before saving characters. Characters are then
  1545.        read from the input stream s until whitespace or an EOF is
  1546.        encountered. The whitespace is left on the input stream.
  1547.           void    resize(unsigned n);
  1548.        Changes the length of self, adding blanks or truncating as necessary.
  1549.           void    restoreFrom(RWvistream& s);
  1550.        Reads an RWCString from the input stream s that had been stored using
  1551.        saveOn(RWvostream&).
  1552.           void    restoreFrom(RWFile& f);
  1553.        Reads an RWCString from the RWFile f that had been stored using
  1554.        storeOn(RWFile&).
  1555.           void    saveOn(RWvostream& s) const;
  1556.        Stores an RWCString on the output stream s.
  1557.           void    saveOn(RWFile& f) const;
  1558.        Stores an RWCString in binary format on the RWFile f.
  1559.           RWCSubString   strip(stripType s = trailing, char c = ' ');
  1560.        Returns a substring of self where the character c has been stripped
  1561.        off the beginning, end, or both ends of the string.  The enum
  1562.        stripType can take values:
  1563.  
  1564. Rogue Wave              Tools.h++   V 5.0   Supplement  29
  1565.  
  1566.  
  1567.  
  1568.  
  1569.  
  1570.  
  1571.  
  1572.  
  1573.                                                                RWCString
  1574.  
  1575.  
  1576.                stripType      Meaning
  1577.                leading        Remove characters at beginning
  1578.                trailing       Remove characters at end
  1579.                both           Remove characters at both ends
  1580.           RWCSubString   subString(const char* cs, int start=0);
  1581.           const RWCSubString  subString(const char* cs, int start=0) const;
  1582.        Returns a substring representing the first occurence of the string
  1583.        pointed to by "cs".  Case sensitivity is set by the static member
  1584.        function setCaseSensitive().  See member function index() for
  1585.        additional information on how the match is performed.
  1586.           void    toLower();
  1587.        Changes all upper-case letters in self to lower-case.
  1588.           void    toUpper();
  1589.        Changes all lower-case letters in self to upper-case.
  1590.  
  1591. Static    static unsigned   initialCapacity(unsigned ic = 63);
  1592. public
  1593. member
  1594. functions
  1595.  
  1596.  
  1597.        Sets the minimum initial capacity of an RWCString. The initial setting
  1598.        is 63 characters. Larger values will use more memory, but result in
  1599.        fewer resizes when concatenating or reading strings. Smaller values
  1600.        will waste less memory, but result in more resizes.
  1601.           Static unsigned     maxWaste(unsigned mw = 63);
  1602.        Sets the maximum amount of unused space allowed in a string should it
  1603.        shrink. If more than this amount of characters is wasted, the space
  1604.        will be reclaimed.
  1605.           Static unsigned     resizeIncrement(unsigned ri = 64);
  1606.        Sets the resize increment when more memory is needed to grow a string.
  1607.           static RWBoolean    setCaseSensitive(RWBoolean s = TRUE);
  1608.  
  1609.        Sets whether pattern matching, hashing, and lexical comparisons are
  1610.        case-sensitive.  Returns the old setting.  The initial setting is
  1611.        case-sensitive pattern matching.
  1612.           static RWBoolean    setParanoidCheck(RWBoolean s = TRUE);
  1613.        Sets whether a pattern match using hash values is followed by a string
  1614.        comparison.  Returns the old setting.  The initial setting is FALSE.
  1615.        See function index() for additional details.
  1616.  
  1617.  
  1618.  
  1619.  
  1620. Rogue Wave              Tools.h++   V 5.0   Supplement  30
  1621.  
  1622.  
  1623.  
  1624.  
  1625.  
  1626.  
  1627.  
  1628.  
  1629.                                                                RWCString
  1630.  
  1631.  
  1632.           static RWBoolean    skipWhitespace(RWBoolean s = TRUE);
  1633.        Sets whether white space is skipped before reading a line.  The
  1634.        initial setting is TRUE.  See function readLine() for additional
  1635.        details.
  1636.  
  1637. Related   RWCString         operator+(const RWCString&, const RWCString&);
  1638. global    RWCString         operator+(const char*, const RWCString&);
  1639. operators RWCString         operator+(const RWCString&, const char*);
  1640.  
  1641.  
  1642.           Concatenation operators.
  1643.           ostream&operator<<(ostream& s, const RWCString&);
  1644.        Output a RWCString on ostream s.
  1645.           istream&operator>>(istream& s, RWCString& str);
  1646.        Calls str.readToken(s).  That is, a token is read from the input
  1647.        stream s.
  1648.           RWCString      toLower(const RWCString& str);
  1649.        Returns a version of str where all upper-case characters have been
  1650.        replaced with lower-case characters.
  1651.           RWCString      toUpper(const RWCString& str);
  1652.        Returns a version of str where all lower-case characters have been
  1653.        replaced with upper-case characters.
  1654.  
  1655.  
  1656.  
  1657.  
  1658.  
  1659.  
  1660.  
  1661.  
  1662.  
  1663.  
  1664.  
  1665.  
  1666.  
  1667.  
  1668.  
  1669.  
  1670.  
  1671.  
  1672.  
  1673.  
  1674.  
  1675.  
  1676. Rogue Wave              Tools.h++   V 5.0   Supplement  31
  1677.  
  1678.  
  1679.  
  1680.  
  1681.  
  1682.  
  1683.  
  1684.  
  1685.  
  1686.  
  1687. RWDiskPageHeapRWDiskPageHeap                        RWDiskPageHeap
  1688.                                                            |
  1689.                                                   RWBufferedPageHeap
  1690.                                                            |
  1691.                                                    RWVirtualPageHeap
  1692.  
  1693. Synopsis   #include <rw/diskpage.h>
  1694.            unsigned nbufs;
  1695.            unsigned pagesize;
  1696.            RWDiskPageHeap heap("filename", nbufs, pagesize);
  1697.  
  1698.  
  1699. Description  Class RWDiskPageHeap is a specializing type of buffered page heap.
  1700.           It swaps its pages to disk as necessary.
  1701.  
  1702.  
  1703. Example   In this example, 100 nodes of a linked list are created and strung
  1704.           together.  The list is then walked, confirming that it contains 100
  1705.           nodes.  Each node is a single page.  The "pointer" to the next node
  1706.           is actually the handle for the next page.
  1707.           BEGIN FILE: diskpage.cpp
  1708.           #include <rw/diskpage.h>
  1709.           #include <rw/rstream.h>
  1710.  
  1711.           struct Node {
  1712.             int     key;
  1713.             RWHandle                                   next;
  1714.           };
  1715.  
  1716.           RWHandle head = 0;
  1717.  
  1718.           const int N = 100;           // Exercise 100 Nodes
  1719.  
  1720.           main() {
  1721.  
  1722.             // Construct a disk-based page heap with page size equal
  1723.             // to the size of Node and with 10 buffers:
  1724.             RWDiskPageHeap heap(0, 10, sizeof(Node));
  1725.  
  1726.             // Build the linked list:
  1727.             for (int i=0; i<N; i++){
  1728.               RWHandle h = heap.allocate();
  1729.               Node* newNode = (Node*)heap.lock(h);
  1730.               newNode->key  = i;
  1731.               newNode->next = head;
  1732.  
  1733.  
  1734.  
  1735.  
  1736.  
  1737.  
  1738.  
  1739.  
  1740.                                                           RWDiskPageHeap
  1741.  
  1742.  
  1743.               head = h;
  1744.               heap.dirty(h);
  1745.               heap.unlock(h);
  1746.             }
  1747.  
  1748.             // Now walk the list:
  1749.             unsigned count = 0;
  1750.             RWHandle nodeHandle = head;
  1751.             while(nodeHandle){
  1752.               Node* node = (Node*)heap.lock(nodeHandle);
  1753.               RWHandle nextHandle = node->next;
  1754.               heap.unlock(nodeHandle);
  1755.               heap.deallocate(nodeHandle);
  1756.               nodeHandle = nextHandle;
  1757.               count++;
  1758.             }
  1759.  
  1760.             cout << "List with " << count << " nodes walked.\n";
  1761.             return 0;
  1762.           }
  1763.           END FILE
  1764.  
  1765. Program output:
  1766.           List with 100 nodes walked.
  1767.  
  1768. Public    RWDiskPageHeap(const char* filename=0,
  1769. constructor          unsigned nbufs=10,
  1770.           unsigned pgsize=512);
  1771.        Constructs a new disk-based page heap.  The heap will use a file with
  1772.        filename filename, otherwise it will negotiate with the operating
  1773.        system for a temporary filename.  The number of buffers, each the size
  1774.        of the page size, will be nbufs.  No more than this many pages can be
  1775.        locked at any one time.  The size of each page is given by pgsize.  To
  1776.        see whether a valid RWDiskPageHeap has been constructed, call member
  1777.        function isValid().
  1778.           virtual ~RWDiskPageHeap();
  1779.        Returns any resources used by the disk page heap back to the operating
  1780.        system.  All pages should have been deallocated before the destructor
  1781.        is called.
  1782.           RWBoolean      isValid() const;
  1783.        Returns TRUE if this is a valid RWDiskPageHeap.
  1784.  
  1785.  
  1786.  
  1787. Rogue Wave              Tools.h++   V 5.0   Supplement  33
  1788.  
  1789.  
  1790.  
  1791.  
  1792.  
  1793.  
  1794.  
  1795.  
  1796.                                                           RWDiskPageHeap
  1797.  
  1798.  
  1799. Public    virtual RWHandle  allocate();
  1800. member
  1801. functions
  1802.  
  1803.  
  1804.        Redefined from class RWVirtualPageHeap.  Allocates a page off the disk
  1805.        page heap and returns a handle for it.  If there is no more space (for
  1806.        example, the disk is full) then returns zero.
  1807.           virtual void   deallocate(RWHandle h);
  1808.        Redefined from class RWBufferedPageHeap.  Deallocate the page
  1809.        associated with handle h.  It is not an error to deallocate a zero
  1810.        handle.
  1811.           virtual void   dirty(RWHandle h);
  1812.        Inherited from RWBufferedPageHeap.
  1813.           virtual void*  lock(RWHandle h);
  1814.        Inherited from RWBufferedPageHeap.
  1815.           virtual void   unlock(RWHandle h) = 0;
  1816.        Inherited from RWBufferedPageHeap.
  1817.  
  1818.  
  1819.  
  1820.  
  1821.  
  1822.  
  1823.  
  1824.  
  1825.  
  1826.  
  1827.  
  1828.  
  1829.  
  1830.  
  1831.  
  1832.  
  1833.  
  1834.  
  1835.  
  1836.  
  1837.  
  1838.  
  1839.  
  1840.  
  1841.  
  1842.  
  1843. Rogue Wave              Tools.h++   V 5.0   Supplement  34
  1844.  
  1845.  
  1846.  
  1847.  
  1848.  
  1849.  
  1850.  
  1851.  
  1852.  
  1853.  
  1854. RWModelRWModel
  1855.  
  1856.  
  1857. Synopsis   #include <rw/model.h>
  1858.            (abstract base class)
  1859.  
  1860.  
  1861. Description          This abstract base class has been designed to implement a
  1862.           dependency hierarchy.  It maintains a list of dependents and,
  1863.           in turn, it can be a dependent of another instance of
  1864.           RWModel.  You should subclass off of it to supply the actual
  1865.           functionality.  It is intended to be a base class for both
  1866.           the "Model" and "View" legs of a Model-View-Controller
  1867.           architecture.
  1868.           When member function changed() is called, the list of dependents
  1869.           will be traversed, calling updateFrom(RWModel*) for each one, with
  1870.           itself as the argument.  Classes subclassing off RWModel should be
  1871.           prepared to accept such a call
  1872.  
  1873. Example   This is an incomplete and somewhat contrived example in that it does
  1874.           not completely define the classes involved.  "Dial" is assumed to be
  1875.           a graphical representation of the internal settings of "Thermostat".
  1876.           The essential point is that there is a dependency relationship
  1877.           between the "Thermostat" and the "Dial": when the setting of the
  1878.           thermostat is changed, the dial must be notified so that it can
  1879.           update itself from the new setting of the thermostat.
  1880.  
  1881.           BEGIN FILE: model.cpp
  1882.           #include <rw/model.h>
  1883.  
  1884.           class Dial : public RWModel {
  1885.           public:
  1886.             virtual void   updateFrom(RWModel* m);
  1887.           };
  1888.  
  1889.  
  1890.           class Thermostat : public RWModel {
  1891.             double         setting;
  1892.           public:
  1893.             Thermostat( Dial* d )
  1894.               { addDependent(d); }
  1895.             double         temperature() const
  1896.               { return setting; }
  1897.             void           setTemperature(double t)
  1898.               { setting = t; changed(); }
  1899.  
  1900.  
  1901.  
  1902.  
  1903.  
  1904.  
  1905.  
  1906.  
  1907.                                                                  RWModel
  1908.  
  1909.  
  1910.             virtual void   updateFrom(RWModel*)
  1911.               { /* No-op: not dependent on anything */ }
  1912.           };
  1913.  
  1914.           void Dial::updateFrom(RWModel* m){
  1915.             Thermostat* t = (Thermostat*)m;
  1916.             double temp = t->temperature();
  1917.             // Redraw graphic.
  1918.           }
  1919.           END FILE
  1920.  
  1921. Public constructor    RWModel();
  1922.  
  1923.  
  1924.        When called by the specializing class, sets up the internal ordered
  1925.        list of dependents.
  1926.           void    addDependent(RWModel* m);
  1927.        Adds the object pointed to by m to the list of dependents of self.
  1928.           void    removeDependent(RWModel* m);
  1929.        Removes the object pointed to by m from the list of dependents of
  1930.        self.
  1931.           virtual void   changed();
  1932.        Traverse the internal list of dependents, calling member function
  1933.        updateFrom(RWModel*) for each one, with self as the argument.
  1934.           virtual void   updateFrom(RWModel* p) = 0;
  1935.        Deriving classes should supply an appropriate definition for this pure
  1936.        virtual function.  The overall semantics of the definition should be
  1937.        to update self from the data presented by the object pointed to by p.
  1938.        That is, self is considered a dependent of the object pointed to by p.
  1939.  
  1940.  
  1941.  
  1942.  
  1943.  
  1944.  
  1945.  
  1946.  
  1947.  
  1948.  
  1949.  
  1950.  
  1951.  
  1952.  
  1953.  
  1954. Rogue Wave              Tools.h++   V 5.0   Supplement  36
  1955.  
  1956.  
  1957.  
  1958.  
  1959.  
  1960.  
  1961.  
  1962.  
  1963.  
  1964.  
  1965. RWTBitVec<size>RWTBitVec<size>
  1966.  
  1967.  
  1968. Synopsis  #include <rw/tbitvec.h>
  1969.           RWTBitVec<22>      // A 22 bit long vector
  1970.  
  1971.  
  1972.           RWTBitVec<size> is a parameterized bit vector of fixed length
  1973.           size.  Unlike class RWBitVec, its length cannot be changed at
  1974.           run time.  Its advantage of RWBitVec is its smaller size, and
  1975.           one less level of indirection, resulting in a slight speed
  1976.           advantage.
  1977.           Bits are numbered from 0 through size-1, inclusive.
  1978.          The copy constructor and assignment operator use copy semantics.
  1979.  
  1980. Example   In this example, a bit vector 24 bits long is exercised:
  1981.  
  1982.           #include <rw/tbitvec.h>
  1983.  
  1984.           main()
  1985.           {
  1986.             RWTBitVec<24> a, b;     // Allocate two vectors.
  1987.             a(2) = TRUE;   // Set bit 2 (the third bit) of a on.
  1988.             b(3) = TRUE;   // Set bit 3 (the fourth bit) of b on.
  1989.             RWTBitVec<24> c = a ^ b;// Set c to the XOR of a and b.
  1990.           }
  1991.  
  1992. Public    RWTBitVec<size>();
  1993. constructo
  1994. r
  1995.  
  1996.  
  1997.           Constructs an instance with all bits set to FALSE.
  1998.           RWTBitVec<size>(RWBoolean val);
  1999.        Constructs an instance with all bits set to val.
  2000. Assignment         RWTBitVec<size>&   operator=(const RWTBitVec<size>& v);
  2001. operators
  2002.  
  2003.  
  2004.           Sets self to a copy of v.
  2005.           RWTBitVec&     operator=(RWBoolean val);
  2006.        Sets all bits in self to the value val.
  2007.  
  2008.  
  2009.  
  2010.  
  2011.  
  2012.  
  2013.  
  2014.  
  2015.                                                          RWTBitVec<size>
  2016.  
  2017.  
  2018.           RWTBitVec&     operator&=(const RWTBitVec& v);
  2019.           RWTBitVec&     operator^=(const RWTBitVec& v)
  2020.           RWTBitVec&     operator|=(const RWTBitVec& v)
  2021.        Logical assignments.  Sets each bit of self to the logical AND, XOR,
  2022.        or OR, respectively, of self and the corresponding bit in v.
  2023.           RWBitRefoperator[](int i);
  2024.        Returns a reference to the i'th bit of self.  This reference can be
  2025.        used as an lvalue.  The index i must be between 0 and size-1,
  2026.        inclusive.  Bounds checking will occur.
  2027.           RWBitRefoperator()(int i);
  2028.        Returns a reference to the i'th bit of self.  This reference can be
  2029.        used as an lvalue.  The index i must be between 0 and size-1,
  2030.        inclusive.  No bounds checking is done.
  2031.  
  2032. Logical   RWBoolean         operator==(RWBoolean b) const;
  2033. operators
  2034.  
  2035.  
  2036.        Returns TRUE if every bit of self is set to the value b.  Otherwise,
  2037.        returns FALSE.
  2038.           RWBoolean      operator!=(RWBoolean b) const;
  2039.        Returns TRUE if any bit of self is not set to the value b.  Otherwise,
  2040.        returns FALSE.
  2041.           RWBoolean      operator==(const RWTBitVec& v) const;
  2042.       Returns TRUE if each bit of self is set to the same value as the
  2043.       corresponding bit in v.  Otherwise, returns FALSE.
  2044.           RWBoolean      operator!=(const RWTBitVec& v) const;
  2045.        Returns TRUE if any bit of self is not set to the same value as the
  2046.        corresponding bit in v.  Otherwise, returns FALSE.
  2047.           void    clearBit(int i);
  2048.        Clears (i.e., sets to FALSE) the bit with index i.  The index i must
  2049.        be between 0 and size-1.  No bounds checking is performed.  The
  2050.        following two lines are equivalent, although clearBit(int) is
  2051.        slightly smaller and faster than using operator()(int):
  2052.                  a(i) = FALSE;
  2053.                  a.clearBit(i);
  2054.  
  2055.           const RWByte*  data() const;
  2056.        Returns a const pointer to the raw data of self.  Should be used with
  2057.        care.
  2058.           void    setBit(int i);
  2059.        Sets (i.e., sets to TRUE) the bit with index i.  The index i must be
  2060.        between 0 and size-1.  No bounds checking is performed.  The following
  2061.  
  2062. Rogue Wave              Tools.h++   V 5.0   Supplement  38
  2063.  
  2064.  
  2065.  
  2066.  
  2067.  
  2068.  
  2069.  
  2070.  
  2071.                                                          RWTBitVec<size>
  2072.  
  2073.  
  2074.        two lines are equivalent, although setBit(int) is slightly smaller and
  2075.        faster than using operator()(int)
  2076.                  a(i) = TRUE;
  2077.                  a.setBit(i);
  2078.  
  2079.           RWBoolean      testBit(int i) const;
  2080.        Tests the bit with index i.  The index i must be between 0 and size-1.
  2081.        No bounds checking is performed.  The following are equivalent,
  2082.        although testBit(int) is slightly smaller and faster than using
  2083.        operator()(int):
  2084.                  if( a(i) )       doSomething();
  2085.                  if( a.testBit(i) ) doSomething();
  2086.  
  2087. Related  RWTBitVec operator&(const RWTBitVec& v1, const RWTBitVec& v2);
  2088. global   RWTBitVec operator^(const RWTBitVec& v1, const RWTBitVec& v2);
  2089. functionsRWTBitVec operator|(const RWTBitVec& v1, const RWTBitVec& v2);
  2090.  
  2091.  
  2092.       Return the logical AND, XOR, and OR, respectively, of vectors v1 and v2.
  2093.  
  2094.  
  2095.  
  2096.  
  2097.  
  2098.  
  2099.  
  2100.  
  2101.  
  2102.  
  2103.  
  2104.  
  2105.  
  2106.  
  2107.  
  2108.  
  2109.  
  2110.  
  2111.  
  2112.  
  2113.  
  2114.  
  2115.  
  2116.  
  2117.  
  2118. Rogue Wave              Tools.h++   V 5.0   Supplement  39
  2119.  
  2120.  
  2121.  
  2122.  
  2123.  
  2124.  
  2125.  
  2126.  
  2127.  
  2128.  
  2129. RWTimerRWTimer
  2130.  
  2131.  
  2132. Synopsis   #include <rw/timer.h>
  2133.            RWTimer timer;
  2134.  
  2135. Description
  2136.  
  2137. This class can measure elapsed real (wall clock) time.  The timer has
  2138. two states: running and stopped.  The timer measures the total amount
  2139. of time spent in the "running" state since it was either constructed or
  2140. reset.
  2141. The timer is put into the "running" state by calling member function
  2142. start().  It is put into the "stopped" state by calling stop().
  2143. Example
  2144.  
  2145. This example times the amount of time that elapsed during a 5 second sleep
  2146. and a 2 second sleep.  Note that Microsoft C/C++ does not implement sleep().
  2147.           BEGIN FILE: timer.cpp
  2148.           #include <rw/timer.h>
  2149.           #include <rw/rstream.h>
  2150.           #ifdef __MSDOS__
  2151.           #  include <dos.h>       /* Looking for sleep() */
  2152.           #else
  2153.           #  include <unistd.h>
  2154.           #endif
  2155.  
  2156.           main()
  2157.           {
  2158.             RWTimer t;
  2159.  
  2160.             t.start();
  2161.             sleep(5);      // Sleep 5 seconds while in running state
  2162.             t.stop();
  2163.             sleep(8);      // Sleep 8 seconds while in stopped state
  2164.             t.start();
  2165.             sleep(2);      // Sleep 2 seconds while in running state
  2166.             t.stop();
  2167.             cout << t.elapsedTime() << NL;
  2168.             return 0;
  2169.           }
  2170.           END FILE
  2171. Program output:
  2172.           7.02936
  2173.  
  2174.  
  2175.  
  2176.  
  2177.  
  2178.  
  2179.  
  2180.  
  2181.                                                                  RWTimer
  2182.  
  2183.  
  2184. Public
  2185. constructor
  2186.  
  2187.           RWTimer();
  2188.        Constructs a new timer.  The timer will not start running until
  2189.        start() is called.
  2190.           double  elapsedTime() const;
  2191.        Returns the amount of (wall clock) time that has accumulated while the
  2192.        timer was in the running state.
  2193.           void    reset();
  2194.        Resets (and stops) the timer.
  2195.           void    start();
  2196.        Puts the timer in the "running" state.  Time accumulates while in this
  2197.        state.
  2198.           void    stop();
  2199.        Puts the timer in the "stopped" state.  Time will not accumulate while
  2200.        in this state.
  2201.  
  2202.  
  2203.  
  2204.  
  2205.  
  2206.  
  2207.  
  2208.  
  2209.  
  2210.  
  2211.  
  2212.  
  2213.  
  2214.  
  2215.  
  2216.  
  2217.  
  2218.  
  2219.  
  2220.  
  2221.  
  2222.  
  2223.  
  2224.  
  2225.  
  2226.  
  2227.  
  2228. Rogue Wave              Tools.h++   V 5.0   Supplement  41
  2229.  
  2230.  
  2231.  
  2232.  
  2233.  
  2234.  
  2235.  
  2236.  
  2237.  
  2238.  
  2239. RWTIsvDlist<T>RWTIsvDlist<T>
  2240.  
  2241.  
  2242. Synopsis   #include <rw/tidlist.h>
  2243.            RWTIsvDlist<T> list;
  2244.  
  2245. Description
  2246.        Class RWTIsvDlist<T> is a class that implements intrusive singly-
  2247.        linked lists.
  2248.        An intrusive list is one where the member of the list must
  2249.        inherit from a common base class, in this case RWIsvDlink.  The
  2250.        advantage of such a list is that memory and space requirements
  2251.        are kept to a minimum.  The disadvantage is that the inheritance
  2252.        hierarchy is inflexible, making it slightly more difficult to use
  2253.        with an existing class.  Class RWTValDlist<T> is offered as an
  2254.        alternative, non-intrusive, linked list.
  2255. See Stroustrup (1991; Section 8.3.1) for more information about intrusive
  2256. lists.
  2257.  
  2258.  
  2259. Note that when you insert an item into an intrusive list, the actual item
  2260. (not a copy) is inserted.  Because each item carries only one link field, the
  2261. same item cannot be inserted into more than one list, nor can it be inserted
  2262. into the same list more than once.
  2263.  
  2264.  
  2265.  
  2266. Example   BEGIN FILE: tidlist.cpp
  2267.           #include <rw/tidlist.h>
  2268.           #include <rw/rstream.h>
  2269.           #include <string.h>
  2270.  
  2271.           struct Symbol : public RWIsvSlink {
  2272.             char name[10];
  2273.             Symbol( const char* cs)
  2274.               { strncpy(name, cs, sizeof(name)); name[9] = '\0'; }
  2275.           };
  2276.  
  2277.           void printem(Symbol* s, void*) { cout << s->name << NL; }
  2278.  
  2279.           main(){
  2280.             RWTIsvDlist<Symbol> list;
  2281.             list.insert( new Symbol("one") );
  2282.             list.insert( new Symbol("two") );
  2283.             list.prepend( new Symbol("zero") );
  2284.  
  2285.  
  2286.  
  2287.  
  2288.  
  2289.  
  2290.  
  2291.  
  2292.                                                           RWTIsvDlist<T>
  2293.  
  2294.  
  2295.             list.apply(printem, 0);
  2296.             list.clearAndDestroy();// Deletes the items inserted into the list
  2297.             return 0;
  2298.           }
  2299.           END FILE
  2300.  
  2301. Program Output:
  2302.           zero
  2303.           one
  2304.           two
  2305.  
  2306. Public    RWTIsvDlist();
  2307. constructors
  2308.  
  2309.  
  2310.        Constructs an empty list.
  2311.           RWTIsvDlist(T* a);
  2312.        Constructs a list with the single item pointed to by a in it.
  2313.           void    append(T* a);
  2314.        Appends the item pointed to by a to the end of the list.
  2315.           void    apply(void (*applyFun)(T*, void*), void* d);
  2316.        Calls the function pointed to by applyFun to every item in the
  2317.        collection.  This must have the prototype:
  2318.             void  yourFun(T* item, void* d);
  2319.        The item will be passed in as argument item.  Client data may be
  2320.        passed through as parameter d.
  2321.           T*      at(int i) const;
  2322.        Returns the item at index i, or nil if the index is an invalid index.
  2323.        Valid indices are between zero and the number of items in the list,
  2324.        less one.
  2325.           void    clear();
  2326.        Removes all items from the list.
  2327.           void    clearAndDestroy();
  2328.        Removes and calls delete for each item in the list.  Note that this
  2329.        assumes that each item was allocated off the heap.
  2330.           RWBoolean      contains(RWBoolean (*testFun)(const T*, void*), void*
  2331.           d) const;
  2332.        Returns TRUE if the list contains an item for which the user-defined
  2333.        "tester" function pointed to by testFun returns TRUE .  The tester
  2334.        function must have the prototype:
  2335.             RWBoolean  yourTester(const T* item, void* d);
  2336.  
  2337.  
  2338.  
  2339. Rogue Wave              Tools.h++   V 5.0   Supplement  43
  2340.  
  2341.  
  2342.  
  2343.  
  2344.  
  2345.  
  2346.  
  2347.  
  2348.                                                           RWTIsvDlist<T>
  2349.  
  2350.  
  2351.        For each item in the list this function will be called with the item
  2352.        as the first argument.  Client data may be passed through as parameter
  2353.        d.
  2354.           RWBoolean      containsReference(const T* a) const;
  2355.        Returns TRUE if the list contains an item with the address a.
  2356.           unsignedentries() const;
  2357.        Returns the number of items currently in the list.
  2358.           T*      find(RWBoolean (*testFun)(const T*, void*), void* d) const;
  2359.        Returns the first item in the list for which the user-defined "tester"
  2360.        function pointed to by testFun returns TRUE.  If there is no such
  2361.        item, then returns nil.  The tester function must have the prototype:
  2362.             RWBoolean  yourTester(const T* item, void* d);
  2363.        For each item in the list this function will be called with the item
  2364.        as the first argument.  Client data may be passed through as parameter
  2365.        d.
  2366.           T*      first() const;
  2367.        Returns (but does not remove) the first item in the list, or nil if
  2368.        the list is empty.
  2369.           T*      get();
  2370.        Returns and removes the first item in the list, or nil if the list is
  2371.        empty.
  2372.           int     index(RWBoolean (*testFun)(const T*, void*), void* d) const;
  2373.        Returns the index of the first item in the list for which the user-
  2374.        defined "tester" function pointed to by testFun returns TRUE.  If
  2375.        there is no such item, then returns -1.  The tester function must have
  2376.        the prototype:
  2377.             RWBoolean  yourTester(const T* item, void* d);
  2378.        For each item in the list this function will be called with the item
  2379.        as the first argument.  Client data may be passed through as parameter
  2380.        d.
  2381.           void    insert(T* a);
  2382.        Appends the item pointed to by a to the end of the list.  This item
  2383.        cannot be inserted into more than one list, nor can it be inserted
  2384.        into the same list more than once.
  2385.           void    insertAt(int i, T* a);
  2386.        Insert the item pointed to by a at the index position i.  This
  2387.        position must be between zero and the number of items in the list.
  2388.        The item cannot be inserted into more than one list, nor can it be
  2389.        inserted into the same list more than once.
  2390.           RWBoolean      isEmpty() const;
  2391.        Returns TRUE if there are no items in the list, FALSE otherwise.
  2392.  
  2393.  
  2394.  
  2395. Rogue Wave              Tools.h++   V 5.0   Supplement  44
  2396.  
  2397.  
  2398.  
  2399.  
  2400.  
  2401.  
  2402.  
  2403.  
  2404.                                                           RWTIsvDlist<T>
  2405.  
  2406.  
  2407.           T*      last() const;
  2408.        Returns (but does not remove) the last item in the list, or nil if the
  2409.        list is empty.
  2410.           unsignedoccurrencesOf(RWBoolean (*testFun)(const T*, void*), void*
  2411.           d) const;
  2412.        Traverses the list and returns the number of times for which the user-
  2413.        defined "tester" function pointed to by testFun returned TRUE .  The
  2414.        tester function must have the prototype:
  2415.             RWBoolean  yourTester(const T* item, void* d);
  2416.        For each item in the list this function will be called with the item
  2417.        as the first argument.  Client data may be passed through as parameter
  2418.        d.
  2419.           unsignedoccurrencesOfReference(const T* a) const;
  2420.        Returns the number of times which the item pointed to by a occurs in
  2421.        the list.  Because items cannot be inserted into a list more than
  2422.        once, this function can only return zero or one.
  2423.           void    prepend(T* a);
  2424.        Prepends the item pointed to by a to the beginning of the list.
  2425.           T*      remove(RWBoolean (*testFun)(const T*, void*), void* d);
  2426.        Removes and returns the first item for which the user-defined tester
  2427.        function pointed to by testFun returns TRUE, or nil if there is no
  2428.        such item.  The tester function must have the prototype:
  2429.             RWBoolean  yourTester(const T* item, void* d);
  2430.        For each item in the list this function will be called with the item
  2431.        as the first argument.  Client data may be passed through as parameter
  2432.        d.
  2433.           T*      removeAt(int i);
  2434.        Removes and returns the item at index i, or nil if the index is an
  2435.        invalid index.  Valid indices are between zero and the number of items
  2436.        in the list, less one.
  2437.           T*      removeFirst();
  2438.        Removes and returns the first item in the list, or nil if there are no
  2439.        items in the list.
  2440.           T*      removeLast();
  2441.        Removes and returns the last item in the list, or nil if there are no
  2442.        items in the list.
  2443.           T*      removeReference(const T* a);
  2444.        Removes and returns the item with address a, or nil if there is no
  2445.        such item.
  2446.  
  2447.  
  2448.  
  2449.  
  2450.  
  2451. Rogue Wave              Tools.h++   V 5.0   Supplement  45
  2452.  
  2453.  
  2454.  
  2455.  
  2456.  
  2457.  
  2458.  
  2459.  
  2460.  
  2461.  
  2462. RWTIsvSlist<T>RWTIsvSlist<T>
  2463.  
  2464.  
  2465. Synopsis  #include <rw/tislist.h>
  2466.           RWTIsvSlist<T> list;
  2467.  
  2468. Description
  2469.     Class RWTIsvSlist<T> is a class that implements intrusive singly-
  2470.     linked lists.
  2471.         An intrusive list is one where the member of the list must inherit
  2472.         from a common base class, in this case RWIsvSlink.  The advantage of
  2473.         such a list is that memory and space requirements are kept to a
  2474.         minimum.  The disadvantage is that the inheritance hierarchy is
  2475.         inflexible, making it slightly more difficult to use with an
  2476.         existing class.  Class RWTValSlist<T> is offered as an alternative,
  2477.         non-intrusive, linked list.
  2478. See Stroustrup (1991; Section 8.3.1) for more information about intrusive
  2479. lists.
  2480.  
  2481.  
  2482. Note that when you insert an item into an intrusive list, the actual item
  2483. (not a copy) is inserted.  Because each item carries only one link field, the
  2484. same item cannot be inserted into more than one list, nor can it be inserted
  2485. into the same list more than once.
  2486.  
  2487.  
  2488.  
  2489. Example   BEGIN FILE: tislist.cpp
  2490.           #include <rw/tislist.h>
  2491.           #include <rw/rstream.h>
  2492.           #include <string.h>
  2493.  
  2494.           struct Symbol : public RWIsvSlink {
  2495.             char name[10];
  2496.             Symbol( const char* cs)
  2497.               { strncpy(name, cs, sizeof(name)); name[9] = '\0'; }
  2498.           };
  2499.  
  2500.           void printem(Symbol* s, void*) { cout << s->name << NL; }
  2501.  
  2502.           main(){
  2503.             RWTIsvSlist<Symbol> list;
  2504.             list.insert( new Symbol("one") );
  2505.             list.insert( new Symbol("two") );
  2506.             list.prepend( new Symbol("zero") );
  2507.  
  2508.  
  2509.  
  2510.  
  2511.  
  2512.  
  2513.  
  2514.  
  2515.                                                           RWTIsvSlist<T>
  2516.  
  2517.  
  2518.             list.apply(printem, 0);
  2519.             list.clearAndDestroy();// Deletes the items inserted into the list
  2520.             return 0;
  2521.           }
  2522.           END FILE
  2523.  
  2524. Program Output:
  2525.           zero
  2526.           one
  2527.           two
  2528.  
  2529. Public    RWTIsvSlist();
  2530. constructors
  2531.  
  2532.  
  2533.           Constructs an empty list.
  2534.           RWTIsvSlist(T* a);
  2535.        Constructs a list with the single item pointed to by a in it.
  2536.           void    append(T* a);
  2537.        Appends the item pointed to by a to the end of the list.
  2538.           void    apply(void (*applyFun)(T*, void*), void* d);
  2539.        Calls the function pointed to by applyFun to every item in the
  2540.        collection.  This must have the prototype:
  2541.             void  yourFun(T* item, void* d);
  2542.        The item will be passed in as argument item.  Client data may be
  2543.        passed through as parameter d.
  2544.           T*      at(int i) const;
  2545.        Returns the item at index i, or nil if the index is an invalid index.
  2546.        Valid indices are between zero and the number of items in the list,
  2547.        less one.
  2548.           void    clear();
  2549.        Removes all items from the list.
  2550.           void    clearAndDestroy();
  2551.        Removes and calls delete for each item in the list.  Note that this
  2552.        assumes that each item was allocated off the heap.
  2553.           RWBoolean      contains(RWBoolean (*testFun)(const T*, void*), void*
  2554.           d) const;
  2555.        Returns TRUE if the list contains an item for which the user-defined
  2556.        "tester" function pointed to by testFun returns TRUE .  The tester
  2557.        function must have the prototype:
  2558.             RWBoolean  yourTester(const T* item, void* d);
  2559.  
  2560.  
  2561.  
  2562. Rogue Wave              Tools.h++   V 5.0   Supplement  47
  2563.  
  2564.  
  2565.  
  2566.  
  2567.  
  2568.  
  2569.  
  2570.  
  2571.                                                           RWTIsvSlist<T>
  2572.  
  2573.  
  2574.        For each item in the list this function will be called with the item
  2575.        as the first argument.  Client data may be passed through as parameter
  2576.        d.
  2577.           RWBoolean      containsReference(const T* a) const;
  2578.        Returns TRUE if the list contains an item with the address a.
  2579.           unsignedentries() const;
  2580.        Returns the number of items currently in the list.
  2581.           T*      find(RWBoolean (*testFun)(const T*, void*), void* d) const;
  2582.        Returns the first item in the list for which the user-defined "tester"
  2583.        function pointed to by testFun returns TRUE.  If there is no such
  2584.        item, then returns nil.  The tester function must have the prototype:
  2585.             RWBoolean  yourTester(const T* item, void* d);
  2586.        For each item in the list this function will be called with the item
  2587.        as the first argument.  Client data may be passed through as parameter
  2588.        d.
  2589.           T*      first() const;
  2590.        Returns (but does not remove) the first item in the list, or nil if
  2591.        the list is empty.
  2592.           T*      get();
  2593.        Returns and removes the first item in the list, or nil if the list is
  2594.        empty.
  2595.           int     index(RWBoolean (*testFun)(const T*, void*), void* d) const;
  2596.        Returns the index of the first item in the list for which the user-
  2597.        defined "tester" function pointed to by testFun returns TRUE.  If
  2598.        there is no such item, then returns -1.  The tester function must have
  2599.        the prototype:
  2600.             RWBoolean  yourTester(const T* item, void* d);
  2601.        For each item in the list this function will be called with the item
  2602.        as the first argument.  Client data may be passed through as parameter
  2603.        d.
  2604.           void    insert(T* a);
  2605.        Appends the item pointed to by a to the end of the list.  This item
  2606.        cannot be inserted into more than one list, nor can it be inserted
  2607.        into the same list more than once.
  2608.           void    insertAt(int i, T* a);
  2609.        Insert the item pointed to by a at the index position i.  This
  2610.        position must be between zero and the number of items in the list.
  2611.        The item cannot be inserted into more than one list, nor can it be
  2612.        inserted into the same list more than once.
  2613.           RWBoolean      isEmpty() const;
  2614.        Returns TRUE if there are no items in the list, FALSE otherwise.
  2615.  
  2616.  
  2617.  
  2618. Rogue Wave              Tools.h++   V 5.0   Supplement  48
  2619.  
  2620.  
  2621.  
  2622.  
  2623.  
  2624.  
  2625.  
  2626.  
  2627.                                                           RWTIsvSlist<T>
  2628.  
  2629.  
  2630.           T*      last() const;
  2631.        Returns (but does not remove) the last item in the list, or nil if the
  2632.        list is empty.
  2633.           unsignedoccurrencesOf(RWBoolean (*testFun)(const T*, void*), void*
  2634.           d) const;
  2635.        Traverses the list and returns the number of times for which the user-
  2636.        defined "tester" function pointed to by testFun returned TRUE .  The
  2637.        tester function must have the prototype:
  2638.             RWBoolean  yourTester(const T* item, void* d);
  2639.        For each item in the list this function will be called with the item
  2640.        as the first argument.  Client data may be passed through as parameter
  2641.        d.
  2642.           unsignedoccurrencesOfReference(const T* a) const;
  2643.        Returns the number of times which the item pointed to by a occurs in
  2644.        the list.  Because items cannot be inserted into a list more than
  2645.        once, this function can only return zero or one.
  2646.           void    prepend(T* a);
  2647.        Prepends the item pointed to by a to the beginning of the list.
  2648.           T*      remove(RWBoolean (*testFun)(const T*, void*), void* d);
  2649.        Removes and returns the first item for which the user-defined tester
  2650.        function pointed to by testFun returns TRUE, or nil if there is no
  2651.        such item.  The tester function must have the prototype:
  2652.             RWBoolean  yourTester(const T* item, void* d);
  2653.        For each item in the list this function will be called with the item
  2654.        as the first argument.  Client data may be passed through as parameter
  2655.        d.
  2656.           T*      removeAt(int i);
  2657.        Removes and returns the item at index i, or nil if the index is an
  2658.        invalid index.  Valid indices are between zero and the number of items
  2659.        in the list, less one.
  2660.           T*      removeFirst();
  2661.        Removes and returns the first item in the list, or nil if there are no
  2662.        items in the list.
  2663.           T*      removeLast();
  2664.        Removes and returns the last item in the list, or nil if there are no
  2665.        items in the list.  This function is relatively slow because removing
  2666.        the last link in a singly-linked list necessitates access to the next-
  2667.        to-the-last link, requiring the whole list to be searched.
  2668.           T*      removeReference(const T* a);
  2669.        Removes and returns the item with address a, or nil if there is no
  2670.        such item.
  2671.  
  2672.  
  2673.  
  2674. Rogue Wave              Tools.h++   V 5.0   Supplement  49
  2675.  
  2676.  
  2677.  
  2678.  
  2679.  
  2680.  
  2681.  
  2682.  
  2683.  
  2684.  
  2685. RWTQueue<T, C>RWTQueue<T, C>
  2686.  
  2687.  
  2688. Synopsis  #include <rw/tqueue.h>
  2689.           RWTQueue<T, C> queue;
  2690.  
  2691. Description          This class represents a parameterized queue.  Not only can
  2692.           the type of object inserted into the queue be parameterized,
  2693.           but also the implementation.
  2694.          Parameter T represents the type of object in the queue, either a
  2695.          class or built in type.  The class T must have:
  2696.           o  well-defined copy semantics (T::T(const T&) or equiv.);
  2697.           o  well-defined assignment semantics (T::operator=(const T&) or
  2698.              equiv.).
  2699.         Parameter C represents the class used for implementation.  Useful
  2700.         choices are RWTValSlist<T> or RWTValDlist<T>.  Vectors, such as
  2701.         RWTValOrderedVector<T>, can also be used, but tend to be less
  2702.         efficient at removing an object off the front of the list.
  2703.  
  2704. Example   In this example a queue of RWCStrings, implemented as a singly-
  2705.           linked list, is exercised.
  2706.           BEGIN FILE: tqueue.cpp
  2707.           #include <rw/tqueue.h>
  2708.           #include <rw/cstring.h>
  2709.           #include <rw/tvslist.h>
  2710.           #include <rw/rstream.h>
  2711.  
  2712.           main() {
  2713.             RWTQueue<RWCString, RWTValSlist<RWCString> > queue;
  2714.  
  2715.             queue.insert("one");   // Type conversion occurs
  2716.             queue.insert("two");
  2717.             queue.insert("three");
  2718.  
  2719.             while (!queue.isEmpty())
  2720.               cout << queue.get() << NL;
  2721.  
  2722.             return 0;
  2723.           }
  2724.           END FILE
  2725.  
  2726. Program output
  2727.           one
  2728.           two
  2729.           three
  2730.  
  2731.  
  2732.  
  2733.  
  2734.  
  2735.  
  2736.  
  2737.  
  2738.                                                           RWTQueue<T, C>
  2739.  
  2740.  
  2741.  
  2742. Public    RWTQueue<T,C>();
  2743. constructor
  2744.  
  2745.  
  2746.           Construct an empty queue of objects of type T, implemented using
  2747.           class C.
  2748.  
  2749. Public   void              clear();
  2750. member
  2751. functions
  2752.  
  2753.  
  2754.           Removes all items from the queue.
  2755.  
  2756.           void                             entries() const;
  2757.           Returns the number of items in the queue.
  2758.           T       first() const;
  2759.        Returns, but does not remove, the first item in the queue (the item
  2760.        least recently inserted into the queue).
  2761.           T       get();
  2762.        Returns and removes the first item in the queue (the item least
  2763.        recently inserted into the queue).
  2764.           RWBoolean      isEmpty() const;
  2765.        Returns TRUE if there are no items in the queue, otherwise FALSE.
  2766.           void    insert(T a);
  2767.        Inserts the item a at the end of the queue.
  2768.           T       last() const;
  2769.        Returns, but does not remove, the last item in the queue (the item
  2770.        most recently inserted into the queue).
  2771.  
  2772.  
  2773.  
  2774.  
  2775.  
  2776.  
  2777.  
  2778.  
  2779.  
  2780.  
  2781.  
  2782.  
  2783.  
  2784.  
  2785. Rogue Wave              Tools.h++   V 5.0   Supplement  51
  2786.  
  2787.  
  2788.  
  2789.  
  2790.  
  2791.  
  2792.  
  2793.  
  2794.  
  2795.  
  2796. RWTStack<T, C>RWTStack<T, C>
  2797.  
  2798.  
  2799. Synopsis  #include <rw/tstack.h>
  2800.           RWTStack<T, C> stack;
  2801.  
  2802. Description          This class maintains a stack of values.  Not only can the
  2803.           type of object inserted onto the stack be parameterized, but
  2804.           also the implementation of the stack.
  2805.          Parameter T represents the type of object in the stack, either a
  2806.          class or built in type.  The class T must have:
  2807.           o  well-defined copy semantics (T::T(const T&) or equiv.);
  2808.           o  well-defined assignment semantics (T::operator=(const T&) or
  2809.              equiv.).
  2810.         Parameter C represents the class used for implementation.
  2811.         Useful choices are RWTValOrderedVector<T> or RWTValDlist<T>.
  2812.         Class RWTValSlist<T> can also be used, but note that singly-
  2813.         linked lists are less efficient at removing the last item of a
  2814.         list (function pop()), because of the necessity of searching
  2815.         the list for the next-to-the-last item.
  2816.  
  2817. Example   In this example a stack of ints, implemented as an ordered
  2818.           vector, is exercised.
  2819.           BEGIN FILE: tstack.cpp
  2820.           #include <rw/tstack.h>
  2821.           #include <rw/tvordvec.h>
  2822.           #include <rw/rstream.h>
  2823.  
  2824.           main() {
  2825.  
  2826.             RWTStack<int, RWTValOrderedVector<int> > stack;
  2827.  
  2828.             stack.push(1);
  2829.             stack.push(5);
  2830.             stack.push(6);
  2831.  
  2832.             while (!stack.isEmpty())
  2833.               cout << stack.pop() << NL;
  2834.             return 0;
  2835.           }
  2836.           END FILE
  2837.  
  2838. Program output:
  2839.           6
  2840.           5
  2841.  
  2842.  
  2843.  
  2844.  
  2845.  
  2846.  
  2847.  
  2848.  
  2849.                                                           RWTStack<T, C>
  2850.  
  2851.  
  2852.           1
  2853.  
  2854. Public    RWTStack<T,C>();
  2855. constructor
  2856.  
  2857.  
  2858.           Constructs an empty stack of objects of type T,
  2859.           implemented using class C.
  2860.  
  2861. Public    void              clear();
  2862. member
  2863. functions
  2864.  
  2865.           Removes all items from the stack.
  2866.  
  2867.           unsigned            entries() const;
  2868.        Returns the number of items currently on the stack.
  2869.           RWBoolean      isEmpty() const;
  2870.        Returns TRUE if there are currently no items on the stack, FALSE
  2871.        otherwise.
  2872.           void    push(T a);
  2873.        Push the item a onto the top of the stack.
  2874.           T       pop();
  2875.        Pop (remove and return) the item at the top of the stack.  If there
  2876.        are no items on the stack then an exception of type TOOL_INDEX will
  2877.        occur.
  2878.           T       top() const;
  2879.        Returns (but does not remove) the item at the top of the stack.
  2880.  
  2881.  
  2882.  
  2883.  
  2884.  
  2885.  
  2886.  
  2887.  
  2888.  
  2889.  
  2890.  
  2891.  
  2892.  
  2893.  
  2894.  
  2895.  
  2896. Rogue Wave              Tools.h++   V 5.0   Supplement  53
  2897.  
  2898.  
  2899.  
  2900.  
  2901.  
  2902.  
  2903.  
  2904.  
  2905.  
  2906.  
  2907. RWTValDlist<T>RWTValDlist<T>
  2908.  
  2909.  
  2910. Synopsis   #include <rw/tvdlist.h>
  2911.            RWTValDlist<T> list;
  2912.  
  2913.  
  2914. Descripti This class maintains a collection of values, implemented as a
  2915. on        doubly linked list.  This is a value based list: objects are
  2916.           copied in and out of the links that make up the list.  Unlike
  2917.           intrusive lists (see class RWTIsvDlist<T>), the objects need
  2918.           not inherit from a link class.  However, this makes the class
  2919.           slightly less efficient than the intrusive lists because of
  2920.           the need to allocate a new link off the heap with every
  2921.           insertion and to make a copy of the object in the newly
  2922.           allocated link.
  2923.           Parameter T represents the type of object to be inserted into
  2924.           the list, either a class or built in type.  The class T must
  2925.           have:
  2926.           o  well-defined copy semantics (T::T(const T&) or equiv.);
  2927.           o  well-defined assignment semantics (T::operator=(const T&) or
  2928.              equiv.);
  2929.           o  well-defined equality semantics (T::operator==(const T&));
  2930.  
  2931. Example   In this example, a doubly-linked list of user type Dog is
  2932.           exercised.
  2933.  
  2934.           BEGIN FILE: tvdlist.cpp
  2935.           #include <rw/tvdlist.h>
  2936.           #include <rw/rstream.h>
  2937.           #include <string.h>
  2938.  
  2939.           class Dog {
  2940.             char* name;
  2941.           public:
  2942.             Dog( const char* c) {
  2943.              name = new char[strlen(c)+1];
  2944.              strcpy(name, c); }
  2945.  
  2946.             ~Dog() { delete name; }
  2947.  
  2948.             // Define a copy constructor:
  2949.             Dog(const Dog& dog) {
  2950.              name = new char[strlen(dog.name)+1];
  2951.              strcpy(name, dog.name); }
  2952.  
  2953.  
  2954.  
  2955.  
  2956.  
  2957.  
  2958.  
  2959.  
  2960.                                                           RWTValDlist<T>
  2961.  
  2962.  
  2963.  
  2964.             // Define an assignment operator:
  2965.             void operator=(const Dog& dog) {
  2966.              if (this!=&dog) {
  2967.                delete name;
  2968.                name = new char[strlen(dog.name)+1];
  2969.                strcpy(name, dog.name);
  2970.              }
  2971.             }
  2972.  
  2973.             // Define an equality test operator:
  2974.             int operator==(const Dog& dog) const {
  2975.              return strcmp(name, dog.name)==0; }
  2976.  
  2977.             friend ostream& operator<<(ostream& str, Dog& dog){
  2978.               str << dog.name;
  2979.               return str;}
  2980.           };
  2981.  
  2982.           main()
  2983.           {
  2984.             RWTValDlist<Dog> terriers;
  2985.             terriers.insert("Cairn Terrier");// NB: type conversion occurs
  2986.             terriers.insert("Irish Terrier");
  2987.             terriers.insert("Schnauzer");
  2988.  
  2989.             cout << "The list " <<
  2990.               (terriers.contains("Schnauzer") ? "does " : "does not ") <<
  2991.               "contain a Schnauzer\n";
  2992.  
  2993.             terriers.insertAt(
  2994.                 terriers.index("Irish Terrier"),
  2995.                 "Fox Terrier"
  2996.               );
  2997.  
  2998.             while (!terriers.isEmpty())
  2999.               cout << terriers.get() << NL;
  3000.  
  3001.             return 0;
  3002.           }
  3003.           END FILE
  3004.  
  3005. Program output:
  3006.  
  3007. Rogue Wave              Tools.h++   V 5.0   Supplement  55
  3008.  
  3009.  
  3010.  
  3011.  
  3012.  
  3013.  
  3014.  
  3015.  
  3016.                                                           RWTValDlist<T>
  3017.  
  3018.  
  3019.           The list does contain a Schnauzer
  3020.           Cairn Terrier
  3021.           Fox Terrier
  3022.           Irish Terrier
  3023.           Schnauzer
  3024.  
  3025. Public    RWTValDlist<T>();
  3026. construct
  3027. ors
  3028.  
  3029.  
  3030.           Construct an empty list.
  3031.           RWTValDlist<T>(const RWTValDlist<T>& list);
  3032.        Construct a copy of the list list.  Depending on the nature of the
  3033.        copy constructor of T, this could be relatively expensive because
  3034.        every item in the list must be copied.
  3035. Public    RWTValDlist&      operator=(const RWTValDlist<T>& list);
  3036. operators
  3037.  
  3038.  
  3039.        Sets self to a copy of the list list.  Depending on the nature of the
  3040.        copy constructor of T, this could be relatively expensive because
  3041.        every item in the list must be copied.
  3042.           T&      operator[](int i);
  3043.        Returns a reference to the item at index i.  The results can be used
  3044.        as an lvalue.  An exception of type TOOL_INDEX will be thrown if i is
  3045.        not a valid index.  Valid indices are from zero to the number of items
  3046.        in the list less one.
  3047.           T       operator[](int i) const;
  3048.        Returns a copy of the item at index i.  The results cannot be used as
  3049.        an lvalue.  An exception of type TOOL_INDEX will be thrown if i is not
  3050.        a valid index.  Valid indices are from zero to the number of items in
  3051.        the list less one.
  3052. Public member functions   void               append(T a);
  3053.  
  3054.  
  3055.           Adds the item a to the end of the list.
  3056.  
  3057.           void                apply(void (*applyFun)(T, void*), void* d);
  3058.        Applies the user-defined function pointed to by applyFun to every item
  3059.        in the list.  This function must have prototype:
  3060.  
  3061.             void yourFun(T a, void* d);
  3062.  
  3063. Rogue Wave              Tools.h++   V 5.0   Supplement  56
  3064.  
  3065.  
  3066.  
  3067.  
  3068.  
  3069.  
  3070.  
  3071.  
  3072.                                                           RWTValDlist<T>
  3073.  
  3074.  
  3075.        Client data may be passed through as parameter d.
  3076.           T&      at(int i);
  3077.        Returns a reference to the item at index i.  The results can be used
  3078.        as an lvalue.  An exception of type TOOL_INDEX will be thrown if i is
  3079.        not a valid index.  Valid indices are from zero to the number of items
  3080.        in the list less one.
  3081.           T       at(int i) const;
  3082.        Returns a copy of the item at index i.  The results cannot be used as
  3083.        an lvalue.  An exception of type TOOL_INDEX will be thrown if i is not
  3084.        a valid index.  Valid indices are from zero to the number of items in
  3085.        the list less one.
  3086.           void    clear();
  3087.        Removes all items from the list.  Their destructors (if any) will be
  3088.        called.
  3089.           RWBoolean      contains(T a) const;
  3090.        Returns TRUE if the list contains an object that is equal to the
  3091.        object a.  Returns FALSE otherwise.  Equality is measured by the
  3092.        class-defined equality operator.
  3093.           RWBoolean      contains(RWBoolean (*testFun)(T, void*), void* d)
  3094.           const;
  3095.        Returns TRUE if the list contains an item for which the user-defined
  3096.        "tester" function pointed to by testFun returns TRUE .  Returns FALSE
  3097.        otherwise.  The tester function must have the prototype:
  3098.             RWBoolean  yourTester(T, void* d);
  3099.        For each item in the list this function will be called with the item
  3100.        as the first argument.  Client data may be passed through as parameter
  3101.        d.
  3102.           unsignedentries() const;
  3103.        Returns the number of items that are currently in the collection.
  3104.           RWBoolean      find(T a, T& k) const;
  3105.        Returns TRUE if the list contains an object that is equal to the
  3106.        object a and puts a copy of the matching object into k.  Returns FALSE
  3107.        otherwise and does not touch k.  Equality is measured by the class-
  3108.        defined equality operator.
  3109.           RWBoolean      find(RWBoolean (*testFun)(T, void*), void* d, T& k)
  3110.           const;
  3111.        Returns TRUE if the list contains an object for which the user-defined
  3112.        tester function pointed to by testFun returns TRUE and puts a copy of
  3113.        the matching object into k.  Returns FALSE otherwise and does not
  3114.        touch k.  The tester function must have the prototype:
  3115.             RWBoolean  yourTester(T, void* d);
  3116.  
  3117.  
  3118.  
  3119. Rogue Wave              Tools.h++   V 5.0   Supplement  57
  3120.  
  3121.  
  3122.  
  3123.  
  3124.  
  3125.  
  3126.  
  3127.  
  3128.                                                           RWTValDlist<T>
  3129.  
  3130.  
  3131.        For each item in the list this function will be called with the item
  3132.        as the first argument.  Client data may be passed through as parameter
  3133.        d.
  3134.           T       first() const;
  3135.        Returns (but does not remove) the first item in the list.  The
  3136.        behavior is undefined if the list is empty.
  3137.           T       get();
  3138.        Returns and removes the first item in the list.  The behavior is
  3139.        undefined if the list is empty.
  3140.           int     index(T a);
  3141.        Returns the index of the first object that is equal to the object a,
  3142.        or -1 if there is no such object.  Equality is measured by the class-
  3143.        defined equality operator.
  3144.           int     index(RWBoolean (*testFun)(T, void*),
  3145.           void* d) const;
  3146.        Returns the index of the first object for which the user-defined
  3147.        tester function pointed to by testFun returns TRUE, or -1 if there is
  3148.        no such object.  The tester function must have the prototype:
  3149.             RWBoolean  yourTester(T, void* d);
  3150.        For each item in the list this function will be called with the item
  3151.        as the first argument.  Client data may be passed through as parameter
  3152.        d.
  3153.           void    insert(T a);
  3154.        Adds the item a to the end of the list.
  3155.           void    insertAt(int i, T a);
  3156.        Insert the item a at the index position i.  This position must be
  3157.        between zero and the number of items in the list.
  3158.           RWBoolean      isEmpty() const;
  3159.        Returns TRUE if there are no items in the list, FALSE otherwise.
  3160.           T       last() const;
  3161.        Returns (but does not remove) the last item in the list.  The behavior
  3162.        is undefined if the list is empty.
  3163.           unsignedoccurrencesOf(T a) const;
  3164.        Returns the number of objects in the list that are equal to the object
  3165.        a.  Equality is measured by the class-defined equality operator.
  3166.           unsignedoccurrencesOf(RWBoolean (*testFun)(T, void*), void* d)
  3167.           const;
  3168.        Returns the number of objects in the list for which the user-defined
  3169.        "tester" function pointed to by testFun returns TRUE .  The tester
  3170.        function must have the prototype:
  3171.             RWBoolean  yourTester(T, void* d);
  3172.  
  3173.  
  3174.  
  3175. Rogue Wave              Tools.h++   V 5.0   Supplement  58
  3176.  
  3177.  
  3178.  
  3179.  
  3180.  
  3181.  
  3182.  
  3183.  
  3184.                                                           RWTValDlist<T>
  3185.  
  3186.  
  3187.        For each item in the list this function will be called with the item
  3188.        as the first argument.  Client data may be passed through as parameter
  3189.        d.
  3190.           void    prepend(T a);
  3191.        Adds the item a to the beginning of the list.
  3192.           RWBoolean      remove(T a);
  3193.        Removes the first object which is equal to the object a and returns
  3194.        TRUE.  Returns FALSE if there is no such object.  Equality is measured
  3195.        by the class-defined equality operator.
  3196.           RWBoolean      remove(RWBoolean (*testFun)(T, void*),
  3197.           void* d);
  3198.        Removes the first object for which the user-defined tester function
  3199.        pointed to by testFun returns TRUE, and returns TRUE.  Returns FALSE
  3200.        if there is no such object.  The tester function must have the
  3201.        prototype:
  3202.             RWBoolean  yourTester(T, void* d);
  3203.        For each item in the list this function will be called with the item
  3204.        as the first argument.  Client data may be passed through as parameter
  3205.        d.
  3206.           unsignedremoveAll(T a);
  3207.        Removes all objects which are equal to the object a.  Returns the
  3208.        number of objects removed.  Equality is measured by the class-defined
  3209.        equality operator.
  3210.           unsignedremoveAll(RWBoolean (*testFun)(T, void*), void* d);
  3211.        Removes all objects for which the user-defined tester function pointed
  3212.        to by testFun returns TRUE.  Returns the number of objects removed.
  3213.        The tester function must have the prototype:
  3214.             RWBoolean  yourTester(T, void* d);
  3215.        For each item in the list this function will be called with the item
  3216.        as the first argument.  Client data may be passed through as parameter
  3217.        d.
  3218.           T       removeAt(int i);
  3219.        Removes and returns the object at index i.  An exception of type
  3220.        TOOL_INDEX will be thrown if i is not a valid index.  Valid indices
  3221.        are from zero to the number of items in the list less one.
  3222.           T       removeFirst();
  3223.        Removes and returns the first item in the list.  The behavior is
  3224.        undefined if the list is empty.
  3225.           T       removeLast()
  3226.        Removes and returns the last item in the list.  The behavior is
  3227.        undefined if the list is empty.
  3228.  
  3229.  
  3230.  
  3231. Rogue Wave              Tools.h++   V 5.0   Supplement  59
  3232.  
  3233.  
  3234.  
  3235.  
  3236.  
  3237.  
  3238.  
  3239.  
  3240.  
  3241.  
  3242. RWTValHashDictionary<K,V>RWTValHashDictionary<K,V>
  3243.  
  3244.  
  3245. Synopsis  #include <rw/tvhdict.h>
  3246.           unsigned hashFun(const K&);
  3247.           RWTValHashDictionary<K,V> dictionary(hashFun);
  3248.  
  3249. Descripti RWTValHashDictionary<K,V> is a dictionary of keys of type K
  3250. on        and values of type V, implemented using a hash table.  While
  3251.           duplicates of values are allowed, duplicates of keys are not.
  3252.         It is a value based collection: keys and values are copied in and out
  3253.         of the hash buckets.
  3254.         Parameters K and V represent the type of the key and the type of the
  3255.         value, respectively, to be inserted into the table.  These can be
  3256.         either classes or built in types.  Classes K and V must have:
  3257.           o  well-defined copy semantics (T::T(const T&) or equiv.);
  3258.           o  well-defined assignment semantics (T::operator=(const T&) or
  3259.              equiv.).
  3260.           In addition, class K must have
  3261.           o  well-defined equality semantics (K::operator==(const K&)).
  3262.  
  3263. A user-supplied hashing function for type K must be supplied to the
  3264. constructor when creating a new table.  If K is a Rogue Wave class, then this
  3265. requirement is usually trivial because all Rogue Wave objects know how to
  3266. return a hashing value.  This function has prototype:
  3267.             unsigned hFun(const K& a);
  3268.  
  3269. and should return a suitable hash value for the object a.
  3270. To find a value, the key is first hashed to determine in which bucket
  3271. the key and value can be found.  The bucket is then searched for an
  3272. object that is equal (as determined by the equality operator) to the
  3273. key.
  3274. The initial number of buckets in the table is set by the constructor.  There
  3275. is a default value.  If the number of (key/value) pairs in the collection
  3276. greatly exceeds the number of buckets then efficiency will sag because each
  3277. bucket must be searched linearly.  The number of buckets can be changed by
  3278. calling member function resize().  This is an expensive proposition because
  3279. not only must all the items be copied into the new buckets, but all of the
  3280. keys must be rehashed.
  3281. If you wish this to be done automatically, then you can subclass from this
  3282. class and implement your own special insert() and remove() functions which
  3283. perform a resize() as necessary.
  3284.  
  3285.  
  3286.  
  3287.  
  3288.  
  3289.  
  3290.  
  3291.  
  3292.                                                RWTValHashDictionary<K,V>
  3293.  
  3294.  
  3295. Example   BEGIN FILE: tvhdict.cpp
  3296.           #include <rw/tvhdict.h>
  3297.           #include <rw/cstring.h>
  3298.           #include <rw/rwdate.h>
  3299.           #include <rw/rstream.h>
  3300.  
  3301.           unsigned hashString(const RWCString& str){return str.hash();}
  3302.  
  3303.           main()
  3304.           {
  3305.             RWTValHashDictionary<RWCString, RWDate> birthdays(hashString);
  3306.  
  3307.             birthdays.insertKeyAndValue("John", RWDate(12, "April", 1975));
  3308.             birthdays.insertKeyAndValue("Ivan", RWDate(2, "Nov", 1980));
  3309.  
  3310.             // Alternative syntax:
  3311.             birthdays["Susan"] = RWDate(30, "June", 1955);
  3312.             birthdays["Gene"] = RWDate(5, "Jan", 1981);
  3313.  
  3314.             // Print a birthday:
  3315.             cout << birthdays["John"] << NL;
  3316.             return 0;
  3317.           }
  3318.           END FILE
  3319.  
  3320. Program output:
  3321.           April 12, 1975
  3322.  
  3323. Public    RWTValHashDictionary<K,V>(unsigned (*hashKey)(const K&),
  3324. constructors          unsigned buckets = RWDEFAULT_CAPACITY);
  3325.  
  3326.  
  3327.        Constructs a new hash dictionary.  The first argument is a pointer to
  3328.        a user-defined hashing function for items of type K (the key).  The
  3329.        table will initally have buckets buckets although this can be changed
  3330.        with member function resize().
  3331.           RWTValHashDictionary<K,V>(const RWTValHashDictionary<K,V>& dict);
  3332.        Copy constructor.  Constructs a new hash dictionary as a copy of dict.
  3333.        The new dictionary will have the same number of buckets as the old
  3334.        table.  Hence, although the keys and values must be copied into the
  3335.        new table, the keys will not be rehashed.
  3336.  
  3337.  
  3338.  
  3339. Rogue Wave              Tools.h++   V 5.0   Supplement  61
  3340.  
  3341.  
  3342.  
  3343.  
  3344.  
  3345.  
  3346.  
  3347.  
  3348.                                                RWTValHashDictionary<K,V>
  3349.  
  3350.  
  3351. Public    RWTValHashDictionary<K,V>&
  3352. operators operator=(const RWTValHashDictionary<K,V>& dict);
  3353.  
  3354.  
  3355.          Sets self to a copy of dict.  Afterwards, the new table will have
  3356.          the same number of buckets as the old table.  Hence, although the
  3357.          keys and values must be copied into the new table, the keys will not
  3358.          be rehashed.
  3359.           V&      operator[](K key);
  3360.        Look up the key key and return its associated value as an lvalue
  3361.        reference.  If the key is not in the dictionary, then it is added to
  3362.        the dictionary.  In this case, the value associated with the key will
  3363.        be provided by the default constructor for objects of type V.
  3364. Public    void              applyToKeyAndValue(
  3365. member    void (*applyFun)(K,V&,void*), void* d);
  3366. functions
  3367.  
  3368.  
  3369.        Applies the user-defined function pointed to by applyFun to every key-
  3370.        value pair in the dictionary.  This function must have prototype:
  3371.             void yourFun(K key, V& value, void* d);
  3372.        The key will be passed by value and hence cannot be changed.  The
  3373.        value will be passed by reference and can be modified.  Client data
  3374.        may be passed through as parameter d.
  3375.           void    clear();
  3376.        Removes all items from the collection.
  3377.           RWBoolean      contains(K key) const;
  3378.        Returns TRUE if the dictionary contains a key which is equal to key.
  3379.        Returns FALSE otherwise.  Equality is measured by the class-defined
  3380.        equality operator for class K.
  3381.           unsignedentries() const;
  3382.        Returns the number of key-value pairs currently in the dictionary.
  3383.           RWBoolean      find(K key, K& retKey) const;
  3384.        Returns TRUE if the dictionary contains a key which is equal to key
  3385.        and puts the matching key into retKey.  Returns FALSE otherwise and
  3386.        leaves retKey untouched.  Equality is measured by the class-defined
  3387.        equality operator for class K.
  3388.           RWBoolean      findValue(K key, V& retVal) const;
  3389.        Returns TRUE if the dictionary contains a key which is equal to key
  3390.        and puts the associated value into retVal.  Returns FALSE otherwise
  3391.        and leaves retVal untouched.  Equality is measured by the class-
  3392.        defined equality operator for class K.
  3393.  
  3394.  
  3395. Rogue Wave              Tools.h++   V 5.0   Supplement  62
  3396.  
  3397.  
  3398.  
  3399.  
  3400.  
  3401.  
  3402.  
  3403.  
  3404.                                                RWTValHashDictionary<K,V>
  3405.  
  3406.  
  3407.           RWBoolean      findKeyAndValue(K key, K& retKey, V& retVal) const;
  3408.        Returns TRUE if the dictionary contains a key which is equal to key
  3409.        and puts the matching key into retKey and the associated value into
  3410.        retVal.  Returns FALSE otherwise and leaves retKey and retVal
  3411.        untouched.  Equality is measured by the class-defined equality
  3412.        operator for class K.
  3413.           void    insertKeyAndValue(K key, V value);
  3414.        Inserts the key key and value value into the dictionary.
  3415.           RWBoolean      isEmpty() const;
  3416.        Returns TRUE if the dictionary has no items in it, FALSE otherwise.
  3417.           RWBoolean      remove(K key);
  3418.        Returns TRUE and removes the (key/value) pair where the key is equal
  3419.        to the key.  Returns FALSE if there is no such key.  Equality is
  3420.        measured by the class-defined equality operator for class K.
  3421.           void    resize(unsigned N);
  3422.        Changes the number of buckets to N, a relatively expensive operation
  3423.        if there are many items in the collection.
  3424.  
  3425.  
  3426.  
  3427.  
  3428.  
  3429.  
  3430.  
  3431.  
  3432.  
  3433.  
  3434.  
  3435.  
  3436.  
  3437.  
  3438.  
  3439.  
  3440.  
  3441.  
  3442.  
  3443.  
  3444.  
  3445.  
  3446.  
  3447.  
  3448.  
  3449.  
  3450.  
  3451. Rogue Wave              Tools.h++   V 5.0   Supplement  63
  3452.  
  3453.  
  3454.  
  3455.  
  3456.  
  3457.  
  3458.  
  3459.  
  3460.  
  3461.  
  3462. RWTValHashSet<T>RWTValHashSet<T>                   RWTValHashSet<T>
  3463.                                                            |
  3464.                                                   RWTValHashTable<T>
  3465.  
  3466.  
  3467.  
  3468. Synopsis  #include <rw/tvhset.h>
  3469.           unsigned hashFun(const T&);
  3470.           RWTValHashSet(hashFun) set;
  3471.  
  3472. Descripti RWTValHashSet<T> is a derived class of RWTValHashTable<T> where
  3473. on        the insert() function has been overridden to accept only one
  3474.           item of a given value.  Hence, each item in the collection will
  3475.           be unique.
  3476.         As with class RWTValHashTable<T>, you must supply a hashing function
  3477.         to the constructor.
  3478.         The class T must have:
  3479.           o  well-defined copy semantics (T::T(const T&) or equiv.);
  3480.           o  well-defined assignment semantics (T::operator=(const T&) or
  3481.              equiv.);
  3482.           o  well-defined equality semantics (T::operator==(const T&)).
  3483.  
  3484. Example   This examples exercises a set of RWCStrings.
  3485.  
  3486.           BEGIN FILE: tvhset.cpp
  3487.           #include <rw/tvhset.h>
  3488.           #include <rw/cstring.h>
  3489.           #include <rw/rstream.h>
  3490.  
  3491.           unsigned hashIt(const RWCString& str){ return str.hash(); }
  3492.  
  3493.           main()
  3494.           {
  3495.             RWTValHashSet<RWCString> set(hashIt);
  3496.  
  3497.             set.insert("one");
  3498.             set.insert("two");
  3499.             set.insert("three");
  3500.             set.insert("one");// Rejected: already in collection
  3501.  
  3502.             cout << set.entries() << NL;       // Prints "3"
  3503.             return 0;
  3504.           }
  3505.           END FILE
  3506.  
  3507.  
  3508.  
  3509.  
  3510.  
  3511.  
  3512.  
  3513.  
  3514.                                                         RWTValHashSet<T>
  3515.  
  3516.  
  3517. Program output:
  3518.           3
  3519.  
  3520.        Inherited from class RWTValHashTable<T>.
  3521.           void    clear();
  3522.        Inherited from class RWTValHashTable<T>.
  3523.           RWBoolean      contains(T val) const;
  3524.        Inherited from class RWTValHashTable<T>.
  3525.           unsignedentries() const;
  3526.        Inherited from class RWTValHashTable<T>.
  3527.           RWBoolean      find(T a, T& k) const;
  3528.        Inherited from class RWTValHashTable<T>.
  3529.           void    insert(T val);
  3530.        Redefined from class RWTValHashTable<T> to allow an object of a given
  3531.        value to be inserted only once.
  3532.           RWBoolean      isEmpty() const;
  3533.        Inherited from class RWTValHashTable<T>.
  3534.           unsignedoccurrencesOf(T val) const;
  3535.        Inherited from class RWTValHashTable<T>.
  3536.           RWBoolean      remove(T val);
  3537.        Inherited from class RWTValHashTable<T>.
  3538.           unsignedremoveAll(T val);
  3539.        Inherited from class RWTValHashTable<T>.
  3540.           void    resize(unsigned N);
  3541.        Inherited from class RWTValHashTable<T>.
  3542.  
  3543.  
  3544.  
  3545.  
  3546.  
  3547.  
  3548.  
  3549.  
  3550.  
  3551.  
  3552.  
  3553.  
  3554.  
  3555.  
  3556.  
  3557.  
  3558.  
  3559.  
  3560.  
  3561. Rogue Wave              Tools.h++   V 5.0   Supplement  65
  3562.  
  3563.  
  3564.  
  3565.  
  3566.  
  3567.  
  3568.  
  3569.  
  3570.  
  3571.  
  3572. RWTValHashTable<T>RWTValHashTable<T>
  3573.  
  3574.  
  3575. Synopsis  #include <rw/tvhasht.h>
  3576.           unsigned hashFun(const T&);
  3577.           RWTValHashTable<T> table(hashFun);
  3578.  
  3579. Description This class implements a parameterized hash table of types T.  It uses
  3580.           chaining to resolve hash collisions.  Duplicates are allowed.
  3581.           It is a value based collection: objects are copied in and out of the
  3582.           hash buckets.
  3583. Parameter T represents the type of object to be inserted into the table,
  3584. either a class or built in type.  The class T must have:
  3585.           o  well-defined copy semantics (T::T(const T&) or equiv.);
  3586.           o  well-defined assignment semantics (T::operator=(const T&) or
  3587.              equiv.);
  3588.           o  well-defined equality semantics (T::operator==(const T&)).
  3589.  
  3590. A user-supplied hashing function for type T must be supplied to the
  3591. constructor when creating a new table.  If T is a Rogue Wave class, then this
  3592. requirement is usually trivial because all Rogue Wave objects know how to
  3593. return a hashing value.  This function has prototype:
  3594.             unsigned hFun(const T& a);
  3595.  
  3596. and should return a suitable hash value for the object a.
  3597. To find an object, it is first hashed to determine in which bucket it occurs.
  3598. The bucket is then searched for an object that is equal (as determined by the
  3599. equality operator) to the candidate.
  3600. The initial number of buckets in the table is set by the constructor.  There
  3601. is a default value.  If the number of items in the collection greatly exceeds
  3602. the number of buckets then efficiency will sag because each bucket must be
  3603. searched linearly.  The number of buckets can be changed by calling member
  3604. function resize().  This is an expensive proposition because not only must
  3605. all items be copied into the new buckets, but they must also be rehashed.
  3606. If you wish this to be automatically done, then you can subclass from this
  3607. class and implement your own special insert() and remove() functions which
  3608. perform a resize() as necessary.
  3609.  
  3610. Example   BEGIN FILE: hasht.cpp
  3611.           #include <rw/tvhasht.h>
  3612.           #include <rw/cstring.h>
  3613.           #include <rw/rstream.h>
  3614.  
  3615.           unsigned hashIt(const RWCString& str) {return str.hash();}
  3616.  
  3617.  
  3618.  
  3619.  
  3620.  
  3621.  
  3622.  
  3623.  
  3624.                                                       RWTValHashTable<T>
  3625.  
  3626.  
  3627.           main()
  3628.           {
  3629.             RWTValHashTable<RWCString> table(hashIt);
  3630.  
  3631.             table.insert("Alabama");// NB: Type conversion occurs
  3632.             table.insert("Pennsylvania");
  3633.             table.insert("Oregon");
  3634.             table.insert("Montana");
  3635.  
  3636.             cout << "The table " <<
  3637.               (table.contains("Oregon") ? "does " : "does not ") <<
  3638.               "contain Oregon\n";
  3639.  
  3640.             table.removeAll("Oregon");
  3641.  
  3642.             cout << "The table " <<
  3643.               (table.contains("Oregon") ? "does " : "does not ") <<
  3644.               "contain Oregon";
  3645.             return 0;
  3646.           }
  3647.           END FILE
  3648.  
  3649. Program output
  3650.           The table does contain Oregon
  3651.           The table does not contain Oregon
  3652.  
  3653. Public    RWTValHashTable<T>(unsigned (*hashFun)(const T&),
  3654. constructors          unsigned buckets = RWDEFAULT_CAPACITY);
  3655.  
  3656.  
  3657.           Constructs a new hash table.  The first argument is a pointer to a
  3658.           user-defined hashing function for items of type T.  The table will
  3659.           initally have buckets buckets although this can be changed with member
  3660.           function resize().
  3661.           RWTValHashTable<T>(const RWTValHashTable<T>& table);
  3662.        Constructs a new hash table as a copy of table.  The new table will
  3663.        have the same number of buckets as the old table.  Hence, although
  3664.        objects must be copied into the new table, they will not be hashed.
  3665. Public operators   RWTValHashTable&   operator=(const RWTValHashTable<T>&);
  3666.  
  3667.  
  3668.  
  3669.  
  3670.  
  3671. Rogue Wave              Tools.h++   V 5.0   Supplement  67
  3672.  
  3673.  
  3674.  
  3675.  
  3676.  
  3677.  
  3678.  
  3679.  
  3680.                                                       RWTValHashTable<T>
  3681.  
  3682.  
  3683.           Sets self to a copy of table.  Afterwards, the new table will have
  3684.           the same number of buckets as the old table.  Hence, although objects
  3685.           must be copied into the new table, they will not be hashed.
  3686.  
  3687. Public    void              apply(void (*applyFun)(T, void*), void* d);
  3688. member
  3689. functions
  3690.  
  3691.  
  3692.           Applies the user-defined function pointed to by applyFun to every
  3693.           item in the table.  This function must have prototype:
  3694.                void yourFun(T a, void* d);
  3695.           Client data may be passed through as parameter d.
  3696.           void    clear();
  3697.        Removes all items from the collection.
  3698.           RWBoolean      contains(T val) const;
  3699.        Returns TRUE if the collection contains an item which is equal to val.
  3700.        Returns FALSE otherwise.  Equality is measured by the class-defined
  3701.        equality operator.
  3702.           unsignedentries() const;
  3703.        Returns the number of items currently in the collection.
  3704.           RWBoolean      find(T a, T& k) const;
  3705.        Returns TRUE if the collection contains an item which is equal to val
  3706.        and puts the matching object into k.  Returns FALSE otherwise and
  3707.        leaves k untouched.  Equality is measured by the class-defined
  3708.        equality operator.
  3709.           void    insert(T val);
  3710.        Inserts the value val into the collection.
  3711.           RWBoolean      isEmpty() const;
  3712.        Returns TRUE if the collection has no items in it, FALSE otherwise.
  3713.           unsignedoccurrencesOf(T val) const;
  3714.        Returns the number of items in the collection which are equal to val.
  3715.        Equality is measured by the class-defined equality operator.
  3716.           RWBoolean      remove(T val);
  3717.        Removes the first object which is equal to the object a and returns
  3718.        TRUE.  Returns FALSE if there is no such object.  Equality is measured
  3719.        by the class-defined equality operator.
  3720.           unsignedremoveAll(T val);
  3721.        Removes all objects which are equal to the object a.  Returns the
  3722.        number of objects removed.  Equality is measured by the class-defined
  3723.        equality operator.
  3724.  
  3725.  
  3726.  
  3727. Rogue Wave              Tools.h++   V 5.0   Supplement  68
  3728.  
  3729.  
  3730.  
  3731.  
  3732.  
  3733.  
  3734.  
  3735.  
  3736.                                                       RWTValHashTable<T>
  3737.  
  3738.  
  3739.           void    resize(unsigned N);
  3740. Changes the number of buckets to N, a relatively expensive operation if there
  3741. are many items in the collection.
  3742.  
  3743.  
  3744.  
  3745.  
  3746.  
  3747.  
  3748.  
  3749.  
  3750.  
  3751.  
  3752.  
  3753.  
  3754.  
  3755.  
  3756.  
  3757.  
  3758.  
  3759.  
  3760.  
  3761.  
  3762.  
  3763.  
  3764.  
  3765.  
  3766.  
  3767.  
  3768.  
  3769.  
  3770.  
  3771.  
  3772.  
  3773.  
  3774.  
  3775.  
  3776.  
  3777.  
  3778.  
  3779.  
  3780.  
  3781.  
  3782.  
  3783. Rogue Wave              Tools.h++   V 5.0   Supplement  69
  3784.  
  3785.  
  3786.  
  3787.  
  3788.  
  3789.  
  3790.  
  3791.  
  3792.  
  3793.  
  3794. RWTValOrderedVector<T>RWTValOrderedVector<T>
  3795.  
  3796.  
  3797. Synopsis   #include <rw/tvordvec.h>
  3798.            RWTValOrderedVector<T> ordvec;
  3799.  
  3800. Description          RWTValOrderedVector<T> is an ordered collection.  That is, the
  3801.           items in the collection have a meaningful ordered relationship with
  3802.           respect to one another and can be accessed by an index number.  The
  3803.           order is set by the order of insertion.  Duplicates are allowed.
  3804.           The class is implemented as a vector, allowing efficient insertion
  3805.           and retrieval from the end of the collection, but somewhat slower
  3806.           from the beginning of the collection.
  3807. The class T must have:
  3808.           o  well-defined copy semantics (T::T(const T&) or equiv.);
  3809.           o  well-defined assignment semantics (T::operator=(const T&) or
  3810.              equiv.);
  3811.           o  well-defined equality semantics (T::operator==(const T&));
  3812.           o  a default constructor.
  3813.  
  3814. Example   BEGIN FILE: tvordvec.cpp
  3815.           #include <rw/tvordvec.h>
  3816.           #include <rw/rstream.h>
  3817.  
  3818.           main() {
  3819.  
  3820.             RWTValOrderedVector<double> vec;
  3821.  
  3822.             vec.insert(22.0);
  3823.             vec.insert(5.3);
  3824.             vec.insert(-102.5);
  3825.             vec.insert(15.0);
  3826.             vec.insert(5.3);
  3827.  
  3828.             cout << vec.entries() << " entries\n" << NL;// Prints "5"
  3829.             for (int i=0; i<vec.length(); i++)
  3830.               cout << vec[i] << NL;
  3831.  
  3832.             return 0;
  3833.           }
  3834.           END FILE
  3835.  
  3836. Program output:
  3837.           5 entries
  3838.           22
  3839.  
  3840.  
  3841.  
  3842.  
  3843.  
  3844.  
  3845.  
  3846.  
  3847.                                                   RWTValOrderedVector<T>
  3848.  
  3849.  
  3850.           5.3
  3851.           -102.5
  3852.           15
  3853.           5.3
  3854.  
  3855. Public   RWTValOrderedVector<T>(unsigned capac=RWDEFAULT_CAPACITY);
  3856. constructor
  3857.  
  3858.  
  3859.           Create an empty ordered vector with capacity capac.  Should the
  3860.           number of items exceed this value, the vector will be resized
  3861.           automatically.
  3862.  
  3863. Public operators      T                 operator()(int i) const;
  3864.                       T&                operator()(int i);
  3865.  
  3866.           Return the i'th value in the vector.  The index i must be between 0 and
  3867.           the length of the vector less one.  No bounds checking is performed.
  3868.           T       operator[](int i) const;
  3869.           T&      operator[](int i);
  3870.        Return the i'th value in the vector.  The index i must be between 0
  3871.        and the length of the vector less one.  Bounds checking will be
  3872.        performed.
  3873. Public    void              append(T a);
  3874. member
  3875. functions
  3876.  
  3877.  
  3878.           Appends the value a to the end of the vector.  The collection will
  3879.           automatically be resized if this causes the number of items in the
  3880.           collection to exceed the capacity.
  3881.           T&      at(int i);
  3882.           T       at(int i) const;
  3883.        Return the i'th value in the vector.  The index i must be between 0
  3884.        and the length of the vector less one.  Bounds checking will be
  3885.        performed.
  3886.           void    clear();
  3887.        Removes all items from the collection.
  3888.           RWBoolean      contains(T a) const;
  3889.        Returns TRUE if the collection contains an item that is equal to a.  A
  3890.        linear search is done.  Equality is measured by the class-defined
  3891.        equality operator.
  3892.  
  3893.  
  3894. Rogue Wave              Tools.h++   V 5.0   Supplement  71
  3895.  
  3896.  
  3897.  
  3898.  
  3899.  
  3900.  
  3901.  
  3902.  
  3903.                                                   RWTValOrderedVector<T>
  3904.  
  3905.  
  3906.           const T*data() const;
  3907.        Returns a pointer to the raw data of the vector.  The contents should
  3908.        not be changed.  Should be used with care.
  3909.           unsignedentries() const;
  3910.        Returns the number of items currently in the collection.
  3911.           RWBoolean      find(T a,T& ret) const;
  3912.        Performs a linear search and returns TRUE if the vector contains an
  3913.        object that is equal to the object a and puts a copy of the matching
  3914.        object into ret.  Returns FALSE otherwise and does not touch ret.
  3915.        Equality is measured by the class-defined equality operator.
  3916.           T       first() const;
  3917.        Returns the first item in the collection.  An exception of type
  3918.        TOOL_INDEX will occur if the vector is empty.
  3919.           int     index(T a) const;
  3920.        Performs a linear search, returning the index of the first item that
  3921.        is equal to a.  Returns -1 if there is no such item.  Equality is
  3922.        measured by the class-defined equality operator.
  3923.           void    insert(T a);
  3924.        Appends the value a to the end of the vector.  The collection will
  3925.        automatically be resized if this causes the number of items in the
  3926.        collection to exceed the capacity.
  3927.           void    insertAt(int i, T a);
  3928.        Inserts the value a into the vector at index i.  The item previously
  3929.        at position i is moved to i+1, etc.  The collection will automatically
  3930.        be resized if this causes the number of items in the collection to
  3931.        exceed the capacity.  The index i must be between 0 and the number of
  3932.        items in the vector or an exception of type TOOL_INDEX will occur.
  3933.           RWBoolean      isEmpty() const;
  3934.        Returns TRUE if there are no items in the collection, FALSE otherwise.
  3935.           T       last() const;
  3936.        Returns the last item in the collection.  If there are no items in the
  3937.        collection then an exception of type TOOL_INDEX will occur.
  3938.           unsignedlength() const;
  3939.        Returns the number of items currently in the collection.
  3940.           unsignedoccurrencesOf(T a) const;
  3941.        Performs a linear search, returning the number of items that are equal
  3942.        to a.  Equality is measured by the class-defined equality operator.
  3943.           void    prepend(T a);
  3944.        Prepends the value a to the beginning of the vector.  The collection
  3945.        will automatically be resized if this causes the number of items in
  3946.        the collection to exceed the capacity.
  3947.  
  3948.  
  3949.  
  3950. Rogue Wave              Tools.h++   V 5.0   Supplement  72
  3951.  
  3952.  
  3953.  
  3954.  
  3955.  
  3956.  
  3957.  
  3958.  
  3959.                                                   RWTValOrderedVector<T>
  3960.  
  3961.  
  3962.           RWBoolean      remove(T a);
  3963.        Performs a linear search, removing the first object which is equal to
  3964.        the object a and returns TRUE.  Returns FALSE if there is no such
  3965.        object.  Equality is measured by the class-defined equality operator.
  3966.           unsignedremoveAll(T a);
  3967.        Removes all items which are equal to a, returning the number removed.
  3968.        Equality is measured by the class-defined equality operator.
  3969.           T       removeAt(int i);
  3970.        Removes and returns the object at index i.  An exception of type
  3971.        TOOL_INDEX will be thrown if i is not a valid index.  Valid indices
  3972.        are from zero to the number of items in the list less one.
  3973.           T       removeFirst();
  3974.        Removes and returns the first object in the collection.  An exception
  3975.        of type TOOL_INDEX will be thrown if the list is empty.
  3976.           T       removeLast();
  3977.        Removes and returns the last object in the collection.  An exception
  3978.        of type TOOL_INDEX will be thrown if the list is empty.
  3979.           void    resize(unsigned N);
  3980.        Changes the capacity of the collection to N.  Note that the number of
  3981.        objects in the collection does not change, just the capacity.
  3982.  
  3983.  
  3984.  
  3985.  
  3986.  
  3987.  
  3988.  
  3989.  
  3990.  
  3991.  
  3992.  
  3993.  
  3994.  
  3995.  
  3996.  
  3997.  
  3998.  
  3999.  
  4000.  
  4001.  
  4002.  
  4003.  
  4004.  
  4005.  
  4006. Rogue Wave              Tools.h++   V 5.0   Supplement  73
  4007.  
  4008.  
  4009.  
  4010.  
  4011.  
  4012.  
  4013.  
  4014.  
  4015.  
  4016.  
  4017. RWTValSlist<T>RWTValSlist<T>
  4018.  
  4019.  
  4020. Synopsis   #include <rw/tvslist.h>
  4021.            RWTValSlist<T> list;
  4022.  
  4023. Description          This class maintains a collection of values, implemented as a
  4024.           singly linked list.  This is a value based list: objects are copied
  4025.           in and out of the links that make up the list.  Unlike intrusive
  4026.           lists (see class RWTIsvSlist<T>) the objects need not inherit from
  4027.           a link class.  However, this makes the class slightly less
  4028.           efficient than the intrusive lists because of the need to allocate
  4029.           a new link off the heap with every insertion and to make a copy of
  4030.           the object in the newly allocated link.
  4031. Parameter T represents the type of object to be inserted into the list,
  4032. either a class or built in type.  The class T must have:
  4033.           o  well-defined copy semantics (T::T(const T&) or equiv.);
  4034.           o  well-defined assignment semantics (T::operator=(const T&) or
  4035.              equiv.);
  4036.           o  well-defined equality semantics (T::operator==(const T&)).
  4037.  
  4038. Example   In this example, a singly-linked list of RWDates is exercised.
  4039.  
  4040.           BEGIN FILE: tvslist.cpp
  4041.           #include <rw/tvslist.h>
  4042.           #include <rw/rwdate.h>
  4043.           #include <rw/rstream.h>
  4044.  
  4045.  
  4046.           main()
  4047.           {
  4048.             RWTValSlist<RWDate> dates;
  4049.             dates.insert(RWDate(2, "June", 52));   // 6/2/52
  4050.             dates.insert(RWDate(30, "March", 46));// 3/30/46
  4051.             dates.insert(RWDate(1, "April", 90));  // 4/1/90
  4052.  
  4053.             // Now look for one of the dates:
  4054.             RWDate ret;
  4055.             if (dates.find(RWDate(2, "June", 52), ret)){
  4056.               cout << "Found date " << ret << NL;
  4057.             }
  4058.  
  4059.             // Remove in reverse order:
  4060.             while (!dates.isEmpty())
  4061.               cout << dates.removeLast() << NL;
  4062.  
  4063.  
  4064.  
  4065.  
  4066.  
  4067.  
  4068.  
  4069.  
  4070.                                                           RWTValSlist<T>
  4071.  
  4072.  
  4073.  
  4074.             return 0;
  4075.           }
  4076.           END FILE
  4077.  
  4078. Program output:
  4079.           Found date June 2, 1952
  4080.           April 1, 1990
  4081.           March 30, 1946
  4082.           June 2, 1952
  4083.  
  4084. Public   RWTValSlist<T>();
  4085. constructors
  4086.  
  4087.  
  4088.           Construct an empty list.
  4089.           RWTValSlist<T>(const RWTValSlist<T>& list);
  4090.        Construct a copy of the list list.  Depending on the nature of the
  4091.        copy constructor of T, this could be relatively expensive because
  4092.        every item in the list must be copied.
  4093. Public   RWTValSlist&      operator=(const RWTValSlist<T>& list);
  4094. operators
  4095.  
  4096.  
  4097.           Sets self to a copy of the list list.  Depending on the nature of the
  4098.           copy constructor of T, this could be relatively expensive because every
  4099.           item in the list must be copied.
  4100.           T&      operator[](int i);
  4101.        Returns a reference to the item at index i.  The results can be used
  4102.        as an lvalue.  An exception of type TOOL_INDEX will be thrown if i is
  4103.        not a valid index.  Valid indices are from zero to the number of items
  4104.        in the list less one.
  4105.           T       operator[](int i) const;
  4106.        Returns a copy of the item at index i.  The results cannot be used as
  4107.        an lvalue.  An exception of type TOOL_INDEX will be thrown if i is not
  4108.        a valid index.  Valid indices are from zero to the number of items in
  4109.        the list less one.
  4110. Public member          void              append(T a);
  4111. functions
  4112.  
  4113.  
  4114.           Adds the item a to the end of the list.
  4115.  
  4116.  
  4117. Rogue Wave              Tools.h++   V 5.0   Supplement  75
  4118.  
  4119.  
  4120.  
  4121.  
  4122.  
  4123.  
  4124.  
  4125.  
  4126.                                                           RWTValSlist<T>
  4127.  
  4128.  
  4129.           void    apply(void (*applyFun)(T, void*), void* d);
  4130.        Applies the user-defined function pointed to by applyFun to every item
  4131.        in the list.  This function must have prototype:
  4132.             void yourFun(T a, void* d);
  4133.        Client data may be passed through as parameter d.
  4134.           T&      at(int i);
  4135.        Returns a reference to the item at index i.  The results can be used
  4136.        as an lvalue.  An exception of type TOOL_INDEX will be thrown if i is
  4137.        not a valid index.  Valid indices are from zero to the number of items
  4138.        in the list less one.
  4139.           T       at(int i) const;
  4140.        Returns a copy of the item at index i.  The results cannot be used as
  4141.        an lvalue.  An exception of type TOOL_INDEX will be thrown if i is not
  4142.        a valid index.  Valid indices are from zero to the number of items in
  4143.        the list less one.
  4144.           void    clear();
  4145.        Removes all items from the list.  Their destructors (if any) will be
  4146.        called.
  4147.           RWBoolean      contains(T a) const;
  4148.        Returns TRUE if the list contains an object that is equal to the
  4149.        object a.  Returns FALSE otherwise.  Equality is measured by the
  4150.        class-defined equality operator.
  4151.           RWBoolean      contains(RWBoolean (*testFun)(T, void*), void* d)
  4152.           const;
  4153.        Returns TRUE if the list contains an item for which the user-defined
  4154.        "tester" function pointed to by testFun returns TRUE .  Returns FALSE
  4155.        otherwise.  The tester function must have the prototype:
  4156.             RWBoolean  yourTester(T, void* d);
  4157.        For each item in the list this function will be called with the item
  4158.        as the first argument.  Client data may be passed through as parameter
  4159.        d.
  4160.           unsignedentries() const;
  4161.        Returns the number of items that are currently in the collection.
  4162.           RWBoolean      find(T a, T& k) const;
  4163.        Returns TRUE if the list contains an object that is equal to the
  4164.        object a and puts a copy of the matching object into k.  Returns FALSE
  4165.        otherwise and does not touch k.  Equality is measured by the class-
  4166.        defined equality operator.
  4167.           RWBoolean      find(RWBoolean (*testFun)(T, void*), void* d, T& k)
  4168.           const;
  4169.        Returns TRUE if the list contains an object for which the user-defined
  4170.        tester function pointed to by testFun returns TRUE and puts a copy of
  4171.  
  4172.  
  4173. Rogue Wave              Tools.h++   V 5.0   Supplement  76
  4174.  
  4175.  
  4176.  
  4177.  
  4178.  
  4179.  
  4180.  
  4181.  
  4182.                                                           RWTValSlist<T>
  4183.  
  4184.  
  4185.        the matching object into k.  Returns FALSE otherwise and does not
  4186.        touch k.  The tester function must have the prototype:
  4187.             RWBoolean  yourTester(T, void* d);
  4188.        For each item in the list this function will be called with the item
  4189.        as the first argument.  Client data may be passed through as parameter
  4190.        d.
  4191.           T       first() const;
  4192.        Returns (but does not remove) the first item in the list.  The
  4193.        behavior is undefined if the list is empty.
  4194.           T       get();
  4195.        Returns and removes the first item in the list.  The behavior is
  4196.        undefined if the list is empty.
  4197.           int     index(T a);
  4198.        Returns the index of the first object that is equal to the object a,
  4199.        or -1 if there is no such object.  Equality is measured by the class-
  4200.        defined equality operator.
  4201.           int     index(RWBoolean (*testFun)(T, void*),
  4202.           void* d) const;
  4203.        Returns the index of the first object for which the user-defined
  4204.        tester function pointed to by testFun returns TRUE, or -1 if there is
  4205.        no such object.  The tester function must have the prototype:
  4206.             RWBoolean  yourTester(T, void* d);
  4207.        For each item in the list this function will be called with the item
  4208.        as the first argument.  Client data may be passed through as parameter
  4209.        d.
  4210.           void    insert(T a);
  4211.        Adds the item a to the end of the list.
  4212.           void    insertAt(int i, T a);
  4213.        Insert the item a at the index position i.  This position must be
  4214.        between zero and the number of items in the list.
  4215.           RWBoolean      isEmpty() const;
  4216.        Returns TRUE if there are no items in the list, FALSE otherwise.
  4217.           T       last() const;
  4218.        Returns (but does not remove) the last item in the list.  The behavior
  4219.        is undefined if the list is empty.
  4220.           unsignedoccurrencesOf(T a) const;
  4221.        Returns the number of objects in the list that are equal to the object
  4222.        a.  Equality is measured by the class-defined equality operator.
  4223.           unsignedoccurrencesOf(RWBoolean (*testFun)(T, void*), void* d)
  4224.           const;
  4225.        Returns the number of objects in the list for which the user-defined
  4226.        "tester" function pointed to by testFun returns TRUE .  The tester
  4227.        function must have the prototype:
  4228.  
  4229. Rogue Wave              Tools.h++   V 5.0   Supplement  77
  4230.  
  4231.  
  4232.  
  4233.  
  4234.  
  4235.  
  4236.  
  4237.  
  4238.                                                           RWTValSlist<T>
  4239.  
  4240.  
  4241.             RWBoolean  yourTester(T, void* d);
  4242.        For each item in the list this function will be called with the item
  4243.        as the first argument.  Client data may be passed through as parameter
  4244.        d.
  4245.           void    prepend(T a);
  4246.        Adds the item a to the beginning of the list.
  4247.           RWBoolean      remove(T a);
  4248.        Removes the first object which is equal to the object a and returns
  4249.        TRUE.  Returns FALSE if there is no such object.  Equality is measured
  4250.        by the class-defined equality operator.
  4251.           RWBoolean      remove(RWBoolean (*testFun)(T, void*),
  4252.           void* d);
  4253.        Removes the first object for which the user-defined tester function
  4254.        pointed to by testFun returns TRUE, and returns TRUE.  Returns FALSE
  4255.        if there is no such object.  The tester function must have the
  4256.        prototype:
  4257.             RWBoolean  yourTester(T, void* d);
  4258.        For each item in the list this function will be called with the item
  4259.        as the first argument.  Client data may be passed through as parameter
  4260.        d.
  4261.           unsignedremoveAll(T a);
  4262.        Removes all objects which are equal to the object a.  Returns the
  4263.        number of objects removed.  Equality is measured by the class-defined
  4264.        equality operator.
  4265.           unsignedremoveAll(RWBoolean (*testFun)(T, void*), void* d);
  4266.        Removes all objects for which the user-defined tester function pointed
  4267.        to by testFun returns TRUE.  Returns the number of objects removed.
  4268.        The tester function must have the prototype:
  4269.             RWBoolean  yourTester(T, void* d);
  4270.        For each item in the list this function will be called with the item
  4271.        as the first argument.  Client data may be passed through as parameter
  4272.        d.
  4273.           T       removeAt(int i);
  4274.        Removes and returns the object at index i.  An exception of type
  4275.        TOOL_INDEX will be thrown if i is not a valid index.  Valid indices
  4276.        are from zero to the number of items in the list less one.
  4277.           T       removeFirst();
  4278.        Removes and returns the first item in the list.  The behavior is
  4279.        undefined if the list is empty.
  4280.           T       removeLast()
  4281.        Removes and returns the last item in the list.  The behavior is
  4282.        undefined if the list is empty.  This function is relatively slow
  4283.        because removing the last link in a singly-linked list necessitates
  4284.  
  4285. Rogue Wave              Tools.h++   V 5.0   Supplement  78
  4286.  
  4287.  
  4288.  
  4289.  
  4290.  
  4291.  
  4292.  
  4293.  
  4294.                                                           RWTValSlist<T>
  4295.  
  4296.  
  4297.        access to the next-to-the-last link, requiring the whole list to be
  4298.        searched.
  4299.  
  4300.  
  4301.  
  4302.  
  4303.  
  4304.  
  4305.  
  4306.  
  4307.  
  4308.  
  4309.  
  4310.  
  4311.  
  4312.  
  4313.  
  4314.  
  4315.  
  4316.  
  4317.  
  4318.  
  4319.  
  4320.  
  4321.  
  4322.  
  4323.  
  4324.  
  4325.  
  4326.  
  4327.  
  4328.  
  4329.  
  4330.  
  4331.  
  4332.  
  4333.  
  4334.  
  4335.  
  4336.  
  4337.  
  4338.  
  4339.  
  4340.  
  4341. Rogue Wave              Tools.h++   V 5.0   Supplement  79
  4342.  
  4343.  
  4344.  
  4345.  
  4346.  
  4347.  
  4348.  
  4349.  
  4350.  
  4351.  
  4352. RWTValSortedVector<T>RWTValSortedVector<T>
  4353.  
  4354.  
  4355. Synopsis   #include <rw/tvsrtvec.h>
  4356.            RWTValSortedVector<T> sortvec;
  4357.  
  4358. Description RWTValSortedVector<T> is an ordered collection.  That is, the items
  4359.           in the collection have a meaningful ordered relationship with
  4360.           respect to each other and can be accessed by an index number.  In
  4361.           the case of RWTValSortedVector<T>, objects are inserted such that
  4362.           objects "less than" themselves are before the object, objects
  4363.           "greater than" themselves after the object.  An insertion sort is
  4364.           used.  Duplicates are allowed.
  4365. Stores a copy of the inserted item into the collection according to an
  4366. ordering determined by the less-than (<) operator.
  4367. The class T must have:
  4368.           o  well-defined copy semantics (T::T(const T&) or equiv.);
  4369.           o  well-defined assignment semantics (T::operator=(const T&) or
  4370.              equiv.);
  4371.           o  well-defined equality semantics (T::operator==(const T&));
  4372.           o  well-defined less-than semantics (T::operator<(const T&));
  4373.           o  a default constructor.
  4374.  
  4375. Example   This example inserts a set of dates into a sorted vector in no
  4376.           particular order, then prints them out in order.
  4377.  
  4378.           BEGIN FILE: tvsrtvec.cpp
  4379.           #include <rw/tvsrtvec.h>
  4380.           #include <rw/rwdate.h>
  4381.           #include <rw/rstream.h>
  4382.  
  4383.           main()
  4384.           {
  4385.             RWTValSortedVector<RWDate> vec;
  4386.  
  4387.             vec.insert(RWDate(10, "Aug", 1991));
  4388.             vec.insert(RWDate(9, "Aug", 1991));
  4389.             vec.insert(RWDate(1, "Sept", 1991));
  4390.             vec.insert(RWDate(14, "May", 1990));
  4391.             vec.insert(RWDate(1, "Sept", 1991));// Add a duplicate
  4392.             vec.insert(RWDate(2, "June", 1991));
  4393.  
  4394.             for (int i=0; i<vec.length(); i++)
  4395.               cout << vec[i] << NL;
  4396.             return 0;
  4397.  
  4398.  
  4399.  
  4400.  
  4401.  
  4402.  
  4403.  
  4404.  
  4405.                                                                    Index
  4406.  
  4407.  
  4408.           }
  4409.           END FILE
  4410.  
  4411. Program output
  4412.           May 14, 1990
  4413.           June 2, 1991
  4414.           August 9, 1991
  4415.           August 10, 1001
  4416.           September 1, 1991
  4417.           September 1, 1991
  4418.  
  4419. Public    RWTValSortedVector(unsigned capac = RWDEFAULT_CAPACITY);
  4420. constructor
  4421.  
  4422.  
  4423.           Create an empty sorted vector with an initial capacity equal to
  4424.           capac.  The vector will be automatically resized should the number of
  4425.           items exceed this amount.
  4426.  
  4427. Public    T                 operator()(int i) const;
  4428. operators T&                operator()(int i);
  4429.  
  4430.  
  4431.           Return the i'th value in the vector.  The index i must be between 0
  4432.           and the length of the vector less one.  No bounds checking is
  4433.           performed.
  4434.           T       operator[](int i) const;
  4435.           T&      operator[](int i);
  4436.        Return the i'th value in the vector.  The index i must be between 0
  4437.        and the length of the vector less one.  Bounds checking will be
  4438.        performed.
  4439.           T&      at(int i);
  4440.           T       at(int i) const;
  4441.        Return the i'th value in the vector.  The index i must be between 0
  4442.        and the length of the vector less one.  Bounds checking will be
  4443.        performed.
  4444.           void    clear();
  4445.        Removes all items from the collection.
  4446.           RWBoolean      contains(T a) const;
  4447.        Returns TRUE if the collection contains an item that is equal to a.  A
  4448.        binary search is done.  Equality is measured by the class-defined
  4449.        equality operator.
  4450.  
  4451.  
  4452. Rogue Wave              Tools.h++   V 5.0   Supplement  82
  4453.  
  4454.  
  4455.  
  4456.  
  4457.  
  4458.  
  4459.  
  4460.  
  4461.                                                                    Index
  4462.  
  4463.  
  4464.           const T*data() const;
  4465.        Returns a pointer to the raw data of the vector.  The contents should
  4466.        not be changed.  Should be used with care.
  4467.           unsignedentries() const;
  4468.        Returns the number of items currently in the collection.
  4469.           RWBoolean      find(T a,T& ret) const;
  4470.        Performs a binary search and returns TRUE if the vector contains an
  4471.        object that is equal to the object a and puts a copy of the matching
  4472.        object into ret.  Returns FALSE otherwise and does not touch ret.
  4473.        Equality is measured by the class-defined equality operator.
  4474.           T       first() const;
  4475.        Returns the first item in the collection.  An exception of type
  4476.        TOOL_INDEX will occur if the vector is empty.
  4477.           int     index(T a) const;
  4478.        Performs a binary search, returning the index of the first item that
  4479.        is equal to a.  Returns -1 if there is no such item.  Equality is
  4480.        measured by the class-defined equality operator.
  4481.           void    insert(T a);
  4482.        Performs a binary search to insert the item a into the collection
  4483.        after all items that compare less than or equal to it, but before all
  4484.        items that compare greater than it.
  4485.           RWBoolean      isEmpty() const;
  4486.        Returns TRUE if there are no items in the collection, FALSE otherwise.
  4487.           T       last() const;
  4488.        Returns the last item in the collection.  If there are no items in the
  4489.        collection then an exception of type TOOL_INDEX will occur.
  4490.           unsignedlength() const;
  4491.        Returns the number of items currently in the collection.
  4492.           unsignedoccurrencesOf(T a) const;
  4493.        Performs a binary search, returning the number of items that are equal
  4494.        to a.  Equality is measured by the class-defined equality operator.
  4495.           RWBoolean      remove(T a);
  4496.        Performs a binary search, removing the first object which is equal to
  4497.        the object a and returns TRUE.  Returns FALSE if there is no such
  4498.        object.  Equality is measured by the class-defined equality operator.
  4499.           unsignedremoveAll(T a);
  4500.        Removes all items which are equal to a, returning the number removed.
  4501.        Equality is measured by the class-defined equality operator.
  4502.           T       removeAt(int i);
  4503.        Removes and returns the object at index i.  An exception of type
  4504.        TOOL_INDEX will be thrown if i is not a valid index.  Valid indices
  4505.        are from zero to the number of items in the list less one.
  4506.  
  4507.  
  4508. Rogue Wave              Tools.h++   V 5.0   Supplement  83
  4509.  
  4510.  
  4511.  
  4512.  
  4513.  
  4514.  
  4515.  
  4516.  
  4517.                                                                    Index
  4518.  
  4519.  
  4520.           T       removeFirst();
  4521.        Removes and returns the first object in the collection.  An exception
  4522.        of type TOOL_INDEX will be thrown if the list is empty.
  4523.           T       removeLast();
  4524.        Removes and returns the last object in the collection.  An exception
  4525.        of type TOOL_INDEX will be thrown if the list is empty.
  4526.           void    resize(unsigned N);
  4527.        Changes the capacity of the collection to N.  Note that the number of
  4528.        objects in the collection does not change, just the capacity.
  4529.  
  4530.  
  4531.  
  4532.  
  4533.  
  4534.  
  4535.  
  4536.  
  4537.  
  4538.  
  4539.  
  4540.  
  4541.  
  4542.  
  4543.  
  4544.  
  4545.  
  4546.  
  4547.  
  4548.  
  4549.  
  4550.  
  4551.  
  4552.  
  4553.  
  4554.  
  4555.  
  4556.  
  4557.  
  4558.  
  4559.  
  4560.  
  4561.  
  4562.  
  4563.  
  4564. Rogue Wave              Tools.h++   V 5.0   Supplement  84
  4565.  
  4566.  
  4567.  
  4568.  
  4569.  
  4570.  
  4571.  
  4572.  
  4573.  
  4574.  
  4575. RWTValVector<T>RWTValVector<T>
  4576.  
  4577.  
  4578. Synopsis   #include <rw/tvvector.h>
  4579.            RWTValVector<T> vec;
  4580.  
  4581. DescriptonClass RWTValVector<T> is a simple parameterized vector of objects of
  4582.           type T.  It is most useful when you know precisely how many objects
  4583.           have to be held in the collection.  If the intention is to "insert" an
  4584.           unknown number of objects into a collection, then class
  4585.           RWTValOrderedVector<T> may be a better choice.
  4586. The class T must have:
  4587.           o  well-defined copy semantics (T::T(const T&) or equiv.);
  4588.           o  well-defined assignment semantics (T::operator=(const T&) or
  4589.              equiv.);
  4590.           o  a default constructor.
  4591.  
  4592. Example   BEGIN FILE: tvvector.cpp
  4593.           #include <rw/tvvector.h>
  4594.           #include <rw/rwdate.h>
  4595.           #include <rw/rstream.h>
  4596.  
  4597.           main() {
  4598.  
  4599.             RWTValVector<RWDate> week(7);
  4600.  
  4601.             RWDate begin;  // Today's date
  4602.  
  4603.             for (int i=0; i<7; i++)
  4604.               week[i] = begin++;
  4605.  
  4606.             for (i=0; i<7; i++)
  4607.               cout << week[i] << NL;
  4608.  
  4609.             return 0;
  4610.           }
  4611.           END FILE
  4612.  
  4613. Program output:
  4614.           March 16, 1992
  4615.           March 17, 1992
  4616.           March 18, 1992
  4617.           March 19, 1992
  4618.           March 20, 1992
  4619.           March 21, 1992
  4620.  
  4621.  
  4622.  
  4623.  
  4624.  
  4625.  
  4626.  
  4627.  
  4628.                                                          RWTValVector<T>
  4629.  
  4630.  
  4631.           March 22, 1992
  4632.  
  4633. Public    RWTValVector<T>();
  4634. constructors
  4635.  
  4636.  
  4637.           Constructs an empty vector of length zero.
  4638.           RWTValVector<T>(unsigned n);
  4639.        Constructs a vector of length n.  The values of the elements will be
  4640.        set by the default constructor of class T.  For a built in type this
  4641.        can (and probably will) be garbage.
  4642.           RWTValVector<T>(unsigned n, T ival);
  4643.        Constructs a vector of length n, with each element initialized to the
  4644.        value ival.
  4645.           RWTValVector<T>(const RWTValVector& v);
  4646.        Constructs self as a copy of v.  Each element in v will be copied into
  4647.        self.
  4648.           ~RWTValVector<T>();
  4649.        Calls the destructor for every element in self.
  4650. Public    RWTValVector<T>&  operator=(const RWTValVector<T>& v);
  4651. operators
  4652.  
  4653.  
  4654.           Sets self to the same length as v and then copies all elements of v
  4655.           into self.
  4656.           RWTValVector<T>&    operator=(T ival);
  4657.        Sets all elements in self to the value ival.
  4658.           T       operator()(int i) const;
  4659.           T&      operator()(int i);
  4660.        Return the i'th value in the vector.  The index i must be between 0
  4661.        and the length of the vector less one.  No bounds checking is
  4662.        performed.
  4663.           T       operator[](int i) const;
  4664.           T&      operator[](int i);
  4665.        Return the i'th value in the vector.  The index i must be between 0
  4666.        and the length of the vector less one.  Bounds checking will be
  4667.        performed.
  4668.           const T*data() const;
  4669.        Returns a pointer to the raw data of self.  Should be used with care.
  4670.           unsignedlength() const;
  4671.        Returns the length of the vector.
  4672.  
  4673.  
  4674.  
  4675. Rogue Wave              Tools.h++   V 5.0   Supplement  86
  4676.  
  4677.  
  4678.  
  4679.  
  4680.  
  4681.  
  4682.  
  4683.  
  4684.                                                          RWTValVector<T>
  4685.  
  4686.  
  4687.           void    reshape(unsigned N);
  4688.        Changes the length of the vector to N.  If this results in the vector
  4689.        being lengthened, then the initial value of the additional elements is
  4690.        set by the default constructor of T.
  4691.  
  4692.  
  4693.  
  4694.  
  4695.  
  4696.  
  4697.  
  4698.  
  4699.  
  4700.  
  4701.  
  4702.  
  4703.  
  4704.  
  4705.  
  4706.  
  4707.  
  4708.  
  4709.  
  4710.  
  4711.  
  4712.  
  4713.  
  4714.  
  4715.  
  4716.  
  4717.  
  4718.  
  4719.  
  4720.  
  4721.  
  4722.  
  4723.  
  4724.  
  4725.  
  4726.  
  4727.  
  4728.  
  4729.  
  4730.  
  4731. Rogue Wave              Tools.h++   V 5.0   Supplement  87
  4732.  
  4733.  
  4734.  
  4735.  
  4736.  
  4737.  
  4738.  
  4739.  
  4740.  
  4741.  
  4742. RWTValVirtualArray<T>RWTValVirtualArray<T>
  4743.  
  4744.  
  4745. Synopsis  #include <rw/tvrtarry.h>
  4746.           RWVirtualPageHeap* heap;
  4747.           RWTValVirtualArray<T> array(1000L, heap);
  4748.  
  4749. Description          This class represents a virtual array of elements of type T of
  4750.           almost any length.  Individual elements are brought into physical
  4751.           memory on an "as needed" basis.  If an element is used as an lvalue
  4752.           it is automatically marked as "dirty" and will be rewritten to the
  4753.           swapping medium.
  4754. The swap space is provided by an abstract page heap which is specified by the
  4755. constructor.  Any number of virtual arrays can use the same abstract page
  4756. heap.  You must take care that the destructor of the abstract page heap is
  4757. not called before all virtual arrays built from it have been destroyed.
  4758. The class supports reference counting using a copy-on-write technique, so
  4759. (for example) returning a virtual array by value from a function is as
  4760. efficient as it can be.  Be aware, however, that if the copy-on-write
  4761. machinery finds that a copy must ultimately be made, then for large arrays
  4762. this could take quite a bit of time.
  4763. For efficiency, more than one element can (and should) be put on a page.  The
  4764. actual number of elements is equal to the page size divided by the element
  4765. size, rounded downwards.  Example: for a page size of 512 bytes, and an
  4766. element size of 8, then 64 elements would be put on a page.
  4767. The indexing operator (operator[](long)) actually returns an object of type
  4768. RWTVirtualElement<T>.  Consider this example:
  4769.             double d = vec[j];
  4770.             vec[i] = 22.0;
  4771. Assume that vec is of type RWTValVirtualArray<double>.  The expression vec[j]
  4772. will return an object of type RWTVirtualElement<double>, which will contain a
  4773. reference to the element being addressed.  In the first line, this expression
  4774. is being used to initialize a double.  The class RWTVirtualElement<T>
  4775. contains a type conversion operator to convert itself to a T, in this case a
  4776. double.  The compiler uses this to initialize d.  In the second line, the
  4777. expression vec[i] is being used as an lvalue.  In this case, the compiler
  4778. uses the assignment operator for RWTVirtualElement<T>.  This assignment
  4779. operator recognizes that the expression is being used as an lvalue and
  4780. automatically marks the appropriate page as "dirty", thus guaranteeing that
  4781. it will be written back out to the swapping medium.
  4782. Slices, as well as individual elements, can also be addressed.  These should
  4783. be used wherever possible as they are much more efficient because they allow
  4784. a page to be locked and used multiple times before unlocking.
  4785. The class T must have:
  4786.           o  well-defined copy semantics (T::T(const T&) or equiv.);
  4787.  
  4788.  
  4789.  
  4790.  
  4791.  
  4792.  
  4793.  
  4794.  
  4795.                                                       RWTVirtualArray<T>
  4796.  
  4797.  
  4798.           o  well-defined assignment semantics (T::operator=(const T&) or
  4799.              equiv.).
  4800. In addition, you must never take the address of an element.
  4801.  
  4802. Example   In this example, a virtual vector of objects of type ErsatzInt is
  4803.           exercised.  A disk-based page heap is used for swapping space.
  4804.  
  4805.           BEGIN FILE: tvrtarry.cpp
  4806.           #include <rw/tvrtarry.h>
  4807.           #include <rw/rstream.h>
  4808.           #include <rw/diskpage.h>
  4809.           #include <stdlib.h>
  4810.           #include <stdio.h>
  4811.  
  4812.           struct ErsatzInt {
  4813.             char  buf[8];
  4814.             ErsatzInt(int i) { sprintf(buf, "%d", i); }
  4815.             friend ostream& operator<<(ostream& str, ErsatzInt& i)
  4816.               { str << atoi(i.buf); return str; }
  4817.           };
  4818.  
  4819.           main() {
  4820.  
  4821.             RWDiskPageHeap heap;
  4822.             RWTValVirtualArray<ErsatzInt> vec1(10000L, &heap);
  4823.  
  4824.             for (long i=0; i<10000L; i++)
  4825.               vec1[i] = i; // Some compilers may need a cast here
  4826.  
  4827.             cout << vec1[100] << NL;         // Prints "100"
  4828.             cout << vec1[300] << NL;         // Prints "300"
  4829.  
  4830.             RWTValVirtualArray<ErsatzInt> vec2 = vec.slice(5000L, 500L);
  4831.             cout << vec2.length() << NL;     // Prints "500"
  4832.             cout << vec2[0] << NL; // Prints "5000";
  4833.  
  4834.             return 0;
  4835.           }
  4836.           END FILE
  4837.  
  4838. Program output:
  4839.           100
  4840.           300
  4841.  
  4842. Rogue Wave              Tools.h++   V 5.0   Supplement  90
  4843.  
  4844.  
  4845.  
  4846.  
  4847.  
  4848.  
  4849.  
  4850.  
  4851.                                                       RWTVirtualArray<T>
  4852.  
  4853.  
  4854.           500
  4855.           5000
  4856.  
  4857. Public   RWTValVirtualArray<T>(long size, RWVirtualPageHeap* heap);
  4858. constructors
  4859.  
  4860.  
  4861.           Construct a vector of length size.  The pages for the vector will be
  4862.           allocated from the page heap given by heap which can be of any type.
  4863.           RWTValVirtualArray<T>(const RWTValVirtualArray<T>& v);
  4864.        Constructs a vector as a copy of v.  The resultant vector will use the
  4865.        same heap and have the same length as v.  The actual copy will not be
  4866.        made until a write, minimizing the amount of heap allocations and
  4867.        copying that must be done.
  4868.           RWTValVirtualArray<T>(const RWTVirtualSlice<T>& sl);
  4869.        Constructs a vector from a slice of another vector.  The resultant
  4870.        vector will use the same heap as the vector whose slice is being
  4871.        taken.  Its length will be given by the length of the slice.  The copy
  4872.        will be made immediately.
  4873. Public    ~RWTValVirtualArray<T>();
  4874. destructor
  4875.  
  4876.  
  4877.           Releases all pages allocated by the vector.
  4878.  
  4879. Public    RWTValVirtualArray&
  4880. operators operator=(const RWTValVirtualArray<T>& v);
  4881.  
  4882.  
  4883.        Sets self to a copy of v.  The resultant vector will use the same 
  4884.        heap and have the same length as v.  The actual copy will not be
  4885.        made until a write, minimizing the amount of heap allocations
  4886.        and copying that must be done.
  4887.           void    operator=(const RWTVirtualSlice<T>& sl);
  4888.        Sets self equal to a slice of another vector.  The resultant vector
  4889.        will use the same heap as the vector whose slice is being taken.  Its
  4890.        length will be given by the length of the slice.  The copy will be
  4891.        made immediately.
  4892.           T       operator=(T val);
  4893.        Sets all elements in self equal to val.  This operator is actually
  4894.        quite efficient because it can work with many elements on a single
  4895.        page at once.
  4896.  
  4897.  
  4898. Rogue Wave              Tools.h++   V 5.0   Supplement  91
  4899.  
  4900.  
  4901.  
  4902.  
  4903.  
  4904.  
  4905.  
  4906.  
  4907.                                                       RWTVirtualArray<T>
  4908.  
  4909.  
  4910. Public    long              length() const;
  4911. member
  4912. functions
  4913.  
  4914.  
  4915.           Returns the length of the vector.
  4916.  
  4917.           T                   val(long i) const;
  4918.           Returns a copy of the value at index i.  The index i
  4919.           must be between zero and the length of the vector less
  4920.           one or an exception of type TOOL_LONGINDEX will occur.
  4921.           void    set(long i, T v);
  4922.        Sets the value at the index i to v.  The index i must be between zero
  4923.        and the length of the vector less one or an exception of type
  4924.        TOOL_LONGINDEX will occur.
  4925.           T       operator[](long i) const;
  4926.        Returns a copy of the value at index i.  The index i must be between
  4927.        zero and the length of the vector less one or an exception of type
  4928.        TOOL_LONGINDEX will occur.
  4929.           RWTVirtualElement<T>     operator[](long);;
  4930.        Returns a reference to the value at index i.  The results can be used
  4931.        as an lvalue.  The index i must be between zero and the length of the
  4932.        vector less one or an exception of type TOOL_LONGINDEX will occur.
  4933.           RWTVirtualSlice<T>  slice(long start, long length);
  4934.        Returns a reference to a slice of self.  The value start is the
  4935.        starting index of the slice, the value length its extent.  The results
  4936.        can be used as an lvalue.
  4937.           void    reshape(long newLength);
  4938.        Change the length of the vector to newLength.  If this results in the
  4939.        vector being lengthened then the value of the new elements is
  4940.        undefined.
  4941.           RWVirtualPageHeap*  heap() const;
  4942.        Returns a pointer to the heap from which the vector is getting its
  4943.        pages.
  4944.  
  4945.  
  4946.  
  4947.  
  4948.  
  4949.  
  4950.  
  4951.  
  4952.  
  4953.  
  4954. Rogue Wave              Tools.h++   V 5.0   Supplement  92
  4955.  
  4956.  
  4957.  
  4958.  
  4959.  
  4960.  
  4961.  
  4962.  
  4963.  
  4964.  
  4965. RWVirtualPageHeapRWVirtualPageHeap
  4966.  
  4967.  
  4968. Synopsis  #include <rw/vpage.h>
  4969.           (Abstract base class)
  4970.  
  4971.  
  4972. Description  This is an abstract base class representing an abstract page
  4973.           heap of fixed sized pages.  The following describes the
  4974.           model by which specializing classes of this class are
  4975.           expected to work.
  4976.           You allocate a page off the abstract heap by calling member
  4977.           function allocate() which will return a memory "handle", an
  4978.           object of type RWHandle.  This handle logically represents the
  4979.           page.
  4980.           In order to use the page it must first be "locked" by calling
  4981.           member function lock() with the handle as an argument.  It is
  4982.           the job of the specializing class of RWVirtualPageHeap to make
  4983.           whatever arrangements are necessary to swap in the page
  4984.           associated with the handle and bring it into physical memory.
  4985.           The actual swapping medium could be disk, expanded or extended
  4986.           memory, or a machine someplace on a network.  Upon return,
  4987.           lock() returns a pointer to the page, now residing in memory.
  4988.           Once a page is in memory, you are free to do anything you want
  4989.           with it although if you change the contents, you must call
  4990.           member function dirty() before unlocking the page.
  4991.           Locked pages use up memory.  In fact, some specializing
  4992.           classes may have only a fixed number of buffers in which to do
  4993.           their swapping.  If you are not using the page, you should
  4994.           call unlock().  After calling unlock() the original address
  4995.           returned by lock() is no longer valid -- to use the page
  4996.           again, it must be locked again with lock().
  4997.           When you are completely done with the page then call
  4998.           deallocate() to return it to the abstract heap.
  4999.           In practice, managing this locking and unlocking and the
  5000.           inevitable type casts can be difficult.  It is usually easier
  5001.           to design a class than can work with an abstract heap to bring
  5002.           things in and out of memory automatically.  Indeed, this is
  5003.           what has been done with class RWTValVirtualArray<T>, which
  5004.           represents a virtual array of elements of type T.  Elements
  5005.           are automatically swapped in as necessary as they are
  5006.           addressed.
  5007. Example   This example illustrates adding N nodes to a linked list.  In this
  5008.           linked list, a "pointer" to the next node is actually a handle.
  5009.  
  5010.  
  5011.  
  5012.  
  5013.  
  5014.  
  5015.  
  5016.  
  5017.                                                        RWVirtualPageHeap
  5018.  
  5019.  
  5020.           BEGIN FILE: vpage.cpp
  5021.           #include <rw/vpage.h>
  5022.  
  5023.           struct Node {
  5024.             int     key;
  5025.             RWHandle                                   next;
  5026.           };
  5027.  
  5028.           RWHandle head = 0;
  5029.  
  5030.           void addNodes(RWVirtualPageHeap& heap, unsigned N) {
  5031.             for (int i=0; i<N; i++){
  5032.               RWHandle h = heap.allocate();
  5033.               Node* newNode = (Node*)heap.lock(h);
  5034.               newNode->key  = i;
  5035.               newNode->next = head;
  5036.               head = h;
  5037.               heap.dirty(h);
  5038.               heap.unlock(h);
  5039.             }
  5040.           }
  5041.           END FILE
  5042.  
  5043. Public    RWVirtualPageHeap(unsigned pgsize);
  5044. constructor
  5045.  
  5046.  
  5047.           Sets the size of a page.
  5048.  
  5049. Public    virtual           ~RWVirtualPageHeap();
  5050. destructor
  5051.  
  5052.  
  5053.        The destructor has been made virtual to give specializing classes a
  5054.        chance to deallocate any resources that they may have allocated.
  5055.  
  5056. Public   unsigned           pageSize() const;
  5057. member
  5058. functions
  5059.  
  5060.  
  5061.           Returns the page size for this abstract page heap.
  5062.  
  5063.  
  5064. Rogue Wave              Tools.h++   V 5.0   Supplement  94
  5065.  
  5066.  
  5067.  
  5068.  
  5069.  
  5070.  
  5071.  
  5072.  
  5073.                                                        RWVirtualPageHeap
  5074.  
  5075.  
  5076. Public    virtual RWHandle  allocate() = 0;;
  5077. pure
  5078. virtual
  5079. functions
  5080.  
  5081.  
  5082.        Allocates a page off the abstract heap and returns a handle for it.
  5083.        If the specializing class is unable to honor the request, then it
  5084.        should return a zero handle.
  5085.           virtual void   deallocate(RWHandle h) = 0;
  5086.        Deallocate the page associated with handle h.  It is not an error to
  5087.        deallocate a zero handle.
  5088.           virtual void   dirty(RWHandle h) = 0;
  5089.        Declare the page associated with handle h to be "dirty".  That is, it
  5090.        has changed since it was last locked.  The page must be locked before
  5091.        calling this function.
  5092.           virtual void*  lock(RWHandle h) = 0;
  5093.        Lock the page, swapping it into physical memory, and return an address
  5094.        for it.  A nil pointer will be returned if the specializing class is
  5095.        unable to honor the lock.  The returned pointer should be regarded as
  5096.        pointing to a buffer of the page size.
  5097.           virtual void   unlock(RWHandle h) = 0;
  5098.        Unlock a page.  A page must be locked before calling this function.
  5099.        After calling this function the address returned by lock() is no
  5100.        longer valid.
  5101.  
  5102.  
  5103.  
  5104.  
  5105.  
  5106.  
  5107.  
  5108.  
  5109.  
  5110.  
  5111.  
  5112.  
  5113.  
  5114.  
  5115.  
  5116.  
  5117.  
  5118.  
  5119.  
  5120. Rogue Wave              Tools.h++   V 5.0   Supplement  95
  5121.  
  5122.  
  5123.  
  5124.  
  5125.  
  5126.  
  5127.  
  5128.  
  5129.  
  5130.  
  5131.                                                                     Appendix A
  5132.                                                            Upgrading from V4.0
  5133.  
  5134.  
  5135.  
  5136. The Rogue Wave Tools.h++ V5.0  library is extremely upwards compatible from
  5137. V4.0.  Incompatibilities are listed below.
  5138.  
  5139. A.1  Include path has changed
  5140.  
  5141.  
  5142. The include file paths must now be given as (for example)
  5143.             #include <rw/rwdate.h>      /* Use this */
  5144.  
  5145. rather than the old
  5146.             #include <rwdate.h>         /* Obsolete */
  5147.  
  5148. Along the same line, the compiler include path should not be given as (using
  5149. Borland C++ V3.0 as an example):
  5150.             bcc -I\rogue myfile.cpp     # Use this
  5151.  
  5152. rather than the old
  5153.             bcc -I\rogue\rw myfile.cpp  # Obsolete
  5154.  
  5155. This was done to improve the separation of file name space should you combine
  5156. Tools.h++ with another library that uses the same header file names.
  5157.  
  5158. A.2  Dropped compilers
  5159.  
  5160.  
  5161. We are no longer supporting the Glockenspiel C++ compiler under MS-DOS.
  5162. Users who require Microsoft compatibility are encouraged to switch to the new
  5163. Microsoft C/C++ V7.0 compiler.
  5164. Of course, other Glockenspiel compilers on other platforms are still
  5165. enthusiastically supported.
  5166.  
  5167. A.3  Borland library names changed
  5168.  
  5169.  
  5170. Borland C++ V3.0 is not upwardly compatible with Borland C++ V2.0.  You may
  5171. not mix and match code between them.  Hence, there are now two separate
  5172. precompiled libraries:
  5173.      Borland C++ V2.0 large memory model:    b2tll.lib
  5174.      Borland C++ V3.0 large memory model:    b3tll.lib
  5175. Similarly, there are two separate makefiles:
  5176.  
  5177.  
  5178.  
  5179.  
  5180.  
  5181.  
  5182.  
  5183.  
  5184.                                                             V5.0 Changes
  5185.  
  5186.  
  5187.      Borland C++ V2.0 makefile:              makefile.bc2
  5188.      Borland C++ V3.0 makefile:              makefile.bc3
  5189.  
  5190. A.4  Windows streambuf constructors have changed
  5191.  
  5192.  
  5193. Some constructors for the two Windows classes "RWCLIPstreambuf" and
  5194. "RWDDEstreambuf" have changed slightly from what was given in the V4.0
  5195. documentation.  This was done to avoid invoking the wrong one accidentally in
  5196. a series of constructors that differed only in whether an argument was signed
  5197. or unsigned.  The two constructors listed in the documentation as:
  5198.             RWCLIPstreambuf(int N);
  5199.             RWDDEstreambuf(         WORD format   = CF_TEXT),
  5200.                          BOOL response  = TRUE,
  5201.                          BOOL ackReq= TRUE,
  5202.                          BOOL release   = TRUE);
  5203.  
  5204. are now given by:
  5205.             RWCLIPstreambuf(int N, int dummy);    // Second arg ignored
  5206.             RWDDEstreambuf(         WORD format   = CF_TEXT),
  5207.                          BOOL response  = TRUE,
  5208.                          BOOL ackReq= TRUE,
  5209.                          BOOL release   = TRUE);
  5210.  
  5211. Note that the particular constructor for a RWCLIPstreambuf shown here now
  5212. takes a dummy second argument which is ignored.  This is to distinguish it
  5213. from the extremely similar constructor which takes a windows handle as a
  5214. single argument.
  5215. Note that the particulare constructor for a RWDDEstreambuf shown here no
  5216. longer has any default arguments.  You must explicitly specify all arguments.
  5217.  
  5218. A.5  RWCString replaces RWString
  5219.  
  5220.  
  5221. Class RWString has been replaced with a new class RWCString.  The two classes
  5222. are identical with two exceptions: the copy constructor and assignment
  5223. operators
  5224.             RWCString::RWCString(const RWCString&);
  5225.             RWCString::operator=(const RWCString&);
  5226.  
  5227. now use "copy semantics" rather than "reference semantics".  Here are two
  5228. example programs that illustrate the difference:
  5229.  
  5230.  
  5231. Rogue Wave              Tools.h++   V 5.0   Supplement  98
  5232.  
  5233.  
  5234.  
  5235.  
  5236.  
  5237.  
  5238.  
  5239.  
  5240.                                                             V5.0 Changes
  5241.  
  5242.  
  5243.             RWCString a("AIX");              RWString a("AIX");
  5244.             RWCString b(a);                  RWString b(a);
  5245.             a[1] = 'U';                      a[1] = 'U';
  5246.  
  5247.             cout << a << " " << b;           cout << a << " " << b;
  5248.  
  5249.  
  5250. OUTPUT:
  5251.  
  5252.             AIX AUX               AUX AUX
  5253.  
  5254.  
  5255. (with apologies to Apple and IBM).  Note that with copy semantics (as
  5256. illustrated on the left), the copy constructor makes a distinct, independent
  5257. copy of the data of its argument.  With reference semantics, the new string
  5258. merely references the old string's data.  To make a distinct copy, you must
  5259. call copy().
  5260. We used reference semantics with the old RWString class because of its speed
  5261. advantage.  However, we have found it confusing to many of our users and so
  5262. we have changed Tools.h++ to consistently use copy semantics everywhere.
  5263. See RWCString in the reference guide for more information.
  5264.  
  5265. A.6  GSortedVector(val)
  5266.  
  5267.  
  5268. The generic sorted vector GSortedVector(val) now requires you to declare and
  5269. implement its base class, GVector(val), as well as the sorted vector itself.
  5270. This used to be done automatically.  Because the new generic class
  5271. GOrderedVector(val) uses the same base class, this can no longer be done
  5272. without causing a compile error (multiple class declaration) should you use
  5273. both classes in the same program.
  5274. Example:
  5275.             declare(GVector,double)          // Declare the base class
  5276.             declare(GSortedVector,double)    // Now the derived class
  5277.             implement(GVector,double)        // Implement base class
  5278.             implement(GSortedVector,double)  // Implement derived class
  5279.  
  5280.  
  5281. Index
  5282.  
  5283. Benchmarking 17
  5284. Bit vector 35
  5285. Copy on write 23, 83
  5286.  
  5287. Rogue Wave              Tools.h++   V 5.0   Supplement  99
  5288.  
  5289.  
  5290.  
  5291.  
  5292.  
  5293.  
  5294.  
  5295.  
  5296.  
  5297. COW (See Copy on write)
  5298. Dictionary
  5299.   RWTValHashDictionary<K,V> 58
  5300.   template
  5301.      example 9
  5302. GOrderedVector(val) 14
  5303. Hashing collections
  5304.   RWTValHashTable<T> 64
  5305. Model-View-Controller 33
  5306. Ordered collection
  5307.   generic 14
  5308. Page heaps
  5309.   abstract 87
  5310.   buffered 21
  5311.   disk based 31
  5312. Regular expressions 25
  5313. Reshape vs. resize 9
  5314. RWBench 17
  5315. RWBitVec 35
  5316. RWBOUNDS_CHECK 8
  5317. RWBufferedPageHeap 21, 31
  5318. RWCString 23
  5319. RWDiskPageHeap 31
  5320. RWModel 33
  5321. RWTBitVec<size> 35
  5322. RWTimer 38
  5323. RWTIsvDlist<T> 40
  5324. RWTIsvSlist<T> 44
  5325. RWTQueue<T, C> 48
  5326. RWTStack<T, C> 50
  5327. RWTValDlist<T> 52
  5328. RWTValHashDictionary<K,V> 58
  5329. RWTValHashSet<T> 62
  5330. RWTValHashTable<T> 64
  5331. RWTValOrderedVector<T> 67
  5332. RWTValSlist<T> 71
  5333. RWTValSortedVector<T> 77
  5334. RWTValVector<T> 81
  5335. RWTValVirtualArray<T> 83
  5336. RWVirtualPageHeap 21, 31, 87
  5337. String 23
  5338.   searches 25, 26
  5339. Templates 3-11
  5340. time
  5341.   measuring elapsed 38
  5342.  
  5343. Rogue Wave              Tools.h++   V 5.0   Supplement  100
  5344.  
  5345.  
  5346.  
  5347.  
  5348.  
  5349.  
  5350.  
  5351.  
  5352.  
  5353. Vector
  5354.   bit 35
  5355.   bounds checking 8
  5356.   generic
  5357.      ordered 14
  5358. reshape vs. resize 9
  5359.  
  5360.  
  5361.  
  5362.  
  5363.  
  5364.  
  5365.  
  5366.  
  5367.  
  5368.  
  5369.  
  5370.  
  5371.  
  5372.  
  5373.  
  5374.  
  5375.  
  5376.  
  5377.  
  5378.  
  5379.  
  5380.  
  5381.  
  5382.  
  5383.  
  5384.  
  5385.  
  5386.  
  5387.  
  5388.  
  5389.  
  5390.  
  5391.  
  5392.  
  5393.  
  5394.  
  5395.  
  5396.  
  5397.  
  5398.  
  5399. Rogue Wave              Tools.h++   V 5.0   Supplement  101
  5400.