-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvtkSequentialStream.cxx
64 lines (55 loc) · 1.5 KB
/
vtkSequentialStream.cxx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include "vtkSequentialStream.h"
vtkSequentialStream::vtkSequentialStream( vtksys_ios::istream &is )
: is(is), ref_count(0)
{
InitializeCriticalSection( &this->critical_section );
}
vtkSequentialStream::~vtkSequentialStream( void )
{
DeleteCriticalSection( &this->critical_section );
}
// IUnknown
HRESULT __stdcall vtkSequentialStream::QueryInterface( const IID &riid, void ** ppvObject )
{
if ( riid == IID_ISequentialStream )
{
*ppvObject = static_cast<void*>(this);
this->AddRef();
return S_OK;
}
if (riid == IID_IUnknown)
{
*ppvObject = static_cast<void*>(this);
this->AddRef();
return S_OK;
}
*ppvObject = 0;
return E_NOINTERFACE;
}
ULONG __stdcall vtkSequentialStream::AddRef( void )
{
return InterlockedIncrement(&this->ref_count);
}
ULONG __stdcall vtkSequentialStream::Release( void )
{
ULONG nRefCount = InterlockedDecrement(&this->ref_count);
if ( nRefCount == 0 ) delete this;
return nRefCount;
}
// ISequentialStream
HRESULT __stdcall vtkSequentialStream::Read( void *pv, ULONG cb, ULONG *pcbRead )
{
EnterCriticalSection( &this->critical_section );
this->is.read( reinterpret_cast<char*>(pv), cb );
ULONG bytesRead = static_cast<ULONG>( this->is.gcount() );
LeaveCriticalSection( &this->critical_section );
if ( pcbRead != NULL )
*pcbRead = bytesRead;
if ( bytesRead < cb )
return S_FALSE;
return S_OK;
}
HRESULT __stdcall vtkSequentialStream::Write( void const *pv, ULONG cb, ULONG *pcbWritten )
{
return STG_E_ACCESSDENIED;
}