home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / yacl-012.zip / base / bytstrng.h < prev    next >
C/C++ Source or Header  |  1995-04-08  |  4KB  |  147 lines

  1.  
  2.  
  3.  
  4. #ifndef _bytstrng_h_
  5. #define _bytstrng_h_
  6.  
  7.  
  8.  
  9.  
  10.  
  11. /*
  12.  *
  13.  *          Copyright (C) 1994, M. A. Sridhar
  14.  *  
  15.  *
  16.  *     This software is Copyright M. A. Sridhar, 1994. You are free
  17.  *     to copy, modify or distribute this software  as you see fit,
  18.  *     and to use  it  for  any  purpose, provided   this copyright
  19.  *     notice and the following   disclaimer are included  with all
  20.  *     copies.
  21.  *
  22.  *                        DISCLAIMER
  23.  *
  24.  *     The author makes no warranties, either expressed or implied,
  25.  *     with respect  to  this  software, its  quality, performance,
  26.  *     merchantability, or fitness for any particular purpose. This
  27.  *     software is distributed  AS IS.  The  user of this  software
  28.  *     assumes all risks  as to its quality  and performance. In no
  29.  *     event shall the author be liable for any direct, indirect or
  30.  *     consequential damages, even if the  author has been  advised
  31.  *     as to the possibility of such damages.
  32.  *
  33.  */
  34.  
  35.  
  36.  
  37. // The {\small\tt ByteString} class differs from the base {\small\tt
  38. // ByteArray} class in that the former owns the memory it works with. As such,
  39. // the {\small\tt ByteString} supports growing and shrinking of the byte
  40. // array and concatenation of {\small\tt ByteString} objects.
  41.  
  42.  
  43. #ifdef __GNUC__
  44. #pragma interface
  45. #endif
  46.  
  47.  
  48. #include "base/bytarray.h"
  49. #include "base/string.h"
  50.  
  51.  
  52. class CL_EXPORT  CL_ByteString: public CL_ByteArray {
  53.  
  54. public:
  55.  
  56.     // ------------------ Construction and destruction ---------------
  57.     
  58.     CL_ByteString();
  59.     // Default constructor: create with zero length.
  60.  
  61.     CL_ByteString (long length);
  62.     // Constructor: build a CL_ByteString of the given length. All bytes
  63.     // of the byte string will be zero.
  64.  
  65.     CL_ByteString (const CL_ByteArray& b);
  66.     // Convert from a CL_ByteArray.
  67.     
  68.     CL_ByteString (uchar* b, long length);
  69.     // Copy (convert) from a uchar array.
  70.  
  71.     CL_ByteString (const CL_String& s);
  72.     // Convert from a String. This ByteString's length will be one more than
  73.     // that of the String, and its contents will include the null terminator
  74.     // byte.
  75.     
  76.     CL_ByteString (const CL_ByteString& b);
  77.     // Copy constructor.
  78.  
  79.     ~CL_ByteString();
  80.  
  81.  
  82.     // ------------------------ Byte string operations ------------
  83.     
  84.     
  85.     virtual void operator= (const CL_ByteArray& b);
  86.     // Assignment operators: inherited from ByteArray. We need to
  87.     // declare these here because of the peculiar definition of
  88.     // inheritance for the assignment operator.
  89.  
  90.     void operator= (const uchar* p) {CL_ByteArray::operator= (p);};
  91.   
  92.     virtual void  operator= (const CL_String&);
  93.     // Copy a string, including the null byte at the end. Grow
  94.     // ourselves if necessary.
  95.     
  96.     virtual CL_ByteArray& operator= (long p);
  97.     // Copy the given long value into ourselves, beginning at position 0.
  98.  
  99.     virtual CL_ByteArray& operator= (short p);
  100.  
  101.     virtual void operator= (const CL_Object& p);
  102.  
  103.  
  104.     virtual CL_ByteString& operator+= (const CL_ByteArray& b);
  105.     // Append the contents of b to this ByteString, thereby growing the
  106.     // latter.
  107.  
  108.  
  109.     virtual bool ChangeSize (long new_size);
  110.     // Tell us to change our size.  If the new size is less than our
  111.     // current size, we lose the appropriate suffix. The return value
  112.     // tells if the change was successful; a FALSE return value
  113.     // indicates memory allocation failure.
  114.  
  115.     // -------------------- Storage and restoration --------------
  116.     
  117.     virtual long StorableFormWidth () const;
  118.  
  119.     bool ReadFrom (const CL_Stream&);
  120.  
  121.     bool WriteTo  (CL_Stream&) const;
  122.  
  123.     // ---------------- Basic methods ----------------------
  124.     
  125.     const char* ClassName() const {return "CL_ByteString";};
  126.  
  127.     CL_ClassId ClassId() const {return _CL_ByteString_CLASSID;};
  128.  
  129.     CL_Object* Clone() const {return new CL_ByteString (*this);}
  130.     // Return a copy of this ByteString.
  131.     
  132.     
  133. };
  134.  
  135.  
  136. inline void CL_ByteString::operator= (const CL_Object& s)
  137. {
  138.     if (CheckClassType (s, "CL_ByteString::operator= (CL_Object&)"))
  139.         *this = (const CL_ByteString&) s;
  140. }
  141.  
  142.  
  143.  
  144.  
  145. #endif
  146.  
  147.