home *** CD-ROM | disk | FTP | other *** search
/ MacHack 2001 / MacHack 2001.toast / pc / Sessions / Traut / ZStrings / Source / CrossPlatform / ZStringData.h < prev    next >
Encoding:
C/C++ Source or Header  |  2001-06-23  |  1.8 KB  |  103 lines

  1. /*==================================================================
  2.     File:        ZStringData.h
  3.     
  4.     Contains:    Data backing object for ZStrings.
  5.  
  6.     Written by:    Eric Traut
  7.     
  8.     Copyright:    2000-2001 Connectix Corporation
  9.     
  10.     This source has been placed into the public domain by
  11.     Connectix Corporation. You have the right to modify, 
  12.     distribute or use this code without any legal limitations
  13.     or finanicial/licensing requirements. Connectix is not 
  14.     liable for any problems that result from the use of this 
  15.     code.
  16.     
  17.     If you have comments, feedback, questions, or would like
  18.     to submit bug fixes or updates to this code, please email
  19.     opensource@connectix.com.
  20. ==================================================================*/
  21.  
  22. #ifndef __ZSTRINGDATA__
  23. #define __ZSTRINGDATA__
  24.  
  25.  
  26. #include "ZStringTypes.h"
  27.  
  28.  
  29. /*==================================================================
  30.     ZStringData
  31. ==================================================================*/
  32.  
  33. class ZStringData
  34. {
  35.     friend class ZString;
  36.     friend class ZStringParser;
  37.     
  38.     public:
  39.         static ZStringData *
  40.         Allocate(
  41.             Z_UInt32        inStringLength);
  42.         
  43.         void
  44.         Deallocate();
  45.  
  46.         inline Z_UInt32
  47.         GetLength()
  48.         {
  49.             return mStringLength;
  50.         }
  51.  
  52.         const char *
  53.         GetStringData()
  54.         {
  55.             return mStringData;
  56.         }
  57.         
  58.         void
  59.         IncrementRefCount()
  60.         {
  61.             mRefCount++;
  62.         }
  63.  
  64.         void
  65.         DecrementRefCount()
  66.         {
  67.             check(mRefCount > 0);
  68.             mRefCount--;
  69.             
  70.             if (mRefCount == 0)
  71.                 Deallocate();
  72.         }
  73.     
  74.     private:
  75.         void
  76.         FillInString(
  77.             const char *        inString,
  78.             Z_UInt16            inOffset,
  79.             Z_UInt16            inLength);
  80.         
  81.         char *
  82.         GetDataArray()
  83.         {
  84.             return mStringData;
  85.         }
  86.         
  87.         ZStringData()
  88.         {
  89.             // The normal constructor is unreachable.
  90.         }
  91.  
  92.         Z_UInt16        mRefCount;
  93.         Z_UInt16        mStringLength;
  94.  
  95.         // Data follows here in a variable-sized array.
  96.         char            mStringData[1];
  97. };
  98.  
  99.  
  100. #endif // __ZSTRINGDATA__
  101.  
  102.  
  103.