home *** CD-ROM | disk | FTP | other *** search
/ Otherware / Otherware_1_SB_Development.iso / amiga / programm / language / gcc222.lha / info / libg++.info-3 < prev    next >
Encoding:
Text File  |  1992-07-19  |  46.7 KB  |  1,378 lines

  1. Info file libg++.info, produced by Makeinfo, -*- Text -*- from input
  2. file libg++.texinfo.
  3.  
  4. START-INFO-DIR-ENTRY
  5. * Libg++: (libg++).        The g++ library.
  6. END-INFO-DIR-ENTRY
  7.  
  8.    This file documents the features and implementation of The GNU C++
  9. library
  10.  
  11.    Copyright (C) 1988, 1991, 1992 Free Software Foundation, Inc.
  12.  
  13.    Permission is granted to make and distribute verbatim copies of
  14. this manual provided the copyright notice and this permission notice
  15. are preserved on all copies.
  16.  
  17.    Permission is granted to copy and distribute modified versions of
  18. this manual under the conditions for verbatim copying, provided also
  19. that the section entitled "GNU Library General Public License" is
  20. included exactly as in the original, and provided that the entire
  21. resulting derived work is distributed under the terms of a permission
  22. notice identical to this one.
  23.  
  24.    Permission is granted to copy and distribute translations of this
  25. manual into another language, under the above conditions for modified
  26. versions, except that the section entitled "GNU Library General Public
  27. License" and this permission notice may be included in translations
  28. approved by the Free Software Foundation instead of in the original
  29. English.
  30.  
  31. 
  32. File: libg++.info,  Node: Obstack,  Next: AllocRing,  Prev: Stream,  Up: Top
  33.  
  34. The Obstack class
  35. *****************
  36.  
  37.    The `Obstack' class is a simple rewrite of the C obstack macros and
  38. functions provided in the GNU CC compiler source distribution.
  39.  
  40.    Obstacks provide a simple method of creating and maintaining a
  41. string table, optimized for the very frequent task of building strings
  42. character-by-character, and sometimes keeping them, and sometimes not.
  43. They seem especially useful in any parsing application. One of the
  44. test files demonstrates usage.
  45.  
  46.    A brief summary:
  47.  
  48. `grow'
  49.      places something on the obstack without committing to wrap it up
  50.      as a single entity yet.
  51.  
  52. `finish'
  53.      wraps up a constructed object as a single entity, and returns the
  54.      pointer to its start address.
  55.  
  56. `copy'
  57.      places things on the obstack, and *does* wrap them up.  `copy' is
  58.      always equivalent to first grow, then finish.
  59.  
  60. `free'
  61.      deletes something, and anything else put on the obstack since its
  62.      creation.
  63.  
  64.    The other functions are less commonly needed:
  65.  
  66. `blank'
  67.      is like grow, except it just grows the space by size units
  68.      without placing anything into this space
  69.  
  70. `alloc'
  71.      is like `blank', but it wraps up the object and returns its
  72.      starting address.
  73.  
  74. `chunk_size, base, next_free, alignment_mask, size, room'
  75.      returns the appropriate class variables.
  76.  
  77. `grow_fast'
  78.      places a character on the obstack without checking if there is
  79.      enough room.
  80.  
  81. `blank_fast'
  82.      like `blank', but without checking if there is enough room.
  83.  
  84. `shrink(int n)'
  85.      shrink the current chunk by n bytes.
  86.  
  87. `contains(void* addr)'
  88.      returns true if the Obstack holds the address addr.
  89.  
  90.    Here is a lightly edited version of the original C documentation:
  91.  
  92.    These functions operate a stack of objects.  Each object starts life
  93. small, and may grow to maturity.  (Consider building a word syllable
  94. by syllable.)  An object can move while it is growing.  Once it has
  95. been "finished" it never changes address again.  So the "top of the
  96. stack" is typically an immature growing object, while the rest of the
  97. stack is of mature, fixed size and fixed address objects.
  98.  
  99.    These routines grab large chunks of memory, using the GNU C++ `new'
  100. operator.  On occasion, they free chunks, via `delete'.
  101.  
  102.    Each independent stack is represented by a Obstack.
  103.  
  104.    One motivation for this package is the problem of growing char
  105. strings in symbol tables.  Unless you are a "fascist pig with a
  106. read-only mind" [Gosper's immortal quote from HAKMEM item 154, out of
  107. context] you would not like to put any arbitrary upper limit on the
  108. length of your symbols.
  109.  
  110.    In practice this often means you will build many short symbols and a
  111. few long symbols.  At the time you are reading a symbol you don't know
  112. how long it is.  One traditional method is to read a symbol into a
  113. buffer, `realloc()'ating the buffer every time you try to read a
  114. symbol that is longer than the buffer.  This is beaut, but you still
  115. will want to copy the symbol from the buffer to a more permanent
  116. symbol-table entry say about half the time.
  117.  
  118.    With obstacks, you can work differently.  Use one obstack for all
  119. symbol names.  As you read a symbol, grow the name in the obstack
  120. gradually.  When the name is complete, finalize it.  Then, if the
  121. symbol exists already, free the newly read name.
  122.  
  123.    The way we do this is to take a large chunk, allocating memory from
  124. low addresses.  When you want to build a symbol in the chunk you just
  125. add chars above the current "high water mark" in the chunk.  When you
  126. have finished adding chars, because you got to the end of the symbol,
  127. you know how long the chars are, and you can create a new object. 
  128. Mostly the chars will not burst over the highest address of the chunk,
  129. because you would typically expect a chunk to be (say) 100 times as
  130. long as an average object.
  131.  
  132.    In case that isn't clear, when we have enough chars to make up the
  133. object, *they are already contiguous in the chunk* (guaranteed) so we
  134. just point to it where it lies.  No moving of chars is needed and this
  135. is the second win: potentially long strings need never be explicitly
  136. shuffled. Once an object is formed, it does not change its address
  137. during its lifetime.
  138.  
  139.    When the chars burst over a chunk boundary, we allocate a larger
  140. chunk, and then copy the partly formed object from the end of the old
  141. chunk to the beginning of the new larger chunk.  We then carry on
  142. accreting characters to the end of the object as we normally would.
  143.  
  144.    A special version of grow is provided to add a single char at a time
  145. to a growing object.
  146.  
  147.    Summary:
  148.  
  149.    * We allocate large chunks.
  150.  
  151.    * We carve out one object at a time from the current chunk.
  152.  
  153.    * Once carved, an object never moves.
  154.  
  155.    * We are free to append data of any size to the currently growing
  156.      object.
  157.  
  158.    * Exactly one object is growing in an obstack at any one time.
  159.  
  160.    * You can run one obstack per control block.
  161.  
  162.    * You may have as many control blocks as you dare.
  163.  
  164.    * Because of the way we do it, you can `unwind' a obstack back to a
  165.      previous state. (You may remove objects much as you would with a
  166.      stack.)
  167.  
  168.    The obstack data structure is used in many places in the GNU C++
  169. compiler.
  170.  
  171.    Differences from the the GNU C version
  172.  
  173.   1. The obvious differences stemming from the use of classes and
  174.      inline functions instead of structs and macros. The C `init' and
  175.      `begin' macros are replaced by constructors.
  176.  
  177.   2. Overloaded function names are used for grow (and others), rather
  178.      than the C `grow', `grow0', etc.
  179.  
  180.   3. All dynamic allocation uses the the built-in `new' operator. 
  181.      This restricts flexibility by a little, but maintains
  182.      compatibility with usual C++ conventions.
  183.  
  184.   4. There are now two versions of finish:
  185.  
  186.        1. finish() behaves like the C version.
  187.  
  188.        2. finish(char terminator) adds `terminator', and then calls
  189.           `finish()'.  This enables the normal invocation of
  190.           `finish(0)' to wrap up a string being grown
  191.           character-by-character.
  192.  
  193.   5. There are special versions of grow(const char* s) and copy(const
  194.      char* s) that add the null-terminated string `s' after computing
  195.      its length.
  196.  
  197.   6. The shrink and contains functions are provided.
  198.  
  199. 
  200. File: libg++.info,  Node: AllocRing,  Next: String,  Prev: Obstack,  Up: Top
  201.  
  202. The AllocRing class
  203. *******************
  204.  
  205.    An AllocRing is a bounded ring (circular list), each of whose
  206. elements contains a pointer to some space allocated via `new
  207. char[some_size]'. The entries are used cyclicly.  The size, n, of the
  208. ring is fixed at construction. After that, every nth use of the ring
  209. will reuse (or reallocate) the same space. AllocRings are needed in
  210. order to temporarily hold chunks of space that are needed transiently,
  211. but across constructor-destructor scopes. They mainly useful for
  212. storing strings containing formatted characters to print acrosss
  213. various functions and coercions. These strings are needed across
  214. routines, so may not be deleted in any one of them, but should be
  215. recovered at some point. In other words, an AllocRing is an extremely
  216. simple minded garbage collection mechanism. The GNU C++ library used
  217. to use one AllocRing for such formatting purposes, but it is being
  218. phased out, and is now only used by obsolete functions.  These days,
  219. AllocRings are probably not very useful.
  220.  
  221.    Support includes:
  222.  
  223. `AllocRing a(int n)'
  224.      constructs an Alloc ring with n entries, all null.
  225.  
  226. `void* mem = a.alloc(sz)'
  227.      moves the ring pointer to the next entry, and reuses the space if
  228.      their is enough, also allocates space via new char[sz].
  229.  
  230. `int present = a.contains(void* ptr)'
  231.      returns true if ptr is held in one of the ring entries.
  232.  
  233. `a.clear()'
  234.      deletes all space pointed to in any entry. This is called
  235.      automatically upon destruction.
  236.  
  237. `a.free(void* ptr)'
  238.      If ptr is one of the entries, calls delete of the pointer, and
  239.      resets to entry pointer to null.
  240.  
  241. 
  242. File: libg++.info,  Node: String,  Next: Integer,  Prev: AllocRing,  Up: Top
  243.  
  244. The String class
  245. ****************
  246.  
  247.    The `String' class is designed to extend GNU C++ to support string
  248. processing capabilities similar to those in languages like Awk.  The
  249. class provides facilities that ought to be convenient and efficient
  250. enough to be useful replacements for `char*' based processing via the
  251. C string library (i.e., `strcpy, strcmp,' etc.) in many applications.
  252. Many details about String representations are described in the
  253. Representation section.
  254.  
  255.    A separate `SubString' class supports substring extraction and
  256. modification operations. This is implemented in a way that user
  257. programs never directly construct or represent substrings, which are
  258. only used indirectly via String operations.
  259.  
  260.    Another separate class, `Regex' is also used indirectly via String
  261. operations in support of regular expression searching, matching, and
  262. the like.  The Regex class is based entirely on the GNU Emacs regex
  263. functions.  *Note Syntax of Regular Expressions: (emacs.info)Regexps,
  264. for a full explanation of regular expression syntax.  (For
  265. implementation details, see the internal documentation in files
  266. `regex.h' and `regex.c'.)
  267.  
  268. Constructors
  269. ============
  270.  
  271.    Strings are initialized and assigned as in the following examples:
  272.  
  273. `String x;  String y = 0; String z = "";'
  274.      Set x, y, and z to the nil string. Note that either 0 or "" may
  275.      always be used to refer to the nil string.
  276.  
  277. `String x = "Hello"; String y("Hello");'
  278.      Set x and y to a copy of the string "Hello".
  279.  
  280. `String x = 'A'; String y('A');'
  281.      Set x and y to the string value "A"
  282.  
  283. `String u = x; String v(x);'
  284.      Set u and v to the same string as String x
  285.  
  286. `String u = x.at(1,4); String v(x.at(1,4));'
  287.      Set u and v to the length 4 substring of x starting at position 1
  288.      (counting indexes from 0).
  289.  
  290. `String x("abc", 2);'
  291.      Sets x to "ab", i.e., the first 2 characters of "abc".
  292.  
  293. `String x = dec(20);'
  294.      Sets x to "20". As here, Strings may be initialized or assigned
  295.      the results of any `char*' function.
  296.  
  297.    There are no directly accessible forms for declaring SubString
  298. variables.
  299.  
  300.    The declaration `Regex r("[a-zA-Z_][a-zA-Z0-9_]*");' creates a
  301. compiled regular expression suitable for use in String operations
  302. described below. (In this case, one that matches any C++ identifier).
  303. The first argument may also be a String.  Be careful in distinguishing
  304. the role of backslashes in quoted GNU C++ char* constants versus those
  305. in Regexes. For example, a Regex that matches either one or more tabs
  306. or all strings beginning with "ba" and ending with any number of
  307. occurrences of "na" could be declared as `Regex r =
  308. "\\(\t+\\)\\|\\(ba\\(na\\)*\\)"' Note that only one backslash is
  309. needed to signify the tab, but two are needed for the parenthesization
  310. and virgule, since the GNU C++ lexical analyzer decodes and strips
  311. backslashes before they are seen by Regex.
  312.  
  313.    There are three additional optional arguments to the Regex
  314. constructor that are less commonly useful:
  315.  
  316. `fast (default 0)'
  317.      `fast' may be set to true (1) if the Regex should be
  318.      "fast-compiled". This causes an additional compilation step that
  319.      is generally worthwhile if the Regex will be used many times.
  320.  
  321. `bufsize (default max(40, length of the string))'
  322.      This is an estimate of the size of the internal compiled
  323.      expression. Set it to a larger value if you know that the
  324.      expression will require a lot of space. If you do not know, do
  325.      not worry: realloc is used if necessary.
  326.  
  327. `transtable (default none == 0)'
  328.      The address of a byte translation table (a char[256]) that
  329.      translates each character before matching.
  330.  
  331.    As a convenience, several Regexes are predefined and usable in any
  332. program. Here are their declarations from `String.h'.
  333.  
  334.      extern Regex RXwhite;      // = "[ \n\t]+"
  335.      extern Regex RXint;        // = "-?[0-9]+"
  336.      extern Regex RXdouble;     // = "-?\\(\\([0-9]+\\.[0-9]*\\)\\|
  337.                                 //    \\([0-9]+\\)\\|
  338.                                 //    \\(\\.[0-9]+\\)\\)
  339.                                 //    \\([eE][---+]?[0-9]+\\)?"
  340.      extern Regex RXalpha;      // = "[A-Za-z]+"
  341.      extern Regex RXlowercase;  // = "[a-z]+"
  342.      extern Regex RXuppercase;  // = "[A-Z]+"
  343.      extern Regex RXalphanum;   // = "[0-9A-Za-z]+"
  344.      extern Regex RXidentifier; // = "[A-Za-z_][A-Za-z0-9_]*"
  345.  
  346. Examples
  347. ========
  348.  
  349.    Most `String' class capabilities are best shown via example.  The
  350. examples below use the following declarations.
  351.  
  352.          String x = "Hello";
  353.          String y = "world";
  354.          String n = "123";
  355.          String z;
  356.          char*  s = ",";
  357.          String lft, mid, rgt;
  358.          Regex  r = "e[a-z]*o";
  359.          Regex  r2("/[a-z]*/");
  360.          char   c;
  361.          int    i, pos, len;
  362.          double f;
  363.          String words[10];
  364.          words[0] = "a";
  365.          words[1] = "b";
  366.          words[2] = "c";
  367.  
  368. Comparing, Searching and Matching
  369. =================================
  370.  
  371.    The usual lexicographic relational operators (`==, !=, <, <=, >,
  372. >=') are defined. A functional form `compare(String, String)' is also
  373. provided, as is `fcompare(String, String)', which compares Strings
  374. without regard for upper vs. lower case.
  375.  
  376.    All other matching and searching operations are based on some form
  377. of the (non-public) `match' and `search' functions.  `match' and
  378. `search' differ in that `match' attempts to match only at the given
  379. starting position, while `search' starts at the position, and then
  380. proceeds left or right looking for a match.  As seen in the following
  381. examples, the second optional `startpos' argument to functions using
  382. `match' and `search' specifies the starting position of the search: If
  383. non-negative, it results in a left-to-right search starting at
  384. position `startpos', and if negative, a right-to-left search starting
  385. at position `x.length() + startpos'. In all cases, the index returned
  386. is that of the beginning of the match, or -1 if there is no match.
  387.  
  388.    Three String functions serve as front ends to `search' and `match'. 
  389. `index' performs a search, returning the index, `matches' performs a
  390. match, returning nonzero (actually, the length of the match) on
  391. success, and `contains' is a boolean function performing either a
  392. search or match, depending on whether an index argument is provided:
  393.  
  394. `x.index("lo")'
  395.      returns the zero-based index of the leftmost occurrence of
  396.      substring "lo" (3, in this case).  The argument may be a String,
  397.      SubString, char, char*, or Regex.
  398.  
  399. `x.index("l", 2)'
  400.      returns the index of the first of the leftmost occurrence of "l"
  401.      found starting the search at position x[2], or 2 in this case.
  402.  
  403. `x.index("l", -1)'
  404.      returns the index of the rightmost occurrence of "l", or 3 here.
  405.  
  406. `x.index("l", -3)'
  407.      returns the index of the rightmost occurrence of "l" found by
  408.      starting the search at the 3rd to the last position of x,
  409.      returning 2 in this case.
  410.  
  411. `pos = r.search("leo", 3, len, 0)'
  412.      returns the index of r in the `char*' string of length 3,
  413.      starting at position 0, also placing the  length of the match in
  414.      reference parameter len.
  415.  
  416. `x.contains("He")'
  417.      returns nonzero if the String x contains the substring "He". The
  418.      argument may be a String, SubString, char, char*, or Regex.
  419.  
  420. `x.contains("el", 1)'
  421.      returns nonzero if x contains the substring "el" at position 1. 
  422.      As in this example, the second argument to `contains', if
  423.      present, means to match the substring only at that position, and
  424.      not to search elsewhere in the string.
  425.  
  426. `x.contains(RXwhite);'
  427.      returns nonzero if x contains any whitespace (space, tab, or
  428.      newline). Recall that `RXwhite' is a global whitespace Regex.
  429.  
  430. `x.matches("lo", 3)'
  431.      returns nonzero if x starting at position 3 exactly matches "lo",
  432.      with no trailing characters (as it does in this example).
  433.  
  434. `x.matches(r)'
  435.      returns nonzero if String x as a whole matches Regex r.
  436.  
  437. `int f = x.freq("l")'
  438.      returns the number of distinct, nonoverlapping matches to the
  439.      argument (2 in this case).
  440.  
  441. Substring extraction
  442. ====================
  443.  
  444.    Substrings may be extracted via the `at', `before', `through',
  445. `from', and `after' functions.  These behave as either lvalues or
  446. rvalues.
  447.  
  448. `z = x.at(2, 3)'
  449.      sets String z to be equal to the length 3 substring of String x
  450.      starting at zero-based position 2, setting z to "llo" in this
  451.      case. A nil String is returned if the arguments don't make sense.
  452.  
  453. `x.at(2, 2) = "r"'
  454.      Sets what was in positions 2 to 3 of x to "r", setting x to
  455.      "Hero" in this case. As indicated here, SubString assignments may
  456.      be of different lengths.
  457.  
  458. `x.at("He") = "je";'
  459.      x("He") is the substring of x that matches the first occurrence of
  460.      it's argument. The substitution sets x to "jello". If "He" did
  461.      not occur, the substring would be nil, and the assignment would
  462.      have no effect.
  463.  
  464. `x.at("l", -1) = "i";'
  465.      replaces the rightmost occurrence of "l" with "i", setting x to
  466.      "Helio".
  467.  
  468. `z = x.at(r)'
  469.      sets String z to the first match in x of Regex r, or "ello" in
  470.      this case. A nil String is returned if there is no match.
  471.  
  472. `z = x.before("o")'
  473.      sets z to the part of x to the left of the first occurrence of
  474.      "o", or "Hell" in this case. The argument may also be a String,
  475.      SubString, or Regex.  (If there is no match, z is set to "".)
  476.  
  477. `x.before("ll") = "Bri";'
  478.      sets the part of x to the left of "ll" to "Bri", setting x to
  479.      "Brillo".
  480.  
  481. `z = x.before(2)'
  482.      sets z to the part of x to the left of x[2], or "He" in this case.
  483.  
  484. `z = x.after("Hel")'
  485.      sets z to the part of x to the right of "Hel", or "lo" in this
  486.      case.
  487.  
  488. `z = x.through("el")'
  489.      sets z to the part of x up and including "el", or "Hel" in this
  490.      case.
  491.  
  492. `z = x.from("el")'
  493.      sets z to the part of x from "el" to the end, or "ello" in this
  494.      case.
  495.  
  496. `x.after("Hel") = "p";'
  497.      sets x to "Help";
  498.  
  499. `z = x.after(3)'
  500.      sets z to the part of x to the right of x[3] or "o" in this case.
  501.  
  502. `z = "  ab c"; z = z.after(RXwhite)'
  503.      sets z to the part of its old string to the right of the first
  504.      group of whitespace, setting z to "ab c"; Use gsub(below) to
  505.      strip out multiple occurrences of whitespace or any pattern.
  506.  
  507. `x[0] = 'J';'
  508.      sets the first element of x to 'J'. x[i] returns a reference to
  509.      the ith element of x, or triggers an error if i is out of range.
  510.  
  511. `common_prefix(x, "Help")'
  512.      returns the String containing the common prefix of the two Strings
  513.      or "Hel" in this case.
  514.  
  515. `common_suffix(x, "to")'
  516.      returns the String containing the common suffix of the two Strings
  517.      or "o" in this case.
  518.  
  519. Concatenation
  520. =============
  521.  
  522. `z = x + s + ' ' + y.at("w") + y.after("w") + ".";'
  523.      sets z to "Hello, world."
  524.  
  525. `x += y;'
  526.      sets x to "Helloworld"
  527.  
  528. `cat(x, y, z)'
  529.      A faster way to say z = x + y.
  530.  
  531. `cat(z, y, x, x)'
  532.      Double concatenation; A faster way to say x = z + y + x.
  533.  
  534. `y.prepend(x);'
  535.      A faster way to say y = x + y.
  536.  
  537. `z = replicate(x, 3);'
  538.      sets z to "HelloHelloHello".
  539.  
  540. `z = join(words, 3, "/")'
  541.      sets z to the concatenation of the first 3 Strings in String
  542.      array words, each separated by "/", setting z to "a/b/c" in this
  543.      case.  The last argument may be "" or 0, indicating no separation.
  544.  
  545. Other manipulations
  546. ===================
  547.  
  548. `z = "this string has five words"; i = split(z, words, 10, RXwhite);'
  549.      sets up to 10 elements of String array words to the parts of z
  550.      separated by whitespace, and returns the number of parts actually
  551.      encountered (5 in this case). Here, words[0] = "this", words[1] =
  552.      "string", etc.  The last argument may be any of the usual.  If
  553.      there is no match, all of z ends up in words[0]. The words array
  554.      is *not* dynamically created by split.
  555.  
  556. `int nmatches x.gsub("l","ll")'
  557.      substitutes all original occurrences of "l" with "ll", setting x
  558.      to "Hellllo". The first argument may be any of the usual,
  559.      including Regex.  If the second argument is "" or 0, all
  560.      occurrences are deleted. gsub returns the number of matches that
  561.      were replaced.
  562.  
  563. `z = x + y;  z.del("loworl");'
  564.      deletes the leftmost occurrence of "loworl" in z, setting z to
  565.      "Held".
  566.  
  567. `z = reverse(x)'
  568.      sets z to the reverse of x, or "olleH".
  569.  
  570. `z = upcase(x)'
  571.      sets z to x, with all letters set to uppercase, setting z to
  572.      "HELLO"
  573.  
  574. `z = downcase(x)'
  575.      sets z to x, with all letters set to lowercase, setting z to
  576.      "hello"
  577.  
  578. `z = capitalize(x)'
  579.      sets z to x, with the first letter of each word set to uppercase,
  580.      and all others to lowercase, setting z to "Hello"
  581.  
  582. `x.reverse(), x.upcase(), x.downcase(), x.capitalize()'
  583.      in-place, self-modifying versions of the above.
  584.  
  585. Reading, Writing and Conversion
  586. ===============================
  587.  
  588. `cout << x'
  589.      writes out x.
  590.  
  591. `cout << x.at(2, 3)'
  592.      writes out the substring "llo".
  593.  
  594. `cin >> x'
  595.      reads a whitespace-bounded string into x.
  596.  
  597. `x.length()'
  598.      returns the length of String x (5, in this case).
  599.  
  600. `s = (const char*)x'
  601.      can be used to extract the `char*' char array. This coercion is
  602.      useful for sending a String as an argument to any function
  603.      expecting a `const char*' argument (like `atoi', and
  604.      `File::open'). This operator must be used with care, since the
  605.      conversion returns a pointer to `String' internals without
  606.      copying the characters: The resulting `(char*)' is only valid
  607.      until the next String operation,  and you must not modify it. 
  608.      (The conversion is defined to return a const value so that GNU
  609.      C++ will produce warning and/or error messages if changes are
  610.      attempted.)
  611.  
  612. 
  613. File: libg++.info,  Node: Integer,  Next: Rational,  Prev: String,  Up: Top
  614.  
  615. The Integer class.
  616. ******************
  617.  
  618.    The `Integer' class provides multiple precision integer arithmetic
  619. facilities. Some representation details are discussed in the
  620. Representation section.
  621.  
  622.    `Integers' may be up to `b * ((1 << b) - 1)' bits long, where `b'
  623. is the number of bits per short (typically 1048560 bits when `b =
  624. 16').  The implementation assumes that a `long' is at least twice as
  625. long as a `short'. This assumption hides beneath almost all primitive
  626. operations, and would be very difficult to change. It also relies on
  627. correct behavior of *unsigned* arithmetic operations.
  628.  
  629.    Some of the arithmetic algorithms are very loosely based on those
  630. provided in the MIT Scheme `bignum.c' release, which is Copyright (c)
  631. 1987 Massachusetts Institute of Technology. Their use here falls
  632. within the provisions described in the Scheme release.
  633.  
  634.    Integers may be constructed in the following ways:
  635.  
  636. `Integer x;'
  637.      Declares an uninitialized Integer.
  638.  
  639. `Integer x = 2; Integer y(2);'
  640.      Set x and y to the Integer value 2;
  641.  
  642. `Integer u(x); Integer v = x;'
  643.      Set u and v to the same value as x.
  644.  
  645.    `Integers' may be coerced back into longs via the `long' coercion
  646. operator. If the Integer cannot fit into a long, this returns MINLONG
  647. or MAXLONG (depending on the sign) where MINLONG is the most negative,
  648. and MAXLONG is the most positive representable long.  The member
  649. function `fits_in_long()' may be used to test this.  `Integers' may
  650. also be coerced into `doubles', with potential loss of precision.
  651. `+/-HUGE' is returned if the Integer cannot fit into a double.
  652. `fits_in_double()' may be used to test this.
  653.  
  654.    All of the usual arithmetic operators are provided (`+, -, *, /, %,
  655. +=, ++, -=, --, *=, /=, %=, ==, !=, <, <=, >, >=').  All operators
  656. support special versions for mixed arguments of Integers and regular
  657. C++ longs in order to avoid useless coercions, as well as to allow
  658. automatic promotion of shorts and ints to longs, so that they may be
  659. applied without additional Integer coercion operators.  The only
  660. operators that behave differently than the corresponding int or long
  661. operators are `++' and `--'.  Because C++ does not distinguish prefix
  662. from postfix application, these are declared as `void' operators, so
  663. that no confusion can result from applying them as postfix.  Thus, for
  664. Integers x and y, ` ++x; y = x; ' is correct, but ` y = ++x; ' and ` y
  665. = x++; ' are not.
  666.  
  667.    Bitwise operators (`~', `&', `|', `^', `<<', `>>', `&=', `|=',
  668. `^=', `<<=', `>>=') are also provided.  However, these operate on
  669. sign-magnitude, rather than two's complement representations. The sign
  670. of the result is arbitrarily taken as the sign of the first argument.
  671. For example, `Integer(-3) & Integer(5)' returns `Integer(-1)', not -3,
  672. as it would using two's complement. Also, `~', the complement
  673. operator, complements only those bits needed for the representation. 
  674. Bit operators are also provided in the BitSet and BitString classes.
  675. One of these classes should be used instead of Integers when the
  676. results of bit manipulations are not interpreted numerically.
  677.  
  678.    The following utility functions are also provided. (All arguments
  679. are Integers unless otherwise noted).
  680.  
  681. `void divide(x, y, q, r);'
  682.      Sets q to the quotient and r to the remainder of x and y.  (q and
  683.      r are returned by reference).
  684.  
  685. `Integer pow(Integer x, Integer p)'
  686.      returns x raised to the power p.
  687.  
  688. `Integer Ipow(long x, long p)'
  689.      returns x raised to the power p.
  690.  
  691. `Integer gcd(x, y)'
  692.      returns the greatest common divisor of x and y.
  693.  
  694. `Integer lcm(x, y)'
  695.      returns the least common multiple of x and y.
  696.  
  697. `Integer abs(x);'
  698.      returns the absolute value of x.
  699.  
  700. `void x.negate();'
  701.      negates x.
  702.  
  703. `Integer sqr(x)'
  704.      returns x * x;
  705.  
  706. `Integer sqrt(x)'
  707.      returns the floor of the  square root of x.
  708.  
  709. `long lg(x);'
  710.      returns the floor of the base 2 logarithm of abs(x)
  711.  
  712. `int sign(x)'
  713.      returns -1 if x is negative, 0 if zero, else +1.  Using `if
  714.      (sign(x) == 0)' is a generally faster method of testing for zero
  715.      than using relational operators.
  716.  
  717. `int even(x)'
  718.      returns true if x is an even number
  719.  
  720. `int odd(x)'
  721.      returns true if x is an odd number.
  722.  
  723. `void setbit(Integer& x, long b)'
  724.      sets the b'th bit (counting right-to-left from zero) of x to 1.
  725.  
  726. `void clearbit(Integer& x, long b)'
  727.      sets the b'th bit of x to 0.
  728.  
  729. `int testbit(Integer x, long b)'
  730.      returns true if the b'th bit of x is 1.
  731.  
  732. `Integer atoI(char* asciinumber, int base = 10);'
  733.      converts the base base char* string into its Integer form.
  734.  
  735. `void Integer::printon(ostream& s, int base = 10, int width = 0);'
  736.      prints the ascii string value of `(*this)' as a base `base'
  737.      number, in field width at least `width'.
  738.  
  739. `ostream << x;'
  740.      prints x in base ten format.
  741.  
  742. `istream >> x;'
  743.      reads x as a base ten number.
  744.  
  745. `int compare(Integer x, Integer y)'
  746.      returns a negative number if x<y, zero if x==y, or positive if
  747.      x>y.
  748.  
  749. `int ucompare(Integer x, Integer y)'
  750.      like compare, but performs unsigned comparison.
  751.  
  752. `add(x, y, z)'
  753.      A faster way to say z = x + y.
  754.  
  755. `sub(x, y, z)'
  756.      A faster way to say z = x - y.
  757.  
  758. `mul(x, y, z)'
  759.      A faster way to say z = x * y.
  760.  
  761. `div(x, y, z)'
  762.      A faster way to say z = x / y.
  763.  
  764. `mod(x, y, z)'
  765.      A faster way to say z = x % y.
  766.  
  767. `and(x, y, z)'
  768.      A faster way to say z = x & y.
  769.  
  770. `or(x, y, z)'
  771.      A faster way to say z = x | y.
  772.  
  773. `xor(x, y, z)'
  774.      A faster way to say z = x ^ y.
  775.  
  776. `lshift(x, y, z)'
  777.      A faster way to say z = x << y.
  778.  
  779. `rshift(x, y, z)'
  780.      A faster way to say z = x >> y.
  781.  
  782. `pow(x, y, z)'
  783.      A faster way to say z = pow(x, y).
  784.  
  785. `complement(x, z)'
  786.      A faster way to say z = ~x.
  787.  
  788. `negate(x, z)'
  789.      A faster way to say z = -x.
  790.  
  791. 
  792. File: libg++.info,  Node: Rational,  Next: Complex,  Prev: Integer,  Up: Top
  793.  
  794. The Rational Class
  795. ******************
  796.  
  797.    Class `Rational' provides multiple precision rational number
  798. arithmetic. All rationals are maintained in simplest form (i.e., with
  799. the numerator and denominator relatively prime, and with the
  800. denominator strictly positive).  Rational arithmetic and relational
  801. operators are provided (`+, -, *, /, +=, -=, *=, /=, ==, !=, <, <=, >,
  802. >=').  Operations resulting in a rational number with zero denominator
  803. trigger an exception.
  804.  
  805.    Rationals may be constructed and used in the following ways:
  806.  
  807. `Rational x;'
  808.      Declares an uninitialized Rational.
  809.  
  810. `Rational x = 2; Rational y(2);'
  811.      Set x and y to the Rational value 2/1;
  812.  
  813. `Rational x(2, 3);'
  814.      Sets x to the Rational value 2/3;
  815.  
  816. `Rational x = 1.2;'
  817.      Sets x to a Rational value close to 1.2. Any double precision
  818.      value may be used to construct a Rational. The Rational will
  819.      possess exactly as much precision as the double. Double values
  820.      that do not have precise floating point equivalents (like 1.2)
  821.      produce similarly imprecise rational values.
  822.  
  823. `Rational x(Integer(123), Integer(4567));'
  824.      Sets x to the Rational value 123/4567.
  825.  
  826. `Rational u(x); Rational v = x;'
  827.      Set u and v to the same value as x.
  828.  
  829. `double(Rational x)'
  830.      A Rational may be coerced to a double with potential loss of
  831.      precision. +/-HUGE is returned if it will not fit.
  832.  
  833. `Rational abs(x)'
  834.      returns the absolute value of x.
  835.  
  836. `void x.negate()'
  837.      negates x.
  838.  
  839. `void x.invert()'
  840.      sets x to 1/x.
  841.  
  842. `int sign(x)'
  843.      returns 0 if x is zero, 1 if positive, and -1 if negative.
  844.  
  845. `Rational sqr(x)'
  846.      returns x * x.
  847.  
  848. `Rational pow(x, Integer y)'
  849.      returns x to the y power.
  850.  
  851. `Integer x.numerator()'
  852.      returns the numerator.
  853.  
  854. `Integer x.denominator()'
  855.      returns the denominator.
  856.  
  857. `Integer floor(x)'
  858.      returns the greatest Integer less than x.
  859.  
  860. `Integer ceil(x)'
  861.      returns the least Integer greater than x.
  862.  
  863. `Integer trunc(x)'
  864.      returns the Integer part of x.
  865.  
  866. `Integer round(x)'
  867.      returns the nearest Integer to x.
  868.  
  869. `int compare(x, y)'
  870.      returns a negative, zero, or positive number signifying whether x
  871.      is less than, equal to, or greater than y.
  872.  
  873. `ostream << x;'
  874.      prints x in the form num/den, or just num if the denominator is
  875.      one.
  876.  
  877. `istream >> x;'
  878.      reads x in the form num/den, or just num in which case the
  879.      denominator is set to one.
  880.  
  881. `add(x, y, z)'
  882.      A faster way to say z = x + y.
  883.  
  884. `sub(x, y, z)'
  885.      A faster way to say z = x - y.
  886.  
  887. `mul(x, y, z)'
  888.      A faster way to say z = x * y.
  889.  
  890. `div(x, y, z)'
  891.      A faster way to say z = x / y.
  892.  
  893. `pow(x, y, z)'
  894.      A faster way to say z = pow(x, y).
  895.  
  896. `negate(x, z)'
  897.      A faster way to say z = -x.
  898.  
  899. 
  900. File: libg++.info,  Node: Complex,  Next: Fix,  Prev: Rational,  Up: Top
  901.  
  902. The Complex class.
  903. ******************
  904.  
  905.    Class `Complex' is implemented in a way similar to that described
  906. by Stroustrup. In keeping with libg++ conventions, the class is named
  907. `Complex', not `complex'.  Complex arithmetic and relational operators
  908. are provided (`+, -, *, /, +=, -=, *=, /=, ==, !=').  Attempted
  909. division by (0, 0) triggers an exception.
  910.  
  911.    Complex numbers may be constructed and used in the following ways:
  912.  
  913. `Complex x;'
  914.      Declares an uninitialized Complex.
  915.  
  916. `Complex x = 2; Complex y(2.0);'
  917.      Set x and y to the Complex value (2.0, 0.0);
  918.  
  919. `Complex x(2, 3);'
  920.      Sets x to the Complex value (2, 3);
  921.  
  922. `Complex u(x); Complex v = x;'
  923.      Set u and v to the same value as x.
  924.  
  925. `double real(Complex& x);'
  926.      returns the real part of x.
  927.  
  928. `double imag(Complex& x);'
  929.      returns the imaginary part of x.
  930.  
  931. `double abs(Complex& x);'
  932.      returns the magnitude of x.
  933.  
  934. `double norm(Complex& x);'
  935.      returns the square of the magnitude of x.
  936.  
  937. `double arg(Complex& x);'
  938.      returns the argument (amplitude) of x.
  939.  
  940. `Complex polar(double r, double t = 0.0);'
  941.      returns a Complex with abs of r and arg of t.
  942.  
  943. `Complex conj(Complex& x);'
  944.      returns the complex conjugate of x.
  945.  
  946. `Complex cos(Complex& x);'
  947.      returns the complex cosine of x.
  948.  
  949. `Complex sin(Complex& x);'
  950.      returns the complex sine of x.
  951.  
  952. `Complex cosh(Complex& x);'
  953.      returns the complex hyperbolic cosine of x.
  954.  
  955. `Complex sinh(Complex& x);'
  956.      returns the complex hyperbolic sine of x.
  957.  
  958. `Complex exp(Complex& x);'
  959.      returns the exponential of x.
  960.  
  961. `Complex log(Complex& x);'
  962.      returns the natural log of x.
  963.  
  964. `Complex pow(Complex& x, long p);'
  965.      returns x raised to the p power.
  966.  
  967. `Complex pow(Complex& x, Complex& p);'
  968.      returns x raised to the p power.
  969.  
  970. `Complex sqrt(Complex& x);'
  971.      returns the square root of x.
  972.  
  973. `ostream << x;'
  974.      prints x in the form (re, im).
  975.  
  976. `istream >> x;'
  977.      reads x in the form (re, im), or just (re) or re in which case the
  978.      imaginary part is set to zero.
  979.  
  980. 
  981. File: libg++.info,  Node: Fix,  Next: Bit,  Prev: Complex,  Up: Top
  982.  
  983. Fixed precision numbers
  984. ***********************
  985.  
  986.    Classes `Fix16', `Fix24', `Fix32', and `Fix48' support operations
  987. on 16, 24, 32, or 48 bit quantities that are considered as real
  988. numbers in the range [-1, +1).  Such numbers are often encountered in
  989. digital signal processing applications. The classes may be be used in
  990. isolation or together.  Class `Fix32' operations are entirely
  991. self-contained.  Class `Fix16' operations are self-contained except
  992. that the multiplication operation `Fix16 * Fix16' returns a `Fix32'.
  993. `Fix24' and `Fix48' are similarly related.
  994.  
  995.    The standard arithmetic and relational operations are supported
  996. (`=', `+', `-', `*', `/', `<<', `>>', `+=', `-=', `*=', `/=', `<<=',
  997. `>>=', `==', `!=', `<', `<=', `>', `>=').  All operations include
  998. provisions for special handling in cases where the result exceeds +/-
  999. 1.0. There are two cases that may be handled separately: "overflow"
  1000. where the results of addition and subtraction operations go out of
  1001. range, and all other "range errors" in which resulting values go
  1002. off-scale (as with division operations, and assignment or
  1003. initialization with off-scale values). In signal processing
  1004. applications, it is often useful to handle these two cases
  1005. differently. Handlers take one argument, a reference to the integer
  1006. mantissa of the offending value, which may then be manipulated.  In
  1007. cases of overflow, this value is the result of the (integer) arithmetic
  1008. computation on the mantissa; in others it is a fully saturated (i.e.,
  1009. most positive or most negative) value. Handling may be reset to any of
  1010. several provided functions or any other user-defined function via
  1011. `set_overflow_handler' and `set_range_error_handler'. The provided
  1012. functions for `Fix16' are as follows (corresponding functions are also
  1013. supported for the others).
  1014.  
  1015. `Fix16_overflow_saturate'
  1016.      The default overflow handler. Results are "saturated": positive
  1017.      results are set to the largest representable value (binary
  1018.      0.111111...), and negative values to -1.0.
  1019.  
  1020. `Fix16_ignore'
  1021.      Performs no action. For overflow, this will allow addition and
  1022.      subtraction operations to "wrap around" in the same manner as
  1023.      integer arithmetic, and for saturation, will leave values
  1024.      saturated.
  1025.  
  1026. `Fix16_overflow_warning_saturate'
  1027.      Prints a warning message on standard error, then saturates the
  1028.      results.
  1029.  
  1030. `Fix16_warning'
  1031.      The default range_error handler. Prints a warning message on
  1032.      standard error; otherwise leaving the argument unmodified.
  1033.  
  1034. `Fix16_abort'
  1035.      prints an error message on standard error, then aborts execution.
  1036.  
  1037.    In addition to arithmetic operations, the following are provided:
  1038.  
  1039. `Fix16 a = 0.5;'
  1040.      Constructs fixed precision objects from double precision values. 
  1041.      Attempting to initialize to a value outside the range invokes the
  1042.      range_error handler, except, as a convenience, initialization to
  1043.      1.0 sets the variable to the most positive representable value
  1044.      (binary 0.1111111...) without invoking the handler.
  1045.  
  1046. `short& mantissa(a); long& mantissa(b);'
  1047.      return a * pow(2, 15) or b * pow(2, 31) as an integer. These are
  1048.      returned by reference, to enable "manual" data manipulation.
  1049.  
  1050. `double value(a); double value(b);'
  1051.      return a or b as floating point numbers.
  1052.  
  1053. 
  1054. File: libg++.info,  Node: Bit,  Next: Random,  Prev: Fix,  Up: Top
  1055.  
  1056. Classes for Bit manipulation
  1057. ****************************
  1058.  
  1059.    libg++ provides several different classes supporting the use and
  1060. manipulation of collections of bits in different ways.
  1061.  
  1062.    * Class `Integer' provides "integer" semantics. It supports
  1063.      manipulation of bits in ways that are often useful when treating
  1064.      bit arrays as numerical (integer) quantities.  This class is
  1065.      described elsewhere.
  1066.  
  1067.    * Class `BitSet' provides "set" semantics. It supports operations
  1068.      useful when treating collections of bits as representing
  1069.      potentially infinite sets of integers.
  1070.  
  1071.    * Class `BitSet32' supports fixed-length BitSets holding exactly 32
  1072.      bits.
  1073.  
  1074.    * Class `Bitset256'supports fixed-length BitSets holding exactly
  1075.      256 bits.
  1076.  
  1077.    * Class `BitString' provides "string" (or "vector") semantics.  It
  1078.      supports operations useful when treating collections of bits as
  1079.      strings of zeros and ones.
  1080.  
  1081.    These classes also differ in the following ways:
  1082.  
  1083.    * BitSets are logically infinite. Their space is dynamically
  1084.      altered to adjust to the smallest number of consecutive bits
  1085.      actually required to represent the sets. Integers also have this
  1086.      property. BitStrings are logically finite, but their sizes are
  1087.      internally dynamically managed to maintain proper length. This
  1088.      means that, for example, BitStrings are concatenatable while
  1089.      BitSets and Integers are not.
  1090.  
  1091.    * BitSet32 and BitSet256 have precisely the same properties as
  1092.      BitSets, except that they use constant fixed length bit vectors.
  1093.  
  1094.    * While all classes support basic unary and binary operations `~, &,
  1095.      |, ^, -', the semantics differ. BitSets perform bit operations
  1096.      that precisely mirror those for infinite sets. For example,
  1097.      complementing an empty BitSet returns one representing an
  1098.      infinite number of set bits.  Operations on BitStrings and
  1099.      Integers operate only on those bits actually present in the
  1100.      representation.  For BitStrings and Integers, the the `&'
  1101.      operation returns a BitString with a length equal to the minimum
  1102.      length of the operands, and `|, ^' return one with length of the
  1103.      maximum.
  1104.  
  1105.    * Only BitStrings support substring extraction and bit pattern
  1106.      matching.
  1107.  
  1108. BitSet
  1109. ======
  1110.  
  1111.    Bitsets are objects that contain logically infinite sets of
  1112. nonnegative integers.  Representational details are discussed in the
  1113. Representation chapter. Because they are logically infinite, all
  1114. BitSets possess a trailing, infinitely replicated 0 or 1 bit, called
  1115. the "virtual bit", and indicated via 0* or 1*.
  1116.  
  1117.    BitSet32 and BitSet256 have they same properties, except they are
  1118. of fixed length, and thus have no virtual bit.
  1119.  
  1120.    BitSets may be constructed as follows:
  1121.  
  1122. `BitSet a;'
  1123.      declares an empty BitSet.
  1124.  
  1125. `BitSet a = atoBitSet("001000");'
  1126.      sets a to the BitSet 0010*, reading left-to-right. The "0*"
  1127.      indicates that the set ends with an infinite number of zero
  1128.      (clear) bits.
  1129.  
  1130. `BitSet a = atoBitSet("00101*");'
  1131.      sets a to the BitSet 00101*, where "1*" means that the set ends
  1132.      with an infinite number of one (set) bits.
  1133.  
  1134. `BitSet a = longtoBitSet((long)23);'
  1135.      sets a to the BitSet 111010*, the binary representation of
  1136.      decimal 23.
  1137.  
  1138. `BitSet a = utoBitSet((unsigned)23);'
  1139.      sets a to the BitSet 111010*, the binary representation of
  1140.      decimal 23.
  1141.  
  1142.    The following functions and operators are provided (Assume the
  1143. declaration of BitSets a = 0011010*, b = 101101*, throughout, as
  1144. examples).
  1145.  
  1146. `~a'
  1147.      returns the complement of a, or 1100101* in this case.
  1148.  
  1149. `a.complement()'
  1150.      sets a to ~a.
  1151.  
  1152. `a & b; a &= b;'
  1153.      returns a intersected with b, or 0011010*.
  1154.  
  1155. `a | b; a |= b;'
  1156.      returns a unioned with b, or 1011111*.
  1157.  
  1158. `a - b; a -= b;'
  1159.      returns the set difference of a and b, or 000010*.
  1160.  
  1161. `a ^ b; a ^= b;'
  1162.      returns the symmetric difference of a and b, or 1000101*.
  1163.  
  1164. `a.empty()'
  1165.      returns true if a is an empty set.
  1166.  
  1167. `a == b;'
  1168.      returns true if a and b contain the same set.
  1169.  
  1170. `a <= b;'
  1171.      returns true if a is a subset of b.
  1172.  
  1173. `a < b;'
  1174.      returns true if a is a proper subset of b;
  1175.  
  1176. `a != b; a >= b; a > b;'
  1177.      are the converses of the above.
  1178.  
  1179. `a.set(7)'
  1180.      sets the 7th (counting from 0) bit of a, setting a to 001111010*
  1181.  
  1182. `a.clear(2)'
  1183.      clears the 2nd bit bit of a, setting a to 00011110*
  1184.  
  1185. `a.clear()'
  1186.      clears all bits of a;
  1187.  
  1188. `a.set()'
  1189.      sets all bits of a;
  1190.  
  1191. `a.invert(0)'
  1192.      complements the 0th bit of a, setting a to 10011110*
  1193.  
  1194. `a.set(0,1)'
  1195.      sets the 0th through 1st bits of a, setting a to 110111110* The
  1196.      two-argument versions of clear and invert are similar.
  1197.  
  1198. `a.test(3)'
  1199.      returns true if the 3rd bit of a is set.
  1200.  
  1201. `a.test(3, 5)'
  1202.      returns true if any of bits 3 through 5 are set.
  1203.  
  1204. `int i = a[3]; a[3] = 0;'
  1205.      The subscript operator allows bits to be inspected and changed
  1206.      via standard subscript semantics, using a friend class BitSetBit. 
  1207.      The use of the subscript operator a[i] rather than a.test(i)
  1208.      requires somewhat greater overhead.
  1209.  
  1210. `a.first(1) or a.first()'
  1211.      returns the index of the first set bit of a (2 in this case), or
  1212.      -1 if no bits are set.
  1213.  
  1214. `a.first(0)'
  1215.      returns the index of the first clear bit of a (0 in this case),
  1216.      or -1 if no bits are clear.
  1217.  
  1218. `a.next(2, 1) or a.next(2)'
  1219.      returns the index of the next bit after position 2 that is set (3
  1220.      in this case) or -1. `first' and `next' may be used as iterators,
  1221.      as in `for (int i = a.first(); i >= 0; i = a.next(i))...'.
  1222.  
  1223. `a.last(1)'
  1224.      returns the index of the rightmost set bit, or -1 if there or no
  1225.      set bits or all set bits.
  1226.  
  1227. `a.previous(3, 0)'
  1228.      returns the index of the previous clear bit before position 3.
  1229.  
  1230. `a.count(1)'
  1231.      returns the number of set bits in a, or -1 if there are an
  1232.      infinite number.
  1233.  
  1234. `a.virtual_bit()'
  1235.      returns the trailing (infinitely replicated) bit of a.
  1236.  
  1237. `a = atoBitSet("ababX", 'a', 'b', 'X');'
  1238.      converts the char* string into a bitset, with 'a' denoting false,
  1239.      'b' denoting true, and 'X' denoting infinite replication.
  1240.  
  1241. `a.printon(cout, '-', '.', 0)'
  1242.      prints `a' to `cout' represented with `'-'' for falses, `'.'' for
  1243.      trues, and no replication marker.
  1244.  
  1245. `cout << a'
  1246.      prints `a' to `cout' (representing lases by `'f'', trues by
  1247.      `'t'', and using `'*'' as the replication marker).
  1248.  
  1249. `diff(x, y, z)'
  1250.      A faster way to say z = x - y.
  1251.  
  1252. `and(x, y, z)'
  1253.      A faster way to say z = x & y.
  1254.  
  1255. `or(x, y, z)'
  1256.      A faster way to say z = x | y.
  1257.  
  1258. `xor(x, y, z)'
  1259.      A faster way to say z = x ^ y.
  1260.  
  1261. `complement(x, z)'
  1262.      A faster way to say z = ~x.
  1263.  
  1264. BitString
  1265. =========
  1266.  
  1267.    BitStrings are objects that contain arbitrary-length strings of
  1268. zeroes and ones. BitStrings possess some features that make them
  1269. behave like sets, and others that behave as strings. They are useful
  1270. in applications (such as signature-based algorithms) where both
  1271. capabilities are needed.  Representational details are discussed in
  1272. the Representation chapter.  Most capabilities are exact analogs of
  1273. those supported in the BitSet and String classes.  A BitSubString is
  1274. used with substring operations along the same lines as the String
  1275. SubString class.  A BitPattern class is used for masked bit pattern
  1276. searching.
  1277.  
  1278.    Only a default constructor is supported.  The declaration
  1279. `BitString a;' initializes a to be an empty BitString.  BitStrings may
  1280. often be initialized via `atoBitString' and `longtoBitString'.
  1281.  
  1282.    Set operations (` ~, complement, &, &=, |, |=, -, ^, ^=') behave
  1283. just as the BitSet versions, except that there is no "virtual bit":
  1284. complementing complements only those bits in the BitString, and all
  1285. binary operations across unequal length BitStrings assume a virtual
  1286. bit of zero. The `&' operation returns a BitString with a length equal
  1287. to the minimum length of the operands, and `|, ^' return one with
  1288. length of the maximum.
  1289.  
  1290.    Set-based relational operations (`==, !=, <=, <, >=, >') follow the
  1291. same rules. A string-like lexicographic comparison function,
  1292. `lcompare', tests the lexicographic relation between two BitStrings.
  1293. For example, lcompare(1100, 0101) returns 1, since the first BitString
  1294. starts with 1 and the second with 0.
  1295.  
  1296.    Individual bit setting, testing, and iterator operations (`set,
  1297. clear, invert, test, first, next, last, previous') are also like those
  1298. for BitSets. BitStrings are automatically expanded when setting bits
  1299. at positions greater than their current length.
  1300.  
  1301.    The string-based capabilities are just as those for class String. 
  1302. BitStrings may be concatenated (`+, +='), searched (`index, contains,
  1303. matches'), and extracted into BitSubStrings (`before, at, after')
  1304. which may be assigned and otherwise manipulated. Other string-based
  1305. utility functions (`reverse, common_prefix, common_suffix') are also
  1306. provided.  These have the same capabilities and descriptions as those
  1307. for Strings.
  1308.  
  1309.    String-oriented operations can also be performed with a mask via
  1310. class BitPattern. BitPatterns consist of two BitStrings, a pattern and
  1311. a mask. On searching and matching, bits in the pattern that correspond
  1312. to 0 bits in the mask are ignored. (The mask may be shorter than the
  1313. pattern, in which case trailing mask bits are assumed to be 0). The
  1314. pattern and mask are both public variables, and may be individually
  1315. subjected to other bit operations.
  1316.  
  1317.    Converting to char* and printing (`(atoBitString, atoBitPattern,
  1318. printon, ostream <<)') are also as in BitSets, except that no virtual
  1319. bit is used, and an 'X' in a BitPattern means that the pattern bit is
  1320. masked out.
  1321.  
  1322.    The following features are unique to BitStrings.
  1323.  
  1324.    Assume declarations of BitString a = atoBitString("01010110") and b
  1325. = atoBitSTring("1101").
  1326.  
  1327. `a = b + c;'
  1328.      Sets a to the concatenation of b and c;
  1329.  
  1330. `a = b + 0; a = b + 1;'
  1331.      sets a to b, appended with a zero (one).
  1332.  
  1333. `a += b;'
  1334.      appends b to a;
  1335.  
  1336. `a += 0; a += 1;'
  1337.      appends a zero (one) to a.
  1338.  
  1339. `a << 2; a <<= 2'
  1340.      return a with 2 zeros prepended, setting a to 0001010110. (Note
  1341.      the necessary confusion of << and >> operators. For consistency
  1342.      with the integer versions, << shifts low bits to high, even though
  1343.      they are printed low bits first.)
  1344.  
  1345. `a >> 3; a >>= 3'
  1346.      return a with the first 3 bits deleted, setting a to 10110.
  1347.  
  1348. `a.left_trim(0)'
  1349.      deletes all 0 bits on the left of a, setting a to 1010110.
  1350.  
  1351. `a.right_trim(0)'
  1352.      deletes all trailing 0 bits of a, setting a to 0101011.
  1353.  
  1354. `cat(x, y, z)'
  1355.      A faster way to say z = x + y.
  1356.  
  1357. `diff(x, y, z)'
  1358.      A faster way to say z = x - y.
  1359.  
  1360. `and(x, y, z)'
  1361.      A faster way to say z = x & y.
  1362.  
  1363. `or(x, y, z)'
  1364.      A faster way to say z = x | y.
  1365.  
  1366. `xor(x, y, z)'
  1367.      A faster way to say z = x ^ y.
  1368.  
  1369. `lshift(x, y, z)'
  1370.      A faster way to say z = x << y.
  1371.  
  1372. `rshift(x, y, z)'
  1373.      A faster way to say z = x >> y.
  1374.  
  1375. `complement(x, z)'
  1376.      A faster way to say z = ~x.
  1377.  
  1378.