home *** CD-ROM | disk | FTP | other *** search
/ The Net: Ultimate Internet Guide / WWLCD1.ISO / mac / SiteBldr / AMOVIE / SDK / _SETUP / COMMON.Z / pstream.h < prev    next >
Encoding:
C/C++ Source or Header  |  1996-04-19  |  4.3 KB  |  116 lines

  1. //==========================================================================;
  2. //
  3. //  THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
  4. //  KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  5. //  IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR
  6. //  PURPOSE.
  7. //
  8. //  Copyright (c) 1992 - 1996  Microsoft Corporation.  All Rights Reserved.
  9. //
  10. //--------------------------------------------------------------------------;
  11.  
  12. #ifndef __PSTREAM__
  13. #define __PSTREAM__
  14.  
  15. // Base class for persistent properties of filters
  16. // (i.e. filter properties in saved graphs)
  17.  
  18. // The simplest way to use this is:
  19. // 1. Arrange for your filter to inherit this class
  20. // 2. Implement in your class WriteToStream and ReadFromStream
  21. //    These will override the "do nothing" functions here.
  22. // 3. Change your NonDelegatingQueryInterface to handle IPersistStream
  23. // 4. Implement SizeMax to return the number of bytes of data you save.
  24. //    If you save UNICODE data, don't forget a char is 2 bytes.
  25. // 5. Whenever your data changes, call SetDirty()
  26. //
  27. // At some point you may decide to alter, or extend the format of your data.
  28. // At that point you will wish that you had a version number in all the old
  29. // saved graphs, so that you can tell, when you read them, whether they
  30. // represent the old or new form.  To assist you in this, this class
  31. // writes and reads a version number.
  32. // When it writes, it calls GetSoftwareVersion()  to enquire what version
  33. // of the software we have at the moment.  (In effect this is a version number
  34. // of the data layout in the file).  It writes this as the first thing in the data.
  35. // If you want to change the version, implement (override) GetSoftwareVersion().
  36. // It reads this from the file into mPS_dwFileVersion before calling ReadFromStream,
  37. // so in ReadFromStream you can check mPS_dwFileVersion to see if you are reading
  38. // an old version file.
  39. // Normally you should accept files whose version is no newer than the software
  40. // version that's reading them.
  41.  
  42.  
  43. // CPersistStream
  44. //
  45. // Implements IPersistStream.
  46. // See 'OLE Programmers Reference (Vol 1):Structured Storage Overview' for
  47. // more implementation information.
  48. class CPersistStream : public IPersistStream {
  49.     private:
  50.  
  51.         // Internal state:
  52.  
  53.     protected:
  54.         DWORD     mPS_dwFileVersion;         // version number of file (being read)
  55.         BOOL      mPS_fDirty;
  56.  
  57.     public:
  58.  
  59.         // IPersistStream methods
  60.  
  61.         STDMETHODIMP IsDirty()
  62.             {return (mPS_fDirty ? S_OK : S_FALSE);}  // note FALSE means clean
  63.         STDMETHODIMP Load(LPSTREAM pStm);
  64.         STDMETHODIMP Save(LPSTREAM pStm, BOOL fClearDirty);
  65.         STDMETHODIMP GetSizeMax(ULARGE_INTEGER * pcbSize)
  66.                          // Allow 24 bytes for version.
  67.                          { pcbSize->QuadPart = 12*sizeof(WCHAR)+SizeMax(); return NOERROR; }
  68.  
  69.         // implementation
  70.  
  71.         CPersistStream(IUnknown *punk, HRESULT *phr);
  72.         ~CPersistStream();
  73.  
  74.         HRESULT SetDirty(BOOL fDirty)
  75.             { mPS_fDirty = fDirty; return NOERROR;}
  76.  
  77.  
  78.         // override to reveal IPersist & IPersistStream
  79.         // STDMETHODIMP NonDelegatingQueryInterface(REFIID riid, void **ppv);
  80.  
  81.         // --- IPersist ---
  82.  
  83.         // You must override this to provide your own class id
  84.         STDMETHODIMP GetClassID(CLSID *pClsid) PURE;
  85.  
  86.         // overrideable if you want
  87.         // file version number.  Override it if you ever change format
  88.         virtual DWORD GetSoftwareVersion(void) { return 0; }
  89.  
  90.  
  91.         //=========================================================================
  92.         // OVERRIDE THESE to read and write your data
  93.         // OVERRIDE THESE to read and write your data
  94.         // OVERRIDE THESE to read and write your data
  95.  
  96.         virtual int SizeMax() {return 0;}
  97.         virtual HRESULT WriteToStream(IStream *pStream);
  98.         virtual HRESULT ReadFromStream(IStream *pStream);
  99.         //=========================================================================
  100.  
  101.     private:
  102.  
  103. };
  104.  
  105.  
  106. // --- Useful helpers ---
  107.  
  108.  
  109. // Writes an int to an IStream as UNICODE.
  110. extern HRESULT WriteInt(IStream *pIStream, int n);
  111.  
  112. // inverse of WriteInt
  113. extern int ReadInt(IStream *pIStream, HRESULT &hr);
  114.  
  115. #endif // __PSTREAM__
  116.