OWLNext
7.0
Borland's Object Windows Library for the modern age
Loading...
Searching...
No Matches
safearray.h
Go to the documentation of this file.
1
#if !defined(_SAFEARRAY_H)
2
#define _SAFEARRAY_H
3
4
#if !defined(_OLE2_H_)
5
# include <
ocf/autodefs.h
>
6
#endif
7
8
//
9
// Class VarType
10
// ~~~~~ ~~~~~~~
11
// VarType provides OLE interpretations to C++ basic types.
12
//
13
template
<
class
T>
14
class
VarType
{
15
public
:
16
virtual
VARTYPE
OLEType
() = 0;
17
};
18
19
template
<>
20
class
VarType
<bool> {
21
public
:
22
VARTYPE
OLEType
()
23
{
24
return
VT_BOOL;
25
}
26
};
27
28
template
<>
29
class
VarType
<char> {
30
public
:
31
VARTYPE
OLEType
()
32
{
33
return
VT_I1;
34
}
35
};
36
37
template
<>
38
class
VarType
<double> {
39
public
:
40
VARTYPE
OLEType
()
41
{
42
return
VT_R8;
43
}
44
};
45
46
template
<>
47
class
VarType
<float> {
48
public
:
49
VARTYPE
OLEType
()
50
{
51
return
VT_R4;
52
}
53
};
54
55
template
<>
56
class
VarType
<int> {
57
public
:
58
VARTYPE
OLEType
()
59
{
60
return
VT_INT;
61
}
62
};
63
64
template
<>
65
class
VarType
<long> {
66
public
:
67
VARTYPE
OLEType
()
68
{
69
return
VT_I4;
70
}
71
};
72
73
template
<>
74
class
VarType
<short> {
75
public
:
76
VARTYPE
OLEType
()
77
{
78
return
VT_I2;
79
}
80
};
81
82
template
<>
83
class
VarType
<unsigned char> {
84
public
:
85
VARTYPE
OLEType
()
86
{
87
return
VT_UI1;
88
}
89
};
90
91
template
<>
92
class
VarType
<unsigned int> {
93
public
:
94
VARTYPE
OLEType
()
95
{
96
return
VT_UINT;
97
}
98
};
99
100
template
<>
101
class
VarType
<unsigned long> {
102
public
:
103
VARTYPE
OLEType
()
104
{
105
return
VT_UI4;
106
}
107
};
108
109
template
<>
110
class
VarType
<unsigned short> {
111
public
:
112
VARTYPE
OLEType
()
113
{
114
return
VT_UI2;
115
}
116
};
117
118
//
119
// Class TSafeArray
120
// ~~~~~ ~~~~~~~~~~
121
// TSafeArray encapsulates the properties of OLE's SAFEARRAY and
122
// provides easy access to individual members of it.
123
//
124
template
<
class
T>
125
class
TSafeArray
:
public
TAutoVal {
126
public
:
127
TSafeArray
(
int
n);
128
~TSafeArray
();
129
130
// Indexing operator
131
//
132
T&
operator[]
(
int
index);
133
};
134
135
// TSafeArray inline functions
136
//
137
template
<
class
T>
138
inline
139
TSafeArray<T>::TSafeArray
(
int
n)
140
:
141
TAutoVal()
142
{
143
SAFEARRAYBOUND bound;
144
bound.lLbound = 0;
145
bound.cElements = n;
146
147
VARTYPE varType =
VarType<T>
().
OLEType
();
148
149
((
VARIANT
*)
this
)->vt = (
VARTYPE
)(
varType
|
VT_ARRAY
);
150
((
VARIANT
*)
this
)->parray =
::SafeArrayCreate
(
varType
, 1, &
bound
);
151
}
152
153
template
<
class
T>
154
inline
155
TSafeArray<T>::~TSafeArray
()
156
{
157
// TAutoVal::~Clear() takes care of freeing the array!
158
}
159
160
template
<
class
T>
161
T&
162
TSafeArray<T>::operator[]
(
int
index)
163
{
164
T*
tmp
= (T*)(GetArray()->pvData);
165
return
tmp
[index];
166
}
167
168
#endif
// _SAFEARRAY_H
autodefs.h
OLE Automation Class Definitions.
TSafeArray
Definition
safearray.h:125
TSafeArray::~TSafeArray
~TSafeArray()
Definition
safearray.h:155
TSafeArray::TSafeArray
TSafeArray(int n)
Definition
safearray.h:139
TSafeArray::operator[]
T & operator[](int index)
Definition
safearray.h:162
VarType< bool >::OLEType
VARTYPE OLEType()
Definition
safearray.h:22
VarType< char >::OLEType
VARTYPE OLEType()
Definition
safearray.h:31
VarType< double >::OLEType
VARTYPE OLEType()
Definition
safearray.h:40
VarType< float >::OLEType
VARTYPE OLEType()
Definition
safearray.h:49
VarType< int >::OLEType
VARTYPE OLEType()
Definition
safearray.h:58
VarType< long >::OLEType
VARTYPE OLEType()
Definition
safearray.h:67
VarType< short >::OLEType
VARTYPE OLEType()
Definition
safearray.h:76
VarType< unsigned char >::OLEType
VARTYPE OLEType()
Definition
safearray.h:85
VarType< unsigned int >::OLEType
VARTYPE OLEType()
Definition
safearray.h:94
VarType< unsigned long >::OLEType
VARTYPE OLEType()
Definition
safearray.h:103
VarType< unsigned short >::OLEType
VARTYPE OLEType()
Definition
safearray.h:112
VarType
Definition
safearray.h:14
VarType::OLEType
virtual VARTYPE OLEType()=0
include
ocf
safearray.h
Generated by
1.10.0