home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 1997 May / Pcwk0597.iso / sybase / starbuck / hpp.z / WGLOBALM.HPP < prev    next >
C/C++ Source or Header  |  1996-10-18  |  4KB  |  134 lines

  1. /*************************************************************************
  2.  *
  3.  * WGlobalMemory
  4.  *
  5.  *    This class is a cover class for accessing and using global
  6.  *    memory objects.
  7.  *
  8.  *************************************************************************/
  9.  
  10. #ifndef _WGLOBALM_HPP_INCLUDED
  11. #define _WGLOBALM_HPP_INCLUDED
  12.  
  13. #ifndef _WNO_PRAGMA_PUSH
  14. #pragma pack(push,8);
  15. #pragma enum int;
  16. #endif
  17.  
  18. #ifndef _WREFOBJ_HPP_INCLUDED
  19. #  include "wrefobj.hpp"
  20. #endif
  21.  
  22. typedef WULong WGlobalMemoryFlags;
  23.  
  24. #define WGMFFixed      0x0000
  25. #define WGMFMoveable   0x0002
  26. #define WGMFZeroInit   0x0040
  27. #define WGMFHandle     (WGMFMoveable|WGMFZeroInit)
  28. #define WGMFPointer    (WGMFFixed|WGMFZeroInit)
  29.  
  30. #define GHND                (GMEM_MOVEABLE | GMEM_ZEROINIT)
  31. #define GPTR                (GMEM_FIXED | GMEM_ZEROINIT)
  32. //
  33. // WGlobalMemory
  34. //
  35.  
  36. class WCMCLASS WGlobalMemory : public WReferenceObject {
  37.     WDeclareSubclass( WGlobalMemory, WReferenceObject );
  38.  
  39.         /**********************************************************
  40.          * Constructors and Destructors
  41.          *********************************************************/
  42.  
  43.         // This class is meant to be used as a reference class, with
  44.         // objects allocated via new.  As such we don't allow
  45.         // copies to be made except via the MakeCopy method.  New
  46.         // objects are allocated via the static function Allocate.
  47.     
  48.     private:
  49.         WGlobalMemory( const WGlobalMemory & gm );
  50.         WGlobalMemory& operator=( const WGlobalMemory & gm );
  51.  
  52.     protected:
  53.         WGlobalMemory( const WMemoryHandle handle, WBool delHandle=FALSE );
  54.         WGlobalMemory( WULong size, WULong flags=WGMFHandle );
  55.  
  56.     public:
  57.         ~WGlobalMemory();
  58.  
  59.         /**********************************************************
  60.          * Properties
  61.          *********************************************************/
  62.  
  63.         // Data
  64.         //
  65.         //    Returns a pointer to the data in a global memory
  66.         //    object.  NULL is returned if the memory is moveable
  67.         //    and Lock has not been called to lock down the memory.
  68.  
  69.         void *GetData() const;
  70.  
  71.         // Handle
  72.         //
  73.         //    Returns the global memory handle.
  74.  
  75.         WMemoryHandle GetHandle() const;
  76.  
  77.         // Size
  78.         //
  79.         //    Returns the size (in bytes) of the memory.
  80.  
  81.         WULong GetSize() const;
  82.  
  83.         /**********************************************************
  84.          * Methods
  85.          *********************************************************/
  86.  
  87.         // Allocate
  88.         //
  89.         //    Allocates a new object.
  90.  
  91.         static WGlobalMemory *Allocate( WULong sizeInBytes,
  92.                                         WULong flags=WGMFHandle );
  93.         static WGlobalMemory *Allocate( WMemoryHandle handle,
  94.                                         WBool delHandle=FALSE );
  95.  
  96.         // Lock
  97.         //
  98.         //    Lock moveable memory.  Returns the lock count.
  99.  
  100.         WLong Lock();
  101.  
  102.         // MakeCopy
  103.         //
  104.         //    Creates a new memory object based on the current
  105.         //    one, copying the data.
  106.  
  107.         WGlobalMemory *MakeCopy();
  108.  
  109.         // Unlock
  110.         //
  111.         //    Unlock moveable memory.  Return the lock count.
  112.  
  113.         WLong Unlock();
  114.  
  115.         /**********************************************************
  116.          * Private
  117.          *********************************************************/
  118.  
  119.     private:
  120.  
  121.         WMemoryHandle   _handle;
  122.         WLong           _lockCount;
  123.         WBool           _deleteHandle;
  124.         void *          _data;
  125. };
  126.  
  127.  
  128. #ifndef _WNO_PRAGMA_PUSH
  129. #pragma enum pop;
  130. #pragma pack(pop);
  131. #endif
  132.  
  133. #endif // _WGLOBALM_HPP_INCLUDED
  134.