-
Notifications
You must be signed in to change notification settings - Fork 0
/
_gr_olio.h
149 lines (126 loc) · 3.36 KB
/
_gr_olio.h
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
#ifndef __GR_OLIO_H
#define __GR_OLIO_H
// Copyright David Lawrence Bien 1997 - 2021.
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// https://www.boost.org/LICENSE_1_0.txt).
// _gr_olio.h
// OLE i/o stuff.
#include <ole2.h>
#include "_oleutil.h"
// _gr_ole.h
// Graph OLE I/O.
__DGRAPH_BEGIN_NAMESPACE
// Specialize for IStream - default version just writes raw memory:
template < class t_TyWrite >
__INLINE void
_RawWriteGraphEl( IStream *& _rs, t_TyWrite const & _rEl )
{
// We don't care about partial writes - so no need to check the third param:
__ThrowOLEFAIL( _rs->Write( &_rEl, sizeof( _rEl ), 0 ) );
}
// Specialize for IStream - default version just reads raw memory:
template < class t_TyRead >
__INLINE void
_RawReadGraphEl( IStream *& _rs, t_TyRead & _rEl )
{
// We don't care about partial reads - so no need to check the third param:
__ThrowOLEFAIL( _rs->Read( &_rEl, sizeof( _rEl ), 0 ) );
}
struct _IStream_RawElIO
{
template < class t_TyEl >
void Write( IStream * _ps, t_TyEl const & _rel )
{
_RawWriteGraphEl( _ps, _rel );
}
template < class t_TyEl >
void Read( IStream * _ps, t_TyEl & _rel )
{
_RawReadGraphEl( _ps, _rel );
}
};
// The OLE object - supports both read and write:
template < class t_TyIONodeEl,
class t_TyIOLinkEl = t_TyIONodeEl >
struct _IStream_object
{
typedef IStream * _TyInitArg;
typedef ULARGE_INTEGER _TyStreamPos;
typedef t_TyIONodeEl _TyIONodeEl;
typedef t_TyIOLinkEl _TyIOLinkEl;
IStream * m_ps;
_TyIONodeEl m_ione;
_TyIOLinkEl m_iole;
_IStream_object( IStream * _ps,
_TyIONodeEl const & _rione,
_TyIOLinkEl const & _riole )
: m_ps( _ps ),
m_ione( _rione ),
m_iole( _riole )
{
m_ps->AddRef();
}
~_IStream_object()
{
m_ps->Release();
}
_TyStreamPos TellG() const
{
return _Tell();
}
void SeekG( _TyStreamPos _sp )
{
_Seek( _sp );
}
_TyStreamPos TellP() const
{
return _Tell();
}
void SeekP( _TyStreamPos _sp )
{
_Seek( _sp );
}
void Write( const void * _pv, ULONG _len )
{
__ThrowOLEFAIL( m_ps->Write( _pv, _len, 0 ) );
}
void Read( void * _pv, ULONG _len )
{
__ThrowOLEFAIL( m_ps->Read( _pv, _len, 0 ) );
}
template < class t_TyEl >
void WriteNodeEl( t_TyEl const & _rel )
{
m_ione.Write( m_ps, _rel );
}
template < class t_TyEl >
void ReadNodeEl( t_TyEl & _rel )
{
m_ione.Read( m_ps, _rel );
}
template < class t_TyEl >
void WriteLinkEl( t_TyEl const & _rel )
{
m_iole.Write( m_ps, _rel );
}
template < class t_TyEl >
void ReadLinkEl( t_TyEl & _rel )
{
m_iole.Read( m_ps, _rel );
}
protected:
_TyStreamPos _Tell() const
{
_TyStreamPos sp;
static const LARGE_INTEGER llZero = { 0ll };
__ThrowOLEFAIL( m_ps->Seek( llZero, STREAM_SEEK_CUR, &sp ) );
return sp;
}
void _Seek( _TyStreamPos _sp )
{
__ThrowOLEFAIL( m_ps->Seek( *(LARGE_INTEGER*)&_sp, STREAM_SEEK_SET, 0 ) );
}
};
__DGRAPH_END_NAMESPACE
#endif //__GR_OLIO_H