home *** CD-ROM | disk | FTP | other *** search
/ IRIX Base Documentation 2001 May / SGI IRIX Base Documentation 2001 May.iso / usr / share / catman / p_man / cat3 / c++ / ssbuf.z / ssbuf
Encoding:
Text File  |  1998-10-30  |  10.0 KB  |  199 lines

  1.  
  2.  
  3.  
  4. SSSSSSSSBBBBUUUUFFFF((((3333CCCC++++++++))))                                                        SSSSSSSSBBBBUUUUFFFF((((3333CCCC++++++++))))
  5.  
  6.  
  7.  
  8. NNNNAAAAMMMMEEEE
  9.      strstreambuf - streambuf specialized to arrays
  10.  
  11. SSSSYYYYNNNNOOOOPPPPSSSSIIIISSSS
  12.      #include <iostream.h>
  13.      #include <strstream.h>
  14.  
  15.      class strstreambuf : public streambuf {
  16.      public:
  17.                          strstreambuf() ;
  18.                          strstreambuf(char*, int, char*);
  19.                          strstreambuf(int);
  20.                          strstreambuf(unsigned char*, int, unsigned char*);
  21.                          strstreambuf(void* (*a)(long), void(*f)(void*));
  22.  
  23.                void      freeze(int n=1) ;
  24.                char*     str();
  25.                virtual streambuf*            setbuf(char*, int)
  26.      };
  27.  
  28. DDDDEEEESSSSCCCCRRRRIIIIPPPPTTTTIIIIOOOONNNN
  29.      A _ssss_tttt_rrrr_ssss_tttt_rrrr_eeee_aaaa_mmmm_bbbb_uuuu_ffff is a _ssss_tttt_rrrr_eeee_aaaa_mmmm_bbbb_uuuu_ffff that uses an array of bytes (a string) to
  30.      hold the sequence of characters.  Given the convention that a _cccc_hhhh_aaaa_rrrr_****
  31.      should be interpreted as pointing just before the _cccc_hhhh_aaaa_rrrr it really points
  32.      at, the mapping between the abstract get/put pointers (see
  33.      _ssss_bbbb_uuuu_ffff_...._pppp_uuuu_bbbb(3C++)) and _cccc_hhhh_aaaa_rrrr_**** pointers is direct.  Moving the pointers
  34.      corresponds exactly to incrementing and decrementing the _cccc_hhhh_aaaa_rrrr_**** values.
  35.  
  36.      To accommodate the need for arbitrary length strings _ssss_tttt_rrrr_ssss_tttt_rrrr_eeee_aaaa_mmmm_bbbb_uuuu_ffff
  37.      supports a dynamic mode.  When a _ssss_tttt_rrrr_ssss_tttt_rrrr_eeee_aaaa_mmmm_bbbb_uuuu_ffff is in dynamic mode, space
  38.      for the character sequence is allocated as needed.  When the sequence is
  39.      extended too far, it will be copied to a new array.
  40.  
  41.      In the following descriptions assume:
  42.      - _s_s_b is a _ssss_tttt_rrrr_ssss_tttt_rrrr_eeee_aaaa_mmmm_bbbb_uuuu_ffff_****.
  43.      - _n is an _iiii_nnnn_tttt.
  44.      - _p_t_r and _p_s_t_a_r_t are _cccc_hhhh_aaaa_rrrr_****s or _uuuu_nnnn_ssss_iiii_gggg_nnnn_eeee_dddd _cccc_hhhh_aaaa_rrrr_****s.
  45.      - _a is a _vvvv_oooo_iiii_dddd_**** _((((_****_))))_((((_llll_oooo_nnnn_gggg_)))).
  46.      - _f is a _vvvv_oooo_iiii_dddd_**** _((((_****_))))_((((_vvvv_oooo_iiii_dddd_****_)))).
  47.  
  48.    CCCCoooonnnnssssttttrrrruuuuccccttttoooorrrrssss::::::::
  49.           _ssss_tttt_rrrr_ssss_tttt_rrrr_eeee_aaaa_mmmm_bbbb_uuuu_ffff_((((_))))
  50.                Constructs an empty _ssss_tttt_rrrr_ssss_tttt_rrrr_eeee_aaaa_mmmm_bbbb_uuuu_ffff in dynamic mode.  This means
  51.                that space will be automatically allocated to accommodate the
  52.                characters that are put into the _ssss_tttt_rrrr_ssss_tttt_rrrr_eeee_aaaa_mmmm_bbbb_uuuu_ffff (using operators
  53.                _nnnn_eeee_wwww and _dddd_eeee_llll_eeee_tttt_eeee).  Because this may require copying the original
  54.                characters, it is recommended that when many characters will be
  55.                inserted, the program should use _ssss_eeee_tttt_bbbb_uuuu_ffff_((((_)))) (described below) to
  56.                inform the _ssss_tttt_rrrr_ssss_tttt_rrrr_eeee_aaaa_mmmm_bbbb_uuuu_ffff.
  57.  
  58.  
  59.  
  60.  
  61.  
  62.  
  63.                                                                         PPPPaaaaggggeeee 1111
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70. SSSSSSSSBBBBUUUUFFFF((((3333CCCC++++++++))))                                                        SSSSSSSSBBBBUUUUFFFF((((3333CCCC++++++++))))
  71.  
  72.  
  73.  
  74.           _ssss_tttt_rrrr_ssss_tttt_rrrr_eeee_aaaa_mmmm_bbbb_uuuu_ffff_((((_a_,,,, _f_))))
  75.                Constructs an empty _ssss_tttt_rrrr_ssss_tttt_rrrr_eeee_aaaa_mmmm_bbbb_uuuu_ffff in dynamic mode.  _a is used as
  76.                the allocator function in dynamic mode.  The argument passed to
  77.                _a will be a _llll_oooo_nnnn_gggg denoting the number of bytes to be allocated.
  78.                If _a is null, _oooo_pppp_eeee_rrrr_aaaa_tttt_oooo_rrrr _nnnn_eeee_wwww will be used.  _f is used to free (or
  79.                delete) areas returned by _a.  The argument to _f will be a
  80.                pointer to the array allocated by _a.  If _f is null, _oooo_pppp_eeee_rrrr_aaaa_tttt_oooo_rrrr
  81.                _dddd_eeee_llll_eeee_tttt_eeee is used.
  82.  
  83.           _ssss_tttt_rrrr_ssss_tttt_rrrr_eeee_aaaa_mmmm_bbbb_uuuu_ffff_((((_n_))))
  84.                Constructs an empty _ssss_tttt_rrrr_ssss_tttt_rrrr_eeee_aaaa_mmmm_bbbb_uuuu_ffff in dynamic mode.  The initial
  85.                allocation of space will be at least _n bytes.
  86.  
  87.           _ssss_tttt_rrrr_ssss_tttt_rrrr_eeee_aaaa_mmmm_bbbb_uuuu_ffff_((((_p_t_r_,,,, _n_,,,, _p_s_t_a_r_t_))))
  88.                Constructs a _ssss_tttt_rrrr_ssss_tttt_rrrr_eeee_aaaa_mmmm_bbbb_uuuu_ffff to use the bytes starting at _p_t_r.
  89.                The _ssss_tttt_rrrr_ssss_tttt_rrrr_eeee_aaaa_mmmm_bbbb_uuuu_ffff will be in static mode; it will not grow
  90.                dynamically.  If _n is positive, then the _n bytes starting at
  91.                _p_t_r are used as the _ssss_tttt_rrrr_ssss_tttt_rrrr_eeee_aaaa_mmmm_bbbb_uuuu_ffff.  If _n is zero, _p_t_r is assumed
  92.                to point to the beginning of a null terminated string and the
  93.                bytes of that string (not including the terminating null
  94.                character) will constitute the _ssss_tttt_rrrr_ssss_tttt_rrrr_eeee_aaaa_mmmm_bbbb_uuuu_ffff.  If _n is negative,
  95.                the _ssss_tttt_rrrr_ssss_tttt_rrrr_eeee_aaaa_mmmm_bbbb_uuuu_ffff is assumed to continue indefinitely.  The get
  96.                pointer is initialized to _p_t_r.  The put pointer is initialized
  97.                to _p_s_t_a_r_t.  If _p_s_t_a_r_t is null, then stores will be treated as
  98.                errors.  If _p_s_t_a_r_t is non-null, then the initial sequence for
  99.                fetching (the get area) consists of the bytes between _p_t_r and
  100.                _p_s_t_a_r_t.  If _p_s_t_a_r_t is null, then the initial get area consists
  101.                of the entire array.
  102.  
  103.    MMMMeeeemmmmbbbbeeeerrrr ffffuuuunnnnccccttttiiiioooonnnnssss::::
  104.           _s_s_b_----_>>>>_ffff_rrrr_eeee_eeee_zzzz_eeee_((((_n_))))
  105.                Inhibits (when _n is nonzero) or permits (when _n is zero)
  106.                automatic deletion of the current array.  Deletion normally
  107.                occurs when more space is needed or when _s_s_b is being
  108.                destroyed.  Only space obtained via dynamic allocation is ever
  109.                freed.  It is an error (and the effect is undefined) to store
  110.                characters into a _ssss_tttt_rrrr_ssss_tttt_rrrr_eeee_aaaa_mmmm_bbbb_uuuu_ffff that was in dynamic allocation
  111.                mode and is now frozen.  It is possible, however, to thaw
  112.                (unfreeze) such a _ssss_tttt_rrrr_ssss_tttt_rrrr_eeee_aaaa_mmmm_bbbb_uuuu_ffff and resume storing characters.
  113.  
  114.           _p_t_r_====_s_s_b_----_>>>>_ssss_tttt_rrrr_((((_))))
  115.                Returns a pointer to the first _cccc_hhhh_aaaa_rrrr of the current array and
  116.                freezes _s_s_b.  If _s_s_b was constructed with an explicit array,
  117.                _p_t_r will point to that array.  If _s_s_b is in dynamic allocation
  118.                mode, but nothing has yet been stored, _p_t_r may be null.
  119.  
  120.           _s_s_b_----_>>>>_ssss_eeee_tttt_bbbb_uuuu_ffff_((((_0000_,,,,_n_))))
  121.                _s_s_b remembers _n and the next time it does a dynamic mode
  122.                allocation, it makes sure that at least _n bytes are allocated.
  123.  
  124.  
  125.  
  126.  
  127.  
  128.  
  129.                                                                         PPPPaaaaggggeeee 2222
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136. SSSSSSSSBBBBUUUUFFFF((((3333CCCC++++++++))))                                                        SSSSSSSSBBBBUUUUFFFF((((3333CCCC++++++++))))
  137.  
  138.  
  139.  
  140. SSSSEEEEEEEE AAAALLLLSSSSOOOO
  141.      _ssss_bbbb_uuuu_ffff_...._pppp_uuuu_bbbb(3C++), _ssss_tttt_rrrr_ssss_tttt_rrrr_eeee_aaaa_mmmm(3C++)
  142.  
  143.  
  144.  
  145.  
  146.  
  147.  
  148.  
  149.  
  150.  
  151.  
  152.  
  153.  
  154.  
  155.  
  156.  
  157.  
  158.  
  159.  
  160.  
  161.  
  162.  
  163.  
  164.  
  165.  
  166.  
  167.  
  168.  
  169.  
  170.  
  171.  
  172.  
  173.  
  174.  
  175.  
  176.  
  177.  
  178.  
  179.  
  180.  
  181.  
  182.  
  183.  
  184.  
  185.  
  186.  
  187.  
  188.  
  189.  
  190.  
  191.  
  192.  
  193.  
  194.  
  195.                                                                         PPPPaaaaggggeeee 3333
  196.  
  197.  
  198.  
  199.