TCNullStreamImpl.h 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. #ifndef __TCNullStreamImpl_h__
  2. #define __TCNullStreamImpl_h__
  3. #pragma once
  4. /////////////////////////////////////////////////////////////////////////////
  5. // CTCNullStreamImpl.h | Declaration of the CTCNullStreamImpl class, which
  6. // implements the CLSID_CTCNullStreamImpl component object.
  7. #include <..\TCLib\ObjectLock.h>
  8. /////////////////////////////////////////////////////////////////////////////
  9. // Description: A class that implements an object that supports the IStream
  10. // and, therefore, also ISequentialStream, to do nothing but keep track of
  11. // the number of bytes having been written to it.
  12. //
  13. // This object provides an implementation of the IStream interface that does
  14. // nothing more that count the number of bytes being written to it. Since
  15. // ATL (currently 3.0) implements IPersistStreamInitImpl::GetSizeMax by
  16. // returning E_NOTIMPL, this object can be used in an override of that
  17. // method. This is accomplished by creating an instance of this null stream
  18. // and 'persisting' an object to it, thereby counting the number of bytes
  19. // needed to persist the object. This object object performs this without
  20. // allocating any memory to back up the stream.
  21. //
  22. // Care should be taken to ensure that the object that thinks it is being
  23. // persisted does not change state from the time the byte count is taken
  24. // until the when the object is written to a real stream.
  25. //
  26. // See Also: CTCNullStreamImpl, CTCNullStream
  27. //
  28. class ATL_NO_VTABLE CTCNullStreamImpl :
  29. public IStream,
  30. public CComObjectRoot
  31. {
  32. // Interface Map
  33. public:
  34. BEGIN_COM_MAP(CTCNullStreamImpl)
  35. COM_INTERFACE_ENTRY(IStream)
  36. COM_INTERFACE_ENTRY(ISequentialStream)
  37. END_COM_MAP()
  38. // Construction
  39. public:
  40. CTCNullStreamImpl();
  41. // ISequentialStream Interface Methods
  42. public:
  43. STDMETHODIMP Read(void* pv, ULONG cb, ULONG* pcbRead);
  44. STDMETHODIMP Write(const void* pv, ULONG cb, ULONG* pcbWritten);
  45. // IStream Interface Methods
  46. public:
  47. STDMETHODIMP Seek(LARGE_INTEGER dlibMove, DWORD dwOrigin,
  48. ULARGE_INTEGER* plibNewPosition);
  49. STDMETHODIMP SetSize(ULARGE_INTEGER libNewSize);
  50. STDMETHODIMP CopyTo(IStream* pstm, ULARGE_INTEGER cb,
  51. ULARGE_INTEGER* pcbRead, ULARGE_INTEGER* pcbWritten);
  52. STDMETHODIMP Commit(DWORD grfCommitFlags);
  53. STDMETHODIMP Revert(void);
  54. STDMETHODIMP LockRegion(ULARGE_INTEGER libOffset, ULARGE_INTEGER cb,
  55. DWORD dwLockType);
  56. STDMETHODIMP UnlockRegion(ULARGE_INTEGER libOffset, ULARGE_INTEGER cb,
  57. DWORD dwLockType);
  58. STDMETHODIMP Stat(STATSTG* pstatstg, DWORD grfStatFlag);
  59. STDMETHODIMP Clone(IStream** ppstm);
  60. // Types
  61. protected:
  62. typedef TCObjectLock<CTCNullStreamImpl> CLock;
  63. // Data Members
  64. protected:
  65. ULONG m_nPosition;
  66. ULONG m_nSize;
  67. FILETIME m_ftCreated, m_ftModified, m_ftAccessed;
  68. };
  69. /////////////////////////////////////////////////////////////////////////////
  70. // CTCNullStreamImpl
  71. typedef CComObjectGlobal<CTCNullStreamImpl> TCNullStreamImpl;
  72. /////////////////////////////////////////////////////////////////////////////
  73. #endif // !__TCNullStreamImpl_h__