home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Professional / OS2PRO194.ISO / os2 / prgramer / unix / info / libgpp.i05 < prev    next >
Encoding:
GNU Info File  |  1993-06-12  |  13.6 KB  |  392 lines

  1. This is Info file libgpp, produced by Makeinfo-1.47 from the input file
  2. libgpp.tex.
  3.  
  4. START-INFO-DIR-ENTRY
  5. * Libg++: (libg++).        The g++ 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: libgpp,  Node: Bag,  Next: Map,  Prev: Set,  Up: Top
  33.  
  34. Bag class prototypes
  35. ********************
  36.  
  37.    Bag classes maintain unbounded collections of items potentially
  38. containing  duplicate elements.
  39.  
  40.    These are currently implemented in several ways, differing in
  41. representation strategy, algorithmic efficiency, and appropriateness for
  42. various tasks. (Listed next to each are average (followed by worst-case,
  43. if different) time complexities for [a] adding, [f] finding (via seek,
  44. contains), [d] deleting elements).
  45.  
  46. `XPBags'
  47.      implement unordered Bags via XPlexes. ([a O(1)], [f O(n)], [d
  48.      O(n)]).
  49.  
  50. `OXPBags'
  51.      implement ordered Bags via XPlexes. ([a O(n)], [f O(log n)], [d
  52.      O(n)]).
  53.  
  54. `SLBags'
  55.      implement unordered Bags via linked lists ([a O(1)], [f O(n)], [d
  56.      O(n)]).
  57.  
  58. `OSLBags'
  59.      implement ordered Bags via linked lists ([a O(n)], [f O(n)], [d
  60.      O(n)]).
  61.  
  62. `SplayBags'
  63.      implement ordered Bags via Sleater and Tarjan's (JACM 1985) splay
  64.      trees. The algorithms use a version of "simple top-down splaying"
  65.      (described on page 669 of the article). (Amortized: [a O(log n)],
  66.      [f O(log n)], [d O(log n)]).
  67.  
  68. `VHBags'
  69.      implement unordered Bags via hash tables. The tables are
  70.      automatically resized when their capacity is exhausted. ([a
  71.      O(1)/O(n)], [f O(1)/O(n)], [d O(1)/O(n)]).
  72.  
  73. `CHBags'
  74.      implement unordered Bags via chained hash tables. ([a O(1)/O(n)],
  75.      [f O(1)/O(n)], [d O(1)/O(n)]).
  76.  
  77.    The implementations differ in whether their constructors require an
  78. argument to specify their initial capacity. Initial capacities are
  79. required for plex and hash table based Bags.  If none is given
  80. `DEFAULT_INITIAL_CAPACITY' (from `<T>defs.h') is used.
  81.  
  82.    Bags support the following operations, for some class `Bag',
  83. instances `a' and `b', `Pix ind', and base element `x'. Since all
  84. implementations are virtual derived classes of the `<T>Bag' class, it
  85. is possible to mix and match operations across different
  86. implementations, although, as usual, operations are generally faster
  87. when the particular classes are specified in functions operating on
  88. Bags.
  89.  
  90.    Pix-based operations are more fully described in the section on
  91. Pixes. *Note Pix::
  92.  
  93. `Bag a; or Bag a(int initial_size)'
  94.      Declares a to be an empty Bag. The second version is allowed in
  95.      Bag classes that require initial capacity or sizing specifications.
  96.  
  97. `a.empty()'
  98.      returns true if a is empty.
  99.  
  100. `a.length()'
  101.      returns the number of elements in a.
  102.  
  103. `ind = a.add(x)'
  104.      inserts x into a, returning its index.
  105.  
  106. `a.del(x)'
  107.      deletes one occurrence of x from a.
  108.  
  109. `a.remove(x)'
  110.      deletes all occurrences of x from a.
  111.  
  112. `a.clear()'
  113.      deletes all elements from a;
  114.  
  115. `a.contains(x)'
  116.      returns true if x is in a.
  117.  
  118. `a.nof(x)'
  119.      returns the number of occurrences of x in a.
  120.  
  121. `a(ind)'
  122.      returns a reference to the item indexed by ind.
  123.  
  124. `int = a.first()'
  125.      returns the Pix of first item in the Bag or 0 if the Bag is empty.
  126.      For ordered Bags, this is the Pix of the least element.
  127.  
  128. `a.next(ind)'
  129.      advances ind to the Pix of next element, or 0 if there are no more.
  130.  
  131. `ind = a.seek(x. Pix from = 0)'
  132.      Sets ind to the Pix of the next occurrence x, or 0 if there are
  133.      none. If from is 0, the first occurrence is returned, else the
  134.      following from.
  135.  
  136. 
  137. File: libgpp,  Node: Map,  Next: GetOpt,  Prev: Bag,  Up: Top
  138.  
  139. Map Class Prototypes
  140. ********************
  141.  
  142.    Maps support associative array operations (insertion, deletion, and
  143. membership of records based on an associated key). They require the
  144. specification of two types, the key type and the contents type.
  145.  
  146.    These are currently implemented in several ways, differing in
  147. representation strategy, algorithmic efficiency, and appropriateness for
  148. various tasks. (Listed next to each are average (followed by worst-case,
  149. if different) time complexities for [a] accessing (via op [],
  150. contains), [d] deleting elements).
  151.  
  152. `AVLMaps'
  153.      implement ordered Maps via threaded AVL trees ([a O(log n)], [d
  154.      O(log n)]).
  155.  
  156. `RAVLMaps'
  157.      Similar, but also maintain ranking information, used via
  158.      `ranktoPix(int r)', that returns the `Pix' of the item at rank r,
  159.      and `rank(key)' that returns the rank of the corresponding item.
  160.      ([a O(log n)], [d O(log n)]).
  161.  
  162. `SplayMaps'
  163.      implement ordered Maps via Sleater and Tarjan's (JACM 1985) splay
  164.      trees. The algorithms use a version of "simple top-down splaying"
  165.      (described on page 669 of the article). (Amortized: [a O(log n)],
  166.      [d O(log n)]).
  167.  
  168. `VHMaps'
  169.      implement unordered Maps via hash tables. The tables are
  170.      automatically resized when their capacity is exhausted. ([a
  171.      O(1)/O(n)], [d O(1)/O(n)]).
  172.  
  173. `CHMaps'
  174.      implement unordered Maps via chained hash tables. ([a O(1)/O(n)],
  175.      [d O(1)/O(n)]).
  176.  
  177.    The different implementations differ in whether their constructors
  178. require an argument specifying their initial capacity. Initial
  179. capacities are required for hash table based Maps.  If none is given
  180. `DEFAULT_INITIAL_CAPACITY' (from `<T>defs.h') is used.
  181.  
  182.    All Map classes share the following operations (for some Map class,
  183. `Map' instance `d', `Pix ind' and key variable `k', and contents
  184. variable `x').
  185.  
  186.    Pix-based operations are more fully described in the section on
  187. Pixes. *Note Pix::
  188.  
  189. `Map d(x);  Map d(x, int initial_capacity)'
  190.      Declare d to be an empty Map. The required argument, x, specifies
  191.      the default contents, i.e., the contents of an otherwise
  192.      uninitialized location. The second version, specifying initial
  193.      capacity is allowed for Maps with an initial capacity argument.
  194.  
  195. `d.empty()'
  196.      returns true if d contains no items.
  197.  
  198. `d.length()'
  199.      returns the number of items in d.
  200.  
  201. `d[k]'
  202.      returns a reference to the contents of item with key k. If no such
  203.      item exists, it is installed with the default contents. Thus d[k]
  204.      = x installs x, and x = d[k] retrieves it.
  205.  
  206. `d.contains(k)'
  207.      returns true if an item with key field k exists in d.
  208.  
  209. `d.del(k)'
  210.      deletes the item with key k.
  211.  
  212. `d.clear()'
  213.      deletes all items from the table.
  214.  
  215. `x = d.dflt()'
  216.      returns the default contents.
  217.  
  218. `k = d.key(ind)'
  219.      returns a reference to the key at Pix ind.
  220.  
  221. `x = d.contents(ind)'
  222.      returns a reference to the contents at Pix ind.
  223.  
  224. `ind = d.first()'
  225.      returns the Pix of the first element in d, or 0 if d is empty.
  226.  
  227. `d.next(ind)'
  228.      advances ind to the next element, or 0 if there are no more.
  229.  
  230. `ind = d.seek(k)'
  231.      returns the Pix of element with key k, or 0 if k is not in d.
  232.  
  233. 
  234. File: libgpp,  Node: GetOpt,  Next: Projects,  Prev: Map,  Up: Top
  235.  
  236. C++ version of the GNU getopt function
  237. **************************************
  238.  
  239.    The GetOpt class provides an efficient and structured mechanism for
  240. processing command-line options from an application program.  The sample
  241. program fragment below illustrates a typical use of the GetOpt class
  242. for some hypothetical application program:
  243.  
  244.      #include <stdio.h>
  245.      #include <GetOpt.h>
  246.      //...
  247.      int debug_flag, compile_flag, size_in_bytes;
  248.      
  249.      int
  250.      main (int argc, char **argv)
  251.      {
  252.        // Invokes ctor `GetOpt (int argc, char **argv,
  253.        //                       char *optstring);'
  254.        GetOpt getopt (argc, argv, "dcs:");
  255.        int option_char;
  256.      
  257.        // Invokes member function `int operator ()(void);'
  258.        while ((option_char = getopt ()) != EOF)
  259.          switch (option_char)
  260.            {
  261.               case 'd': debug_flag = 1; break;
  262.               case 'c': compile_flag = 1; break;
  263.               case 's': size_in_bytes = atoi (getopt.optarg); break;
  264.               case '?': fprintf (stderr,
  265.                                  "usage: %s [dcs<size>]\n", argv[0]);
  266.            }
  267.      }
  268.  
  269.    Unlike the C library version, the libg++ GetOpt class uses its
  270. constructor to initialize class data members containing the argument
  271. count, argument vector, and the option string.  This simplifies the
  272. interface for each subsequent call to member function `int operator
  273. ()(void)'.
  274.  
  275.    The C version, on the other hand, uses hidden static variables to
  276. retain the option string and argument list values between calls to
  277. `getopt'.  This complicates the `getopt' interface since the argument
  278. count, argument vector, and option string must be passed as parameters
  279. for each invocation.  For the C version, the loop in the previous
  280. example becomes:
  281.  
  282.        while ((option_char = getopt (argc, argv, "dcs:")) != EOF)
  283.          // ...
  284.  
  285.    which requires extra overhead to pass the parameters for every call.
  286.  
  287.    Along with the GetOpt constructor and `int operator ()(void)', the
  288. other relevant elements of class GetOpt are:
  289.  
  290. `char *optarg'
  291.      Used for communication from `operator ()(void)' to the caller.
  292.      When `operator ()(void)' finds an option that takes an argument,
  293.      the argument value is stored here.
  294.  
  295. `int optind'
  296.      Index in `argv' of the next element to be scanned. This is used
  297.      for communication to and from the caller and for communication
  298.      between successive calls to `operator ()(void)'.
  299.  
  300.      When `operator ()(void)' returns EOF, this is the index of the
  301.      first of the non-option elements that the caller should itself
  302.      scan.
  303.  
  304.      Otherwise, `optind' communicates from one call to the next how much
  305.      of `argv' has been scanned so far.
  306.  
  307.    The libg++ version of GetOpt acts like standard UNIX `getopt' for
  308. the calling routine, but it behaves differently for the user, since it
  309. allows the user to intersperse the options with the other arguments.
  310.  
  311.    As GetOpt works, it permutes the elements of `argv' so that, when it
  312. is done, all the options precede everything else.  Thus all application
  313. programs are extended to handle flexible argument order.
  314.  
  315.    Setting the environment variable _POSIX_OPTION_ORDER disables
  316. permutation.  Then the behavior is completely standard.
  317.  
  318. 
  319. File: libgpp,  Node: Projects,  Prev: GetOpt,  Up: Top
  320.  
  321. Projects and other things left to do
  322. ************************************
  323.  
  324. Coming Attractions
  325. ==================
  326.  
  327.    Some things that will probably be available in libg++ in the near
  328. future:
  329.  
  330.    * Revamped C-compatibility header files that will be compatible with
  331.      the forthcoming (ANSI-based) GNU libc.a
  332.  
  333.    * A revision of the File-based classes that will use the GNU stdio
  334.      library, and also be 100% compatible (even at the streambuf level)
  335.      with the AT&T 2.0 stream classes.
  336.  
  337.    * Additional container class prototypes.
  338.  
  339.    * generic Matrix class prototypes.
  340.  
  341.    * A task package probably based on Dirk Grunwald's threads package.
  342.  
  343. Wish List
  344. =========
  345.  
  346.    Some things that people have mentioned that they would like to see
  347. in libg++, but for which there have not been any offers:
  348.  
  349.    * Class-based interfaces to Sun RPC using g++ wrappers.
  350.  
  351.    * A method to automatically convert or incorporate libg++ classes so
  352.      they can be used directly in Gorlen's OOPS environment.
  353.  
  354.    * A class browser.
  355.  
  356.    * A better general exception-handling strategy.
  357.  
  358.    * Better documentation.
  359.  
  360. How to contribute
  361. =================
  362.  
  363.    Programmers who have written C++ classes that they believe to be of
  364. general interest are encourage to write to dl at rocky.oswego.edu.
  365. Contributing code is not difficult. Here are some general guidelines:
  366.  
  367.    * FSF must maintain the right to accept or reject potential
  368.      contributions. Generally, the only reasons for rejecting
  369.      contributions are cases where they duplicate existing or
  370.      nearly-released code, contain unremovable specific machine
  371.      dependencies, or are somehow incompatible with the rest of the
  372.      library.
  373.  
  374.    * Acceptance of contributions means that the code is accepted for
  375.      adaptation into libg++.  FSF must reserve the right to make
  376.      various editorial changes in code. Very often, this merely entails
  377.      formatting, maintenance of various conventions, etc. Contributors
  378.      are always given authorship credit and shown the final version for
  379.      approval.
  380.  
  381.    * Contributors must assign their copyright to FSF via a form sent out
  382.      upon acceptance. Assigning copyright to FSF ensures that the code
  383.      may be freely distributed.
  384.  
  385.    * Assistance in providing documentation, test files, and debugging
  386.      support is strongly encouraged.
  387.  
  388.    Extensions, comments, and suggested modifications of existing libg++
  389. features are also very welcome.
  390.  
  391.  
  392.