home *** CD-ROM | disk | FTP | other *** search
/ Media Share 9 / MEDIASHARE_09.ISO / cprog / gccdoc2.zip / LIBGPP.TXT < prev    next >
Text File  |  1992-04-05  |  176KB  |  4,853 lines

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