home *** CD-ROM | disk | FTP | other *** search
/ QBasic & Borland Pascal & C / Delphi5.iso / C / BC_502 / SRCBDTO.PAK / STREAM.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1997-05-06  |  3.0 KB  |  161 lines

  1. //-----------------------------------------------------------------------------
  2. // Visual Database Tools
  3. // Copyright (c) 1996 by Borland International, All Rights Reserved
  4. //
  5. // stream.cpp
  6. // TMemoryStream wrapper class
  7. //-----------------------------------------------------------------------------
  8.  
  9. #include <vdbt\bdto.h>
  10.  
  11. #pragma hdrstop
  12.  
  13. #include "misc.h"
  14.  
  15. //-----------------------------------------------------------------------------
  16.  
  17. void TMemoryStream::SetTMemoryStream( PIUnknown p )
  18. {
  19.     stream = 0;
  20.     if (p)
  21.         p->QueryInterface( IID_ITMemoryStream, (void**) &stream );
  22. }
  23.  
  24. void TMemoryStream::ClearTMemoryStream( void )
  25. {
  26.     if (stream)
  27.     {
  28.         stream->Release();
  29.         stream = 0;
  30.     }
  31. }
  32.  
  33. TMemoryStream::TMemoryStream( void )
  34. {
  35.     stream = CreateITMemoryStream();
  36. }
  37.  
  38. TMemoryStream::TMemoryStream( PITMemoryStream p )
  39. {
  40.     SetTMemoryStream( p );
  41. }
  42.  
  43. TMemoryStream::TMemoryStream( const TMemoryStream& p )
  44. {
  45.     SetTMemoryStream( p.stream );
  46. }
  47.  
  48. TMemoryStream::TMemoryStream( PTMemoryStream p )
  49. {
  50.     SetTMemoryStream( p ? p->stream : 0 );
  51. }
  52.  
  53. TMemoryStream& TMemoryStream::operator=( PITMemoryStream p )
  54. {
  55.     ClearTMemoryStream();
  56.     SetTMemoryStream( p );
  57.     return *this;
  58. }
  59.  
  60. TMemoryStream& TMemoryStream::operator=( const TMemoryStream& p )
  61. {
  62.     if (this != &p)
  63.     {
  64.         ClearTMemoryStream();
  65.         SetTMemoryStream( p.stream );
  66.     }
  67.     return *this;
  68. }
  69.  
  70. int TMemoryStream::operator==( const TMemoryStream& p ) const
  71. {
  72.     if (this == &p)
  73.         return true;
  74.     if (stream == p.stream)
  75.         return true;
  76.     return false;
  77. }
  78.  
  79. int TMemoryStream::operator!=( const TMemoryStream& p ) const
  80. {
  81.     return ! operator==(p);
  82. }
  83.  
  84. TMemoryStream::~TMemoryStream()
  85. {
  86.     ClearTMemoryStream();
  87. }
  88.  
  89. void TMemoryStream::SetPIT( PIUnknown p )
  90. {
  91.     ClearTMemoryStream();
  92.     SetTMemoryStream( p );
  93. }
  94.  
  95. void TMemoryStream::Detach( void )
  96. {
  97.     if (stream)
  98.         stream->Detach();
  99. }
  100.  
  101. int32 TMemoryStream::Read( LPVOID Buffer, int32 Count )
  102. {
  103.     if (stream)
  104.         return stream->Read( Buffer, Count );
  105.     return 0;
  106. }
  107.  
  108. int32 TMemoryStream::Write( LPVOID Buffer, int32 Count )
  109. {
  110.     if (stream)
  111.         return stream->Write( Buffer, Count );
  112.     return 0;
  113. }
  114.  
  115. int32 TMemoryStream::Seek( int32 Offset, TSeekOrigin Origin )
  116. {
  117.     if (stream)
  118.         return stream->Seek( Offset, Origin );
  119.     return 0;
  120. }
  121.  
  122. void TMemoryStream::ReadBuffer( LPVOID Buffer, int32 Count )
  123. {
  124.     if (stream)
  125.         stream->ReadBuffer( Buffer, Count );
  126. }
  127.  
  128. void TMemoryStream::WriteBuffer( LPVOID Buffer, int32 Count )
  129. {
  130.     if (stream)
  131.         stream->WriteBuffer( Buffer, Count );
  132. }
  133.  
  134. int32 TMemoryStream::CopyFrom( TMemoryStream& Source, int32 Count )
  135. {
  136.     if (stream)
  137.         return stream->CopyFrom( Source.stream, Count );
  138.     return 0;
  139. }
  140.  
  141. DEFINE_BDTO_PROP_RW( TMemoryStream, int32, Position );
  142. DEFINE_BDTO_PROP_RO( TMemoryStream, int32, Size );
  143.  
  144. void TMemoryStream::GetPosition( int32& p )
  145. {
  146.     if (stream)
  147.         p = stream->get_Position();
  148. }
  149.  
  150. void TMemoryStream::SetPosition( int32 p )
  151. {
  152.     if (stream)
  153.         stream->put_Position( p );
  154. }
  155.  
  156. void TMemoryStream::GetSize( int32& s )
  157. {
  158.     if (stream)
  159.         s = stream->get_Size();
  160. }
  161.