home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 22 gnu / 22-gnu.zip / db02_src.zip / mystring.cc < prev    next >
C/C++ Source or Header  |  1993-11-05  |  3KB  |  130 lines

  1. /**************************************************************************
  2.  * Source Id :
  3.  *
  4.  * $Id: mystring.cc,v 1.8 1993/10/28 13:31:20 davison Exp $
  5.  *-------------------------------------------------------------------------
  6.  * Project Notes :
  7.  *
  8.  *  Diamond Base
  9.  *  ============
  10.  *      A solid database implementation, spurred on by the continuing
  11.  *  Metal (Lead) Base saga.
  12.  *
  13.  *  Project Team :
  14.  *        A. Davison
  15.  *        K. Lentin
  16.  *        D. Platt
  17.  *
  18.  *    Project Commenced : 05-02-1993
  19.  *
  20.  *-------------------------------------------------------------------------
  21.  *  Module Notes :
  22.  *
  23.  *  mystring.cc:
  24.  *  Operators for the variable length string class.
  25.  *
  26.  *  Original Author : Kev
  27.  *
  28.  *-------------------------------------------------------------------------
  29.  * Revision History:
  30.  *
  31.  * $Log: mystring.cc,v $
  32. // Revision 1.8  1993/10/28  13:31:20  davison
  33. // Changed clear() method to clr().
  34. //
  35. // Revision 1.7  1993/10/05  07:34:31  kevinl
  36. // Now handles dbData AND dbString properly
  37. //
  38. // Revision 1.6  1993/08/29  12:56:27  kevinl
  39. // Fixed problems of assigning relations to each other.
  40. //
  41. // Revision 1.5  1993/07/11  09:42:05  kevinl
  42. // Changed String to dbString
  43. //
  44. // Revision 1.4  1993/07/11  08:20:42  kevinl
  45. // Fixed >> operator. Now gets enough memory for itself.
  46. //
  47. // Revision 1.3  1993/06/23  05:21:22  kevinl
  48. // Mallocs are now in angular brackets
  49. //
  50. // Revision 1.2  1993/06/20  13:40:01  kevinl
  51. // Fixed multiple mallocs
  52. // += removed and put in header
  53. //
  54. // Revision 1.1  1993/06/18  12:31:14  kevinl
  55. // Initial revision
  56. //
  57.  **************************************************************************/
  58.  
  59. #include <ctype.h>
  60. #include <mystring.h>
  61.  
  62. void
  63. dbData::fill(char c, unsigned int count)
  64. {
  65.     if (count == 0) {
  66.         if (size == 0)
  67.             return;
  68.         else
  69.             count = size-isstr;
  70.     } else
  71.         setSize(count+isstr);
  72.     memset(data, c, count);
  73.     if (isstr)
  74.         data[count] = 0;
  75. }
  76.  
  77. dbData operator + (dbData& S, char* s) 
  78. {
  79.     dbData res(S);
  80.     res.cat(s);
  81.     return res;
  82. }
  83. dbData operator + (dbData& S, dbData& s) 
  84. {
  85.     dbData res(S);
  86.     res.cat(s);
  87.     return res;
  88. }
  89. ostream& operator << (ostream& o, dbData& s)
  90. {
  91.     if (s.isstr)
  92.         o << (char*)s;
  93.     else
  94.         o.write((char*)s, s.getSize());
  95.     return o;
  96. }
  97. istream& operator >> (istream& i, dbData& s)
  98. {
  99.     s.clr();
  100.     s.setSize(CHUNKSIZE);
  101.     long len = 0; // Speeds things up
  102.     s[len] = 0;
  103.     char c;
  104.     if (s.isstr) {
  105.         do {
  106.             c = i.get();
  107.             if (c == EOF || !i.good())
  108.                 return i;
  109.         } while (isspace(c));
  110.         i.putback(c);
  111.     }
  112.     while (i.good()) {
  113.         c = i.get();
  114.         if (c == EOF || !i.good())
  115.             break;
  116.         else if (s.isstr)
  117.             if (isspace(c)) {
  118.                 i.putback(c);
  119.                 break;
  120.             }
  121.         if (len >= s.getSize()-1)
  122.             s+=CHUNKSIZE;
  123.         s[len++] = c;
  124.     }
  125.     if (s.isstr)
  126.         s[len] = 0;
  127.     s.setSize(len);
  128.     return i;
  129. }
  130.