home *** CD-ROM | disk | FTP | other *** search
/ Chip 2001 Mobile / Chip_Mobile_2001.iso / palm / business / printcar / printcar.exe / src / Util / MemBuffer.h < prev    next >
C/C++ Source or Header  |  2000-06-03  |  1KB  |  65 lines

  1. //
  2. //  $Id: MemBuffer.h,v 1.1.1.1 2000/06/02 22:23:04 sergey Exp $
  3. //
  4.  
  5. #ifndef _MemBuffer_h_
  6. #define _MemBuffer_h_
  7.  
  8. #include "Serializable.h"
  9.  
  10.  
  11. namespace Util
  12. {
  13.     class MemBuffer: public Serializable
  14.     {
  15.     public:
  16.         MemBuffer();
  17.         MemBuffer(VoidHand handle);
  18.         ~MemBuffer();
  19.  
  20.         // shallow copy, transfers ovnership to destination
  21.         MemBuffer(const MemBuffer& other);
  22.         MemBuffer& operator =(const MemBuffer& other);
  23.  
  24.     // operations
  25.  
  26.         void* lock();
  27.         const void* lock() const;
  28.  
  29.         // Ensures that buffer size will be not less then lockSize argument.
  30.         void* lock(int lockSize);
  31.         const void* lock(int lockSize) const;
  32.  
  33.         void unlock() const;
  34.  
  35.         bool allocate(int size);
  36.         bool resize(int size);
  37.         void free();
  38.         VoidHand release();
  39.  
  40.     // attributes
  41.  
  42.         int size() const;
  43.         bool isLocked() const   { return _lockCount > 0; }
  44.         bool isNull() const     { return _handle == 0; }
  45.  
  46.     // serialization
  47.  
  48.         virtual void serialize(DataOutputStream& stream) const;
  49.         virtual void restore(const DataInputStream& stream);
  50.  
  51.     // implemntation
  52.     private:
  53.         bool ensureBufferSize(int size);
  54.         void unlockAll() const;
  55.  
  56.     // data members
  57.     private:
  58.         VoidHand    _handle;
  59.         mutable int _lockCount;
  60.     };
  61. }
  62. // namespace Util
  63.  
  64. #endif // _MemBuffer_h_
  65.