home *** CD-ROM | disk | FTP | other *** search
/ ARM Club 3 / TheARMClub_PDCD3.iso / hensa / programming / libg_ / libgpp / !libgpp / docs / libg++ < prev   
Encoding:
GNU Info File  |  1996-11-16  |  187.4 KB  |  4,969 lines

  1. This is Info file libg++, produced by Makeinfo-1.63 from the input file
  2. texi.libg++.
  3.  
  4. START-INFO-DIR-ENTRY
  5. * Libg++: (libg++).             The g++ class library.
  6. END-INFO-DIR-ENTRY
  7.  
  8.    This file documents the features and implementation of The GNU C++
  9. library
  10.  
  11.    Copyright (C) 1988, 1991, 1992 Free Software Foundation, Inc.
  12.  
  13.    Permission is granted to make and distribute verbatim copies of this
  14. manual provided the copyright notice and this permission notice are
  15. preserved on all copies.
  16.  
  17.    Permission is granted to copy and distribute modified versions of
  18. this manual under the conditions for verbatim copying, provided also
  19. that the section entitled "GNU Library General Public License" is
  20. included exactly as in the original, and provided that the entire
  21. resulting derived work is distributed under the terms of a permission
  22. notice identical to this one.
  23.  
  24.    Permission is granted to copy and distribute translations of this
  25. manual into another language, under the above conditions for modified
  26. versions, except that the section entitled "GNU Library General Public
  27. License" and this permission notice may be included in translations
  28. approved by the Free Software Foundation instead of in the original
  29. English.
  30.  
  31. 
  32. File: libg++,  Node: Top,  Next: Copying,  Up: (DIR)
  33.  
  34.    Introduction ************
  35.  
  36.    This manual documents how to install and use the GNU C++ library.
  37.  
  38. * Menu:
  39.  
  40. * Copying::        GNU Library Public License says how you can copy
  41.                     and share the GNU C++ library.
  42. * Contributors::    People who have contributed to GNU C++ library.
  43. * Installation::    How to configure, compile and install GNU C++ library
  44. * Trouble::         If you have trouble installing GNU C++ library.
  45. * General::         Aims, objectives, and limitations of the GNU C++ library
  46. * Conventions::     Stylistic conventions
  47. * OK::              Support for representation invariants
  48. * Proto::           Introduction to container class prototypes
  49. * Pix::             Pseudo-indexes
  50. * Representations:: How variable-sized objects are represented
  51. * Expressions::     Some guidance on programming expression-oriented classes
  52. * Headers::         Header files and other support for interfacing C++ to C
  53. * Builtin::         Utility functions for builtin types
  54. * New::             Library dynamic allocation primitives
  55. * IOStream:(iostream)Top.
  56.                     The input/output library (istreams and ostreams).
  57. * Stream::          obsolete I/O library
  58. * Obstack::         Obstacks and their uses.
  59. * AllocRing::       A place to store objects for a while
  60. * String::          String, SubString, and Regex classes.
  61. * Integer::         Multiple precision Integer class.
  62. * Rational::        Multiple precision Rational class
  63. * Complex::         Complex number class
  64. * Fix::             Fixed point proportion classes
  65. * Bit::             BitSet and BitString classes
  66. * Random::          Random number generators
  67. * Data::            SampleStatistic and related classes for data collection
  68. * Curses::          CursesWindow class
  69. * List::            Lisp-like List prototype
  70. * LinkList::        Singly and doubly linked list class prototypes
  71. * Vector::          Vector prototypes
  72. * Plex::            Plex (adjustable array) prototypes
  73. * Stack::           Stack prototypes
  74. * Queue::           Queue prototypes
  75. * Deque::           Double ended queue prototypes
  76. * PQ::              Heap (priority queue) class prototypes
  77. * Set::             Set class prototypes
  78. * Bag::             Bag class prototypes
  79. * Map::             Map (Associative array) prototypes
  80. * GetOpt::          C++ class-based version of the GNU/UNIX getopt function
  81. * Projects::        Things Still Left to do
  82.  
  83. 
  84. File: libg++,  Node: Copying,  Next: Contributors,  Prev: Top,  Up: Top
  85.  
  86. GNU LIBRARY GENERAL PUBLIC LICENSE
  87. **********************************
  88.  
  89.                          Version 2, June 1991
  90.  
  91.      Copyright (C) 1991 Free Software Foundation, Inc.
  92.      59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
  93.      Everyone is permitted to copy and distribute verbatim copies
  94.      of this license document, but changing it is not allowed.
  95.      
  96.      [This is the first released version of the library GPL.  It is
  97.       numbered 2 because it goes with version 2 of the ordinary GPL.]
  98.  
  99. Preamble
  100. ========
  101.  
  102.    The licenses for most software are designed to take away your
  103. freedom to share and change it.  By contrast, the GNU General Public
  104. Licenses are intended to guarantee your freedom to share and change
  105. free software--to make sure the software is free for all its users.
  106.  
  107.    This license, the Library General Public License, applies to some
  108. specially designated Free Software Foundation software, and to any
  109. other libraries whose authors decide to use it.  You can use it for
  110. your libraries, too.
  111.  
  112.    When we speak of free software, we are referring to freedom, not
  113. price.  Our General Public Licenses are designed to make sure that you
  114. have the freedom to distribute copies of free software (and charge for
  115. this service if you wish), that you receive source code or can get it
  116. if you want it, that you can change the software or use pieces of it in
  117. new free programs; and that you know you can do these things.
  118.  
  119.    To protect your rights, we need to make restrictions that forbid
  120. anyone to deny you these rights or to ask you to surrender the rights.
  121. These restrictions translate to certain responsibilities for you if you
  122. distribute copies of the library, or if you modify it.
  123.  
  124.    For example, if you distribute copies of the library, whether gratis
  125. or for a fee, you must give the recipients all the rights that we gave
  126. you.  You must make sure that they, too, receive or can get the source
  127. code.  If you link a program with the library, you must provide
  128. complete object files to the recipients so that they can relink them
  129. with the library, after making changes to the library and recompiling
  130. it.  And you must show them these terms so they know their rights.
  131.  
  132.    Our method of protecting your rights has two steps: (1) copyright
  133. the library, and (2) offer you this license which gives you legal
  134. permission to copy, distribute and/or modify the library.
  135.  
  136.    Also, for each distributor's protection, we want to make certain
  137. that everyone understands that there is no warranty for this free
  138. library.  If the library is modified by someone else and passed on, we
  139. want its recipients to know that what they have is not the original
  140. version, so that any problems introduced by others will not reflect on
  141. the original authors' reputations.
  142.  
  143.    Finally, any free program is threatened constantly by software
  144. patents.  We wish to avoid the danger that companies distributing free
  145. software will individually obtain patent licenses, thus in effect
  146. transforming the program into proprietary software.  To prevent this,
  147. we have made it clear that any patent must be licensed for everyone's
  148. free use or not licensed at all.
  149.  
  150.    Most GNU software, including some libraries, is covered by the
  151. ordinary GNU General Public License, which was designed for utility
  152. programs.  This license, the GNU Library General Public License,
  153. applies to certain designated libraries.  This license is quite
  154. different from the ordinary one; be sure to read it in full, and don't
  155. assume that anything in it is the same as in the ordinary license.
  156.  
  157.    The reason we have a separate public license for some libraries is
  158. that they blur the distinction we usually make between modifying or
  159. adding to a program and simply using it.  Linking a program with a
  160. library, without changing the library, is in some sense simply using
  161. the library, and is analogous to running a utility program or
  162. application program.  However, in a textual and legal sense, the linked
  163. executable is a combined work, a derivative of the original library,
  164. and the ordinary General Public License treats it as such.
  165.  
  166.    Because of this blurred distinction, using the ordinary General
  167. Public License for libraries did not effectively promote software
  168. sharing, because most developers did not use the libraries.  We
  169. concluded that weaker conditions might promote sharing better.
  170.  
  171.    However, unrestricted linking of non-free programs would deprive the
  172. users of those programs of all benefit from the free status of the
  173. libraries themselves.  This Library General Public License is intended
  174. to permit developers of non-free programs to use free libraries, while
  175. preserving your freedom as a user of such programs to change the free
  176. libraries that are incorporated in them.  (We have not seen how to
  177. achieve this as regards changes in header files, but we have achieved
  178. it as regards changes in the actual functions of the Library.)  The
  179. hope is that this will lead to faster development of free libraries.
  180.  
  181.    The precise terms and conditions for copying, distribution and
  182. modification follow.  Pay close attention to the difference between a
  183. "work based on the library" and a "work that uses the library".  The
  184. former contains code derived from the library, while the latter only
  185. works together with the library.
  186.  
  187.    Note that it is possible for a library to be covered by the ordinary
  188. General Public License rather than by this special one.
  189.  
  190.     TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
  191.  
  192.   0. This License Agreement applies to any software library which
  193.      contains a notice placed by the copyright holder or other
  194.      authorized party saying it may be distributed under the terms of
  195.      this Library General Public License (also called "this License").
  196.      Each licensee is addressed as "you".
  197.  
  198.      A "library" means a collection of software functions and/or data
  199.      prepared so as to be conveniently linked with application programs
  200.      (which use some of those functions and data) to form executables.
  201.  
  202.      The "Library", below, refers to any such software library or work
  203.      which has been distributed under these terms.  A "work based on the
  204.      Library" means either the Library or any derivative work under
  205.      copyright law: that is to say, a work containing the Library or a
  206.      portion of it, either verbatim or with modifications and/or
  207.      translated straightforwardly into another language.  (Hereinafter,
  208.      translation is included without limitation in the term
  209.      "modification".)
  210.  
  211.      "Source code" for a work means the preferred form of the work for
  212.      making modifications to it.  For a library, complete source code
  213.      means all the source code for all modules it contains, plus any
  214.      associated interface definition files, plus the scripts used to
  215.      control compilation and installation of the library.
  216.  
  217.      Activities other than copying, distribution and modification are
  218.      not covered by this License; they are outside its scope.  The act
  219.      of running a program using the Library is not restricted, and
  220.      output from such a program is covered only if its contents
  221.      constitute a work based on the Library (independent of the use of
  222.      the Library in a tool for writing it).  Whether that is true
  223.      depends on what the Library does and what the program that uses
  224.      the Library does.
  225.  
  226.   1. You may copy and distribute verbatim copies of the Library's
  227.      complete source code as you receive it, in any medium, provided
  228.      that you conspicuously and appropriately publish on each copy an
  229.      appropriate copyright notice and disclaimer of warranty; keep
  230.      intact all the notices that refer to this License and to the
  231.      absence of any warranty; and distribute a copy of this License
  232.      along with the Library.
  233.  
  234.      You may charge a fee for the physical act of transferring a copy,
  235.      and you may at your option offer warranty protection in exchange
  236.      for a fee.
  237.  
  238.   2. You may modify your copy or copies of the Library or any portion
  239.      of it, thus forming a work based on the Library, and copy and
  240.      distribute such modifications or work under the terms of Section 1
  241.      above, provided that you also meet all of these conditions:
  242.  
  243.        a. The modified work must itself be a software library.
  244.  
  245.        b. You must cause the files modified to carry prominent notices
  246.           stating that you changed the files and the date of any change.
  247.  
  248.        c. You must cause the whole of the work to be licensed at no
  249.           charge to all third parties under the terms of this License.
  250.  
  251.        d. If a facility in the modified Library refers to a function or
  252.           a table of data to be supplied by an application program that
  253.           uses the facility, other than as an argument passed when the
  254.           facility is invoked, then you must make a good faith effort
  255.           to ensure that, in the event an application does not supply
  256.           such function or table, the facility still operates, and
  257.           performs whatever part of its purpose remains meaningful.
  258.  
  259.           (For example, a function in a library to compute square roots
  260.           has a purpose that is entirely well-defined independent of the
  261.           application.  Therefore, Subsection 2d requires that any
  262.           application-supplied function or table used by this function
  263.           must be optional: if the application does not supply it, the
  264.           square root function must still compute square roots.)
  265.  
  266.      These requirements apply to the modified work as a whole.  If
  267.      identifiable sections of that work are not derived from the
  268.      Library, and can be reasonably considered independent and separate
  269.      works in themselves, then this License, and its terms, do not
  270.      apply to those sections when you distribute them as separate
  271.      works.  But when you distribute the same sections as part of a
  272.      whole which is a work based on the Library, the distribution of
  273.      the whole must be on the terms of this License, whose permissions
  274.      for other licensees extend to the entire whole, and thus to each
  275.      and every part regardless of who wrote it.
  276.  
  277.      Thus, it is not the intent of this section to claim rights or
  278.      contest your rights to work written entirely by you; rather, the
  279.      intent is to exercise the right to control the distribution of
  280.      derivative or collective works based on the Library.
  281.  
  282.      In addition, mere aggregation of another work not based on the
  283.      Library with the Library (or with a work based on the Library) on
  284.      a volume of a storage or distribution medium does not bring the
  285.      other work under the scope of this License.
  286.  
  287.   3. You may opt to apply the terms of the ordinary GNU General Public
  288.      License instead of this License to a given copy of the Library.
  289.      To do this, you must alter all the notices that refer to this
  290.      License, so that they refer to the ordinary GNU General Public
  291.      License, version 2, instead of to this License.  (If a newer
  292.      version than version 2 of the ordinary GNU General Public License
  293.      has appeared, then you can specify that version instead if you
  294.      wish.)  Do not make any other change in these notices.
  295.  
  296.      Once this change is made in a given copy, it is irreversible for
  297.      that copy, so the ordinary GNU General Public License applies to
  298.      all subsequent copies and derivative works made from that copy.
  299.  
  300.      This option is useful when you wish to copy part of the code of
  301.      the Library into a program that is not a library.
  302.  
  303.   4. You may copy and distribute the Library (or a portion or
  304.      derivative of it, under Section 2) in object code or executable
  305.      form under the terms of Sections 1 and 2 above provided that you
  306.      accompany it with the complete corresponding machine-readable
  307.      source code, which must be distributed under the terms of Sections
  308.      1 and 2 above on a medium customarily used for software
  309.      interchange.
  310.  
  311.      If distribution of object code is made by offering access to copy
  312.      from a designated place, then offering equivalent access to copy
  313.      the source code from the same place satisfies the requirement to
  314.      distribute the source code, even though third parties are not
  315.      compelled to copy the source along with the object code.
  316.  
  317.   5. A program that contains no derivative of any portion of the
  318.      Library, but is designed to work with the Library by being
  319.      compiled or linked with it, is called a "work that uses the
  320.      Library".  Such a work, in isolation, is not a derivative work of
  321.      the Library, and therefore falls outside the scope of this License.
  322.  
  323.      However, linking a "work that uses the Library" with the Library
  324.      creates an executable that is a derivative of the Library (because
  325.      it contains portions of the Library), rather than a "work that
  326.      uses the library".  The executable is therefore covered by this
  327.      License.  Section 6 states terms for distribution of such
  328.      executables.
  329.  
  330.      When a "work that uses the Library" uses material from a header
  331.      file that is part of the Library, the object code for the work may
  332.      be a derivative work of the Library even though the source code is
  333.      not.  Whether this is true is especially significant if the work
  334.      can be linked without the Library, or if the work is itself a
  335.      library.  The threshold for this to be true is not precisely
  336.      defined by law.
  337.  
  338.      If such an object file uses only numerical parameters, data
  339.      structure layouts and accessors, and small macros and small inline
  340.      functions (ten lines or less in length), then the use of the object
  341.      file is unrestricted, regardless of whether it is legally a
  342.      derivative work.  (Executables containing this object code plus
  343.      portions of the Library will still fall under Section 6.)
  344.  
  345.      Otherwise, if the work is a derivative of the Library, you may
  346.      distribute the object code for the work under the terms of Section
  347.      6.  Any executables containing that work also fall under Section 6,
  348.      whether or not they are linked directly with the Library itself.
  349.  
  350.   6. As an exception to the Sections above, you may also compile or
  351.      link a "work that uses the Library" with the Library to produce a
  352.      work containing portions of the Library, and distribute that work
  353.      under terms of your choice, provided that the terms permit
  354.      modification of the work for the customer's own use and reverse
  355.      engineering for debugging such modifications.
  356.  
  357.      You must give prominent notice with each copy of the work that the
  358.      Library is used in it and that the Library and its use are covered
  359.      by this License.  You must supply a copy of this License.  If the
  360.      work during execution displays copyright notices, you must include
  361.      the copyright notice for the Library among them, as well as a
  362.      reference directing the user to the copy of this License.  Also,
  363.      you must do one of these things:
  364.  
  365.        a. Accompany the work with the complete corresponding
  366.           machine-readable source code for the Library including
  367.           whatever changes were used in the work (which must be
  368.           distributed under Sections 1 and 2 above); and, if the work
  369.           is an executable linked with the Library, with the complete
  370.           machine-readable "work that uses the Library", as object code
  371.           and/or source code, so that the user can modify the Library
  372.           and then relink to produce a modified executable containing
  373.           the modified Library.  (It is understood that the user who
  374.           changes the contents of definitions files in the Library will
  375.           not necessarily be able to recompile the application to use
  376.           the modified definitions.)
  377.  
  378.        b. Accompany the work with a written offer, valid for at least
  379.           three years, to give the same user the materials specified in
  380.           Subsection 6a, above, for a charge no more than the cost of
  381.           performing this distribution.
  382.  
  383.        c. If distribution of the work is made by offering access to copy
  384.           from a designated place, offer equivalent access to copy the
  385.           above specified materials from the same place.
  386.  
  387.        d. Verify that the user has already received a copy of these
  388.           materials or that you have already sent this user a copy.
  389.  
  390.      For an executable, the required form of the "work that uses the
  391.      Library" must include any data and utility programs needed for
  392.      reproducing the executable from it.  However, as a special
  393.      exception, the source code distributed need not include anything
  394.      that is normally distributed (in either source or binary form)
  395.      with the major components (compiler, kernel, and so on) of the
  396.      operating system on which the executable runs, unless that
  397.      component itself accompanies the executable.
  398.  
  399.      It may happen that this requirement contradicts the license
  400.      restrictions of other proprietary libraries that do not normally
  401.      accompany the operating system.  Such a contradiction means you
  402.      cannot use both them and the Library together in an executable
  403.      that you distribute.
  404.  
  405.   7. You may place library facilities that are a work based on the
  406.      Library side-by-side in a single library together with other
  407.      library facilities not covered by this License, and distribute
  408.      such a combined library, provided that the separate distribution
  409.      of the work based on the Library and of the other library
  410.      facilities is otherwise permitted, and provided that you do these
  411.      two things:
  412.  
  413.        a. Accompany the combined library with a copy of the same work
  414.           based on the Library, uncombined with any other library
  415.           facilities.  This must be distributed under the terms of the
  416.           Sections above.
  417.  
  418.        b. Give prominent notice with the combined library of the fact
  419.           that part of it is a work based on the Library, and explaining
  420.           where to find the accompanying uncombined form of the same
  421.           work.
  422.  
  423.   8. You may not copy, modify, sublicense, link with, or distribute the
  424.      Library except as expressly provided under this License.  Any
  425.      attempt otherwise to copy, modify, sublicense, link with, or
  426.      distribute the Library is void, and will automatically terminate
  427.      your rights under this License.  However, parties who have
  428.      received copies, or rights, from you under this License will not
  429.      have their licenses terminated so long as such parties remain in
  430.      full compliance.
  431.  
  432.   9. You are not required to accept this License, since you have not
  433.      signed it.  However, nothing else grants you permission to modify
  434.      or distribute the Library or its derivative works.  These actions
  435.      are prohibited by law if you do not accept this License.
  436.      Therefore, by modifying or distributing the Library (or any work
  437.      based on the Library), you indicate your acceptance of this
  438.      License to do so, and all its terms and conditions for copying,
  439.      distributing or modifying the Library or works based on it.
  440.  
  441.  10. Each time you redistribute the Library (or any work based on the
  442.      Library), the recipient automatically receives a license from the
  443.      original licensor to copy, distribute, link with or modify the
  444.      Library subject to these terms and conditions.  You may not impose
  445.      any further restrictions on the recipients' exercise of the rights
  446.      granted herein.  You are not responsible for enforcing compliance
  447.      by third parties to this License.
  448.  
  449.  11. If, as a consequence of a court judgment or allegation of patent
  450.      infringement or for any other reason (not limited to patent
  451.      issues), conditions are imposed on you (whether by court order,
  452.      agreement or otherwise) that contradict the conditions of this
  453.      License, they do not excuse you from the conditions of this
  454.      License.  If you cannot distribute so as to satisfy simultaneously
  455.      your obligations under this License and any other pertinent
  456.      obligations, then as a consequence you may not distribute the
  457.      Library at all.  For example, if a patent license would not permit
  458.      royalty-free redistribution of the Library by all those who
  459.      receive copies directly or indirectly through you, then the only
  460.      way you could satisfy both it and this License would be to refrain
  461.      entirely from distribution of the Library.
  462.  
  463.      If any portion of this section is held invalid or unenforceable
  464.      under any particular circumstance, the balance of the section is
  465.      intended to apply, and the section as a whole is intended to apply
  466.      in other circumstances.
  467.  
  468.      It is not the purpose of this section to induce you to infringe any
  469.      patents or other property right claims or to contest validity of
  470.      any such claims; this section has the sole purpose of protecting
  471.      the integrity of the free software distribution system which is
  472.      implemented by public license practices.  Many people have made
  473.      generous contributions to the wide range of software distributed
  474.      through that system in reliance on consistent application of that
  475.      system; it is up to the author/donor to decide if he or she is
  476.      willing to distribute software through any other system and a
  477.      licensee cannot impose that choice.
  478.  
  479.      This section is intended to make thoroughly clear what is believed
  480.      to be a consequence of the rest of this License.
  481.  
  482.  12. If the distribution and/or use of the Library is restricted in
  483.      certain countries either by patents or by copyrighted interfaces,
  484.      the original copyright holder who places the Library under this
  485.      License may add an explicit geographical distribution limitation
  486.      excluding those countries, so that distribution is permitted only
  487.      in or among countries not thus excluded.  In such case, this
  488.      License incorporates the limitation as if written in the body of
  489.      this License.
  490.  
  491.  13. The Free Software Foundation may publish revised and/or new
  492.      versions of the Library General Public License from time to time.
  493.      Such new versions will be similar in spirit to the present version,
  494.      but may differ in detail to address new problems or concerns.
  495.  
  496.      Each version is given a distinguishing version number.  If the
  497.      Library specifies a version number of this License which applies
  498.      to it and "any later version", you have the option of following
  499.      the terms and conditions either of that version or of any later
  500.      version published by the Free Software Foundation.  If the Library
  501.      does not specify a license version number, you may choose any
  502.      version ever published by the Free Software Foundation.
  503.  
  504.  14. If you wish to incorporate parts of the Library into other free
  505.      programs whose distribution conditions are incompatible with these,
  506.      write to the author to ask for permission.  For software which is
  507.      copyrighted by the Free Software Foundation, write to the Free
  508.      Software Foundation; we sometimes make exceptions for this.  Our
  509.      decision will be guided by the two goals of preserving the free
  510.      status of all derivatives of our free software and of promoting
  511.      the sharing and reuse of software generally.
  512.  
  513.                                 NO WARRANTY
  514.  
  515.  15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO
  516.      WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE
  517.      LAW.  EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
  518.      HOLDERS AND/OR OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT
  519.      WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT
  520.      NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  521.      FITNESS FOR A PARTICULAR PURPOSE.  THE ENTIRE RISK AS TO THE
  522.      QUALITY AND PERFORMANCE OF THE LIBRARY IS WITH YOU.  SHOULD THE
  523.      LIBRARY PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY
  524.      SERVICING, REPAIR OR CORRECTION.
  525.  
  526.  16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN
  527.      WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY
  528.      MODIFY AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE
  529.      LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL,
  530.      INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR
  531.      INABILITY TO USE THE LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF
  532.      DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU
  533.      OR THIRD PARTIES OR A FAILURE OF THE LIBRARY TO OPERATE WITH ANY
  534.      OTHER SOFTWARE), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN
  535.      ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
  536.  
  537.                       END OF TERMS AND CONDITIONS
  538.  
  539. How to Apply These Terms to Your New Libraries
  540. ==============================================
  541.  
  542.    If you develop a new library, and you want it to be of the greatest
  543. possible use to the public, we recommend making it free software that
  544. everyone can redistribute and change.  You can do so by permitting
  545. redistribution under these terms (or, alternatively, under the terms of
  546. the ordinary General Public License).
  547.  
  548.    To apply these terms, attach the following notices to the library.
  549. It is safest to attach them to the start of each source file to most
  550. effectively convey the exclusion of warranty; and each file should have
  551. at least the "copyright" line and a pointer to where the full notice is
  552. found.
  553.  
  554.      ONE LINE TO GIVE THE LIBRARY'S NAME AND AN IDEA OF WHAT IT DOES.
  555.      Copyright (C) YEAR  NAME OF AUTHOR
  556.      
  557.      This library is free software; you can redistribute it and/or
  558.      modify it under the terms of the GNU Library General Public
  559.      License as published by the Free Software Foundation; either
  560.      version 2 of the License, or (at your option) any later version.
  561.      
  562.      This library is distributed in the hope that it will be useful,
  563.      but WITHOUT ANY WARRANTY; without even the implied warranty of
  564.      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  565.      Library General Public License for more details.
  566.      
  567.      You should have received a copy of the GNU Library General Public
  568.      License along with this library; if not, write to the
  569.      Free Software Foundation, Inc., 59 Temple Place - Suite 330, Cambridge,
  570.      MA 02139, USA.
  571.  
  572.    Also add information on how to contact you by electronic and paper
  573. mail.
  574.  
  575.    You should also get your employer (if you work as a programmer) or
  576. your school, if any, to sign a "copyright disclaimer" for the library,
  577. if necessary.  Here is a sample; alter the names:
  578.  
  579.      Yoyodyne, Inc., hereby disclaims all copyright interest in
  580.      the library `Frob' (a library for tweaking knobs) written
  581.      by James Random Hacker.
  582.      
  583.      SIGNATURE OF TY COON, 1 April 1990
  584.      Ty Coon, President of Vice
  585.  
  586.    That's all there is to it!
  587.  
  588. 
  589. File: libg++,  Node: Contributors,  Next: Installation,  Prev: Copying,  Up: Top
  590.  
  591. Contributors to GNU C++ library
  592. *******************************
  593.  
  594.    Aside from Michael Tiemann, who worked out the front end for GNU
  595. C++, and Richard Stallman, who worked out the back end, the following
  596. people (not including those who have made their contributions to GNU
  597. CC) should not go unmentioned.
  598.  
  599.    * Doug Lea contributed most otherwise unattributed classes.
  600.  
  601.    * Per Bothner contributed the iostream I/O classes.
  602.  
  603.    * Dirk Grunwald contributed the Random number generation classes,
  604.      and PairingHeaps.
  605.  
  606.    * Kurt Baudendistel contributed Fixed precision reals.
  607.  
  608.    * Doug Schmidt contributed ordered hash tables, a perfect hash
  609.      function generator, and several other utilities.
  610.  
  611.    * Marc Shapiro contributed the ideas and preliminary code for Plexes.
  612.  
  613.    * Eric Newton contributed the curses window classes.
  614.  
  615.    * Some of the I/O code is derived from BSD 4.4, and was developed by
  616.      the University of California, Berkeley.
  617.  
  618.    * The code for converting accurately between floating point numbers
  619.      and their string representations was written by David M. Gay of
  620.      AT&T.
  621.  
  622. 
  623. File: libg++,  Node: Installation,  Next: Trouble,  Prev: Contributors,  Up: Top
  624.  
  625. Installing GNU C++ library
  626. **************************
  627.  
  628.   1. Read through the README file and the Makefile. Make sure that all
  629.      paths, system-dependent compile switches, and program names are
  630.      correct.
  631.  
  632.   2. Check that files  `values.h', `stdio.h', and `math.h' declare and
  633.      define values appropriate for your system.
  634.  
  635.   3. Type `make all' to compile the library, test, and install.
  636.      Current details about contents of the tests and utilities are in
  637.      the `README' file.
  638.  
  639.  
  640. 
  641. File: libg++,  Node: Trouble,  Next: General,  Prev: Installation,  Up: Top
  642.  
  643. Trouble in Installation
  644. ***********************
  645.  
  646.    Here are some of the things that have caused trouble for people
  647. installing GNU C++ library.
  648.  
  649.   1. Make sure that your GNU C++ version number is at least as high as
  650.      your libg++ version number. For example, libg++ 1.22.0 requires
  651.      g++ 1.22.0 or later releases.
  652.  
  653.   2. Double-check system constants in the header files mentioned above.
  654.  
  655.  
  656. 
  657. File: libg++,  Node: General,  Next: Conventions,  Prev: Trouble,  Up: Top
  658.  
  659. GNU C++ library aims, objectives, and limitations
  660. *************************************************
  661.  
  662.    The GNU C++ library, libg++ is an attempt to provide a variety of C++
  663. programming tools and other support to GNU C++ programmers.
  664.  
  665.    Differences in distribution policy are only part of the difference
  666. between libg++.a and AT&T libC.a.  libg++ is not intended to be an
  667. exact clone of libC. For one, libg++ contains bits of code that depend
  668. on special features of GNU g++ that are either different or lacking in
  669. the AT&T version, including slightly different inlining and overloading
  670. strategies, dynamic local arrays, etc.  All of these differences are
  671. minor. For example, while the AT&T and GNU stream classes are
  672. implemented in very different ways, the vast majority of C++ programs
  673. compile and run under either version with no visible difference.
  674. Additionally, all g++-specific constructs are conditionally compiled;
  675. The library is designed to be compatible with any 2.0 C++ compiler.
  676.  
  677.    libg++ has also contained workarounds for some limitations in g++:
  678. both g++ and libg++ are still undergoing rapid development and
  679. testing--a task that is helped tremendously by the feedback of active
  680. users.  This manual is also still under development; it has some
  681. catching up to do to include all the facilities now in the library.
  682.  
  683.    libg++ is not the only freely available source of C++ class
  684. libraries.  Some notable alternative sources are Interviews and NIHCL.
  685. (InterViews has been available on the X-windows X11 tapes and also from
  686. interviews.stanford.edu.  NIHCL is available by anonymous ftp from GNU
  687. archives (such as the pub directory of prep.ai.mit.edu), although it is
  688. not supported by the FSF - and needs some work before it will work with
  689. g++.)
  690.  
  691.    As every C++ programmer knows, the design (moreso than the
  692. implementation) of a C++ class library is something of a challenge.
  693. Part of the reason is that C++ supports two, partially incompatible,
  694. styles of object-oriented programming - The "forest" approach,
  695. involving a collection of free-standing classes that can be mixed and
  696. matched, versus the completely hierarchical (smalltalk style) approach,
  697. in which all classes are derived from a common ancestor.  Of course,
  698. both styles have advantages and disadvantages.  So far, libg++ has
  699. adopted the "forest" approach.  Keith Gorlen's OOPS library adopts the
  700. hierarchical approach, and may be an attractive alternative for C++
  701. programmers who prefer this style.
  702.  
  703.    Currently (and/or in the near future) libg++ provides support for a
  704. few basic kinds of classes:
  705.  
  706.    The first kind of support provides an interface between C++ programs
  707. and C libraries. This includes basic header files (like `stdio.h') as
  708. well as things like the File and stream classes. Other classes that
  709. interface to other aspects of C libraries (like those that maintain
  710. environmental information) are in various stages of development; all
  711. will undergo implementation modifications when the forthcoming GNU libc
  712. library is released.
  713.  
  714.    The second kind of support contains general-purpose basic classes
  715. that transparently manage variable-sized objects on the freestore.  This
  716. includes Obstacks, multiple-precision Integers and Rationals, arbitrary
  717. length Strings, BitSets, and BitStrings.
  718.  
  719.    Third, several classes and utilities of common interest (e.g.,
  720. Complex numbers) are provided.
  721.  
  722.    Fourth, a set of pseudo-generic prototype files are available as a
  723. mechanism for generating common container classes. These are described
  724. in more detail in the introduction to container prototypes. Currently,
  725. only a textual substitution mechanism is available for generic class
  726. creation.
  727.  
  728. 
  729. File: libg++,  Node: Conventions,  Next: OK,  Prev: General,  Up: Top
  730.  
  731. GNU C++ library stylistic conventions
  732. *************************************
  733.  
  734.    * C++ source files have file extension `.cc'. Both C-compatibility
  735.      header files and class declaration files have extension `.h'.
  736.  
  737.    * C++ class names begin with capital letters, except for `istream'
  738.      and `ostream', for AT&T C++ compatibility. Multi-word class names
  739.      capitalize each word, with no underscore separation.
  740.  
  741.    * Include files that define C++ classes begin with capital letters
  742.      (as do the names of the classes themselves).  `stream.h' is
  743.      uncapitalized for AT&T C++ compatibility.
  744.  
  745.    * Include files that supply function prototypes for other C
  746.      functions (system calls and libraries) are all lower case.
  747.  
  748.    * All include files define a preprocessor variable _X_h, where X is
  749.      the name of the file, and conditionally compile only if this has
  750.      not been already defined. The `#pragma once' facility is also used
  751.      to avoid re-inclusion.
  752.  
  753.    * Structures and objects that must be publicly defined, but are not
  754.      intended for public use have names beginning with an underscore.
  755.      (for example, the `_Srep' struct, which is used only by the String
  756.      and SubString classes.)
  757.  
  758.    * The underscore is used to separate components of long function
  759.      names,
  760.      e.g., `set_File_exception_handler()'.
  761.  
  762.    * When a function could be usefully defined either as a member or a
  763.      friend, it is generally a member if it modifies and/or returns
  764.      itself, else it is a friend. There are cases where naturalness of
  765.      expression wins out over this rule.
  766.  
  767.    * Class declaration files are formatted so that it is easy to
  768.      quickly check them to determine function names, parameters, and so
  769.      on. Because of the different kinds of things that may appear in
  770.      class declarations, there is no perfect way to do this. Any
  771.      suggestions on developing a common class declaration formatting
  772.      style are welcome.
  773.  
  774.    * All classes use the same simple error (exception) handling
  775.      strategy.  Almost every class has a member function named
  776.      `error(char* msg)' that invokes an associated error handler
  777.      function via a pointer to that function, so that the error
  778.      handling function may be reset by programmers. By default nearly
  779.      all call `*lib_error_handler', which prints the message and then
  780.      aborts execution. This system is subject to change. In general,
  781.      errors are assumed to be non-recoverable: Library classes do not
  782.      include code that allows graceful continuation after exceptions.
  783.  
  784. 
  785. File: libg++,  Node: OK,  Next: Proto,  Prev: Conventions,  Up: Top
  786.  
  787. Support for representation invariants
  788. *************************************
  789.  
  790.    Most GNU C++ library classes possess a method named `OK()', that is
  791. useful in helping to verify correct performance of class operations.
  792.  
  793.    The `OK()' operations checks the "representation invariant" of a
  794. class object. This is a test to check whether the object is in a valid
  795. state. In effect, it is a (sometimes partial) verification of the
  796. library's promise that (1) class operations always leave objects in
  797. valid states, and (2) the class protects itself so that client functions
  798. cannot corrupt this state.
  799.  
  800.    While no simple validation technique can assure that all operations
  801. perform correctly, calls to `OK()' can at least verify that operations
  802. do not corrupt representations. For example for `String a, b, c; ... a
  803. = b + c;', a call to `a.OK();' will guarantee that `a' is a valid
  804. `String', but does not guarantee that it contains the concatenation of
  805. `b + c'. However, given that `a' is known to be valid, it is possible
  806. to further verify its properties, for example via `a.after(b) == c &&
  807. a.before(c) == b'. In other words, `OK()' generally checks only those
  808. internal representation properties that are otherwise inaccessible to
  809. users of the class. Other class operations are often useful for further
  810. validation.
  811.  
  812.    Failed calls to `OK()' call a class's `error' method if one exists,
  813. else directly call `abort'. Failure indicates an implementation error
  814. that should be reported.
  815.  
  816.    With only rare exceptions, the internal support functions for a class
  817. never themselves call `OK()' (although many of the test files in the
  818. distribution call `OK()' extensively).
  819.  
  820.    Verification of representational invariants can sometimes be very
  821. time consuming for complicated data structures.
  822.  
  823. 
  824. File: libg++,  Node: Proto,  Next: Representations,  Prev: OK,  Up: Top
  825.  
  826. Introduction to container class prototypes
  827. ******************************************
  828.  
  829.    As a temporary mechanism enabling the support of generic classes,
  830. the GNU C++ Library distribution contains a directory (`g++-include')
  831. of files designed to serve as the basis for generating container
  832. classes of specified elements.  These files can be used to generate
  833. `.h' and `.cc' files in the current directory via a supplied shell
  834. script program that performs simple textual substitution to create
  835. specific classes.
  836.  
  837.    While these classes are generated independently, and thus share no
  838. code, it is possible to create versions that do share code among
  839. subclasses. For example, using `typedef void* ent', and then generating
  840. a `entList' class, other derived classes could be created using the
  841. `void*' coercion method described in Stroustrup, pp204-210.
  842.  
  843.    This very simple class-generation facility is useful enough to serve
  844. current purposes, but will be replaced with a more coherent mechanism
  845. for handling C++ generics in a way that minimally disrupts current
  846. usage.  Without knowing exactly when or how parametric classes might be
  847. added to the C++ language, provision of this simplest possible
  848. mechanism, textual substitution, appears to be the safest strategy,
  849. although it does require certain redundancies and awkward constructions.
  850.  
  851.    Specific classes may be generated via the `genclass' shell script
  852. program. This program has arguments specifying the kinds of base
  853. types(s) to be used. Specifying base types requires two arguments. The
  854. first is the name of the base type, which may be any named type, like
  855. `int' or `String'. Only named types are supported; things like `int*'
  856. are not accepted. However, pointers like this may be used by supplying
  857. the appropriate typedefs (e.g., editing the resulting files to include
  858. `typedef int* intp;'). The type name must be followed by one of the
  859. words `val' or `ref', to indicate whether the base elements should be
  860. passed to functions by-value or by-reference.
  861.  
  862.    You can specify basic container classes using `genclass base
  863. [val,ref] proto', where `proto' is the name of the class being
  864. generated.  Container classes like dictionaries and maps that require
  865. two types may be specified via `genclass -2 keytype [val, ref],
  866. basetype [val, ref] proto', where the key type is specified first and
  867. the contents type second.  The resulting classnames and filenames are
  868. generated by prepending the specified type names to the prototype names,
  869. and separating the filename parts with dots.  For example, `genclass
  870. int val List' generates class `intList' residing in files `int.List.h'
  871. and `int.List.cc'. `genclass -2 String ref int val VHMap' generates
  872. (the awkward, but unavoidable) class name `StringintVHMap'. Of course,
  873. programmers may use `typedef' or simple editing to create more
  874. appropriate names.  The existence of dot seperators in file names
  875. allows the use of GNU make to help automate configuration and
  876. recompilation. An example Makefile exploiting such capabilities may be
  877. found in the `libg++/proto-kit' directory.
  878.  
  879.    The `genclass' utility operates via simple text substitution using
  880. `sed'. All occurrences of the pseudo-types `<T>' and `<C>' (if there
  881. are two types) are replaced with the indicated type, and occurrences of
  882. `<T&>' and `<C&>' are replaced by just the types, if `val' is
  883. specified, or types followed by "&" if `ref' is specified.
  884.  
  885.    Programmers will frequently need to edit the `.h' file in order to
  886. insert additional `#include' directives or other modifications.  A
  887. simple utility, `prepend-header' to prepend other `.h' files to
  888. generated files is provided in the distribution.
  889.  
  890.    One dubious virtue of the prototyping mechanism is that, because
  891. sources files, not archived library classes, are generated, it is
  892. relatively simple for programmers to modify container classes in the
  893. common case where slight variations of standard container classes are
  894. required.
  895.  
  896.    It is often a good idea for programmers to archive (via `ar')
  897. generated classes into `.a' files so that only those class functions
  898. actually used in a given application will be loaded.  The test
  899. subdirectory of the distribution shows an example of this.
  900.  
  901.    Because of `#pragma interface' directives, the `.cc' files should be
  902. compiled with `-O' or `-DUSE_LIBGXX_INLINES' enabled.
  903.  
  904.    Many container classes require specifications over and above the base
  905. class type. For example, classes that maintain some kind of ordering of
  906. elements require specification of a comparison function upon which to
  907. base the ordering.  This is accomplished via a prototype file `defs.hP'
  908. that contains macros for these functions. While these macros default to
  909. perform reasonable actions, they can and should be changed in
  910. particular cases. Most prototypes require only one or a few of these.
  911. No harm is done if unused macros are defined to perform nonsensical
  912. actions. The macros are:
  913.  
  914. `DEFAULT_INITIAL_CAPACITY'
  915.      The initial capacity for containers (e.g., hash tables) that
  916.      require an initial capacity argument for constructors.  Default:
  917.      100
  918.  
  919. `<T>EQ(a, b)'
  920.      return true if a is considered equal to b for the purposes of
  921.      locating, etc., an element in a container.  Default: (a == b)
  922.  
  923. `<T>LE(a, b)'
  924.      return true if a is less than or equal to b Default: (a <= b)
  925.  
  926. `<T>CMP(a, b)'
  927.      return an integer < 0 if a<b, 0 if a==b, or > 0 if a>b.  Default:
  928.      (a <= b)? (a==b)? 0 : -1 : 1
  929.  
  930. `<T>HASH(a)'
  931.      return an unsigned integer representing the hash of a.  Default:
  932.      hash(a) ; where extern unsigned int hash(<T&>).  (note: several
  933.      useful hash functions are declared in builtin.h and defined in
  934.      hash.cc)
  935.  
  936.    Nearly all prototypes container classes support container traversal
  937. via `Pix' pseudo indices, as described elsewhere.
  938.  
  939.    All object containers must perform either a `X::X(X&)' (or `X::X()'
  940. followed by `X::operator =(X&)') to copy objects into containers.  (The
  941. latter form is used for containers built from C++ arrays, like
  942. `VHSets'). When containers are destroyed, they invoke `X::~X()'.  Any
  943. objects used in containers must have well behaved constructors and
  944. destructors. If you want to create containers that merely reference
  945. (point to) objects that reside elsewhere, and are not copied or
  946. destroyed inside the container, you must use containers of pointers,
  947. not containers of objects.
  948.  
  949.    All prototypes are designed to generate *HOMOGENOUS* container
  950. classes.  There is no universally applicable method in C++ to support
  951. heterogenous object collections with elements of various subclasses of
  952. some specified base class. The only way to get heterogenous structures
  953. is to use collections of pointers-to-objects, not collections of objects
  954. (which also requires you to take responsibility for managing storage for
  955. the objects pointed to yourself).
  956.  
  957.    For example, the following usage illustrates a commonly encountered
  958. danger in trying to use container classes for heterogenous structures:
  959.  
  960.      class Base { int x; ...}
  961.      class Derived : public Base { int y; ... }
  962.      
  963.      BaseVHSet s; // class BaseVHSet generated via something like
  964.                   // `genclass Base ref VHSet'
  965.      
  966.      void f()
  967.      {
  968.        Base b;
  969.        s.add(b); // OK
  970.      
  971.        Derived d;
  972.        s.add(d);  // (CHOP!)
  973.      }
  974.  
  975.    At the line flagged with `(CHOP!)', a `Base::Base(Base&)' is called
  976. inside `Set::add(Base&)'--*not* `Derived::Derived(Derived&)'.
  977. Actually, in `VHSet', a `Base::operator =(Base&)', is used instead to
  978. place the element in an array slot, but with the same effect.  So only
  979. the Base part is copied as a `VHSet' element (a so-called
  980. chopped-copy). In this case, it has an `x' part, but no `y' part; and a
  981. Base, not Derived, vtable. Objects formed via chopped copies are rarely
  982. sensible.
  983.  
  984.    To avoid this, you must resort to pointers:
  985.  
  986.      typedef Base* BasePtr;
  987.      
  988.      BasePtrVHSet s; // class BaseVHSet generated via something like
  989.                      // `genclass BasePtr val VHSet'
  990.      
  991.      void f()
  992.      {
  993.        Base* bp = new Base;
  994.        s.add(b);
  995.      
  996.        Base* dp = new Derived;
  997.        s.add(d);  // works fine.
  998.      
  999.        // Don't forget to delete bp and dp sometime.
  1000.        // The VHSet won't do this for you.
  1001.      }
  1002.  
  1003. Example
  1004. =======
  1005.  
  1006.    The prototypes can be difficult to use on first attempt. Here is an
  1007. example that may be helpful. The utilities in the `proto-kit' simplify
  1008. much of the actions described, but are not used here.
  1009.  
  1010.    Suppose you create a class `Person', and want to make an Map that
  1011. links the social security numbers associated with each person. You start
  1012. off with a file `Person.h'
  1013.  
  1014.  
  1015.      #include <String.h>
  1016.      
  1017.      class Person
  1018.      {
  1019.        String nm;
  1020.        String addr;
  1021.        //...
  1022.      public:
  1023.        const String& name() { return nm; }
  1024.        const String& address() { return addr; }
  1025.        void          print() { ... }
  1026.        //...
  1027.      }
  1028.  
  1029.    And in file `SSN.h',
  1030.  
  1031.      typedef unsigned int SSN;
  1032.  
  1033.    Your first decision is what storage/usage strategy to use. There are
  1034. several reasonable alternatives here: You might create an "object
  1035. collection" of Persons, a "pointer collection" of pointers-to-Persons,
  1036. or even a simple String map, housing either copies of pointers to the
  1037. names of Persons, since other fields are unused for purposes of the
  1038. Map. In an object collection, instances of class Person "live" inside
  1039. the Map, while in a pointer collection, the instances live elsewhere.
  1040. Also, as above, if instances of subclasses of Person are to be used
  1041. inside the Map, you must use pointers. In a String Map, the same
  1042. difference holds, but now only for the name fields. Any of these
  1043. choices might make sense in particular applications.
  1044.  
  1045.    The second choice is the Map implementation strategy. Either a tree
  1046. or a hash table might make sense. Suppose you want an AVL tree Map.
  1047. There are two things to now check. First, as an object collection, the
  1048. AVLMap requires that the elsement class contain an `X(X&)' constructor.
  1049. In C++, if you don't specify such a constructor, one is constructed for
  1050. you, but it is a very good idea to always do this yourself, to avoid
  1051. surprises. In this example, you'd use something like
  1052.      class Person
  1053.      { ...;
  1054.          Person(const Person& p) :nm(p.nm), addr(p.addr) {}
  1055.      };
  1056.  
  1057.    Also, an AVLMap requires a comparison function for elements in order
  1058. to maintain order. Rather than requiring you to write a particular
  1059. comparison function, a `defs' file is consulted to determine how to
  1060. compare items. You must create and edit such a file.
  1061.  
  1062.    Before creating `Person.defs.h', you must first make one additional
  1063. decision. Should the Map member functions like `m.contains(p)' take
  1064. arguments (`p') by reference (i.e., typed as `int Map::contains(const
  1065. Person& p)' or by value (i.e., typed as `int Map::contains(const Person
  1066. p)'. Generally, for user-defined classes, you want to pass by
  1067. reference, and for builtins and pointers, to pass by value. SO you
  1068. should pick by-reference.
  1069.  
  1070.    You can now create `Person.defs.h' via `genclass Person ref defs'.
  1071. This creates a simple skeleton that you must edit. First, add `#include
  1072. "Person.h"' to the top. Second, edit the `<T>CMP(a,b)' macro to compare
  1073. on name, via
  1074.  
  1075.      #define <T>CMP(a, b) ( compare(a.name(), b.name()) )
  1076.  
  1077. which invokes the `int compare(const String&, const String&)' function
  1078. from `String.h'. Of course, you could define this in any other way as
  1079. well. In fact, the default versions in the skeleton turn out to be OK
  1080. (albeit inefficient) in this particular example.
  1081.  
  1082.    You may also want to create file `SSN.defs.h'. Here, choosing
  1083. call-by-value makes sense, and since no other capabilities (like
  1084. comparison functions) of the SSNs are used (and the defaults are OK
  1085. anyway), you'd type
  1086.  
  1087.      genclass SSN val defs
  1088.  
  1089. and then edit to place `#include "SSN.h"' at the top.
  1090.  
  1091.    Finally, you can generate the classes. First, generate the base
  1092. class for Maps via
  1093.  
  1094.      genclass -2 Person ref SSN val Map
  1095.  
  1096. This generates only the abstract class, not the implementation, in file
  1097. `Person.SSN.Map.h' and `Person.SSN.Map.cc'.  To create the AVL
  1098. implementation, type
  1099.  
  1100.      genclass -2 Person ref SSN val AVLMap
  1101.  
  1102. This creates the class `PersonSSNAVLMap', in `Person.SSN.AVLMap.h' and
  1103. `Person.SSN.AVLMap.cc'.
  1104.  
  1105.    To use the AVL implementation, compile the two generated `.cc'
  1106. files, and specify `#include "Person.SSN.AVLMap.h"' in the application
  1107. program.  All other files are included in the right ways automatically.
  1108.  
  1109.    One last consideration, peculiar to Maps, is to pick a reasonable
  1110. default contents when declaring an AVLMap. Zero might be appropriate
  1111. here, so you might declare a Map,
  1112.  
  1113.      PersonSSNAVLMap m((SSN)0);
  1114.  
  1115.    Suppose you wanted a `VHMap' instead of an `AVLMap' Besides
  1116. generating different implementations, there are two differences in how
  1117. you should prepare the `defs' file. First, because a VHMap uses a C++
  1118. array internally, and because C++ array slots are initialized
  1119. differently than single elements, you must ensure that class Person
  1120. contains (1) a no-argument constructor, and (2) an assignment operator.
  1121. You could arrange this via
  1122.  
  1123.      class Person
  1124.      { ...;
  1125.          Person() {}
  1126.        void operator = (const Person& p) { nm = p.nm; addr = p.addr; }
  1127.      };
  1128.  
  1129.    (The lack of action in the constructor is OK here because `Strings'
  1130. possess usable no-argument constructors.)
  1131.  
  1132.    You also need to edit `Person.defs.h' to indicate a usable hash
  1133. function and default capacity, via something like
  1134.  
  1135.      #include <builtin.h>
  1136.      #define <T>HASH(x)  (hashpjw(x.name().chars()))
  1137.      #define DEFAULT_INITIAL_CAPACITY 1000
  1138.  
  1139.    Since the `hashpjw' function from `builtin.h' is appropriate here.
  1140. Changing the default capacity to a value expected to exceed the actual
  1141. capacity helps to avoid "hidden" inefficiencies when a new VHMap is
  1142. created without overriding the default, which is all too easy to do.
  1143.  
  1144.    Otherwise, everything is the same as above, substituting `VHMap' for
  1145. `AVLMap'.
  1146.  
  1147. 
  1148. File: libg++,  Node: Representations,  Next: Expressions,  Prev: Proto,  Up: Top
  1149.  
  1150. Variable-Sized Object Representation
  1151. ************************************
  1152.  
  1153.    One of the first goals of the GNU C++ library is to enrich the kinds
  1154. of basic classes that may be considered as (nearly) "built into" C++. A
  1155. good deal of the inspiration for these efforts is derived from
  1156. considering features of other type-rich languages, particularly Common
  1157. Lisp and Scheme.  The general characteristics of most class and friend
  1158. operators and functions supported by these classes has been heavily
  1159. influenced by such languages.
  1160.  
  1161.    Four of these types, Strings, Integers, BitSets, and BitStrings (as
  1162. well as associated and/or derived classes) require representations
  1163. suitable for managing variable-sized objects on the free-store. The
  1164. basic technique used for all of these is the same, although various
  1165. details necessarily differ from class to class.
  1166.  
  1167.    The general strategy for representing such objects is to create
  1168. chunks of memory that include both header information (e.g., the size
  1169. of the object), as well as the variable-size data (an array of some
  1170. sort) at the end of the chunk. Generally the maximum size of an object
  1171. is limited to something less than all of addressable memory, as a
  1172. safeguard. The minimum size is also limited so as not to waste
  1173. allocations expanding very small chunks. Internally, chunks are
  1174. allocated in blocks well-tuned to the performance of the `new' operator.
  1175.  
  1176.    Class elements themselves are merely pointers to these chunks.  Most
  1177. class operations are performed via inline "translation" functions that
  1178. perform the required operation on the corresponding representation.
  1179. However, constructors and assignments operate by copying entire
  1180. representations, not just pointers.
  1181.  
  1182.    No attempt is made to control temporary creation in expressions and
  1183. functions involving these classes. Users of previous versions of the
  1184. classes will note the disappearance of both "Tmp" classes and reference
  1185. counting. These were dropped because, while they did improve
  1186. performance in some cases, they obscure class mechanics, lead
  1187. programmers into the false belief that they need not worry about such
  1188. things, and occasionally have paradoxical behavior.
  1189.  
  1190.    These variable-sized object classes are integrated as well as
  1191. possible into C++. Most such classes possess converters that allow
  1192. automatic coercion both from and to builtin basic types. (e.g., char*
  1193. to and from String, long int to and from Integer, etc.). There are
  1194. pro's and con's to circular converters, since they can sometimes lead
  1195. to the conversion from a builtin type through to a class function and
  1196. back to a builtin type without any special attention on the part of the
  1197. programmer, both for better and worse.
  1198.  
  1199.    Most of these classes also provide special-case operators and
  1200. functions mixing basic with class types, as a way to avoid constructors
  1201. in cases where the operations do not rely on anything special about the
  1202. representations.  For example, there is a special case concatenation
  1203. operator for a String concatenated with a char, since building the
  1204. result does not rely on anything about the String header. Again, there
  1205. are arguments both for and against this approach. Supporting these cases
  1206. adds a non-trivial degree of (mainly inline) function proliferation, but
  1207. results in more efficient operations. Efficiency wins out over parsimony
  1208. here, as part of the goal to produce classes that provide sufficient
  1209. functionality and efficiency so that programmers are not tempted to try
  1210. to manipulate or bypass the underlying representations.
  1211.  
  1212. 
  1213. File: libg++,  Node: Expressions,  Next: Pix,  Prev: Representations,  Up: Top
  1214.  
  1215. Some guidelines for using expression-oriented classes
  1216. *****************************************************
  1217.  
  1218.    The fact that C++ allows operators to be overloaded for user-defined
  1219. classes can make programming with library classes like `Integer',
  1220. `String', and so on very convenient. However, it is worth becoming
  1221. familiar with some of the inherent limitations and problems associated
  1222. with such operators.
  1223.  
  1224.    Many operators are *constructive*, i.e., create a new object based
  1225. on some function of some arguments. Sometimes the creation of such
  1226. objects is wasteful. Most library classes supporting expressions
  1227. contain facilities that help you avoid such waste.
  1228.  
  1229.    For example, for `Integer a, b, c; ...;  c = a + b + a;', the plus
  1230. operator is called to sum a and b, creating a new temporary object as
  1231. its result. This temporary is then added with a, creating another
  1232. temporary, which is finally copied into c, and the temporaries are then
  1233. deleted. In other words, this code might have an effect similar to
  1234. `Integer a, b, c; ...; Integer t1(a); t1 += b; Integer t2(t1); t2 += a;
  1235. c = t2;'.
  1236.  
  1237.    For small objects, simple operators, and/or non-time/space critical
  1238. programs, creation of temporaries is not a big problem. However, often,
  1239. when fine-tuning a program, it may be a good idea to rewrite such code
  1240. in a less pleasant, but more efficient manner.
  1241.  
  1242.    For builtin types like ints, and floats, C and C++ compilers already
  1243. know how to optimize such expressions to reduce the need for
  1244. temporaries. Unfortunately, this is not true for C++ user defined
  1245. types, for the simple (but very annoying, in this context) reason that
  1246. nothing at all is guaranteed about the semantics of overloaded operators
  1247. and their interrelations. For example, if the above expression just
  1248. involved ints, not Integers, a compiler might internally convert the
  1249. statement into something like ` c = a; c += b; c+= a; ', or perhaps
  1250. something even more clever.  But since C++ does not know that Integer
  1251. operator += has any relation to Integer operator +, A C++ compiler
  1252. cannot do this kind of expression optimization itself.
  1253.  
  1254.    In many cases, you can avoid construction of temporaries simply by
  1255. using the assignment versions of operators whenever possible, since
  1256. these versions create no temporaries. However, for maximum flexibility,
  1257. most classes provide a set of "embedded assembly code" procedures that
  1258. you can use to fully control time, space, and evaluation strategies.
  1259. Most of these procedures are "three-address" procedures that take two
  1260. `const' source arguments, and a destination argument. The procedures
  1261. perform the appropriate actions, placing the results in the destination
  1262. (which is may involve overwriting old contents). These procedures are
  1263. designed to be fast and robust. In particular, aliasing is always
  1264. handled correctly, so that, for example `add(x, x, x); ' is perfectly
  1265. OK. (The names of these procedures are listed along with the classes.)
  1266.  
  1267.    For example, suppose you had an Integer expression ` a = (b - a) *
  1268. -(d / c); '
  1269.  
  1270.    This would be compiled as if it were ` Integer t1=b-a; Integer
  1271. t2=d/c; Integer t3=-t2; Integer t4=t1*t3; a=t4;'
  1272.  
  1273.    But, with some manual cleverness, you might yourself some up with `
  1274. sub(a, b, a); mul(a, d, a); div(a, c, a); '
  1275.  
  1276.    A related phenomenon occurs when creating your own constructive
  1277. functions returning instances of such types. Suppose you wanted to
  1278. write function `Integer f(const Integer& a) { Integer r = a;  r += a;
  1279. return r; }'
  1280.  
  1281.    This function, when called (as in ` a = f(a); ') demonstrates a
  1282. similar kind of wasted copy. The returned value r must be copied out of
  1283. the function before it can be used by the caller. In GNU C++, there is
  1284. an alternative via the use of named return values.  Named return values
  1285. allow you to manipulate the returned object directly, rather than
  1286. requiring you to create a local inside a function and then copy it out
  1287. as the returned value. In this example, this can be done via `Integer
  1288. f(const Integer& a) return r(a) { r += a; return; }'
  1289.  
  1290.    A final guideline: The overloaded operators are very convenient, and
  1291. much clearer to use than procedural code. It is almost always a good
  1292. idea to make it right, *then* make it fast, by translating expression
  1293. code into procedural code after it is known to be correct.
  1294.  
  1295. 
  1296. File: libg++,  Node: Pix,  Next: Headers,  Prev: Expressions,  Up: Top
  1297.  
  1298. Pseudo-indexes
  1299. **************
  1300.  
  1301.    Many useful classes operate as containers of elements. Techniques for
  1302. accessing these elements from a container differ from class to class.
  1303. In the GNU C++ library, access methods have been partially standardized
  1304. across different classes via the use of pseudo-indexes called `Pixes'.
  1305. A `Pix' acts in some ways like an index, and in some ways like a
  1306. pointer. (Their underlying representations are just `void*' pointers).
  1307. A `Pix' is a kind of "key" that is translated into an element access by
  1308. the class.  In virtually all cases, `Pixes' are pointers to some kind
  1309. internal storage cells. The containers use these pointers to extract
  1310. items.
  1311.  
  1312.    `Pixes' support traversal and inspection of elements in a collection
  1313. using analogs of array indexing. However, they are pointer-like in that
  1314. `0' is treated as an invalid `Pix', and unsafe insofar as programmers
  1315. can attempt to access nonexistent elements via dangling or otherwise
  1316. invalid `Pixes' without first checking for their validity.
  1317.  
  1318.    In general it is a very bad idea to perform traversals in the the
  1319. midst of destructive modifications to containers.
  1320.  
  1321.    Typical applications might include code using the idiom
  1322.      for (Pix i = a.first(); i != 0; a.next(i)) use(a(i));
  1323.    for some container `a' and function `use'.
  1324.  
  1325.    Classes supporting the use of `Pixes' always contain the following
  1326. methods, assuming a container `a' of element types of `Base'.
  1327.  
  1328. `Pix i = a.first()'
  1329.      Set i to index the first element of a or 0 if a is empty.
  1330.  
  1331. `a.next(i)'
  1332.      advance i to the next element of a or 0 if there is no next
  1333.      element;
  1334.  
  1335. `Base x = a(i); a(i) = x;'
  1336.      a(i) returns a reference to the element indexed by i.
  1337.  
  1338. `int present = a.owns(i)'
  1339.      returns true if Pix i is a valid Pix in a. This is often a
  1340.      relatively slow operation, since the collection must usually
  1341.      traverse through elements to see if any correspond to the Pix.
  1342.  
  1343.    Some container classes also support backwards traversal via
  1344.  
  1345. `Pix i = a.last()'
  1346.      Set i to the last element of a or 0 if a is empty.
  1347.  
  1348. `a.prev(i)'
  1349.      sets i to the previous element in a, or 0 if there is none.
  1350.  
  1351.    Collections supporting elements with an equality operation possess
  1352.  
  1353. `Pix j = a.seek(x)'
  1354.      sets j to the index of the first occurrence of x, or 0 if x is not
  1355.      contained in a.
  1356.  
  1357.    Bag classes possess
  1358.  
  1359. `Pix j = a.seek(x, Pix from = 0)'
  1360.      sets j to the index of the next occurrence of x following i, or 0
  1361.      if x is not contained in a. If i == 0, the first occurrence is
  1362.      returned.
  1363.  
  1364.    Set, Bag, and PQ classes possess
  1365.  
  1366. `Pix j = a.add(x) (or a.enq(x) for priority queues)'
  1367.      add x to the collection, returning its Pix. The Pix of an item can
  1368.      change in collections where further additions and deletions
  1369.      involve the actual movement of elements (currently in OXPSet,
  1370.      OXPBag, XPPQ, VOHSet), but in all other cases, an item's Pix may
  1371.      be considered a permanent key to its location.
  1372.  
  1373. 
  1374. File: libg++,  Node: Headers,  Next: Builtin,  Prev: Pix,  Up: Top
  1375.  
  1376. Header files for interfacing C++ to C
  1377. *************************************
  1378.  
  1379.    The following files are provided so that C++ programmers may invoke
  1380. common C library and system calls. The names and contents of these
  1381. files are subject to change in order to be compatible with the
  1382. forthcoming GNU C library. Other files, not listed here, are simply
  1383. C++-compatible interfaces to corresponding C library files.
  1384.  
  1385. `values.h'
  1386.      A collection of constants defining the numbers of bits in builtin
  1387.      types, minimum and maximum values, and the like. Most names are
  1388.      the same as those found in `values.h' found on Sun systems.
  1389.  
  1390. `std.h'
  1391.      A collection of common system calls and `libc.a' functions.  Only
  1392.      those functions that can be declared without introducing new type
  1393.      definitions (socket structures, for example) are provided. Common
  1394.      `char*' functions (like `strcmp') are among the declarations. All
  1395.      functions are declared along with their library names, so that
  1396.      they may be safely overloaded.
  1397.  
  1398. `string.h'
  1399.      This file merely includes `<std.h>', where string function
  1400.      prototypes are declared. This is a workaround for the fact that
  1401.      system `string.h' and `strings.h' files often differ in contents.
  1402.  
  1403. `osfcn.h'
  1404.      This file merely includes `<std.h>', where system function
  1405.      prototypes are declared.
  1406.  
  1407. `libc.h'
  1408.      This file merely includes `<std.h>', where C library function
  1409.      prototypes are declared.
  1410.  
  1411. `math.h'
  1412.      A collection of prototypes for functions usually found in libm.a,
  1413.      plus some `#define'd constants that appear to be consistent with
  1414.      those provided in the AT&T version. The value of `HUGE' should be
  1415.      checked before using. Declarations of all common math functions
  1416.      are preceded with `overload' declarations, since these are
  1417.      commonly overloaded.
  1418.  
  1419. `stdio.h'
  1420.      Declaration of `FILE' (`_iobuf'), common macros (like `getc'), and
  1421.      function prototypes for `libc.a' functions that operate on
  1422.      `FILE*''s. The value `BUFSIZ' and the declaration of `_iobuf'
  1423.      should be checked before using.
  1424.  
  1425. `assert.h'
  1426.      C++ versions of assert macros.
  1427.  
  1428. `generic.h'
  1429.      String concatenation macros useful in creating generic classes.
  1430.      They are similar in function to the AT&T CC versions.
  1431.  
  1432. `new.h'
  1433.      Declarations of the default global operator new, the two-argument
  1434.      placement version, and associated error handlers.
  1435.  
  1436. 
  1437. File: libg++,  Node: Builtin,  Next: New,  Prev: Headers,  Up: Top
  1438.  
  1439. Utility functions for built in types
  1440. ************************************
  1441.  
  1442.    Files `builtin.h' and corresponding `.cc' implementation files
  1443. contain various convenient inline and non-inline utility functions.
  1444. These include useful enumeration types, such as `TRUE', `FALSE' ,the
  1445. type definition for pointers to libg++ error handling functions, and
  1446. the following functions.
  1447.  
  1448. `long abs(long x); double abs(double x);'
  1449.      inline versions of abs. Note that the standard libc.a version,
  1450.      `int abs(int)' is *not* declared as inline.
  1451.  
  1452. `void clearbit(long& x, long b);'
  1453.      clears the b'th bit of x (inline).
  1454.  
  1455. `void setbit(long& x, long b);'
  1456.      sets the b'th bit of x (inline)
  1457.  
  1458. `int testbit(long x, long b);'
  1459.      returns the b'th bit of x (inline).
  1460.  
  1461. `int even(long y);'
  1462.      returns true if x is even (inline).
  1463.  
  1464. `int odd(long y);'
  1465.      returns true is x is odd (inline).
  1466.  
  1467. `int sign(long x); int sign(double x);'
  1468.      returns -1, 0, or 1, indicating whether x is less than, equal to,
  1469.      or greater than zero (inline).
  1470.  
  1471. `long gcd(long x, long y);'
  1472.      returns the greatest common divisor of x and y.
  1473.  
  1474. `long lcm(long x, long y);'
  1475.      returns the least common multiple of x and y.
  1476.  
  1477. `long lg(long x);'
  1478.      returns the floor of the base 2 log of x.
  1479.  
  1480. `long pow(long x, long y); double pow(double x, long y);'
  1481.      returns x to the integer power y using via the iterative O(log y)
  1482.      "Russian peasant" method.
  1483.  
  1484. `long sqr(long x); double sqr(double x);'
  1485.      returns x squared (inline).
  1486.  
  1487. `long sqrt(long y);'
  1488.      returns the floor of the square root of x.
  1489.  
  1490. `unsigned int hashpjw(const char* s);'
  1491.      a hash function for null-terminated char* strings using the method
  1492.      described in Aho, Sethi, & Ullman, p 436.
  1493.  
  1494. `unsigned int multiplicativehash(int x);'
  1495.      a hash function for integers that returns the lower bits of
  1496.      multiplying x by the golden ratio times pow(2, 32).  See Knuth,
  1497.      Vol 3, p 508.
  1498.  
  1499. `unsigned int foldhash(double x);'
  1500.      a hash function for doubles that exclusive-or's the first and
  1501.      second words of x, returning the result as an integer.
  1502.  
  1503. `double start_timer()'
  1504.      Starts a process timer.
  1505.  
  1506. `double return_elapsed_time(double last_time)'
  1507.      Returns the process time since last_time.  If last_time == 0
  1508.      returns the time since the last start_timer.  Returns -1 if
  1509.      start_timer was not first called.
  1510.  
  1511.    File `Maxima.h' includes versions of `MAX, MIN' for builtin types.
  1512.  
  1513.    File `compare.h' includes versions of `compare(x, y)' for builtin
  1514. types. These return negative if the first argument is less than the
  1515. second, zero for equal, and positive for greater.
  1516.  
  1517. 
  1518. File: libg++,  Node: New,  Next: Stream,  Prev: Builtin,  Up: Top
  1519.  
  1520. Library dynamic allocation primitives
  1521. *************************************
  1522.  
  1523.    Libg++ contains versions of `malloc, free, realloc' that were
  1524. designed to be well-tuned to C++ applications. The source file
  1525. `malloc.c' contains some design and implementation details.  Here are
  1526. the major user-visible differences from most system malloc routines:
  1527.  
  1528.   1. These routines *overwrite* storage of freed space. This means that
  1529.      it is never permissible to use a `delete''d object in any way.
  1530.      Doing so will either result in trapped fatal errors or random
  1531.      aborts within malloc, free, or realloc.
  1532.  
  1533.   2. The routines tend to perform well when a large number of objects
  1534.      of the same size are allocated and freed. You may find that it is
  1535.      not worth it to create your own special allocation schemes in such
  1536.      cases.
  1537.  
  1538.   3. The library sets top-level `operator new()' to call malloc and
  1539.      `operator delete()' to call free. Of course, you may override these
  1540.      definitions in C++ programs by creating your own operators that
  1541.      will take precedence over the library versions. However, if you do
  1542.      so, be sure to define *both* `operator new()' and `operator
  1543.      delete()'.
  1544.  
  1545.   4. These routines do *not* support the odd convention, maintained by
  1546.      some versions of malloc, that you may call `realloc' with a pointer
  1547.      that has been `free''d.
  1548.  
  1549.   5. The routines automatically perform simple checks on `free''d
  1550.      pointers that can often determine whether users have accidentally
  1551.      written beyond the boundaries of allocated space, resulting in a
  1552.      fatal error.
  1553.  
  1554.   6. The function `malloc_usable_size(void* p)' returns the number of
  1555.      bytes actually allocated for `p'. For a valid pointer (i.e., one
  1556.      that has been `malloc''d or `realloc''d but not yet `free''d) this
  1557.      will return a number greater than or equal to the requested size,
  1558.      else it will normally return 0. Unfortunately, a non-zero return
  1559.      can not be an absolutely perfect indication of lack of error. If a
  1560.      chunk has been `free''d but then re-allocated for a different
  1561.      purpose somewhere elsewhere, then `malloc_usable_size' will return
  1562.      non-zero. Despite this, the function can be very valuable for
  1563.      performing run-time consistency checks.
  1564.  
  1565.   7. `malloc' requires 8 bytes of overhead per allocated chunk, plus a
  1566.      mmaximum alignment adjustment of 8 bytes. The number of bytes of
  1567.      usable space is exactly as requested, rounded to the nearest 8
  1568.      byte boundary.
  1569.  
  1570.   8. The routines do *not* contain any synchronization support for
  1571.      multiprocessing. If you perform global allocation on a shared
  1572.      memory multiprocessor, you should disable compilation and use of
  1573.      libg++ malloc in the distribution `Makefile' and use your system
  1574.      version of malloc.
  1575.  
  1576.  
  1577. 
  1578. File: libg++,  Node: Stream,  Next: Obstack,  Prev: New,  Up: Top
  1579.  
  1580. The old I/O library
  1581. *******************
  1582.  
  1583.    WARNING: This chapter describes classes that are *obsolete*.  These
  1584. classes are normally not available when libg++ is installed normally.
  1585. The sources are currently included in the distribution, and you can
  1586. configure libg++ to use these classes instead of the new iostream
  1587. classes.  This is only a temporary measure; you should convert your
  1588. code to use iostreams as soon as possible.  The iostream classes
  1589. provide some compatibility support, but it is very incomplete (there is
  1590. no longer a `File' class).
  1591.  
  1592. File-based classes
  1593. ==================
  1594.  
  1595.    The `File' class supports basic IO on Unix files.  Operations are
  1596. based on common C stdio library functions.
  1597.  
  1598.    `File' serves as the base class for istreams, ostreams, and other
  1599. derived classes. It contains the interface between the Unix stdio file
  1600. library and these more structured classes.  Most operations are
  1601. implemented as simple calls to stdio functions. `File' class operations
  1602. are also fully compatible with raw system file reads and writes (like
  1603. the system `read' and `lseek' calls) when buffering is disabled (see
  1604. below).  The `FILE*' stdio file pointer is, however maintained as
  1605. protected.  Classes derived from File may only use the IO operations
  1606. provided by File, which encompass essentially all stdio capabilities.
  1607.  
  1608.    The class contains four general kinds of functions: methods for
  1609. binding `File's to physical Unix files, basic IO methods, file and
  1610. buffer control methods, and methods for maintaining logical and
  1611. physical file status.
  1612.  
  1613.    Binding and related tasks are accomplished via `File' constructors
  1614. and destructors, and member functions `open, close, remove, filedesc,
  1615. name, setname'.
  1616.  
  1617.    If a file name is provided in a constructor or open, it is
  1618. maintained as class variable `nm' and is accessible via `name'.  If no
  1619. name is provided, then `nm' remains null, except that `Files' bound to
  1620. the default files stdin, stdout, and stderr are automatically given the
  1621. names `(stdin), (stdout), (stderr)' respectively.  The function
  1622. `setname' may be used to change the internal name of the `File'. This
  1623. does not change the name of the physical file bound to the File.
  1624.  
  1625.    The member function `close' closes a file.  The `~File' destructor
  1626. closes a file if it is open, except that stdin, stdout, and stderr are
  1627. flushed but left open for the system to close on program exit since
  1628. some systems may require this, and on others it does not matter.
  1629. `remove' closes the file, and then deletes it if possible by calling the
  1630. system function to delete the file with the name provided in the `nm'
  1631. field.
  1632.  
  1633. Basic IO
  1634. ========
  1635.  
  1636.    * `read' and `write' perform binary IO via stdio `fread' and
  1637.      `fwrite'.
  1638.  
  1639.    * `get' and `put' for chars invoke stdio `getc' and `putc' macros.
  1640.  
  1641.    * `put(const char* s)' outputs a null-terminated string via stdio
  1642.      `fputs'.
  1643.  
  1644.    * `unget' and `putback' are synonyms.  Both call stdio `ungetc'.
  1645.  
  1646. File Control
  1647. ============
  1648.  
  1649.    `flush', `seek', `tell', and `tell' call the corresponding stdio
  1650. functions.
  1651.  
  1652.    `flush(char)' and `fill()' call stdio `_flsbuf' and `_filbuf'
  1653. respectively.
  1654.  
  1655.    `setbuf' is mainly useful to turn off buffering in cases where
  1656. nonsequential binary IO is being performed. `raw' is a synonym for
  1657. `setbuf(_IONBF)'.  After a `f.raw()', using the stdio functions instead
  1658. of the system `read, write', etc., calls entails very little overhead.
  1659. Moreover, these become fully compatible with intermixed system calls
  1660. (e.g., `lseek(f.filedesc(), 0, 0)'). While intermixing `File' and
  1661. system IO calls is not at all recommended, this technique does allow
  1662. the `File' class to be used in conjunction with other functions and
  1663. libraries already set up to operate on file descriptors. `setbuf'
  1664. should be called at most once after a constructor or open, but before
  1665. any IO.
  1666.  
  1667. File Status
  1668. ===========
  1669.  
  1670.    File status is maintained in several ways.
  1671.  
  1672.    A `File' may be checked for accessibility via `is_open()', which
  1673. returns true if the File is bound to a usable physical file,
  1674. `readable()', which returns true if the File can be read from (opened
  1675. for reading, and not in a _fail state), or `writable()', which returns
  1676. true if the File can be written to.
  1677.  
  1678.    `File' operations return their status via two means: failure and
  1679. success are represented via the logical state. Also, the return values
  1680. of invoked stdio and system functions that return useful numeric values
  1681. (not just failure/success flags) are held in a class variable
  1682. accessible via `iocount'.  (This is useful, for example, in determining
  1683. the number of items actually read by the `read' function.)
  1684.  
  1685.    Like the AT&T i/o-stream classes, but unlike the description in the
  1686. Stroustrup book, p238, `rdstate()' returns the bitwise OR of `_eof',
  1687. `_fail' and `_bad', not necessarily distinct values. The functions
  1688. `eof()', `fail()', `bad()', and `good()' can be used to test for each of
  1689. these conditions independently.
  1690.  
  1691.    `_fail' becomes set for any input operation that could not read in
  1692. the desired data, and for other failed operations. As with all Unix IO,
  1693. `_eof' becomes true only when an input operations fails because of an
  1694. end of file. Therefore, `_eof' is not immediately true after the last
  1695. successful read of a file, but only after one final read attempt. Thus,
  1696. for input operations, `_fail' and `_eof' almost always become true at
  1697. the same time.  `bad' is set for unbound files, and may also be set by
  1698. applications in order to communicate input corruption. Conversely,
  1699. `_good' is defined as 0 and is returned by `rdstate()' if all is well.
  1700.  
  1701.    The state may be modified via `clear(flag)', which, despite its
  1702. name, sets the corresponding state_value flag.  `clear()' with no
  1703. arguments resets the state to `_good'.  `failif(int cond)' sets the
  1704. state to `_fail' only if `cond' is true.
  1705.  
  1706.    Errors occuring during constructors and file opens also invoke the
  1707. function `error'.  `error' in turn calls a resetable error handling
  1708. function pointed to by the non-member global variable
  1709. `File_error_handler' only if a system error has been generated.  Since
  1710. `error' cannot tell if the current system error is actually responsible
  1711. for a failure, it may at times print out spurious messages.  Three
  1712. error handlers are provided. The default, `verbose_File_error_handler'
  1713. calls the system function `perror' to print the corresponding error
  1714. message on standard error, and then returns to the caller.
  1715. `quiet_File_error_handler' does nothing, and simply returns.
  1716. `fatal_File_error_handler' prints the error and then aborts execution.
  1717. These three handlers, or any other user-defined error handlers can be
  1718. selected via the non-member function `set_File_error_handler'.
  1719.  
  1720.    All read and write operations communicate either logical or physical
  1721. failure by setting the `_fail' flag.  All further operations are
  1722. blocked if the state is in a `_fail' or`_bad' condition. Programmers
  1723. must explicitly use `clear()' to reset the state in order to continue
  1724. IO processing after either a logical or physical failure.  C
  1725. programmers who are unfamiliar with these conventions should note that,
  1726. unlike the stdio library, `File' functions indicate IO success, status,
  1727. or failure solely through the state, not via return values of the
  1728. functions.  The `void*' operator or `rdstate()' may be used to test
  1729. success.  In particular, according to c++ conversion rules, the `void*'
  1730. coercion is automatically applied whenever the `File&' return value of
  1731. any `File' function is tested in an `if' or `while'.  Thus, for
  1732. example, an easy way to copy all of stdin to stdout until eof (at which
  1733. point `get' fails) or some error is `char c; while(cin.get(c) &&
  1734. cout.put(c));'.
  1735.  
  1736.    The current version of istreams and ostreams differs significantly
  1737. from previous versions in order to obtain compatibility with AT&T 1.2
  1738. streams. Most code using previous versions should still work. However,
  1739. the following features of `File' are not incorporated in streams (they
  1740. are still present in `File'): `scan(const char* fmt...), remove(),
  1741. read(), write(), setbuf(), raw()'. Additionally, the feature of
  1742. previous streams that allowed free intermixing of stream and stdio
  1743. input and output is no longer guaranteed to always behave as desired.
  1744.  
  1745. 
  1746. File: libg++,  Node: Obstack,  Next: AllocRing,  Prev: Stream,  Up: Top
  1747.  
  1748. The Obstack class
  1749. *****************
  1750.  
  1751.    The `Obstack' class is a simple rewrite of the C obstack macros and
  1752. functions provided in the GNU CC compiler source distribution.
  1753.  
  1754.    Obstacks provide a simple method of creating and maintaining a string
  1755. table, optimized for the very frequent task of building strings
  1756. character-by-character, and sometimes keeping them, and sometimes not.
  1757. They seem especially useful in any parsing application. One of the test
  1758. files demonstrates usage.
  1759.  
  1760.    A brief summary:
  1761. `grow'
  1762.      places something on the obstack without committing to wrap it up
  1763.      as a single entity yet.
  1764.  
  1765. `finish'
  1766.      wraps up a constructed object as a single entity, and returns the
  1767.      pointer to its start address.
  1768.  
  1769. `copy'
  1770.      places things on the obstack, and *does* wrap them up.  `copy' is
  1771.      always equivalent to first grow, then finish.
  1772.  
  1773. `free'
  1774.      deletes something, and anything else put on the obstack since its
  1775.      creation.
  1776.  
  1777.    The other functions are less commonly needed:
  1778. `blank'
  1779.      is like grow, except it just grows the space by size units without
  1780.      placing anything into this space
  1781.  
  1782. `alloc'
  1783.      is like `blank', but it wraps up the object and returns its
  1784.      starting address.
  1785.  
  1786. `chunk_size, base, next_free, alignment_mask, size, room'
  1787.      returns the appropriate class variables.
  1788.  
  1789. `grow_fast'
  1790.      places a character on the obstack without checking if there is
  1791.      enough room.
  1792.  
  1793. `blank_fast'
  1794.      like `blank', but without checking if there is enough room.
  1795.  
  1796. `shrink(int n)'
  1797.      shrink the current chunk by n bytes.
  1798.  
  1799. `contains(void* addr)'
  1800.      returns true if the Obstack holds the address addr.
  1801.  
  1802.    Here is a lightly edited version of the original C documentation:
  1803.  
  1804.    These functions operate a stack of objects.  Each object starts life
  1805. small, and may grow to maturity.  (Consider building a word syllable by
  1806. syllable.)  An object can move while it is growing.  Once it has been
  1807. "finished" it never changes address again.  So the "top of the stack"
  1808. is typically an immature growing object, while the rest of the stack is
  1809. of mature, fixed size and fixed address objects.
  1810.  
  1811.    These routines grab large chunks of memory, using the GNU C++ `new'
  1812. operator.  On occasion, they free chunks, via `delete'.
  1813.  
  1814.    Each independent stack is represented by a Obstack.
  1815.  
  1816.    One motivation for this package is the problem of growing char
  1817. strings in symbol tables.  Unless you are a "fascist pig with a
  1818. read-only mind" [Gosper's immortal quote from HAKMEM item 154, out of
  1819. context] you would not like to put any arbitrary upper limit on the
  1820. length of your symbols.
  1821.  
  1822.    In practice this often means you will build many short symbols and a
  1823. few long symbols.  At the time you are reading a symbol you don't know
  1824. how long it is.  One traditional method is to read a symbol into a
  1825. buffer, `realloc()'ating the buffer every time you try to read a symbol
  1826. that is longer than the buffer.  This is beaut, but you still will want
  1827. to copy the symbol from the buffer to a more permanent symbol-table
  1828. entry say about half the time.
  1829.  
  1830.    With obstacks, you can work differently.  Use one obstack for all
  1831. symbol names.  As you read a symbol, grow the name in the obstack
  1832. gradually.  When the name is complete, finalize it.  Then, if the
  1833. symbol exists already, free the newly read name.
  1834.  
  1835.    The way we do this is to take a large chunk, allocating memory from
  1836. low addresses.  When you want to build a symbol in the chunk you just
  1837. add chars above the current "high water mark" in the chunk.  When you
  1838. have finished adding chars, because you got to the end of the symbol,
  1839. you know how long the chars are, and you can create a new object.
  1840. Mostly the chars will not burst over the highest address of the chunk,
  1841. because you would typically expect a chunk to be (say) 100 times as
  1842. long as an average object.
  1843.  
  1844.    In case that isn't clear, when we have enough chars to make up the
  1845. object, *they are already contiguous in the chunk* (guaranteed) so we
  1846. just point to it where it lies.  No moving of chars is needed and this
  1847. is the second win: potentially long strings need never be explicitly
  1848. shuffled. Once an object is formed, it does not change its address
  1849. during its lifetime.
  1850.  
  1851.    When the chars burst over a chunk boundary, we allocate a larger
  1852. chunk, and then copy the partly formed object from the end of the old
  1853. chunk to the beginning of the new larger chunk.  We then carry on
  1854. accreting characters to the end of the object as we normally would.
  1855.  
  1856.    A special version of grow is provided to add a single char at a time
  1857. to a growing object.
  1858.  
  1859.    Summary:
  1860.  
  1861.    * We allocate large chunks.
  1862.  
  1863.    * We carve out one object at a time from the current chunk.
  1864.  
  1865.    * Once carved, an object never moves.
  1866.  
  1867.    * We are free to append data of any size to the currently growing
  1868.      object.
  1869.  
  1870.    * Exactly one object is growing in an obstack at any one time.
  1871.  
  1872.    * You can run one obstack per control block.
  1873.  
  1874.    * You may have as many control blocks as you dare.
  1875.  
  1876.    * Because of the way we do it, you can `unwind' a obstack back to a
  1877.      previous state. (You may remove objects much as you would with a
  1878.      stack.)
  1879.  
  1880.    The obstack data structure is used in many places in the GNU C++
  1881. compiler.
  1882.  
  1883.    Differences from the the GNU C version
  1884.   1. The obvious differences stemming from the use of classes and
  1885.      inline functions instead of structs and macros. The C `init' and
  1886.      `begin' macros are replaced by constructors.
  1887.  
  1888.   2. Overloaded function names are used for grow (and others), rather
  1889.      than the C `grow', `grow0', etc.
  1890.  
  1891.   3. All dynamic allocation uses the the built-in `new' operator.  This
  1892.      restricts flexibility by a little, but maintains compatibility
  1893.      with usual C++ conventions.
  1894.  
  1895.   4. There are now two versions of finish:
  1896.  
  1897.        1. finish() behaves like the C version.
  1898.  
  1899.        2. finish(char terminator) adds `terminator', and then calls
  1900.           `finish()'.  This enables the normal invocation of
  1901.           `finish(0)' to wrap up a string being grown
  1902.           character-by-character.
  1903.  
  1904.   5. There are special versions of grow(const char* s) and copy(const
  1905.      char* s) that add the null-terminated string `s' after computing
  1906.      its length.
  1907.  
  1908.   6. The shrink and contains functions are provided.
  1909.  
  1910.  
  1911. 
  1912. File: libg++,  Node: AllocRing,  Next: String,  Prev: Obstack,  Up: Top
  1913.  
  1914. The AllocRing class
  1915. *******************
  1916.  
  1917.    An AllocRing is a bounded ring (circular list), each of whose
  1918. elements contains a pointer to some space allocated via `new
  1919. char[some_size]'. The entries are used cyclicly.  The size, n, of the
  1920. ring is fixed at construction. After that, every nth use of the ring
  1921. will reuse (or reallocate) the same space. AllocRings are needed in
  1922. order to temporarily hold chunks of space that are needed transiently,
  1923. but across constructor-destructor scopes. They mainly useful for storing
  1924. strings containing formatted characters to print across various
  1925. functions and coercions. These strings are needed across routines, so
  1926. may not be deleted in any one of them, but should be recovered at some
  1927. point. In other words, an AllocRing is an extremely simple minded
  1928. garbage collection mechanism. The GNU C++ library used to use one
  1929. AllocRing for such formatting purposes, but it is being phased out, and
  1930. is now only used by obsolete functions.  These days, AllocRings are
  1931. probably not very useful.
  1932.  
  1933.    Support includes:
  1934.  
  1935. `AllocRing a(int n)'
  1936.      constructs an Alloc ring with n entries, all null.
  1937.  
  1938. `void* mem = a.alloc(sz)'
  1939.      moves the ring pointer to the next entry, and reuses the space if
  1940.      their is enough, also allocates space via new char[sz].
  1941.  
  1942. `int present = a.contains(void* ptr)'
  1943.      returns true if ptr is held in one of the ring entries.
  1944.  
  1945. `a.clear()'
  1946.      deletes all space pointed to in any entry. This is called
  1947.      automatically upon destruction.
  1948.  
  1949. `a.free(void* ptr)'
  1950.      If ptr is one of the entries, calls delete of the pointer, and
  1951.      resets to entry pointer to null.
  1952.  
  1953. 
  1954. File: libg++,  Node: String,  Next: Integer,  Prev: AllocRing,  Up: Top
  1955.  
  1956. The String class
  1957. ****************
  1958.  
  1959.    The `String' class is designed to extend GNU C++ to support string
  1960. processing capabilities similar to those in languages like Awk.  The
  1961. class provides facilities that ought to be convenient and efficient
  1962. enough to be useful replacements for `char*' based processing via the C
  1963. string library (i.e., `strcpy, strcmp,' etc.) in many applications.
  1964. Many details about String representations are described in the
  1965. Representation section.
  1966.  
  1967.    A separate `SubString' class supports substring extraction and
  1968. modification operations. This is implemented in a way that user
  1969. programs never directly construct or represent substrings, which are
  1970. only used indirectly via String operations.
  1971.  
  1972.    Another separate class, `Regex' is also used indirectly via String
  1973. operations in support of regular expression searching, matching, and the
  1974. like.  The Regex class is based entirely on the GNU Emacs regex
  1975. functions.  *Note Syntax of Regular Expressions: (emacs.info)Regexps,
  1976. for a full explanation of regular expression syntax.  (For
  1977. implementation details, see the internal documentation in files
  1978. `regex.h' and `regex.c'.)
  1979.  
  1980. Constructors
  1981. ============
  1982.  
  1983.    Strings are initialized and assigned as in the following examples:
  1984.  
  1985. `String x;  String y = 0; String z = "";'
  1986.      Set x, y, and z to the nil string. Note that either 0 or "" may
  1987.      always be used to refer to the nil string.
  1988.  
  1989. `String x = "Hello"; String y("Hello");'
  1990.      Set x and y to a copy of the string "Hello".
  1991.  
  1992. `String x = 'A'; String y('A');'
  1993.      Set x and y to the string value "A"
  1994.  
  1995. `String u = x; String v(x);'
  1996.      Set u and v to the same string as String x
  1997.  
  1998. `String u = x.at(1,4); String v(x.at(1,4));'
  1999.      Set u and v to the length 4 substring of x starting at position 1
  2000.      (counting indexes from 0).
  2001.  
  2002. `String x("abc", 2);'
  2003.      Sets x to "ab", i.e., the first 2 characters of "abc".
  2004.  
  2005. `String x = dec(20);'
  2006.      Sets x to "20". As here, Strings may be initialized or assigned
  2007.      the results of any `char*' function.
  2008.  
  2009.    There are no directly accessible forms for declaring SubString
  2010. variables.
  2011.  
  2012.    The declaration `Regex r("[a-zA-Z_][a-zA-Z0-9_]*");' creates a
  2013. compiled regular expression suitable for use in String operations
  2014. described below. (In this case, one that matches any C++ identifier).
  2015. The first argument may also be a String.  Be careful in distinguishing
  2016. the role of backslashes in quoted GNU C++ char* constants versus those
  2017. in Regexes. For example, a Regex that matches either one or more tabs
  2018. or all strings beginning with "ba" and ending with any number of
  2019. occurrences of "na" could be declared as `Regex r =
  2020. "\\(\t+\\)\\|\\(ba\\(na\\)*\\)"' Note that only one backslash is needed
  2021. to signify the tab, but two are needed for the parenthesization and
  2022. virgule, since the GNU C++ lexical analyzer decodes and strips
  2023. backslashes before they are seen by Regex.
  2024.  
  2025.    There are three additional optional arguments to the Regex
  2026. constructor that are less commonly useful:
  2027.  
  2028. `fast (default 0)'
  2029.      `fast' may be set to true (1) if the Regex should be
  2030.      "fast-compiled". This causes an additional compilation step that
  2031.      is generally worthwhile if the Regex will be used many times.
  2032.  
  2033. `bufsize (default max(40, length of the string))'
  2034.      This is an estimate of the size of the internal compiled
  2035.      expression. Set it to a larger value if you know that the
  2036.      expression will require a lot of space. If you do not know, do not
  2037.      worry: realloc is used if necessary.
  2038.  
  2039. `transtable (default none == 0)'
  2040.      The address of a byte translation table (a char[256]) that
  2041.      translates each character before matching.
  2042.  
  2043.    As a convenience, several Regexes are predefined and usable in any
  2044. program. Here are their declarations from `String.h'.
  2045.  
  2046.      extern Regex RXwhite;      // = "[ \n\t]+"
  2047.      extern Regex RXint;        // = "-?[0-9]+"
  2048.      extern Regex RXdouble;     // = "-?\\(\\([0-9]+\\.[0-9]*\\)\\|
  2049.                                 //    \\([0-9]+\\)\\|
  2050.                                 //    \\(\\.[0-9]+\\)\\)
  2051.                                 //    \\([eE][---+]?[0-9]+\\)?"
  2052.      extern Regex RXalpha;      // = "[A-Za-z]+"
  2053.      extern Regex RXlowercase;  // = "[a-z]+"
  2054.      extern Regex RXuppercase;  // = "[A-Z]+"
  2055.      extern Regex RXalphanum;   // = "[0-9A-Za-z]+"
  2056.      extern Regex RXidentifier; // = "[A-Za-z_][A-Za-z0-9_]*"
  2057.  
  2058. Examples
  2059. ========
  2060.  
  2061.    Most `String' class capabilities are best shown via example.  The
  2062. examples below use the following declarations.
  2063.  
  2064.          String x = "Hello";
  2065.          String y = "world";
  2066.          String n = "123";
  2067.          String z;
  2068.          char*  s = ",";
  2069.          String lft, mid, rgt;
  2070.          Regex  r = "e[a-z]*o";
  2071.          Regex  r2("/[a-z]*/");
  2072.          char   c;
  2073.          int    i, pos, len;
  2074.          double f;
  2075.          String words[10];
  2076.          words[0] = "a";
  2077.          words[1] = "b";
  2078.          words[2] = "c";
  2079.  
  2080. Comparing, Searching and Matching
  2081. =================================
  2082.  
  2083.    The usual lexicographic relational operators (`==, !=, <, <=, >, >=')
  2084. are defined. A functional form `compare(String, String)' is also
  2085. provided, as is `fcompare(String, String)', which compares Strings
  2086. without regard for upper vs. lower case.
  2087.  
  2088.    All other matching and searching operations are based on some form
  2089. of the (non-public) `match' and `search' functions.  `match' and
  2090. `search' differ in that `match' attempts to match only at the given
  2091. starting position, while `search' starts at the position, and then
  2092. proceeds left or right looking for a match.  As seen in the following
  2093. examples, the second optional `startpos' argument to functions using
  2094. `match' and `search' specifies the starting position of the search: If
  2095. non-negative, it results in a left-to-right search starting at position
  2096. `startpos', and if negative, a right-to-left search starting at
  2097. position `x.length() + startpos'. In all cases, the index returned is
  2098. that of the beginning of the match, or -1 if there is no match.
  2099.  
  2100.    Three String functions serve as front ends to `search' and `match'.
  2101. `index' performs a search, returning the index, `matches' performs a
  2102. match, returning nonzero (actually, the length of the match) on success,
  2103. and `contains' is a boolean function performing either a search or
  2104. match, depending on whether an index argument is provided:
  2105.  
  2106. `x.index("lo")'
  2107.      returns the zero-based index of the leftmost occurrence of
  2108.      substring "lo" (3, in this case).  The argument may be a String,
  2109.      SubString, char, char*, or Regex.
  2110.  
  2111. `x.index("l", 2)'
  2112.      returns the index of the first of the leftmost occurrence of "l"
  2113.      found starting the search at position x[2], or 2 in this case.
  2114.  
  2115. `x.index("l", -1)'
  2116.      returns the index of the rightmost occurrence of "l", or 3 here.
  2117.  
  2118. `x.index("l", -3)'
  2119.      returns the index of the rightmost occurrence of "l" found by
  2120.      starting the search at the 3rd to the last position of x,
  2121.      returning 2 in this case.
  2122.  
  2123. `pos = r.search("leo", 3, len, 0)'
  2124.      returns the index of r in the `char*' string of length 3, starting
  2125.      at position 0, also placing the  length of the match in reference
  2126.      parameter len.
  2127.  
  2128. `x.contains("He")'
  2129.      returns nonzero if the String x contains the substring "He". The
  2130.      argument may be a String, SubString, char, char*, or Regex.
  2131.  
  2132. `x.contains("el", 1)'
  2133.      returns nonzero if x contains the substring "el" at position 1.
  2134.      As in this example, the second argument to `contains', if present,
  2135.      means to match the substring only at that position, and not to
  2136.      search elsewhere in the string.
  2137.  
  2138. `x.contains(RXwhite);'
  2139.      returns nonzero if x contains any whitespace (space, tab, or
  2140.      newline). Recall that `RXwhite' is a global whitespace Regex.
  2141.  
  2142. `x.matches("lo", 3)'
  2143.      returns nonzero if x starting at position 3 exactly matches "lo",
  2144.      with no trailing characters (as it does in this example).
  2145.  
  2146. `x.matches(r)'
  2147.      returns nonzero if String x as a whole matches Regex r.
  2148.  
  2149. `int f = x.freq("l")'
  2150.      returns the number of distinct, nonoverlapping matches to the
  2151.      argument (2 in this case).
  2152.  
  2153. Substring extraction
  2154. ====================
  2155.  
  2156.    Substrings may be extracted via the `at', `before', `through',
  2157. `from', and `after' functions.  These behave as either lvalues or
  2158. rvalues.
  2159.  
  2160. `z = x.at(2, 3)'
  2161.      sets String z to be equal to the length 3 substring of String x
  2162.      starting at zero-based position 2, setting z to "llo" in this
  2163.      case. A nil String is returned if the arguments don't make sense.
  2164.  
  2165. `x.at(2, 2) = "r"'
  2166.      Sets what was in positions 2 to 3 of x to "r", setting x to "Hero"
  2167.      in this case. As indicated here, SubString assignments may be of
  2168.      different lengths.
  2169.  
  2170. `x.at("He") = "je";'
  2171.      x("He") is the substring of x that matches the first occurrence of
  2172.      it's argument. The substitution sets x to "jello". If "He" did not
  2173.      occur, the substring would be nil, and the assignment would have
  2174.      no effect.
  2175.  
  2176. `x.at("l", -1) = "i";'
  2177.      replaces the rightmost occurrence of "l" with "i", setting x to
  2178.      "Helio".
  2179.  
  2180. `z = x.at(r)'
  2181.      sets String z to the first match in x of Regex r, or "ello" in this
  2182.      case. A nil String is returned if there is no match.
  2183.  
  2184. `z = x.before("o")'
  2185.      sets z to the part of x to the left of the first occurrence of
  2186.      "o", or "Hell" in this case. The argument may also be a String,
  2187.      SubString, or Regex.  (If there is no match, z is set to "".)
  2188.  
  2189. `x.before("ll") = "Bri";'
  2190.      sets the part of x to the left of "ll" to "Bri", setting x to
  2191.      "Brillo".
  2192.  
  2193. `z = x.before(2)'
  2194.      sets z to the part of x to the left of x[2], or "He" in this case.
  2195.  
  2196. `z = x.after("Hel")'
  2197.      sets z to the part of x to the right of "Hel", or "lo" in this
  2198.      case.
  2199.  
  2200. `z = x.through("el")'
  2201.      sets z to the part of x up and including "el", or "Hel" in this
  2202.      case.
  2203.  
  2204. `z = x.from("el")'
  2205.      sets z to the part of x from "el" to the end, or "ello" in this
  2206.      case.
  2207.  
  2208. `x.after("Hel") = "p";'
  2209.      sets x to "Help";
  2210.  
  2211. `z = x.after(3)'
  2212.      sets z to the part of x to the right of x[3] or "o" in this case.
  2213.  
  2214. `z = "  ab c"; z = z.after(RXwhite)'
  2215.      sets z to the part of its old string to the right of the first
  2216.      group of whitespace, setting z to "ab c"; Use gsub(below) to strip
  2217.      out multiple occurrences of whitespace or any pattern.
  2218.  
  2219. `x[0] = 'J';'
  2220.      sets the first element of x to 'J'. x[i] returns a reference to
  2221.      the ith element of x, or triggers an error if i is out of range.
  2222.  
  2223. `common_prefix(x, "Help")'
  2224.      returns the String containing the common prefix of the two Strings
  2225.      or "Hel" in this case.
  2226.  
  2227. `common_suffix(x, "to")'
  2228.      returns the String containing the common suffix of the two Strings
  2229.      or "o" in this case.
  2230.  
  2231. Concatenation
  2232. =============
  2233.  
  2234. `z = x + s + ' ' + y.at("w") + y.after("w") + ".";'
  2235.      sets z to "Hello, world."
  2236.  
  2237. `x += y;'
  2238.      sets x to "Helloworld"
  2239.  
  2240. `cat(x, y, z)'
  2241.      A faster way to say z = x + y.
  2242.  
  2243. `cat(z, y, x, x)'
  2244.      Double concatenation; A faster way to say x = z + y + x.
  2245.  
  2246. `y.prepend(x);'
  2247.      A faster way to say y = x + y.
  2248.  
  2249. `z = replicate(x, 3);'
  2250.      sets z to "HelloHelloHello".
  2251.  
  2252. `z = join(words, 3, "/")'
  2253.      sets z to the concatenation of the first 3 Strings in String array
  2254.      words, each separated by "/", setting z to "a/b/c" in this case.
  2255.      The last argument may be "" or 0, indicating no separation.
  2256.  
  2257. Other manipulations
  2258. ===================
  2259.  
  2260. `z = "this string has five words"; i = split(z, words, 10, RXwhite);'
  2261.      sets up to 10 elements of String array words to the parts of z
  2262.      separated by whitespace, and returns the number of parts actually
  2263.      encountered (5 in this case). Here, words[0] = "this", words[1] =
  2264.      "string", etc.  The last argument may be any of the usual.  If
  2265.      there is no match, all of z ends up in words[0]. The words array
  2266.      is *not* dynamically created by split.
  2267.  
  2268. `int nmatches x.gsub("l","ll")'
  2269.      substitutes all original occurrences of "l" with "ll", setting x
  2270.      to "Hellllo". The first argument may be any of the usual,
  2271.      including Regex.  If the second argument is "" or 0, all
  2272.      occurrences are deleted. gsub returns the number of matches that
  2273.      were replaced.
  2274.  
  2275. `z = x + y;  z.del("loworl");'
  2276.      deletes the leftmost occurrence of "loworl" in z, setting z to
  2277.      "Held".
  2278.  
  2279. `z = reverse(x)'
  2280.      sets z to the reverse of x, or "olleH".
  2281.  
  2282. `z = upcase(x)'
  2283.      sets z to x, with all letters set to uppercase, setting z to
  2284.      "HELLO"
  2285.  
  2286. `z = downcase(x)'
  2287.      sets z to x, with all letters set to lowercase, setting z to
  2288.      "hello"
  2289.  
  2290. `z = capitalize(x)'
  2291.      sets z to x, with the first letter of each word set to uppercase,
  2292.      and all others to lowercase, setting z to "Hello"
  2293.  
  2294. `x.reverse(), x.upcase(), x.downcase(), x.capitalize()'
  2295.      in-place, self-modifying versions of the above.
  2296.  
  2297. Reading, Writing and Conversion
  2298. ===============================
  2299.  
  2300. `cout << x'
  2301.      writes out x.
  2302.  
  2303. `cout << x.at(2, 3)'
  2304.      writes out the substring "llo".
  2305.  
  2306. `cin >> x'
  2307.      reads a whitespace-bounded string into x.
  2308.  
  2309. `x.length()'
  2310.      returns the length of String x (5, in this case).
  2311.  
  2312. `s = (const char*)x'
  2313.      can be used to extract the `char*' char array. This coercion is
  2314.      useful for sending a String as an argument to any function
  2315.      expecting a `const char*' argument (like `atoi', and
  2316.      `File::open'). This operator must be used with care, since the
  2317.      conversion returns a pointer to `String' internals without copying
  2318.      the characters: The resulting `(char*)' is only valid until the
  2319.      next String operation,  and you must not modify it.  (The
  2320.      conversion is defined to return a const value so that GNU C++ will
  2321.      produce warning and/or error messages if changes are attempted.)
  2322.  
  2323. 
  2324. File: libg++,  Node: Integer,  Next: Rational,  Prev: String,  Up: Top
  2325.  
  2326. The Integer class.
  2327. ******************
  2328.  
  2329.    The `Integer' class provides multiple precision integer arithmetic
  2330. facilities. Some representation details are discussed in the
  2331. Representation section.
  2332.  
  2333.    `Integers' may be up to `b * ((1 << b) - 1)' bits long, where `b' is
  2334. the number of bits per short (typically 1048560 bits when `b = 16').
  2335. The implementation assumes that a `long' is at least twice as long as a
  2336. `short'. This assumption hides beneath almost all primitive operations,
  2337. and would be very difficult to change. It also relies on correct
  2338. behavior of *unsigned* arithmetic operations.
  2339.  
  2340.    Some of the arithmetic algorithms are very loosely based on those
  2341. provided in the MIT Scheme `bignum.c' release, which is Copyright (c)
  2342. 1987 Massachusetts Institute of Technology. Their use here falls within
  2343. the provisions described in the Scheme release.
  2344.  
  2345.    Integers may be constructed in the following ways:
  2346. `Integer x;'
  2347.      Declares an uninitialized Integer.
  2348.  
  2349. `Integer x = 2; Integer y(2);'
  2350.      Set x and y to the Integer value 2;
  2351.  
  2352. `Integer u(x); Integer v = x;'
  2353.      Set u and v to the same value as x.
  2354.  
  2355.  - Method: long Integer::as_long() const
  2356.      Used to coerce an `Integer' back into longs via the `long'
  2357.      coercion operator. If the Integer cannot fit into a long, this
  2358.      returns MINLONG or MAXLONG (depending on the sign) where MINLONG
  2359.      is the most negative, and MAXLONG is the most positive
  2360.      representable long.
  2361.  
  2362.  - Method: int Integer::fits_in_long() const
  2363.      Returns true iff the `Integer' is `< MAXLONG' and `> MINLONG'.
  2364.  
  2365.  - Method: double Integer::as_double() const
  2366.      Coerce the `Integer' to a `double', with potential loss of
  2367.      precision.  `+/-HUGE' is returned if the Integer cannot fit into a
  2368.      double.
  2369.  
  2370.  - Method: int Integer::fits_in_double() const
  2371.      Returns true iff the `Integer' can fit into a double.
  2372.  
  2373.    All of the usual arithmetic operators are provided (`+, -, *, /, %,
  2374. +=, ++, -=, --, *=, /=, %=, ==, !=, <, <=, >, >=').  All operators
  2375. support special versions for mixed arguments of Integers and regular
  2376. C++ longs in order to avoid useless coercions, as well as to allow
  2377. automatic promotion of shorts and ints to longs, so that they may be
  2378. applied without additional Integer coercion operators.  The only
  2379. operators that behave differently than the corresponding int or long
  2380. operators are `++' and `--'.  Because C++ does not distinguish prefix
  2381. from postfix application, these are declared as `void' operators, so
  2382. that no confusion can result from applying them as postfix.  Thus, for
  2383. Integers x and y, ` ++x; y = x; ' is correct, but ` y = ++x; ' and ` y
  2384. = x++; ' are not.
  2385.  
  2386.    Bitwise operators (`~', `&', `|', `^', `<<', `>>', `&=', `|=', `^=',
  2387. `<<=', `>>=') are also provided.  However, these operate on
  2388. sign-magnitude, rather than two's complement representations. The sign
  2389. of the result is arbitrarily taken as the sign of the first argument.
  2390. For example, `Integer(-3) & Integer(5)' returns `Integer(-1)', not -3,
  2391. as it would using two's complement. Also, `~', the complement operator,
  2392. complements only those bits needed for the representation.  Bit
  2393. operators are also provided in the BitSet and BitString classes. One of
  2394. these classes should be used instead of Integers when the results of
  2395. bit manipulations are not interpreted numerically.
  2396.  
  2397.    The following utility functions are also provided. (All arguments
  2398. are Integers unless otherwise noted).
  2399.  
  2400.  - Function: void divide(const Integer& X, const Integer& Y, Integer&
  2401.           Q, Integer& R)
  2402.      Sets Q to the quotient and R to the remainder of X and Y.  (Q and
  2403.      R are returned by reference).
  2404.  
  2405.  - Function: Integer pow(const Integer& X, const Integer& P)
  2406.      Returns X raised to the power P.
  2407.  
  2408.  - Function: Integer Ipow(long X, long P)
  2409.      Returns X raised to the power P.
  2410.  
  2411.  - Function: Integer gcd(const Integer& X, const Integer& P)
  2412.      Returns the greatest common divisor of X and Y.
  2413.  
  2414.  - Function: Integer lcm(const Integer& X, const Integer& P)
  2415.      Returns the least common multiple of X and Y.
  2416.  
  2417.  - Function: Integer abs(const Integer& X
  2418.      Returns the absolute value of X.
  2419.  
  2420.  - Method: void Integer::negate()
  2421.      Negates `this' in place.
  2422.  
  2423. `Integer sqr(x)'
  2424.      returns x * x;
  2425.  
  2426. `Integer sqrt(x)'
  2427.      returns the floor of the  square root of x.
  2428.  
  2429. `long lg(x);'
  2430.      returns the floor of the base 2 logarithm of abs(x)
  2431.  
  2432. `int sign(x)'
  2433.      returns -1 if x is negative, 0 if zero, else +1.  Using `if
  2434.      (sign(x) == 0)' is a generally faster method of testing for zero
  2435.      than using relational operators.
  2436.  
  2437. `int even(x)'
  2438.      returns true if x is an even number
  2439.  
  2440. `int odd(x)'
  2441.      returns true if x is an odd number.
  2442.  
  2443. `void setbit(Integer& x, long b)'
  2444.      sets the b'th bit (counting right-to-left from zero) of x to 1.
  2445.  
  2446. `void clearbit(Integer& x, long b)'
  2447.      sets the b'th bit of x to 0.
  2448.  
  2449. `int testbit(Integer x, long b)'
  2450.      returns true if the b'th bit of x is 1.
  2451.  
  2452. `Integer atoI(char* asciinumber, int base = 10);'
  2453.      converts the base base char* string into its Integer form.
  2454.  
  2455. `void Integer::printon(ostream& s, int base = 10, int width = 0);'
  2456.      prints the ascii string value of `(*this)' as a base `base'
  2457.      number, in field width at least `width'.
  2458.  
  2459. `ostream << x;'
  2460.      prints x in base ten format.
  2461.  
  2462. `istream >> x;'
  2463.      reads x as a base ten number.
  2464.  
  2465. `int compare(Integer x, Integer y)'
  2466.      returns a negative number if x<y, zero if x==y, or positive if x>y.
  2467.  
  2468. `int ucompare(Integer x, Integer y)'
  2469.      like compare, but performs unsigned comparison.
  2470.  
  2471. `add(x, y, z)'
  2472.      A faster way to say z = x + y.
  2473.  
  2474. `sub(x, y, z)'
  2475.      A faster way to say z = x - y.
  2476.  
  2477. `mul(x, y, z)'
  2478.      A faster way to say z = x * y.
  2479.  
  2480. `div(x, y, z)'
  2481.      A faster way to say z = x / y.
  2482.  
  2483. `mod(x, y, z)'
  2484.      A faster way to say z = x % y.
  2485.  
  2486. `and(x, y, z)'
  2487.      A faster way to say z = x & y.
  2488.  
  2489. `or(x, y, z)'
  2490.      A faster way to say z = x | y.
  2491.  
  2492. `xor(x, y, z)'
  2493.      A faster way to say z = x ^ y.
  2494.  
  2495. `lshift(x, y, z)'
  2496.      A faster way to say z = x << y.
  2497.  
  2498. `rshift(x, y, z)'
  2499.      A faster way to say z = x >> y.
  2500.  
  2501. `pow(x, y, z)'
  2502.      A faster way to say z = pow(x, y).
  2503.  
  2504. `complement(x, z)'
  2505.      A faster way to say z = ~x.
  2506.  
  2507. `negate(x, z)'
  2508.      A faster way to say z = -x.
  2509.  
  2510. 
  2511. File: libg++,  Node: Rational,  Next: Complex,  Prev: Integer,  Up: Top
  2512.  
  2513. The Rational Class
  2514. ******************
  2515.  
  2516.    Class `Rational' provides multiple precision rational number
  2517. arithmetic. All rationals are maintained in simplest form (i.e., with
  2518. the numerator and denominator relatively prime, and with the
  2519. denominator strictly positive).  Rational arithmetic and relational
  2520. operators are provided (`+, -, *, /, +=, -=, *=, /=, ==, !=, <, <=, >,
  2521. >=').  Operations resulting in a rational number with zero denominator
  2522. trigger an exception.
  2523.  
  2524.    Rationals may be constructed and used in the following ways:
  2525.  
  2526. `Rational x;'
  2527.      Declares an uninitialized Rational.
  2528.  
  2529. `Rational x = 2; Rational y(2);'
  2530.      Set x and y to the Rational value 2/1;
  2531.  
  2532. `Rational x(2, 3);'
  2533.      Sets x to the Rational value 2/3;
  2534.  
  2535. `Rational x = 1.2;'
  2536.      Sets x to a Rational value close to 1.2. Any double precision value
  2537.      may be used to construct a Rational. The Rational will possess
  2538.      exactly as much precision as the double. Double values that do not
  2539.      have precise floating point equivalents (like 1.2) produce
  2540.      similarly imprecise rational values.
  2541.  
  2542. `Rational x(Integer(123), Integer(4567));'
  2543.      Sets x to the Rational value 123/4567.
  2544.  
  2545. `Rational u(x); Rational v = x;'
  2546.      Set u and v to the same value as x.
  2547.  
  2548. `double(Rational x)'
  2549.      A Rational may be coerced to a double with potential loss of
  2550.      precision. +/-HUGE is returned if it will not fit.
  2551.  
  2552. `Rational abs(x)'
  2553.      returns the absolute value of x.
  2554.  
  2555. `void x.negate()'
  2556.      negates x.
  2557.  
  2558. `void x.invert()'
  2559.      sets x to 1/x.
  2560.  
  2561. `int sign(x)'
  2562.      returns 0 if x is zero, 1 if positive, and -1 if negative.
  2563.  
  2564. `Rational sqr(x)'
  2565.      returns x * x.
  2566.  
  2567. `Rational pow(x, Integer y)'
  2568.      returns x to the y power.
  2569.  
  2570. `Integer x.numerator()'
  2571.      returns the numerator.
  2572.  
  2573. `Integer x.denominator()'
  2574.      returns the denominator.
  2575.  
  2576. `Integer floor(x)'
  2577.      returns the greatest Integer less than x.
  2578.  
  2579. `Integer ceil(x)'
  2580.      returns the least Integer greater than x.
  2581.  
  2582. `Integer trunc(x)'
  2583.      returns the Integer part of x.
  2584.  
  2585. `Integer round(x)'
  2586.      returns the nearest Integer to x.
  2587.  
  2588. `int compare(x, y)'
  2589.      returns a negative, zero, or positive number signifying whether x
  2590.      is less than, equal to, or greater than y.
  2591.  
  2592. `ostream << x;'
  2593.      prints x in the form num/den, or just num if the denominator is
  2594.      one.
  2595.  
  2596. `istream >> x;'
  2597.      reads x in the form num/den, or just num in which case the
  2598.      denominator is set to one.
  2599.  
  2600. `add(x, y, z)'
  2601.      A faster way to say z = x + y.
  2602.  
  2603. `sub(x, y, z)'
  2604.      A faster way to say z = x - y.
  2605.  
  2606. `mul(x, y, z)'
  2607.      A faster way to say z = x * y.
  2608.  
  2609. `div(x, y, z)'
  2610.      A faster way to say z = x / y.
  2611.  
  2612. `pow(x, y, z)'
  2613.      A faster way to say z = pow(x, y).
  2614.  
  2615. `negate(x, z)'
  2616.      A faster way to say z = -x.
  2617.  
  2618. 
  2619. File: libg++,  Node: Complex,  Next: Fix,  Prev: Rational,  Up: Top
  2620.  
  2621. The Complex class.
  2622. ******************
  2623.  
  2624.    Class `Complex' is implemented in a way similar to that described by
  2625. Stroustrup. In keeping with libg++ conventions, the class is named
  2626. `Complex', not `complex'.  Complex arithmetic and relational operators
  2627. are provided (`+, -, *, /, +=, -=, *=, /=, ==, !=').  Attempted
  2628. division by (0, 0) triggers an exception.
  2629.  
  2630.    Complex numbers may be constructed and used in the following ways:
  2631.  
  2632. `Complex x;'
  2633.      Declares an uninitialized Complex.
  2634.  
  2635. `Complex x = 2; Complex y(2.0);'
  2636.      Set x and y to the Complex value (2.0, 0.0);
  2637.  
  2638. `Complex x(2, 3);'
  2639.      Sets x to the Complex value (2, 3);
  2640.  
  2641. `Complex u(x); Complex v = x;'
  2642.      Set u and v to the same value as x.
  2643.  
  2644. `double real(Complex& x);'
  2645.      returns the real part of x.
  2646.  
  2647. `double imag(Complex& x);'
  2648.      returns the imaginary part of x.
  2649.  
  2650. `double abs(Complex& x);'
  2651.      returns the magnitude of x.
  2652.  
  2653. `double norm(Complex& x);'
  2654.      returns the square of the magnitude of x.
  2655.  
  2656. `double arg(Complex& x);'
  2657.      returns the argument (amplitude) of x.
  2658.  
  2659. `Complex polar(double r, double t = 0.0);'
  2660.      returns a Complex with abs of r and arg of t.
  2661.  
  2662. `Complex conj(Complex& x);'
  2663.      returns the complex conjugate of x.
  2664.  
  2665. `Complex cos(Complex& x);'
  2666.      returns the complex cosine of x.
  2667.  
  2668. `Complex sin(Complex& x);'
  2669.      returns the complex sine of x.
  2670.  
  2671. `Complex cosh(Complex& x);'
  2672.      returns the complex hyperbolic cosine of x.
  2673.  
  2674. `Complex sinh(Complex& x);'
  2675.      returns the complex hyperbolic sine of x.
  2676.  
  2677. `Complex exp(Complex& x);'
  2678.      returns the exponential of x.
  2679.  
  2680. `Complex log(Complex& x);'
  2681.      returns the natural log of x.
  2682.  
  2683. `Complex pow(Complex& x, long p);'
  2684.      returns x raised to the p power.
  2685.  
  2686. `Complex pow(Complex& x, Complex& p);'
  2687.      returns x raised to the p power.
  2688.  
  2689. `Complex sqrt(Complex& x);'
  2690.      returns the square root of x.
  2691.  
  2692. `ostream << x;'
  2693.      prints x in the form (re, im).
  2694.  
  2695. `istream >> x;'
  2696.      reads x in the form (re, im), or just (re) or re in which case the
  2697.      imaginary part is set to zero.
  2698.  
  2699. 
  2700. File: libg++,  Node: Fix,  Next: Bit,  Prev: Complex,  Up: Top
  2701.  
  2702. Fixed precision numbers
  2703. ***********************
  2704.  
  2705.    Classes `Fix16', `Fix24', `Fix32', and `Fix48' support operations on
  2706. 16, 24, 32, or 48 bit quantities that are considered as real numbers in
  2707. the range [-1, +1).  Such numbers are often encountered in digital
  2708. signal processing applications. The classes may be be used in isolation
  2709. or together.  Class `Fix32' operations are entirely self-contained.
  2710. Class `Fix16' operations are self-contained except that the
  2711. multiplication operation `Fix16 * Fix16' returns a `Fix32'. `Fix24' and
  2712. `Fix48' are similarly related.
  2713.  
  2714.    The standard arithmetic and relational operations are supported
  2715. (`=', `+', `-', `*', `/', `<<', `>>', `+=', `-=', `*=', `/=', `<<=',
  2716. `>>=', `==', `!=', `<', `<=', `>', `>=').  All operations include
  2717. provisions for special handling in cases where the result exceeds +/-
  2718. 1.0. There are two cases that may be handled separately: "overflow"
  2719. where the results of addition and subtraction operations go out of
  2720. range, and all other "range errors" in which resulting values go
  2721. off-scale (as with division operations, and assignment or
  2722. initialization with off-scale values). In signal processing
  2723. applications, it is often useful to handle these two cases differently.
  2724. Handlers take one argument, a reference to the integer mantissa of the
  2725. offending value, which may then be manipulated.  In cases of overflow,
  2726. this value is the result of the (integer) arithmetic computation on the
  2727. mantissa; in others it is a fully saturated (i.e., most positive or
  2728. most negative) value. Handling may be reset to any of several provided
  2729. functions or any other user-defined function via `set_overflow_handler'
  2730. and `set_range_error_handler'. The provided functions for `Fix16' are
  2731. as follows (corresponding functions are also supported for the others).
  2732.  
  2733. `Fix16_overflow_saturate'
  2734.      The default overflow handler. Results are "saturated": positive
  2735.      results are set to the largest representable value (binary
  2736.      0.111111...), and negative values to -1.0.
  2737.  
  2738. `Fix16_ignore'
  2739.      Performs no action. For overflow, this will allow addition and
  2740.      subtraction operations to "wrap around" in the same manner as
  2741.      integer arithmetic, and for saturation, will leave values
  2742.      saturated.
  2743.  
  2744. `Fix16_overflow_warning_saturate'
  2745.      Prints a warning message on standard error, then saturates the
  2746.      results.
  2747.  
  2748. `Fix16_warning'
  2749.      The default range_error handler. Prints a warning message on
  2750.      standard error; otherwise leaving the argument unmodified.
  2751.  
  2752. `Fix16_abort'
  2753.      prints an error message on standard error, then aborts execution.
  2754.  
  2755.    In addition to arithmetic operations, the following are provided:
  2756.  
  2757. `Fix16 a = 0.5;'
  2758.      Constructs fixed precision objects from double precision values.
  2759.      Attempting to initialize to a value outside the range invokes the
  2760.      range_error handler, except, as a convenience, initialization to
  2761.      1.0 sets the variable to the most positive representable value
  2762.      (binary 0.1111111...) without invoking the handler.
  2763.  
  2764. `short& mantissa(a); long& mantissa(b);'
  2765.      return a * pow(2, 15) or b * pow(2, 31) as an integer. These are
  2766.      returned by reference, to enable "manual" data manipulation.
  2767.  
  2768. `double value(a); double value(b);'
  2769.      return a or b as floating point numbers.
  2770.  
  2771. 
  2772. File: libg++,  Node: Bit,  Next: Random,  Prev: Fix,  Up: Top
  2773.  
  2774. Classes for Bit manipulation
  2775. ****************************
  2776.  
  2777.    libg++ provides several different classes supporting the use and
  2778. manipulation of collections of bits in different ways.
  2779.  
  2780.    * Class `Integer' provides "integer" semantics. It supports
  2781.      manipulation of bits in ways that are often useful when treating
  2782.      bit arrays as numerical (integer) quantities.  This class is
  2783.      described elsewhere.
  2784.  
  2785.    * Class `BitSet' provides "set" semantics. It supports operations
  2786.      useful when treating collections of bits as representing
  2787.      potentially infinite sets of integers.
  2788.  
  2789.    * Class `BitSet32' supports fixed-length BitSets holding exactly 32
  2790.      bits.
  2791.  
  2792.    * Class `BitSet256' supports fixed-length BitSets holding exactly
  2793.      256 bits.
  2794.  
  2795.    * Class `BitString' provides "string" (or "vector") semantics.  It
  2796.      supports operations useful when treating collections of bits as
  2797.      strings of zeros and ones.
  2798.  
  2799.    These classes also differ in the following ways:
  2800.  
  2801.    * BitSets are logically infinite. Their space is dynamically altered
  2802.      to adjust to the smallest number of consecutive bits actually
  2803.      required to represent the sets. Integers also have this property.
  2804.      BitStrings are logically finite, but their sizes are internally
  2805.      dynamically managed to maintain proper length. This means that,
  2806.      for example, BitStrings are concatenatable while BitSets and
  2807.      Integers are not.
  2808.  
  2809.    * BitSet32 and BitSet256 have precisely the same properties as
  2810.      BitSets, except that they use constant fixed length bit vectors.
  2811.  
  2812.    * While all classes support basic unary and binary operations `~, &,
  2813.      |, ^, -', the semantics differ. BitSets perform bit operations that
  2814.      precisely mirror those for infinite sets. For example,
  2815.      complementing an empty BitSet returns one representing an infinite
  2816.      number of set bits.  Operations on BitStrings and Integers operate
  2817.      only on those bits actually present in the representation.  For
  2818.      BitStrings and Integers, the the `&' operation returns a BitString
  2819.      with a length equal to the minimum length of the operands, and `|,
  2820.      ^' return one with length of the maximum.
  2821.  
  2822.    * Only BitStrings support substring extraction and bit pattern
  2823.      matching.
  2824.  
  2825. BitSet
  2826. ======
  2827.  
  2828.    BitSets are objects that contain logically infinite sets of
  2829. nonnegative integers.  Representational details are discussed in the
  2830. Representation chapter. Because they are logically infinite, all
  2831. BitSets possess a trailing, infinitely replicated 0 or 1 bit, called
  2832. the "virtual bit", and indicated via 0* or 1*.
  2833.  
  2834.    BitSet32 and BitSet256 have they same properties, except they are of
  2835. fixed length, and thus have no virtual bit.
  2836.  
  2837.    BitSets may be constructed as follows:
  2838.  
  2839. `BitSet a;'
  2840.      declares an empty BitSet.
  2841.  
  2842. `BitSet a = atoBitSet("001000");'
  2843.      sets a to the BitSet 0010*, reading left-to-right. The "0*"
  2844.      indicates that the set ends with an infinite number of zero
  2845.      (clear) bits.
  2846.  
  2847. `BitSet a = atoBitSet("00101*");'
  2848.      sets a to the BitSet 00101*, where "1*" means that the set ends
  2849.      with an infinite number of one (set) bits.
  2850.  
  2851. `BitSet a = longtoBitSet((long)23);'
  2852.      sets a to the BitSet 111010*, the binary representation of decimal
  2853.      23.
  2854.  
  2855. `BitSet a = utoBitSet((unsigned)23);'
  2856.      sets a to the BitSet 111010*, the binary representation of decimal
  2857.      23.
  2858.  
  2859.    The following functions and operators are provided (Assume the
  2860. declaration of BitSets a = 0011010*, b = 101101*, throughout, as
  2861. examples).
  2862.  
  2863. `~a'
  2864.      returns the complement of a, or 1100101* in this case.
  2865.  
  2866. `a.complement()'
  2867.      sets a to ~a.
  2868.  
  2869. `a & b; a &= b;'
  2870.      returns a intersected with b, or 0011010*.
  2871.  
  2872. `a | b; a |= b;'
  2873.      returns a unioned with b, or 1011111*.
  2874.  
  2875. `a - b; a -= b;'
  2876.      returns the set difference of a and b, or 000010*.
  2877.  
  2878. `a ^ b; a ^= b;'
  2879.      returns the symmetric difference of a and b, or 1000101*.
  2880.  
  2881. `a.empty()'
  2882.      returns true if a is an empty set.
  2883.  
  2884. `a == b;'
  2885.      returns true if a and b contain the same set.
  2886.  
  2887. `a <= b;'
  2888.      returns true if a is a subset of b.
  2889.  
  2890. `a < b;'
  2891.      returns true if a is a proper subset of b;
  2892.  
  2893. `a != b; a >= b; a > b;'
  2894.      are the converses of the above.
  2895.  
  2896. `a.set(7)'
  2897.      sets the 7th (counting from 0) bit of a, setting a to 001111010*
  2898.  
  2899. `a.clear(2)'
  2900.      clears the 2nd bit bit of a, setting a to 00011110*
  2901.  
  2902. `a.clear()'
  2903.      clears all bits of a;
  2904.  
  2905. `a.set()'
  2906.      sets all bits of a;
  2907.  
  2908. `a.invert(0)'
  2909.      complements the 0th bit of a, setting a to 10011110*
  2910.  
  2911. `a.set(0,1)'
  2912.      sets the 0th through 1st bits of a, setting a to 110111110* The
  2913.      two-argument versions of clear and invert are similar.
  2914.  
  2915. `a.test(3)'
  2916.      returns true if the 3rd bit of a is set.
  2917.  
  2918. `a.test(3, 5)'
  2919.      returns true if any of bits 3 through 5 are set.
  2920.  
  2921. `int i = a[3]; a[3] = 0;'
  2922.      The subscript operator allows bits to be inspected and changed via
  2923.      standard subscript semantics, using a friend class BitSetBit.  The
  2924.      use of the subscript operator a[i] rather than a.test(i) requires
  2925.      somewhat greater overhead.
  2926.  
  2927. `a.first(1) or a.first()'
  2928.      returns the index of the first set bit of a (2 in this case), or
  2929.      -1 if no bits are set.
  2930.  
  2931. `a.first(0)'
  2932.      returns the index of the first clear bit of a (0 in this case), or
  2933.      -1 if no bits are clear.
  2934.  
  2935. `a.next(2, 1) or a.next(2)'
  2936.      returns the index of the next bit after position 2 that is set (3
  2937.      in this case) or -1. `first' and `next' may be used as iterators,
  2938.      as in `for (int i = a.first(); i >= 0; i = a.next(i))...'.
  2939.  
  2940. `a.last(1)'
  2941.      returns the index of the rightmost set bit, or -1 if there or no
  2942.      set bits or all set bits.
  2943.  
  2944. `a.prev(3, 0)'
  2945.      returns the index of the previous clear bit before position 3.
  2946.  
  2947. `a.count(1)'
  2948.      returns the number of set bits in a, or -1 if there are an
  2949.      infinite number.
  2950.  
  2951. `a.virtual_bit()'
  2952.      returns the trailing (infinitely replicated) bit of a.
  2953.  
  2954. `a = atoBitSet("ababX", 'a', 'b', 'X');'
  2955.      converts the char* string into a bitset, with 'a' denoting false,
  2956.      'b' denoting true, and 'X' denoting infinite replication.
  2957.  
  2958. `a.printon(cout, '-', '.', 0)'
  2959.      prints `a' to `cout' represented with `'-'' for falses, `'.'' for
  2960.      trues, and no replication marker.
  2961.  
  2962. `cout << a'
  2963.      prints `a' to `cout' (representing lases by `'f'', trues by `'t'',
  2964.      and using `'*'' as the replication marker).
  2965.  
  2966. BitString
  2967. =========
  2968.  
  2969.    BitStrings are objects that contain arbitrary-length strings of
  2970. zeroes and ones. BitStrings possess some features that make them behave
  2971. like sets, and others that behave as strings. They are useful in
  2972. applications (such as signature-based algorithms) where both
  2973. capabilities are needed.  Representational details are discussed in the
  2974. Representation chapter.  Most capabilities are exact analogs of those
  2975. supported in the BitSet and String classes.  A BitSubString is used
  2976. with substring operations along the same lines as the String SubString
  2977. class.  A BitPattern class is used for masked bit pattern searching.
  2978.  
  2979.    Only a default constructor is supported.  The declaration `BitString
  2980. a;' initializes a to be an empty BitString.  BitStrings may often be
  2981. initialized via `atoBitString' and `longtoBitString'.
  2982.  
  2983.    Set operations (` ~, complement, &, &=, |, |=, -, ^, ^=') behave
  2984. just as the BitSet versions, except that there is no "virtual bit":
  2985. complementing complements only those bits in the BitString, and all
  2986. binary operations across unequal length BitStrings assume a virtual bit
  2987. of zero. The `&' operation returns a BitString with a length equal to
  2988. the minimum length of the operands, and `|, ^' return one with length
  2989. of the maximum.
  2990.  
  2991.    Set-based relational operations (`==, !=, <=, <, >=, >') follow the
  2992. same rules. A string-like lexicographic comparison function,
  2993. `lcompare', tests the lexicographic relation between two BitStrings.
  2994. For example, lcompare(1100, 0101) returns 1, since the first BitString
  2995. starts with 1 and the second with 0.
  2996.  
  2997.    Individual bit setting, testing, and iterator operations (`set,
  2998. clear, invert, test, first, next, last, prev') are also like those for
  2999. BitSets. BitStrings are automatically expanded when setting bits at
  3000. positions greater than their current length.
  3001.  
  3002.    The string-based capabilities are just as those for class String.
  3003. BitStrings may be concatenated (`+, +='), searched (`index, contains,
  3004. matches'), and extracted into BitSubStrings (`before, at, after') which
  3005. may be assigned and otherwise manipulated. Other string-based utility
  3006. functions (`reverse, common_prefix, common_suffix') are also provided.
  3007. These have the same capabilities and descriptions as those for Strings.
  3008.  
  3009.    String-oriented operations can also be performed with a mask via
  3010. class BitPattern. BitPatterns consist of two BitStrings, a pattern and
  3011. a mask. On searching and matching, bits in the pattern that correspond
  3012. to 0 bits in the mask are ignored. (The mask may be shorter than the
  3013. pattern, in which case trailing mask bits are assumed to be 0). The
  3014. pattern and mask are both public variables, and may be individually
  3015. subjected to other bit operations.
  3016.  
  3017.    Converting to char* and printing (`(atoBitString, atoBitPattern,
  3018. printon, ostream <<)') are also as in BitSets, except that no virtual
  3019. bit is used, and an 'X' in a BitPattern means that the pattern bit is
  3020. masked out.
  3021.  
  3022.    The following features are unique to BitStrings.
  3023.  
  3024.    Assume declarations of BitString a = atoBitString("01010110") and b =
  3025. atoBitSTring("1101").
  3026.  
  3027. `a = b + c;'
  3028.      Sets a to the concatenation of b and c;
  3029.  
  3030. `a = b + 0; a = b + 1;'
  3031.      sets a to b, appended with a zero (one).
  3032.  
  3033. `a += b;'
  3034.      appends b to a;
  3035.  
  3036. `a += 0; a += 1;'
  3037.      appends a zero (one) to a.
  3038.  
  3039. `a << 2; a <<= 2'
  3040.      return a with 2 zeros prepended, setting a to 0001010110. (Note
  3041.      the necessary confusion of << and >> operators. For consistency
  3042.      with the integer versions, << shifts low bits to high, even though
  3043.      they are printed low bits first.)
  3044.  
  3045. `a >> 3; a >>= 3'
  3046.      return a with the first 3 bits deleted, setting a to 10110.
  3047.  
  3048. `a.left_trim(0)'
  3049.      deletes all 0 bits on the left of a, setting a to 1010110.
  3050.  
  3051. `a.right_trim(0)'
  3052.      deletes all trailing 0 bits of a, setting a to 0101011.
  3053.  
  3054. `cat(x, y, z)'
  3055.      A faster way to say z = x + y.
  3056.  
  3057. `diff(x, y, z)'
  3058.      A faster way to say z = x - y.
  3059.  
  3060. `and(x, y, z)'
  3061.      A faster way to say z = x & y.
  3062.  
  3063. `or(x, y, z)'
  3064.      A faster way to say z = x | y.
  3065.  
  3066. `xor(x, y, z)'
  3067.      A faster way to say z = x ^ y.
  3068.  
  3069. `lshift(x, y, z)'
  3070.      A faster way to say z = x << y.
  3071.  
  3072. `rshift(x, y, z)'
  3073.      A faster way to say z = x >> y.
  3074.  
  3075. `complement(x, z)'
  3076.      A faster way to say z = ~x.
  3077.  
  3078. 
  3079. File: libg++,  Node: Random,  Next: Data,  Prev: Bit,  Up: Top
  3080.  
  3081. Random Number Generators and related classes
  3082. ********************************************
  3083.  
  3084.    The two classes `RNG' and `Random' are used together to generate a
  3085. variety of random number distributions.  A distinction must be made
  3086. between *random number generators*, implemented by class `RNG', and
  3087. *random number distributions*.  A random number generator produces a
  3088. series of randomly ordered bits.  These bits can be used directly, or
  3089. cast to other representations, such as a floating point value.  A
  3090. random number generator should produce a *uniform* distribution.  A
  3091. random number distribution, on the other hand, uses the randomly
  3092. generated bits of a generator to produce numbers from a distribution
  3093. with specific properties.  Each instance of `Random' uses an instance
  3094. of class `RNG' to provide the raw, uniform distribution used to produce
  3095. the specific distribution.  Several instances of `Random' classes can
  3096. share the same instance of `RNG', or each instance can use its own copy.
  3097.  
  3098. RNG
  3099. ===
  3100.  
  3101.    Random distributions are constructed from members of class `RNG',
  3102. the actual random number generators.  The `RNG' class contains no data;
  3103. it only serves to define the interface to random number generators.
  3104. The `RNG::asLong' member returns an unsigned long (typically 32 bits)
  3105. of random bits.  Applications that require a number of random bits can
  3106. use this directly.  More often, these random bits are transformed to a
  3107. uniform random number:
  3108.  
  3109.          //
  3110.          // Return random bits converted to either a float or a double
  3111.          //
  3112.          float asFloat();
  3113.          double asDouble();
  3114.      };
  3115.  
  3116. using either `asFloat' or `asDouble'.  It is intended that `asFloat'
  3117. and `asDouble' return differing precisions; typically, `asDouble' will
  3118. draw two random longwords and transform them into a legal `double',
  3119. while `asFloat' will draw a single longword and transform it into a
  3120. legal `float'.  These members are used by subclasses of the `Random'
  3121. class to implement a variety of random number distributions.
  3122.  
  3123. ACG
  3124. ===
  3125.  
  3126.    Class `ACG' is a variant of a Linear Congruential Generator
  3127. (Algorithm M) described in Knuth, *Art of Computer Programming, Vol
  3128. III*.  This result is permuted with a Fibonacci Additive Congruential
  3129. Generator to get good independence between samples.  This is a very high
  3130. quality random number generator, although it requires a fair amount of
  3131. memory for each instance of the generator.
  3132.  
  3133.    The `ACG::ACG' constructor takes two parameters: the seed and the
  3134. size.  The seed is any number to be used as an initial seed. The
  3135. performance of the generator depends on having a distribution of bits
  3136. through the seed.  If you choose a number in the range of 0 to 31, a
  3137. seed with more bits is chosen. Other values are deterministically
  3138. modified to give a better distribution of bits.  This provides a good
  3139. random number generator while still allowing a sequence to be repeated
  3140. given the same initial seed.
  3141.  
  3142.    The `size' parameter determines the size of two tables used in the
  3143. generator. The first table is used in the Additive Generator; see the
  3144. algorithm in Knuth for more information. In general, this table is
  3145. `size' longwords long. The default value, used in the algorithm in
  3146. Knuth, gives a table of 220 bytes. The table size affects the period of
  3147. the generators; smaller values give shorter periods and larger tables
  3148. give longer periods. The smallest table size is 7 longwords, and the
  3149. longest is 98 longwords. The `size' parameter also determines the size
  3150. of the table used for the Linear Congruential Generator. This value is
  3151. chosen implicitly based on the size of the Additive Congruential
  3152. Generator table. It is two powers of two larger than the power of two
  3153. that is larger than `size'.  For example, if `size' is 7, the ACG table
  3154. is 7 longwords and the LCG table is 128 longwords. Thus, the default
  3155. size (55) requires 55 + 256 longwords, or 1244 bytes. The largest table
  3156. requires 2440 bytes and the smallest table requires 100 bytes.
  3157. Applications that require a large number of generators or applications
  3158. that aren't so fussy about the quality of the generator may elect to
  3159. use the `MLCG' generator.
  3160.  
  3161. MLCG
  3162. ====
  3163.  
  3164.    The `MLCG' class implements a *Multiplicative Linear Congruential
  3165. Generator*. In particular, it is an implementation of the double MLCG
  3166. described in *"Efficient and Portable Combined Random Number
  3167. Generators"* by Pierre L'Ecuyer, appearing in *Communications of the
  3168. ACM, Vol. 31. No. 6*. This generator has a fairly long period, and has
  3169. been statistically analyzed to show that it gives good inter-sample
  3170. independence.
  3171.  
  3172.    The `MLCG::MLCG' constructor has two parameters, both of which are
  3173. seeds for the generator. As in the `MLCG' generator, both seeds are
  3174. modified to give a "better" distribution of seed digits. Thus, you can
  3175. safely use values such as `0' or `1' for the seeds. The `MLCG'
  3176. generator used much less state than the `ACG' generator; only two
  3177. longwords (8 bytes) are needed for each generator.
  3178.  
  3179. Random
  3180. ======
  3181.  
  3182.    A random number generator may be declared by first declaring a `RNG'
  3183. and then a `Random'. For example, `ACG gen(10, 20); NegativeExpntl rnd
  3184. (1.0, &gen);' declares an additive congruential generator with seed 10
  3185. and table size 20, that is used to generate exponentially distributed
  3186. values with mean of 1.0.
  3187.  
  3188.    The virtual member `Random::operator()' is the common way of
  3189. extracting a random number from a particular distribution.  The base
  3190. class, `Random' does not implement `operator()'. This is performed by
  3191. each of the subclasses. Thus, given the above declaration of `rnd', new
  3192. random values may be obtained via, for example, `double next_exp_rand =
  3193. rnd();' Currently, the following subclasses are provided.
  3194.  
  3195. Binomial
  3196. ========
  3197.  
  3198.    The binomial distribution models successfully drawing items from a
  3199. pool.  The first parameter to the constructor, `n', is the number of
  3200. items in the pool, and the second parameter, `u', is the probability of
  3201. each item being successfully drawn.  The member `asDouble' returns the
  3202. number of samples drawn from the pool.  Although it is not checked, it
  3203. is assumed that `n>0' and `0 <= u <= 1'.  The remaining members allow
  3204. you to read and set the parameters.
  3205.  
  3206. Erlang
  3207. ======
  3208.  
  3209.    The `Erlang' class implements an Erlang distribution with mean
  3210. `mean' and variance `variance'.
  3211.  
  3212. Geometric
  3213. =========
  3214.  
  3215.    The `Geometric' class implements a discrete geometric distribution.
  3216. The first parameter to the constructor, `mean', is the mean of the
  3217. distribution.  Although it is not checked, it is assumed that `0 <=
  3218. mean <= 1'.  `Geometric()' returns the number of uniform random samples
  3219. that were drawn before the sample was larger than `mean'.  This
  3220. quantity is always greater than zero.
  3221.  
  3222. HyperGeometric
  3223. ==============
  3224.  
  3225.    The `HyperGeometric' class implements the hypergeometric
  3226. distribution.  The first parameter to the constructor, `mean', is the
  3227. mean and the second, `variance', is the variance.  The remaining
  3228. members allow you to inspect and change the mean and variance.
  3229.  
  3230. NegativeExpntl
  3231. ==============
  3232.  
  3233.    The `NegativeExpntl' class implements the negative exponential
  3234. distribution.  The first parameter to the constructor is the mean.  The
  3235. remaining members allow you to inspect and change the mean.
  3236.  
  3237. Normal
  3238. ======
  3239.  
  3240.    The `Normal'class implements the normal distribution.  The first
  3241. parameter to the constructor, `mean', is the mean and the second,
  3242. `variance', is the variance.  The remaining members allow you to
  3243. inspect and change the mean and variance.  The `LogNormal' class is a
  3244. subclass of `Normal'.
  3245.  
  3246. LogNormal
  3247. =========
  3248.  
  3249.    The `LogNormal'class implements the logarithmic normal distribution.
  3250. The first parameter to the constructor, `mean', is the mean and the
  3251. second, `variance', is the variance.  The remaining members allow you
  3252. to inspect and change the mean and variance.  The `LogNormal' class is
  3253. a subclass of `Normal'.
  3254.  
  3255. Poisson
  3256. =======
  3257.  
  3258.    The `Poisson' class implements the poisson distribution.  The first
  3259. parameter to the constructor is the mean.  The remaining members allow
  3260. you to inspect and change the mean.
  3261.  
  3262. DiscreteUniform
  3263. ===============
  3264.  
  3265.    The `DiscreteUniform' class implements a uniform random variable over
  3266. the closed interval ranging from `[low..high]'.  The first parameter to
  3267. the constructor is `low', and the second is `high', although the order
  3268. of these may be reversed.  The remaining members allow you to inspect
  3269. and change `low' and `high'.
  3270.  
  3271. Uniform
  3272. =======
  3273.  
  3274.    The `Uniform' class implements a uniform random variable over the
  3275. open interval ranging from `[low..high)'.  The first parameter to the
  3276. constructor is `low', and the second is `high', although the order of
  3277. these may be reversed.  The remaining members allow you to inspect and
  3278. change `low' and `high'.
  3279.  
  3280. Weibull
  3281. =======
  3282.  
  3283.    The `Weibull' class implements a weibull distribution with
  3284. parameters `alpha' and `beta'.  The first parameter to the class
  3285. constructor is `alpha', and the second parameter is `beta'.  The
  3286. remaining members allow you to inspect and change `alpha' and `beta'.
  3287.  
  3288. RandomInteger
  3289. =============
  3290.  
  3291.    The `RandomInteger' class is *not* a subclass of Random, but a
  3292. stand-alone integer-oriented class that is dependent on the RNG
  3293. classes. RandomInteger returns random integers uniformly from the
  3294. closed interval `[low..high]'.  The first parameter to the constructor
  3295. is `low', and the second is `high', although both are optional.  The
  3296. last argument is always a generator.  Additional members allow you to
  3297. inspect and change `low' and `high'.  Random integers are generated
  3298. using `asInt()' or `asLong()'.  Operator syntax (`()') is also
  3299. available as a shorthand for `asLong()'.  Because `RandomInteger' is
  3300. often used in simulations for which uniform random integers are desired
  3301. over a variety of ranges, `asLong()' and `asInt' have `high' as an
  3302. optional argument.  Using this optional argument produces a single
  3303. value from the new range, but does not change the default range.
  3304.  
  3305. 
  3306. File: libg++,  Node: Data,  Next: Curses,  Prev: Random,  Up: Top
  3307.  
  3308. Data Collection
  3309. ***************
  3310.  
  3311.    Libg++ currently provides two classes for *data collection* and
  3312. analysis of the collected data.
  3313.  
  3314. SampleStatistic
  3315. ===============
  3316.  
  3317.    Class `SampleStatistic' provides a means of accumulating samples of
  3318. `double' values and providing common sample statistics.
  3319.  
  3320.    Assume declaration of `double x'.
  3321.  
  3322. `SampleStatistic a;'
  3323.      declares and initializes a.
  3324.  
  3325. `a.reset();'
  3326.      re-initializes a.
  3327.  
  3328. `a += x;'
  3329.      adds sample x.
  3330.  
  3331. `int n = a.samples();'
  3332.      returns the number of samples.
  3333.  
  3334. `x = a.mean;'
  3335.      returns the means of the samples.
  3336.  
  3337. `x = a.var()'
  3338.      returns the sample variance of the samples.
  3339.  
  3340. `x = a.stdDev()'
  3341.      returns the sample standard deviation of the samples.
  3342.  
  3343. `x = a.min()'
  3344.      returns the minimum encountered sample.
  3345.  
  3346. `x = a.max()'
  3347.      returns the maximum encountered sample.
  3348.  
  3349. `x = a.confidence(int p)'
  3350.      returns the p-percent (0 <= p < 100) confidence interval.
  3351.  
  3352. `x = a.confidence(double p)'
  3353.      returns the p-probability (0 <= p < 1) confidence interval.
  3354.  
  3355. SampleHistogram
  3356. ===============
  3357.  
  3358.    Class `SampleHistogram' is a derived class of `SampleStatistic' that
  3359. supports collection and display of samples in bucketed intervals. It
  3360. supports the following in addition to `SampleStatisic' operations.
  3361.  
  3362. `SampleHistogram h(double lo, double hi, double width);'
  3363.      declares and initializes h to have buckets of size width from lo
  3364.      to hi.  If the optional argument width is not specified, 10
  3365.      buckets are created. The first bucket and also holds samples less
  3366.      than lo, and the last one holds samples greater than hi.
  3367.  
  3368. `int n = h.similarSamples(x)'
  3369.      returns the number of samples in the same bucket as x.
  3370.  
  3371. `int n = h.inBucket(int i)'
  3372.      returns the number of samples in  bucket i.
  3373.  
  3374. `int b = h.buckets()'
  3375.      returns the number of buckets.
  3376.  
  3377. `h.printBuckets(ostream s)'
  3378.      prints bucket counts on ostream s.
  3379.  
  3380. `double bound = h.bucketThreshold(int i)'
  3381.      returns the upper bound of bucket i.
  3382.  
  3383. 
  3384. File: libg++,  Node: Curses,  Next: List,  Prev: Data,  Up: Top
  3385.  
  3386. Curses-based classes
  3387. ********************
  3388.  
  3389.    The `CursesWindow' class is a repackaging of standard curses library
  3390. features into a class. It relies on `curses.h'.
  3391.  
  3392.    The supplied `curses.h' is a fairly conservative declaration of
  3393. curses library features, and does not include features like "screen" or
  3394. X-window support. It is, for the most part, an adaptation, rather than
  3395. an improvement of C-based `curses.h' files. The only substantive
  3396. changes are the declarations of many functions as inline functions
  3397. rather than macros, which was done solely to allow overloading.
  3398.  
  3399.    The `CursesWindow' class encapsulates curses window functions within
  3400. a class. Only those functions that control windows are included:
  3401. Terminal control functions and macros like `cbreak' are not part of the
  3402. class.  All `CursesWindows' member functions have names identical to
  3403. the corresponding curses library functions, except that the "w" prefix
  3404. is generally dropped. Descriptions of these functions may be found in
  3405. your local curses library documentation.
  3406.  
  3407.    A `CursesWindow' may be declared via
  3408.  
  3409. `CursesWindow w(WINDOW* win)'
  3410.      attaches w to the existing WINDOW* win. This is constructor is
  3411.      normally used only in the following special case.
  3412.  
  3413. `CursesWindow w(stdscr)'
  3414.      attaches w to the default curses library standard screen window.
  3415.  
  3416. `CursesWindow w(int lines, int cols, int begin_y, int begin_x)'
  3417.      attaches to an allocated curses window with the indicated size and
  3418.      screen position.
  3419.  
  3420. `CursesWindow sub(CursesWindow& w,int l,int c,int by,int bx,char ar='a')'
  3421.      attaches to a subwindow of w created via the curses `subwin'
  3422.      command.  If ar is sent as `r', the origin (by, bx) is relative to
  3423.      the parent window, else it is absolute.
  3424.  
  3425.    The class maintains a static counter that is used in order to
  3426. automatically call the curses library `initscr' and `endscr' functions
  3427. at the proper times. These need not, and should not be called
  3428. "manually".
  3429.  
  3430.    `CursesWindow's maintain a tree of their subwindows. Upon
  3431. destruction of a `CursesWindow', all of their subwindows are also
  3432. invalidated if they had not previously been destroyed.
  3433.  
  3434.    It is possible to traverse trees of subwindows via the following
  3435. member functions
  3436.  
  3437. `CursesWindow* w.parent()'
  3438.      returns a pointer to the parent of the subwindow, or 0 if there is
  3439.      none.
  3440.  
  3441. `CursesWindow* w.child()'
  3442.      returns the first child subwindow of the window, or 0 if there is
  3443.      none.
  3444.  
  3445. `CursesWindow* w.sibling()'
  3446.      returns the next sibling of the subwindow, or 0 if there is none.
  3447.  
  3448.    For example, to call some function `visit' for all subwindows of a
  3449. window, you could write
  3450.  
  3451.  
  3452.      void traverse(CursesWindow& w)
  3453.      {
  3454.        visit(w);
  3455.        if (w.child() != 0) traverse(*w.child);
  3456.        if (w.sibling() != 0) traverse(*w.sibling);
  3457.      }
  3458.  
  3459. 
  3460. File: libg++,  Node: List,  Next: LinkList,  Prev: Curses,  Up: Top
  3461.  
  3462. List classes
  3463. ************
  3464.  
  3465.    The files `g++-include/List.hP' and `g++-include/List.ccP' provide
  3466. pseudo-generic Lisp-type List classes.  These lists are homogeneous
  3467. lists, more similar to lists in statically typed functional languages
  3468. like ML than Lisp, but support operations very similar to those found
  3469. in Lisp.  Any particular kind of list class may be generated via the
  3470. `genclass' shell command. However, the implementation assumes that the
  3471. base class supports an equality operator `=='.  All equality tests use
  3472. the `==' operator, and are thus equivalent to the use of `equal', not
  3473. `eq' in Lisp.
  3474.  
  3475.    All list nodes are created dynamically, and managed via reference
  3476. counts.  `List' variables are actually pointers to these list nodes.
  3477. Lists may also be traversed via Pixes, as described in the section
  3478. describing Pixes. *Note Pix::
  3479.  
  3480.    Supported operations are mirrored closely after those in Lisp.
  3481. Generally, operations with functional forms are constructive,
  3482. functional operations, while member forms (often with the same name)
  3483. are sometimes procedural, possibly destructive operations.
  3484.  
  3485.    As with Lisp, destructive operations are supported. Programmers are
  3486. allowed to change head and tail fields in any fashion, creating
  3487. circular structures and the like. However, again as with Lisp, some
  3488. operations implicitly assume that they are operating on pure lists, and
  3489. may enter infinite loops when presented with improper lists. Also, the
  3490. reference-counting storage management facility may fail to reclaim
  3491. unused circularly-linked nodes.
  3492.  
  3493.    Several Lisp-like higher order functions are supported (e.g., `map').
  3494. Typedef declarations for the required functional forms are provided int
  3495. the `.h' file.
  3496.  
  3497.    For purposes of illustration, assume the specification of class
  3498. `intList'.  Common Lisp versions of supported operations are shown in
  3499. brackets for comparison purposes.
  3500.  
  3501. Constructors and assignment
  3502. ===========================
  3503.  
  3504. `intList a;           [ (setq a nil) ]'
  3505.      Declares a to be a nil intList.
  3506.  
  3507. `intList b(2);        [ (setq b (cons 2 nil)) ]'
  3508.      Declares b to be an intList with a head value of 2, and a nil tail.
  3509.  
  3510. `intList c(3, b);     [ (setq c (cons 3 b)) ]'
  3511.      Declares c to be an intList with a head value of 3, and b as its
  3512.      tail.
  3513.  
  3514. `b = a;               [ (setq b a) ]'
  3515.      Sets b to be the same list as a.
  3516.  
  3517.    Assume the declarations of intLists a, b, and c in the following.
  3518. *Note Pix::.
  3519.  
  3520. List status
  3521. ===========
  3522.  
  3523. `a.null(); OR !a;      [ (null a) ]'
  3524.      returns true if a is null.
  3525.  
  3526. `a.valid();            [ (listp a) ]'
  3527.      returns true if a is non-null. Inside a conditional test, the
  3528.      `void*' coercion may also be used as in `if (a) ...'.
  3529.  
  3530. `intList();            [ nil ]'
  3531.      intList() may be used to null terminate a list, as in `intList
  3532.      f(int x) {if (x == 0) return intList(); ... } '.
  3533.  
  3534. `a.length();           [ (length a) ]'
  3535.      returns the length of a.
  3536.  
  3537. `a.list_length();      [ (list-length a) ]'
  3538.      returns the length of a, or -1 if a is circular.
  3539.  
  3540. heads and tails
  3541. ===============
  3542.  
  3543. `a.get(); OR a.head()  [ (car a) ]'
  3544.      returns a reference to the head field.
  3545.  
  3546. `a[2];                 [ (elt a 2) ]'
  3547.      returns a reference to the second (counting from zero) head field.
  3548.  
  3549. `a.tail();             [ (cdr a) ]'
  3550.      returns the intList that is the tail of a.
  3551.  
  3552. `a.last();             [ (last a) ]'
  3553.      returns the intList that is the last node of a.
  3554.  
  3555. `a.nth(2);             [ (nth a 2) ]'
  3556.      returns the intList that is the nth node of a.
  3557.  
  3558. `a.set_tail(b);        [ (rplacd a b) ]'
  3559.      sets a's tail to b.
  3560.  
  3561. `a.push(2);            [ (push 2 a) ]'
  3562.      equivalent to a = intList(2, a);
  3563.  
  3564. `int x = a.pop()       [ (setq x (car a)) (pop a) ]'
  3565.      returns the head of a, also setting a to its tail.
  3566.  
  3567. Constructive operations
  3568. =======================
  3569.  
  3570. `b = copy(a);          [ (setq b (copy-seq a)) ]'
  3571.      sets b to a copy of a.
  3572.  
  3573. `b = reverse(a);       [ (setq b (reverse a)) ]'
  3574.      Sets b to a reversed copy of a.
  3575.  
  3576. `c = concat(a, b);     [ (setq c (concat a b)) ]'
  3577.      Sets c to a concatenated copy of a and b.
  3578.  
  3579. `c = append(a, b);     [ (setq c (append a b)) ]'
  3580.      Sets c to a concatenated copy of a and b. All nodes of a are
  3581.      copied, with the last node pointing to b.
  3582.  
  3583. `b = map(f, a);        [ (setq b (mapcar f a)) ]'
  3584.      Sets b to a new list created by applying function f to each node
  3585.      of a.
  3586.  
  3587. `c = combine(f, a, b);'
  3588.      Sets c to a new list created by applying function f to successive
  3589.      pairs of a and b. The resulting list has length the shorter of a
  3590.      and b.
  3591.  
  3592. `b = remove(x, a);     [ (setq b (remove x a)) ]'
  3593.      Sets b to a copy of a, omitting all occurrences of x.
  3594.  
  3595. `b = remove(f, a);     [ (setq b (remove-if f a)) ]'
  3596.      Sets b to a copy of a, omitting values causing function f to
  3597.      return true.
  3598.  
  3599. `b = select(f, a);     [ (setq b (remove-if-not f a)) ]'
  3600.      Sets b to a copy of a, omitting values causing function f to
  3601.      return false.
  3602.  
  3603. `c = merge(a, b, f);   [ (setq c (merge a b f)) ]'
  3604.      Sets c to a list containing the ordered elements (using the
  3605.      comparison function f) of the sorted lists a and b.
  3606.  
  3607. Destructive operations
  3608. ======================
  3609.  
  3610. `a.append(b);          [ (rplacd (last a) b) ]'
  3611.      appends b to the end of a. No new nodes are constructed.
  3612.  
  3613. `a.prepend(b);         [ (setq a (append b a)) ]'
  3614.      prepends b to the beginning of a.
  3615.  
  3616. `a.del(x);             [ (delete x a) ]'
  3617.      deletes all nodes with value x from a.
  3618.  
  3619. `a.del(f);             [ (delete-if f a) ]'
  3620.      deletes all nodes causing function f to return true.
  3621.  
  3622. `a.select(f);          [ (delete-if-not f a) ]'
  3623.      deletes all nodes causing function f to return false.
  3624.  
  3625. `a.reverse();          [ (nreverse a) ]'
  3626.      reverses a in-place.
  3627.  
  3628. `a.sort(f);            [ (sort a f) ]'
  3629.      sorts a in-place using ordering (comparison) function f.
  3630.  
  3631. `a.apply(f);           [ (mapc f a) ]'
  3632.      Applies void function f (int x) to each element of a.
  3633.  
  3634. `a.subst(int old, int repl); [ (nsubst repl old a) ]'
  3635.      substitutes repl for each occurrence of old in a. Note the
  3636.      different argument order than the Lisp version.
  3637.  
  3638. Other operations
  3639. ================
  3640.  
  3641. `a.find(int x);       [ (find x a) ]'
  3642.      returns the intList at the first occurrence of x.
  3643.  
  3644. `a.find(b);           [ (find b a) ]'
  3645.      returns the intList at the first occurrence of sublist b.
  3646.  
  3647. `a.contains(int x);    [ (member x a) ]'
  3648.      returns true if a contains x.
  3649.  
  3650. `a.contains(b);        [ (member b a) ]'
  3651.      returns true if a contains sublist b.
  3652.  
  3653. `a.position(int x);    [ (position x a) ]'
  3654.      returns the zero-based index of x in a, or -1 if x does not occur.
  3655.  
  3656. `int x = a.reduce(f, int base); [ (reduce f a :initial-value base) ]'
  3657.      Accumulates the result of applying int function f(int, int) to
  3658.      successive elements of a, starting with base.
  3659.  
  3660. 
  3661. File: libg++,  Node: LinkList,  Next: Vector,  Prev: List,  Up: Top
  3662.  
  3663. Linked Lists
  3664. ************
  3665.  
  3666.    SLLists provide pseudo-generic singly linked lists.  DLLists provide
  3667. doubly linked lists.  The lists are designed for the simple maintenance
  3668. of elements in a linked structure, and do not provide the more extensive
  3669. operations (or node-sharing) of class `List'. They behave similarly to
  3670. the `slist' and similar classes described by Stroustrup.
  3671.  
  3672.    All list nodes are created dynamically. Assignment is performed via
  3673. copying.
  3674.  
  3675.    Class `DLList' supports all `SLList' operations, plus additional
  3676. operations described below.
  3677.  
  3678.    For purposes of illustration, assume the specification of class
  3679. `intSLList'. In addition to the operations listed here, SLLists support
  3680. traversal via Pixes. *Note Pix::
  3681.  
  3682. `intSLList a;'
  3683.      Declares a to be an empty list.
  3684.  
  3685. `intSLList b = a;'
  3686.      Sets b to an element-by-element copy of a.
  3687.  
  3688. `a.empty()'
  3689.      returns true if a contains no elements
  3690.  
  3691. `a.length();'
  3692.      returns the number of elements in a.
  3693.  
  3694. `a.prepend(x);'
  3695.      places x at the front of the list.
  3696.  
  3697. `a.append(x);'
  3698.      places x at the end of the list.
  3699.  
  3700. `a.join(b)'
  3701.      places all nodes from b to the end of a, simultaneously destroying
  3702.      b.
  3703.  
  3704. `x = a.front()'
  3705.      returns a reference to the item stored at the head of the list, or
  3706.      triggers an error if the list is empty.
  3707.  
  3708. `a.rear()'
  3709.      returns a reference to the rear of the list, or triggers an error
  3710.      if the list is empty.
  3711.  
  3712. `x = a.remove_front()'
  3713.      deletes and returns the item stored at the head of the list.
  3714.  
  3715. `a.del_front()'
  3716.      deletes the first element, without returning it.
  3717.  
  3718. `a.clear()'
  3719.      deletes all items from the list.
  3720.  
  3721. `a.ins_after(Pix i, item);'
  3722.      inserts item after position i. If i is null, insertion is at the
  3723.      front.
  3724.  
  3725. `a.del_after(Pix i);'
  3726.      deletes the element following i. If i is 0, the first item is
  3727.      deleted.
  3728.  
  3729. Doubly linked lists
  3730. ===================
  3731.  
  3732.    Class `DLList' supports the following additional operations, as well
  3733. as backward traversal via Pixes.
  3734.  
  3735. `x = a.remove_rear();'
  3736.      deletes and returns the item stored at the rear of the list.
  3737.  
  3738. `a.del_rear();'
  3739.      deletes the last element, without returning it.
  3740.  
  3741. `a.ins_before(Pix i, x)'
  3742.      inserts x before the i.
  3743.  
  3744. `a.del(Pix& iint dir = 1)'
  3745.      deletes the item at the current position, then advances forward if
  3746.      dir is positive, else backward.
  3747.  
  3748. 
  3749. File: libg++,  Node: Vector,  Next: Plex,  Prev: LinkList,  Up: Top
  3750.  
  3751. Vector classes
  3752. **************
  3753.  
  3754.    The files `g++-include/Vec.ccP' and `g++-include/AVec.ccP' provide
  3755. pseudo-generic standard array-based vector operations.  The
  3756. corresponding header files are `g++-include/Vec.hP' and
  3757. `g++-include/AVec.hP'.  Class `Vec' provides operations suitable for
  3758. any base class that includes an equality operator. Subclass `AVec'
  3759. provides additional arithmetic operations suitable for base classes
  3760. that include the full complement of arithmetic operators.
  3761.  
  3762.    `Vecs' are constructed and assigned by copying. Thus, they should
  3763. normally be passed by reference in applications programs.
  3764.  
  3765.    Several mapping functions are provided that allow programmers to
  3766. specify operations on vectors as a whole.
  3767.  
  3768.    For illustrative purposes assume that classes `intVec' and `intAVec'
  3769. have been generated via `genclass'.
  3770.  
  3771. Constructors and assignment
  3772. ===========================
  3773.  
  3774. `intVec a;'
  3775.      declares a to be an empty vector. Its size may be changed via
  3776.      resize.
  3777.  
  3778. `intVec a(10);'
  3779.      declares a to be an uninitialized vector of ten elements (numbered
  3780.      0-9).
  3781.  
  3782. `intVec b(6, 0);'
  3783.      declares b to be a vector of six elements, all initialized to
  3784.      zero. Any value can be used as the initial fill argument.
  3785.  
  3786. `a = b;'
  3787.      Copies b to a. a is resized to be the same as b.
  3788.  
  3789. `a = b.at(2, 4)'
  3790.      constructs a from the 4 elements of b starting at b[2].
  3791.  
  3792.    Assume declarations of `intVec a, b, c' and `int i, x' in the
  3793. following.
  3794.  
  3795. Status and access
  3796. =================
  3797.  
  3798. `a.capacity();'
  3799.      returns the number of elements that can be held in a.
  3800.  
  3801. `a.resize(20);'
  3802.      sets a's length to 20. All elements are unchanged, except that if
  3803.      the new size is smaller than the original, than trailing elements
  3804.      are deleted, and if greater, trailing elements are uninitialized.
  3805.  
  3806. `a[i];'
  3807.      returns a reference to the i'th element of a, or produces an error
  3808.      if i is out of range.
  3809.  
  3810. `a.elem(i)'
  3811.      returns a reference to the i'th element of a. Unlike the `[]'
  3812.      operator, i is not checked to ensure that it is within range.
  3813.  
  3814. `a == b;'
  3815.      returns true if a and b contain the same elements in the same
  3816.      order.
  3817.  
  3818. `a != b;'
  3819.      is the converse of a == b.
  3820.  
  3821. Constructive operations
  3822. =======================
  3823.  
  3824. `c = concat(a, b);'
  3825.      sets c to the new vector constructed from all of the elements of a
  3826.      followed by all of b.
  3827.  
  3828. `c = map(f, a);'
  3829.      sets c to the new vector constructed by applying int function
  3830.      f(int) to each element of a.
  3831.  
  3832. `c = merge(a, b, f);'
  3833.      sets c to the new vector constructed by merging the elements of
  3834.      ordered vectors a and b using ordering (comparison) function f.
  3835.  
  3836. `c = combine(f, a, b);'
  3837.      sets c to the new vector constructed by applying int function
  3838.      f(int, int) to successive pairs of a and b. The result has length
  3839.      the shorter of a and b.
  3840.  
  3841. `c = reverse(a)'
  3842.      sets c to a, with elements in reverse order.
  3843.  
  3844. Destructive operations
  3845. ======================
  3846.  
  3847. `a.reverse();'
  3848.      reverses a in-place.
  3849.  
  3850. `a.sort(f)'
  3851.      sorts a in-place using comparison function f. The sorting method
  3852.      is a variation of the quicksort functions supplied with GNU emacs.
  3853.  
  3854. `a.fill(0, 4, 2)'
  3855.      fills the 2 elements starting at a[4] with zero.
  3856.  
  3857. Other operations
  3858. ================
  3859.  
  3860. `a.apply(f)'
  3861.      applies function f to each element in a.
  3862.  
  3863. `x = a.reduce(f, base)'
  3864.      accumulates the results of applying function f to successive
  3865.      elements of a starting with base.
  3866.  
  3867. `a.index(int targ);'
  3868.      returns the index of the leftmost occurrence of the target, or -1,
  3869.      if it does not occur.
  3870.  
  3871. `a.error(char* msg)'
  3872.      invokes the error handler. The default version prints the error
  3873.      message, then aborts.
  3874.  
  3875. AVec operations.
  3876. ================
  3877.  
  3878.    AVecs provide additional arithmetic operations.  All vector-by-vector
  3879. operators generate an error if the vectors are not the same length. The
  3880. following operations are provided, for `AVecs a, b' and base element
  3881. (scalar) `s'.
  3882.  
  3883. `a = b;'
  3884.      Copies b to a. a and b must be the same size.
  3885.  
  3886. `a = s;'
  3887.      fills all elements of a with the value s. a is not resized.
  3888.  
  3889. `a + s; a - s; a * s; a / s'
  3890.      adds, subtracts, multiplies, or divides each element of a with the
  3891.      scalar.
  3892.  
  3893. `a += s; a -= s; a *= s; a /= s;'
  3894.      adds, subtracts, multiplies, or divides the scalar into a.
  3895.  
  3896. `a + b; a - b; product(a, b), quotient(a, b)'
  3897.      adds, subtracts, multiplies, or divides corresponding elements of
  3898.      a and b.
  3899.  
  3900. `a += b; a -= b; a.product(b); a.quotient(b);'
  3901.      adds, subtracts, multiplies, or divides corresponding elements of
  3902.      b into a.
  3903.  
  3904. `s = a * b;'
  3905.      returns the inner (dot) product of a and b.
  3906.  
  3907. `x = a.sum();'
  3908.      returns the sum of elements of a.
  3909.  
  3910. `x = a.sumsq();'
  3911.      returns the sum of squared elements of a.
  3912.  
  3913. `x = a.min();'
  3914.      returns the minimum element of a.
  3915.  
  3916. `x = a.max();'
  3917.      returns the maximum element of a.
  3918.  
  3919. `i = a.min_index();'
  3920.      returns the index of the minimum element of a.
  3921.  
  3922. `i = a.max_index();'
  3923.      returns the index of the maximum element of a.
  3924.  
  3925.      Note that it is possible to apply vector versions other arithmetic
  3926.      operators via the mapping functions. For example, to set vector b
  3927.      to the  cosines of doubleVec a, use `b = map(cos, a);'.  This is
  3928.      often more efficient than performing the operations in an
  3929.      element-by-element fashion.
  3930.  
  3931. 
  3932. File: libg++,  Node: Plex,  Next: Stack,  Prev: Vector,  Up: Top
  3933.  
  3934. Plex classes
  3935. ************
  3936.  
  3937.    A "Plex" is a kind of array with the following properties:
  3938.  
  3939.    * Plexes may have arbitrary upper and lower index bounds. For example
  3940.      a Plex may be declared to run from indices -10 .. 10.
  3941.  
  3942.    * Plexes may be dynamically expanded at both the lower and upper
  3943.      bounds of the array in steps of one element.
  3944.  
  3945.    * Only elements that have been specifically initialized or added may
  3946.      be accessed.
  3947.  
  3948.    * Elements may be accessed via indices. Indices are always checked
  3949.      for validity at run time.  Plexes may be traversed via simple
  3950.      variations of standard array indexing loops.
  3951.  
  3952.    * Plex elements may be accessed and traversed via Pixes.
  3953.  
  3954.    * Plex-to-Plex assignment and related operations on entire Plexes
  3955.      are supported.
  3956.  
  3957.    * Plex classes contain methods to help programmers check the validity
  3958.      of indexing and pointer operations.
  3959.  
  3960.    * Plexes form "natural" base classes for many restricted-access data
  3961.      structures relying on logically contiguous indices, such as
  3962.      array-based stacks and queues.
  3963.  
  3964.    * Plexes are implemented as pseudo-generic classes, and must be
  3965.      generated via the `genclass' utility.
  3966.  
  3967.    Four subclasses of Plexes are supported: A `FPlex' is a Plex that
  3968. may only grow or shrink within declared bounds; an `XPlex' may
  3969. dynamically grow or shrink without bounds; an `RPlex' is the same as an
  3970. `XPlex' but better supports indexing with poor locality of reference; a
  3971. `MPlex' may grow or shrink, and additionally allows the logical
  3972. deletion and restoration of elements. Because these classes are virtual
  3973. subclasses of the "abstract" class `Plex', it is possible to write user
  3974. code such as `void f(Plex& a) ...' that operates on any kind of Plex.
  3975. However, as with nearly any virtual class, specifying the particular
  3976. Plex class being used results in more efficient code.
  3977.  
  3978.    Plexes are implemented as a linked list of `IChunks'.  Each chunk
  3979. contains a part of the array. Chunk sizes may be specified within Plex
  3980. constructors.  Default versions also exist, that use a `#define'd'
  3981. default.  Plexes grow by filling unused space in existing chunks, if
  3982. possible, else, except for FPlexes, by adding another chunk.  Whenever
  3983. Plexes grow by a new chunk, the default element constructors (i.e.,
  3984. those which take no arguments) for all chunk elements are called at
  3985. once. When Plexes shrink, destructors for the elements are not called
  3986. until an entire chunk is freed. For this reason, Plexes (like C++
  3987. arrays) should only be used for elements with default constructors and
  3988. destructors that have no side effects.
  3989.  
  3990.    Plexes may be indexed and used like arrays, although traversal
  3991. syntax is slightly different. Even though Plexes maintain elements in
  3992. lists of chunks, they are implemented so that iteration and other
  3993. constructs that maintain locality of reference require very little
  3994. overhead over that for simple array traversal Pix-based traversal is
  3995. also supported. For example, for a plex, p, of ints, the following
  3996. traversal methods could be used.
  3997.  
  3998.      for (int i = p.low(); i < p.fence(); p.next(i)) use(p[i]);
  3999.      for (int i = p.high(); i > p.ecnef(); p.prev(i)) use(p[i]);
  4000.      for (Pix t = p.first(); t != 0; p.next(t)) use(p(i));
  4001.      for (Pix t = p.last(); t != 0; p.prev(t)) use(p(i));
  4002.  
  4003.    Except for MPlexes, simply using `++i' and `--i' works just as well
  4004. as `p.next(i)' and `p.prev(i)' when traversing by index.  Index-based
  4005. traversal is generally a bit faster than Pix-based traversal.
  4006.  
  4007.    `XPlexes' and `MPlexes' are less than optimal for applications in
  4008. which widely scattered elements are indexed, as might occur when using
  4009. Plexes as hash tables or "manually" allocated linked lists.  In such
  4010. applications, `RPlexes' are often preferable. `RPlexes' use a secondary
  4011. chunk index table that requires slightly greater, but entirely uniform
  4012. overhead per index operation.
  4013.  
  4014.    Even though they may grow in either direction, Plexes are normally
  4015. constructed so that their "natural" growth direction is upwards, in
  4016. that default chunk construction leaves free space, if present, at the
  4017. end of the plex. However, if the chunksize arguments to constructors
  4018. are negative, they leave space at the beginning.
  4019.  
  4020.    All versions of Plexes support the following basic capabilities.
  4021. (letting `Plex' stand for the type name constructed via the genclass
  4022. utility (e.g., `intPlex', `doublePlex')).  Assume declarations of `Plex
  4023. p, q', `int i, j', base element `x', and Pix `pix'.
  4024.  
  4025. `Plex p;'
  4026.      Declares p to be an initially zero-sized Plex with low index of
  4027.      zero, and the default chunk size. For FPlexes, chunk sizes
  4028.      represent maximum sizes.
  4029.  
  4030. `Plex p(int size);'
  4031.      Declares p to be an initially zero-sized Plex with low index of
  4032.      zero, and the indicated chunk size. If size is negative, then the
  4033.      Plex is created with free space at the beginning of the Plex,
  4034.      allowing more efficient add_low() operations. Otherwise, it leaves
  4035.      space at the end.
  4036.  
  4037. `Plex p(int low, int size);'
  4038.      Declares p to be an initially zero-sized Plex with low index of
  4039.      low, and the indicated chunk size.
  4040.  
  4041. `Plex p(int low, int high, Base initval, int size = 0);'
  4042.      Declares p to be a Plex with indices from low to high, initially
  4043.      filled with initval, and the indicated chunk size if specified,
  4044.      else the default or (high - low + 1), whichever is greater.
  4045.  
  4046. `Plex q(p);'
  4047.      Declares q to be a copy of p.
  4048.  
  4049. `p = q;'
  4050.      Copies Plex q into p, deleting its previous contents.
  4051.  
  4052. `p.length()'
  4053.      Returns the number of elements in the Plex.
  4054.  
  4055. `p.empty()'
  4056.      Returns true if Plex p contains no elements.
  4057.  
  4058. `p.full()'
  4059.      Returns true if Plex p cannot be expanded. This always returns
  4060.      false for XPlexes and MPlexes.
  4061.  
  4062. `p[i]'
  4063.      Returns a reference to the i'th element of p. An exception (error)
  4064.      occurs if i is not a valid index.
  4065.  
  4066. `p.valid(i)'
  4067.      Returns true if i is a valid index into Plex p.
  4068.  
  4069. `p.low(); p.high();'
  4070.      Return the minimum (maximum) valid index of the Plex, or the high
  4071.      (low) fence if the plex is empty.
  4072.  
  4073. `p.ecnef(); p.fence();'
  4074.      Return the index one position past the minimum (maximum) valid
  4075.      index.
  4076.  
  4077. `p.next(i); i = p.prev(i);'
  4078.      Set i to the next (previous) index. This index may not be within
  4079.      bounds.
  4080.  
  4081. `p(pix)'
  4082.      returns a reference to the item at Pix pix.
  4083.  
  4084. `pix = p.first(); pix = p.last();'
  4085.      Return the minimum (maximum) valid Pix of the Plex, or 0 if the
  4086.      plex is empty.
  4087.  
  4088. `p.next(pix); p.prev(pix);'
  4089.      set pix to the next (previous) Pix, or 0 if there is none.
  4090.  
  4091. `p.owns(pix)'
  4092.      Returns true if the Plex contains the element associated with pix.
  4093.  
  4094. `p.Pix_to_index(pix)'
  4095.      If pix is a valid Pix to an element of the Plex, returns its
  4096.      corresponding index, else raises an exception.
  4097.  
  4098. `ptr = p.index_to_Pix(i)'
  4099.      if i is a valid index, returns a the corresponding Pix.
  4100.  
  4101. `p.low_element(); p.high_element();'
  4102.      Return a reference to the element at the minimum (maximum) valid
  4103.      index.  An exception occurs if the Plex is empty.
  4104.  
  4105. `p.can_add_low();  p.can_add_high();'
  4106.      Returns true if the plex can be extended one element downward
  4107.      (upward).  These always return true for XPlex and MPlex.
  4108.  
  4109. `j = p.add_low(x); j = p.add_high(x);'
  4110.      Extend the Plex by one element downward (upward). The new minimum
  4111.      (maximum) index is returned.
  4112.  
  4113. `j = p.del_low(); j = p.del_high()'
  4114.      Shrink the Plex by one element on the low (high) end. The new
  4115.      minimum (maximum) element is returned. An exception occurs if the
  4116.      Plex is empty.
  4117.  
  4118. `p.append(q);'
  4119.      Append all of Plex q to the high side of p.
  4120.  
  4121. `p.prepend(q);'
  4122.      Prepend all of q to the low side of p.
  4123.  
  4124. `p.clear()'
  4125.      Delete all elements, resetting p to a zero-sized Plex.
  4126.  
  4127. `p.reset_low(i);'
  4128.      Resets p to be indexed starting at low() = i. For example.  if p
  4129.      were initially declared via `Plex p(0, 10, 0)', and then
  4130.      re-indexed via `p.reset_low(5)', it could then be indexed from
  4131.      indices 5 .. 14.
  4132.  
  4133. `p.fill(x)'
  4134.      sets all p[i] to x.
  4135.  
  4136. `p.fill(x, lo, hi)'
  4137.      sets all of p[i] from lo to hi, inclusive, to x.
  4138.  
  4139. `p.reverse()'
  4140.      reverses p in-place.
  4141.  
  4142. `p.chunk_size()'
  4143.      returns the chunk size used for the plex.
  4144.  
  4145. `p.error(const char * msg)'
  4146.      calls the resettable error handler.
  4147.  
  4148.    MPlexes are plexes with bitmaps that allow items to be logically
  4149. deleted and restored. They behave like other plexes, but also support
  4150. the following additional and modified capabilities:
  4151.  
  4152. `p.del_index(i); p.del_Pix(pix)'
  4153.      logically deletes p[i] (p(pix)). After deletion, attempts to
  4154.      access p[i] generate a error. Indexing via low(), high(), prev(),
  4155.      and next() skip the element. Deleting an element never changes the
  4156.      logical bounds of the plex.
  4157.  
  4158. `p.undel_index(i); p.undel_Pix(pix)'
  4159.      logically undeletes p[i] (p(pix)).
  4160.  
  4161. `p.del_low(); p.del_high()'
  4162.      Delete the lowest (highest) undeleted element, resetting the
  4163.      logical bounds of the plex to the next lowest (highest) undeleted
  4164.      index. Thus, MPlex del_low() and del_high() may shrink the bounds
  4165.      of the plex by more than one index.
  4166.  
  4167. `p.adjust_bounds()'
  4168.      Resets the low and high bounds of the Plex to the indexes of the
  4169.      lowest and highest actual undeleted elements.
  4170.  
  4171. `int i = p.add(x)'
  4172.      Adds x in an unused index, if possible, else performs add_high.
  4173.  
  4174. `p.count()'
  4175.      returns the number of valid (undeleted) elements.
  4176.  
  4177. `p.available()'
  4178.      returns the number of available (deleted) indices.
  4179.  
  4180. `int i = p.unused_index()'
  4181.      returns the index of some deleted element, if one exists, else
  4182.      triggers an error. An unused element may be reused via undel.
  4183.  
  4184. `pix = p.unused_Pix()'
  4185.      returns the pix of some deleted element, if one exists, else 0.
  4186.      An unused element may be reused via undel.
  4187.  
  4188. 
  4189. File: libg++,  Node: Stack,  Next: Queue,  Prev: Plex,  Up: Top
  4190.  
  4191. Stacks
  4192. ******
  4193.  
  4194.    Stacks are declared as an "abstract" class. They are currently
  4195. implemented in any of three ways.
  4196.  
  4197. `VStack'
  4198.      implement fixed sized stacks via arrays.
  4199.  
  4200. `XPStack'
  4201.      implement dynamically-sized stacks via XPlexes.
  4202.  
  4203. `SLStack'
  4204.      implement dynamically-size stacks via linked lists.
  4205.  
  4206.    All possess the same capabilities. They differ only in constructors.
  4207. VStack constructors require a fixed maximum capacity argument.  XPStack
  4208. constructors optionally take a chunk size argument.  SLStack
  4209. constructors take no argument.
  4210.  
  4211.    Assume the declaration of a base element `x'.
  4212.  
  4213. `Stack s;  or Stack s(int capacity)'
  4214.      declares a Stack.
  4215.  
  4216. `s.empty()'
  4217.      returns true if stack s is empty.
  4218.  
  4219. `s.full()'
  4220.      returns true if stack s is full. XPStacks and SLStacks never
  4221.      become full.
  4222.  
  4223. `s.length()'
  4224.      returns the current number of elements in the stack.
  4225.  
  4226. `s.push(x)'
  4227.      pushes x on stack s.
  4228.  
  4229. `x = s.pop()'
  4230.      pops and returns the top of stack
  4231.  
  4232. `s.top()'
  4233.      returns a reference to the top of stack.
  4234.  
  4235. `s.del_top()'
  4236.      pops, but does not return the top of stack. When large items are
  4237.      held on the stack it is often a good idea to use `top()' to
  4238.      inspect and use the top of stack, followed by a `del_top()'
  4239.  
  4240. `s.clear()'
  4241.      removes all elements from the stack.
  4242.  
  4243. 
  4244. File: libg++,  Node: Queue,  Next: Deque,  Prev: Stack,  Up: Top
  4245.  
  4246. Queues
  4247. ******
  4248.  
  4249.    Queues are declared as an "abstract" class. They are currently
  4250. implemented in any of three ways.
  4251.  
  4252. `VQueue'
  4253.      implement fixed sized Queues via arrays.
  4254.  
  4255. `XPQueue'
  4256.      implement dynamically-sized Queues via XPlexes.
  4257.  
  4258. `SLQueue'
  4259.      implement dynamically-size Queues via linked lists.
  4260.  
  4261.    All possess the same capabilities; they differ only in constructors.
  4262. `VQueue' constructors require a fixed maximum capacity argument.
  4263. `XPQueue' constructors optionally take a chunk size argument.
  4264. `SLQueue' constructors take no argument.
  4265.  
  4266.    Assume the declaration of a base element `x'.
  4267.  
  4268. `Queue q; or Queue q(int capacity);'
  4269.      declares a queue.
  4270.  
  4271. `q.empty()'
  4272.      returns true if queue q is empty.
  4273.  
  4274. `q.full()'
  4275.      returns true if queue q is full. XPQueues and SLQueues are never
  4276.      full.
  4277.  
  4278. `q.length()'
  4279.      returns the current number of elements in the queue.
  4280.  
  4281. `q.enq(x)'
  4282.      enqueues x on queue q.
  4283.  
  4284. `x = q.deq()'
  4285.      dequeues and returns the front of queue
  4286.  
  4287. `q.front()'
  4288.      returns a reference to the front of queue.
  4289.  
  4290. `q.del_front()'
  4291.      dequeues, but does not return the front of queue
  4292.  
  4293. `q.clear()'
  4294.      removes all elements from the queue.
  4295.  
  4296. 
  4297. File: libg++,  Node: Deque,  Next: PQ,  Prev: Queue,  Up: Top
  4298.  
  4299. Double ended Queues
  4300. *******************
  4301.  
  4302.    Deques are declared as an "abstract" class. They are currently
  4303. implemented in two ways.
  4304.  
  4305. `XPDeque'
  4306.      implement dynamically-sized Deques via XPlexes.
  4307.  
  4308. `DLDeque'
  4309.      implement dynamically-size Deques via linked lists.
  4310.  
  4311.    All possess the same capabilities. They differ only in constructors.
  4312. XPDeque constructors optionally take a chunk size argument.  DLDeque
  4313. constructors take no argument.
  4314.  
  4315.    Double-ended queues support both stack-like and queue-like
  4316. capabilities:
  4317.  
  4318.    Assume the declaration of a base element `x'.
  4319.  
  4320. `Deque d; or Deque d(int initial_capacity)'
  4321.      declares a deque.
  4322.  
  4323. `d.empty()'
  4324.      returns true if deque d is empty.
  4325.  
  4326. `d.full()'
  4327.      returns true if deque d is full.  Always returns false in current
  4328.      implementations.
  4329.  
  4330. `d.length()'
  4331.      returns the current number of elements in the deque.
  4332.  
  4333. `d.enq(x)'
  4334.      inserts x at the rear of deque d.
  4335.  
  4336. `d.push(x)'
  4337.      inserts x at the front of deque d.
  4338.  
  4339. `x = d.deq()'
  4340.      dequeues and returns the front of deque
  4341.  
  4342. `d.front()'
  4343.      returns a reference to the front of deque.
  4344.  
  4345. `d.rear()'
  4346.      returns a reference to the rear of the deque.
  4347.  
  4348. `d.del_front()'
  4349.      deletes, but does not return the front of deque
  4350.  
  4351. `d.del_rear()'
  4352.      deletes, but does not return the rear of the deque.
  4353.  
  4354. `d.clear()'
  4355.      removes all elements from the deque.
  4356.  
  4357. 
  4358. File: libg++,  Node: PQ,  Next: Set,  Prev: Deque,  Up: Top
  4359.  
  4360. Priority Queue class prototypes.
  4361. ********************************
  4362.  
  4363.    Priority queues maintain collections of objects arranged for fast
  4364. access to the least element.
  4365.  
  4366.    Several prototype implementations of priority queues are supported.
  4367.  
  4368. `XPPQs'
  4369.      implement 2-ary heaps via XPlexes.
  4370.  
  4371. `SplayPQs'
  4372.      implement  PQs via Sleator and Tarjan's (JACM 1985) splay trees.
  4373.      The algorithms use a version of "simple top-down splaying"
  4374.      (described on page 669 of the article).  The simple-splay
  4375.      mechanism for priority queue functions is loosely based on the one
  4376.      used by D. Jones in the C splay tree functions available from
  4377.      volume 14 of the uunet.uu.net archives.
  4378.  
  4379. `PHPQs'
  4380.      implement pairing heaps (as described by Fredman and Sedgewick in
  4381.      `Algorithmica', Vol 1, p111-129).  Storage for heap elements is
  4382.      managed via an internal freelist technique. The constructor allows
  4383.      an initial capacity estimate for freelist space.  The storage is
  4384.      automatically expanded if necessary to hold new items. The
  4385.      deletion technique is a fast "lazy deletion" strategy that marks
  4386.      items as deleted, without reclaiming space until the items come to
  4387.      the top of the heap.
  4388.  
  4389.    All PQ classes support the following operations, for some PQ class
  4390. `Heap', instance `h', `Pix ind', and base class variable `x'.
  4391.  
  4392. `h.empty()'
  4393.      returns true if there are no elements in the PQ.
  4394.  
  4395. `h.length()'
  4396.      returns the number of elements in h.
  4397.  
  4398. `ind = h.enq(x)'
  4399.      Places x in the PQ, and returns its index.
  4400.  
  4401. `x = h.deq()'
  4402.      Dequeues the minimum element of the PQ into x, or generates an
  4403.      error if the PQ is empty.
  4404.  
  4405. `h.front()'
  4406.      returns a reference to the minimum element.
  4407.  
  4408. `h.del_front()'
  4409.      deletes the minimum element.
  4410.  
  4411. `h.clear();'
  4412.      deletes all elements from h;
  4413.  
  4414. `h.contains(x)'
  4415.      returns true if x is in h.
  4416.  
  4417. `h(ind)'
  4418.      returns a reference to the item indexed by ind.
  4419.  
  4420. `ind = h.first()'
  4421.      returns the Pix of first item in the PQ or 0 if empty.  This need
  4422.      not be the Pix of the least element.
  4423.  
  4424. `h.next(ind)'
  4425.      advances ind to the Pix of next element, or 0 if there are no more.
  4426.  
  4427. `ind = h.seek(x)'
  4428.      Sets ind to the Pix of x, or 0 if x is not in h.
  4429.  
  4430. `h.del(ind)'
  4431.      deletes the item with Pix ind.
  4432.  
  4433. 
  4434. File: libg++,  Node: Set,  Next: Bag,  Prev: PQ,  Up: Top
  4435.  
  4436. Set class prototypes
  4437. ********************
  4438.  
  4439.    Set classes maintain unbounded collections of items containing no
  4440. duplicate elements.
  4441.  
  4442.    These are currently implemented in several ways, differing in
  4443. representation strategy, algorithmic efficiency, and appropriateness for
  4444. various tasks. (Listed next to each are average (followed by worst-case,
  4445. if different) time complexities for [a] adding, [f] finding (via seek,
  4446. contains), [d] deleting, elements, and [c] comparing (via ==, <=) and
  4447. [m] merging (via |=, -=, &=) sets).
  4448.  
  4449. `XPSets'
  4450.      implement unordered sets via XPlexes.  ([a O(n)], [f O(n)], [d
  4451.      O(n)], [c O(n^2)] [m O(n^2)]).
  4452.  
  4453. `OXPSets'
  4454.      implement ordered sets via XPlexes.  ([a O(n)], [f O(log n)], [d
  4455.      O(n)], [c O(n)] [m O(n)]).
  4456.  
  4457. `SLSets'
  4458.      implement unordered sets via linked lists ([a O(n)], [f O(n)], [d
  4459.      O(n)], [c O(n^2)] [m O(n^2)]).
  4460.  
  4461. `OSLSets'
  4462.      implement ordered sets via linked lists ([a O(n)], [f O(n)], [d
  4463.      O(n)], [c O(n)] [m O(n)]).
  4464.  
  4465. `AVLSets'
  4466.      implement ordered sets via threaded AVL trees ([a O(log n)], [f
  4467.      O(log n)], [d O(log n)], [c O(n)] [m O(n)]).
  4468.  
  4469. `BSTSets'
  4470.      implement ordered sets via binary search trees. The trees may be
  4471.      manually rebalanced via the O(n) `balance()' member function.  ([a
  4472.      O(log n)/O(n)], [f O(log n)/O(n)], [d O(log n)/O(n)], [c O(n)] [m
  4473.      O(n)]).
  4474.  
  4475. `SplaySets'
  4476.      implement ordered sets via Sleator and Tarjan's (JACM 1985) splay
  4477.      trees. The algorithms use a version of "simple top-down splaying"
  4478.      (described on page 669 of the article).  (Amortized: [a O(log n)],
  4479.      [f O(log n)], [d O(log n)], [c O(n)] [m O(n log n)]).
  4480.  
  4481. `VHSets'
  4482.      implement unordered sets via hash tables.  The tables are
  4483.      automatically resized when their capacity is exhausted.  ([a
  4484.      O(1)/O(n)], [f O(1)/O(n)], [d O(1)/O(n)], [c O(n)/O(n^2)] [m
  4485.      O(n)/O(n^2)]).
  4486.  
  4487. `VOHSets'
  4488.      implement unordered sets via ordered hash tables The tables are
  4489.      automatically resized when their capacity is exhausted.  ([a
  4490.      O(1)/O(n)], [f O(1)/O(n)], [d O(1)/O(n)], [c O(n)/O(n^2)] [m
  4491.      O(n)/O(n^2)]).
  4492.  
  4493. `CHSets'
  4494.      implement unordered sets via chained hash tables.  ([a O(1)/O(n)],
  4495.      [f O(1)/O(n)], [d O(1)/O(n)], [c O(n)/O(n^2)] [m O(n)/O(n^2)]).
  4496.  
  4497.    The different implementations differ in whether their constructors
  4498. require an argument specifying their initial capacity. Initial
  4499. capacities are required for plex and hash table based Sets.  If none is
  4500. given `DEFAULT_INITIAL_CAPACITY' (from `<T>defs.h') is used.
  4501.  
  4502.    Sets support the following operations, for some class `Set',
  4503. instances `a' and `b', `Pix ind', and base element `x'. Since all
  4504. implementations are virtual derived classes of the `<T>Set' class, it
  4505. is possible to mix and match operations across different
  4506. implementations, although, as usual, operations are generally faster
  4507. when the particular classes are specified in functions operating on
  4508. Sets.
  4509.  
  4510.    Pix-based operations are more fully described in the section on
  4511. Pixes. *Note Pix::
  4512.  
  4513. `Set a; or Set a(int initial_size);'
  4514.      Declares a to be an empty Set. The second version is allowed in
  4515.      set classes that require initial capacity or sizing specifications.
  4516.  
  4517. `a.empty()'
  4518.      returns true if a is empty.
  4519.  
  4520. `a.length()'
  4521.      returns the number of elements in a.
  4522.  
  4523. `Pix ind = a.add(x)'
  4524.      inserts x into a, returning its index.
  4525.  
  4526. `a.del(x)'
  4527.      deletes x from a.
  4528.  
  4529. `a.clear()'
  4530.      deletes all elements from a;
  4531.  
  4532. `a.contains(x)'
  4533.      returns true if x is in a.
  4534.  
  4535. `a(ind)'
  4536.      returns a reference to the item indexed by ind.
  4537.  
  4538. `ind = a.first()'
  4539.      returns the Pix of first item in the set or 0 if the Set is empty.
  4540.      For ordered Sets, this is the Pix of the least element.
  4541.  
  4542. `a.next(ind)'
  4543.      advances ind to the Pix of next element, or 0 if there are no more.
  4544.  
  4545. `ind = a.seek(x)'
  4546.      Sets ind to the Pix of x, or 0 if x is not in a.
  4547.  
  4548. `a == b'
  4549.      returns true if a and b contain all the same elements.
  4550.  
  4551. `a != b'
  4552.      returns true if a and b do not contain all the same elements.
  4553.  
  4554. `a <= b'
  4555.      returns true if a is a subset of b.
  4556.  
  4557. `a |= b'
  4558.      Adds all elements of b to a.
  4559.  
  4560. `a -= b'
  4561.      Deletes all elements of b from a.
  4562.  
  4563. `a &= b'
  4564.      Deletes all elements of a not occurring in b.
  4565.  
  4566. 
  4567. File: libg++,  Node: Bag,  Next: Map,  Prev: Set,  Up: Top
  4568.  
  4569. Bag class prototypes
  4570. ********************
  4571.  
  4572.    Bag classes maintain unbounded collections of items potentially
  4573. containing  duplicate elements.
  4574.  
  4575.    These are currently implemented in several ways, differing in
  4576. representation strategy, algorithmic efficiency, and appropriateness for
  4577. various tasks. (Listed next to each are average (followed by worst-case,
  4578. if different) time complexities for [a] adding, [f] finding (via seek,
  4579. contains), [d] deleting elements).
  4580.  
  4581. `XPBags'
  4582.      implement unordered Bags via XPlexes.  ([a O(1)], [f O(n)], [d
  4583.      O(n)]).
  4584.  
  4585. `OXPBags'
  4586.      implement ordered Bags via XPlexes.  ([a O(n)], [f O(log n)], [d
  4587.      O(n)]).
  4588.  
  4589. `SLBags'
  4590.      implement unordered Bags via linked lists ([a O(1)], [f O(n)], [d
  4591.      O(n)]).
  4592.  
  4593. `OSLBags'
  4594.      implement ordered Bags via linked lists ([a O(n)], [f O(n)], [d
  4595.      O(n)]).
  4596.  
  4597. `SplayBags'
  4598.      implement ordered Bags via Sleator and Tarjan's (JACM 1985) splay
  4599.      trees. The algorithms use a version of "simple top-down splaying"
  4600.      (described on page 669 of the article).  (Amortized: [a O(log n)],
  4601.      [f O(log n)], [d O(log n)]).
  4602.  
  4603. `VHBags'
  4604.      implement unordered Bags via hash tables.  The tables are
  4605.      automatically resized when their capacity is exhausted.  ([a
  4606.      O(1)/O(n)], [f O(1)/O(n)], [d O(1)/O(n)]).
  4607.  
  4608. `CHBags'
  4609.      implement unordered Bags via chained hash tables.  ([a O(1)/O(n)],
  4610.      [f O(1)/O(n)], [d O(1)/O(n)]).
  4611.  
  4612.    The implementations differ in whether their constructors require an
  4613. argument to specify their initial capacity. Initial capacities are
  4614. required for plex and hash table based Bags.  If none is given
  4615. `DEFAULT_INITIAL_CAPACITY' (from `<T>defs.h') is used.
  4616.  
  4617.    Bags support the following operations, for some class `Bag',
  4618. instances `a' and `b', `Pix ind', and base element `x'. Since all
  4619. implementations are virtual derived classes of the `<T>Bag' class, it
  4620. is possible to mix and match operations across different
  4621. implementations, although, as usual, operations are generally faster
  4622. when the particular classes are specified in functions operating on
  4623. Bags.
  4624.  
  4625.    Pix-based operations are more fully described in the section on
  4626. Pixes. *Note Pix::
  4627.  
  4628. `Bag a; or Bag a(int initial_size)'
  4629.      Declares a to be an empty Bag. The second version is allowed in
  4630.      Bag classes that require initial capacity or sizing specifications.
  4631.  
  4632. `a.empty()'
  4633.      returns true if a is empty.
  4634.  
  4635. `a.length()'
  4636.      returns the number of elements in a.
  4637.  
  4638. `ind = a.add(x)'
  4639.      inserts x into a, returning its index.
  4640.  
  4641. `a.del(x)'
  4642.      deletes one occurrence of x from a.
  4643.  
  4644. `a.remove(x)'
  4645.      deletes all occurrences of x from a.
  4646.  
  4647. `a.clear()'
  4648.      deletes all elements from a;
  4649.  
  4650. `a.contains(x)'
  4651.      returns true if x is in a.
  4652.  
  4653. `a.nof(x)'
  4654.      returns the number of occurrences of x in a.
  4655.  
  4656. `a(ind)'
  4657.      returns a reference to the item indexed by ind.
  4658.  
  4659. `int = a.first()'
  4660.      returns the Pix of first item in the Bag or 0 if the Bag is empty.
  4661.      For ordered Bags, this is the Pix of the least element.
  4662.  
  4663. `a.next(ind)'
  4664.      advances ind to the Pix of next element, or 0 if there are no more.
  4665.  
  4666. `ind = a.seek(x, Pix from = 0)'
  4667.      Sets ind to the Pix of the next occurrence x, or 0 if there are
  4668.      none.  If from is 0, the first occurrence is returned, else the
  4669.      following from.
  4670.  
  4671. 
  4672. File: libg++,  Node: Map,  Next: GetOpt,  Prev: Bag,  Up: Top
  4673.  
  4674. Map Class Prototypes
  4675. ********************
  4676.  
  4677.    Maps support associative array operations (insertion, deletion, and
  4678. membership of records based on an associated key). They require the
  4679. specification of two types, the key type and the contents type.
  4680.  
  4681.    These are currently implemented in several ways, differing in
  4682. representation strategy, algorithmic efficiency, and appropriateness for
  4683. various tasks. (Listed next to each are average (followed by worst-case,
  4684. if different) time complexities for [a] accessing (via op [],
  4685. contains), [d] deleting elements).
  4686.  
  4687. `AVLMaps'
  4688.      implement ordered Maps via threaded AVL trees ([a O(log n)], [d
  4689.      O(log n)]).
  4690.  
  4691. `RAVLMaps'
  4692.      Similar, but also maintain ranking information, used via
  4693.      `ranktoPix(int r)', that returns the `Pix' of the item at rank r,
  4694.      and `rank(key)' that returns the rank of the corresponding item.
  4695.      ([a O(log n)], [d O(log n)]).
  4696.  
  4697. `SplayMaps'
  4698.      implement ordered Maps via Sleator and Tarjan's (JACM 1985) splay
  4699.      trees. The algorithms use a version of "simple top-down splaying"
  4700.      (described on page 669 of the article).  (Amortized: [a O(log n)],
  4701.      [d O(log n)]).
  4702.  
  4703. `VHMaps'
  4704.      implement unordered Maps via hash tables.  The tables are
  4705.      automatically resized when their capacity is exhausted.  ([a
  4706.      O(1)/O(n)], [d O(1)/O(n)]).
  4707.  
  4708. `CHMaps'
  4709.      implement unordered Maps via chained hash tables.  ([a O(1)/O(n)],
  4710.      [d O(1)/O(n)]).
  4711.  
  4712.    The different implementations differ in whether their constructors
  4713. require an argument specifying their initial capacity. Initial
  4714. capacities are required for hash table based Maps.  If none is given
  4715. `DEFAULT_INITIAL_CAPACITY' (from `<T>defs.h') is used.
  4716.  
  4717.    All Map classes share the following operations (for some Map class,
  4718. `Map' instance `d', `Pix ind' and key variable `k', and contents
  4719. variable `x').
  4720.  
  4721.    Pix-based operations are more fully described in the section on
  4722. Pixes. *Note Pix::
  4723.  
  4724. `Map d(x);  Map d(x, int initial_capacity)'
  4725.      Declare d to be an empty Map. The required argument, x, specifies
  4726.      the default contents, i.e., the contents of an otherwise
  4727.      uninitialized location. The second version, specifying initial
  4728.      capacity is allowed for Maps with an initial capacity argument.
  4729.  
  4730. `d.empty()'
  4731.      returns true if d contains no items.
  4732.  
  4733. `d.length()'
  4734.      returns the number of items in d.
  4735.  
  4736. `d[k]'
  4737.      returns a reference to the contents of item with key k. If no such
  4738.      item exists, it is installed with the default contents.  Thus d[k]
  4739.      = x installs x, and x = d[k] retrieves it.
  4740.  
  4741. `d.contains(k)'
  4742.      returns true if an item with key field k exists in d.
  4743.  
  4744. `d.del(k)'
  4745.      deletes the item with key k.
  4746.  
  4747. `d.clear()'
  4748.      deletes all items from the table.
  4749.  
  4750. `x = d.dflt()'
  4751.      returns the default contents.
  4752.  
  4753. `k = d.key(ind)'
  4754.      returns a reference to the key at Pix ind.
  4755.  
  4756. `x = d.contents(ind)'
  4757.      returns a reference to the contents at Pix ind.
  4758.  
  4759. `ind = d.first()'
  4760.      returns the Pix of the first element in d, or 0 if d is empty.
  4761.  
  4762. `d.next(ind)'
  4763.      advances ind to the next element, or 0 if there are no more.
  4764.  
  4765. `ind = d.seek(k)'
  4766.      returns the Pix of element with key k, or 0 if k is not in d.
  4767.  
  4768. 
  4769. File: libg++,  Node: GetOpt,  Next: Projects,  Prev: Map,  Up: Top
  4770.  
  4771. C++ version of the GNU getopt function
  4772. **************************************
  4773.  
  4774.    The GetOpt class provides an efficient and structured mechanism for
  4775. processing command-line options from an application program.  The sample
  4776. program fragment below illustrates a typical use of the GetOpt class
  4777. for some hypothetical application program:
  4778.  
  4779.      #include <stdio.h>
  4780.      #include <GetOpt.h>
  4781.      //...
  4782.      int debug_flag, compile_flag, size_in_bytes;
  4783.      
  4784.      int
  4785.      main (int argc, char **argv)
  4786.      {
  4787.        // Invokes ctor `GetOpt (int argc, char **argv,
  4788.        //                       char *optstring);'
  4789.        GetOpt getopt (argc, argv, "dcs:");
  4790.        int option_char;
  4791.      
  4792.        // Invokes member function `int operator ()(void);'
  4793.        while ((option_char = getopt ()) != EOF)
  4794.          switch (option_char)
  4795.            {
  4796.               case 'd': debug_flag = 1; break;
  4797.               case 'c': compile_flag = 1; break;
  4798.               case 's': size_in_bytes = atoi (getopt.optarg); break;
  4799.               case '?': fprintf (stderr,
  4800.                                  "usage: %s [dcs<size>]\n", argv[0]);
  4801.            }
  4802.      }
  4803.  
  4804.    Unlike the C library version, the libg++ GetOpt class uses its
  4805. constructor to initialize class data members containing the argument
  4806. count, argument vector, and the option string.  This simplifies the
  4807. interface for each subsequent call to member function `int operator
  4808. ()(void)'.
  4809.  
  4810.    The C version, on the other hand, uses hidden static variables to
  4811. retain the option string and argument list values between calls to
  4812. `getopt'.  This complicates the `getopt' interface since the argument
  4813. count, argument vector, and option string must be passed as parameters
  4814. for each invocation.  For the C version, the loop in the previous
  4815. example becomes:
  4816.  
  4817.        while ((option_char = getopt (argc, argv, "dcs:")) != EOF)
  4818.          // ...
  4819.  
  4820.    which requires extra overhead to pass the parameters for every call.
  4821.  
  4822.    Along with the GetOpt constructor and `int operator ()(void)', the
  4823. other relevant elements of class GetOpt are:
  4824.  
  4825. `char *optarg'
  4826.      Used for communication from `operator ()(void)' to the caller.
  4827.      When `operator ()(void)' finds an option that takes an argument,
  4828.      the argument value is stored here.
  4829.  
  4830. `int optind'
  4831.      Index in `argv' of the next element to be scanned.  This is used
  4832.      for communication to and from the caller and for communication
  4833.      between successive calls to `operator ()(void)'.
  4834.  
  4835.      When `operator ()(void)' returns EOF, this is the index of the
  4836.      first of the non-option elements that the caller should itself
  4837.      scan.
  4838.  
  4839.      Otherwise, `optind' communicates from one call to the next how much
  4840.      of `argv' has been scanned so far.
  4841.  
  4842.    The libg++ version of GetOpt acts like standard UNIX `getopt' for
  4843. the calling routine, but it behaves differently for the user, since it
  4844. allows the user to intersperse the options with the other arguments.
  4845.  
  4846.    As GetOpt works, it permutes the elements of `argv' so that, when it
  4847. is done, all the options precede everything else.  Thus all application
  4848. programs are extended to handle flexible argument order.
  4849.  
  4850.    Setting the environment variable _POSIX_OPTION_ORDER disables
  4851. permutation.  Then the behavior is completely standard.
  4852.  
  4853. 
  4854. File: libg++,  Node: Projects,  Prev: GetOpt,  Up: Top
  4855.  
  4856. Projects and other things left to do
  4857. ************************************
  4858.  
  4859. Coming Attractions
  4860. ==================
  4861.  
  4862.    Some things that will probably be available in libg++ in the near
  4863. future:
  4864.  
  4865.    * Revamped C-compatibility header files that will be compatible with
  4866.      the forthcoming (ANSI-based) GNU libc.a
  4867.  
  4868.    * A revision of the File-based classes that will use the GNU stdio
  4869.      library, and also be 100% compatible (even at the streambuf level)
  4870.      with the AT&T 2.0 stream classes.
  4871.  
  4872.    * Additional container class prototypes.
  4873.  
  4874.    * generic Matrix class prototypes.
  4875.  
  4876.    * A task package probably based on Dirk Grunwald's threads package.
  4877.  
  4878. Wish List
  4879. =========
  4880.  
  4881.    Some things that people have mentioned that they would like to see
  4882. in libg++, but for which there have not been any offers:
  4883.  
  4884.    * A method to automatically convert or incorporate libg++ classes so
  4885.      they can be used directly in Gorlen's OOPS environment.
  4886.  
  4887.    * A class browser.
  4888.  
  4889.    * A better general exception-handling strategy.
  4890.  
  4891.    * Better documentation.
  4892.  
  4893. How to contribute
  4894. =================
  4895.  
  4896.    Programmers who have written C++ classes that they believe to be of
  4897. general interest are encourage to write to dl at rocky.oswego.edu.
  4898. Contributing code is not difficult. Here are some general guidelines:
  4899.  
  4900.    * FSF must maintain the right to accept or reject potential
  4901.      contributions.  Generally, the only reasons for rejecting
  4902.      contributions are cases where they duplicate existing or
  4903.      nearly-released code, contain unremovable specific machine
  4904.      dependencies, or are somehow incompatible with the rest of the
  4905.      library.
  4906.  
  4907.    * Acceptance of contributions means that the code is accepted for
  4908.      adaptation into libg++.  FSF must reserve the right to make
  4909.      various editorial changes in code. Very often, this merely entails
  4910.      formatting, maintenance of various conventions, etc. Contributors
  4911.      are always given authorship credit and shown the final version for
  4912.      approval.
  4913.  
  4914.    * Contributors must assign their copyright to FSF via a form sent out
  4915.      upon acceptance. Assigning copyright to FSF ensures that the code
  4916.      may be freely distributed.
  4917.  
  4918.    * Assistance in providing documentation, test files, and debugging
  4919.      support is strongly encouraged.
  4920.  
  4921.    Extensions, comments, and suggested modifications of existing libg++
  4922. features are also very welcome.
  4923.  
  4924.  
  4925. 
  4926. Tag Table:
  4927. Node: Top1220
  4928. Node: Copying3665
  4929. Node: Contributors30559
  4930. Node: Installation31741
  4931. Node: Trouble32315
  4932. Node: General32789
  4933. Node: Conventions36525
  4934. Node: OK39156
  4935. Node: Proto41001
  4936. Node: Representations54996
  4937. Node: Expressions58593
  4938. Node: Pix62953
  4939. Node: Headers65981
  4940. Node: Builtin68456
  4941. Node: New71131
  4942. Node: Stream73995
  4943. Node: Obstack82235
  4944. Node: AllocRing88526
  4945. Node: String90222
  4946. Node: Integer103931
  4947. Node: Rational110185
  4948. Node: Complex112963
  4949. Node: Fix115035
  4950. Node: Bit118368
  4951. Node: Random128982
  4952. Node: Data138929
  4953. Node: Curses140963
  4954. Node: List143832
  4955. Node: LinkList150691
  4956. Node: Vector153095
  4957. Node: Plex158465
  4958. Node: Stack168260
  4959. Node: Queue169619
  4960. Node: Deque170847
  4961. Node: PQ172260
  4962. Node: Set174578
  4963. Node: Bag178840
  4964. Node: Map182152
  4965. Node: GetOpt185383
  4966. Node: Projects188693
  4967. 
  4968. End Tag Table
  4969.