summaryrefslogblamecommitdiffstats
path: root/public/sdk/inc/stgvara.hxx
blob: e71090d9ce1056db3680374505d1b0626e7a6e1b (plain) (tree)
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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430













































































































































































































































































































































































































































                                                                                    
//+-------------------------------------------------------------------------
//
//  Microsoft Windows
//  Copyright (C) Microsoft Corporation, 1992 - 1992.
//
//  File:       StgVarA.hxx - Storage Variant Class with/Allocation support
//
//  Contents:   C++ Alloc wrapper for PROPVARIANT.
//
//  History:    01-Aug-94 KyleP     Created
//              09-May-96 MikeHill  Use the 'boolVal' member of PropVariant,
//                                  rather than the member named 'bool'
//                                  (which is a reserved keyword).
//
//--------------------------------------------------------------------------

#if !defined(__STGVARA_HXX__)
#define __STGVARA_HXX__

#include <stgvarb.hxx>

//+-------------------------------------------------------------------------
//
//  Class:      CAllocStorageVariant
//
//  Purpose:    C++ wrapper for PROPVARIANT
//
//  History:    01-Aug-94 KyleP     Created
//
//  Notes:      This class should only be instantiated through subclasses that
//              define PMemoryAllocator.  CStorageVariant is the most common
//              subclass, which uses CoTaskMemAlloc/Free inside its allocator.
//
//              Constructors that allocate memory require a PMemoryAllocator.
//              The destructor is private to force use of the ResetType()
//              method, which also requires a PMemoryAllocator.
//
//              A couple of variant arms are not implemented below.
//              VT_BSTR because its type signature is identical to that of
//              VT_LPSTR.
//
//              Some types are duplicate base types with a different variant
//              tag.  These include:
//                  VARIANT_BOOL (short)
//                  SCODE        (long)
//                  DATE         (double)
//              We cannot create trivial constructors for the above because
//              of the type collision.  You must use the Set methods.
//
//--------------------------------------------------------------------------

class CAllocStorageVariant: public CBaseStorageVariant
{
public:

    //
    // Simple types
    //

    CAllocStorageVariant()                  { vt = VT_EMPTY; }
    CAllocStorageVariant(short i)           { vt = VT_I2; iVal = i; }
    CAllocStorageVariant(long l)            { vt = VT_I4; lVal = l; }
    CAllocStorageVariant(LARGE_INTEGER h)   { vt = VT_I8; hVal = h; }
    CAllocStorageVariant(float flt)         { vt = VT_R4; fltVal = flt; }
    CAllocStorageVariant(double dbl)        { vt = VT_R8; dblVal = dbl; }
    CAllocStorageVariant(CY cy)             { vt = VT_CY; cyVal = cy; }
    CAllocStorageVariant(FILETIME ft)       { vt = VT_FILETIME; filetime = ft; }

    //
    // Types with indirection
    //

    CAllocStorageVariant(BLOB b, PMemoryAllocator &ma)
    {
        new (this) CAllocStorageVariant(b.pBlobData, b.cbSize, ma);
    }
    CAllocStorageVariant(BYTE *pb, ULONG cb, PMemoryAllocator &ma);
    CAllocStorageVariant(char const *psz, PMemoryAllocator &ma);
    CAllocStorageVariant(WCHAR const *pwsz, PMemoryAllocator &ma);
    CAllocStorageVariant(CLSID const *pcid, PMemoryAllocator &ma);

    //
    // Interface types
    //

    CAllocStorageVariant(IStream *pstr, PMemoryAllocator &ma);
    CAllocStorageVariant(IStorage *pstor, PMemoryAllocator &ma);

    //
    // Counted array types.  Elements initially zeroed.  Use Set/Get/Size
    // for access.
    //

    CAllocStorageVariant(VARENUM vt, ULONG cElements, PMemoryAllocator &ma);

    //
    // To/From C style PROPVARIANT and copy constructor
    //

    CAllocStorageVariant(PROPVARIANT &var, PMemoryAllocator &ma);

    operator PROPVARIANT *() const { return((PROPVARIANT *) this); }
    operator PROPVARIANT &() const { return(*(PROPVARIANT *) this); }

    operator PROPVARIANT const *() { return((PROPVARIANT *) this); }
    operator PROPVARIANT const &() { return(*(PROPVARIANT *) this); }


    CAllocStorageVariant(PDeSerStream &stm, PMemoryAllocator &ma);

    //
    // Casts for simple types.
    //

    operator short() const          { return(iVal); }
    operator USHORT() const         { return(uiVal); }
    operator long() const           { return(lVal); }
    operator ULONG() const          { return(ulVal); }
    operator LARGE_INTEGER() const  { return(hVal); }
    operator ULARGE_INTEGER() const { return(uhVal); }
    operator float() const          { return(fltVal); }
    operator double() const         { return(dblVal); }
    operator CY() const             { return(cyVal); }
    operator FILETIME() const       { return(filetime); }
    operator char const *() const   { return(pszVal); }
    operator WCHAR const *() const  { return(pwszVal); }
    operator IStream *() const      { return(pStream); }
    operator IStorage *() const     { return(pStorage); }

    BOOL IsValid() const;

    //
    // Member variable access
    //

    VARENUM Type() const { return((VARENUM) vt); }

    //
    // Set/Get, all types including arrays.
    //

    void SetEMPTY(PMemoryAllocator &ma)
    {
        ResetType(ma);
        vt = VT_EMPTY;
    }

    void SetNULL(PMemoryAllocator &ma)
    {
        ResetType(ma);
        vt = VT_NULL;
    }

    void SetUI1(BYTE b, PMemoryAllocator &ma)
    {
        ResetType(ma);
        vt = VT_UI1;
        bVal = b;
    }

    BYTE GetUI1() const { return bVal; }

    void SetI2(short i, PMemoryAllocator &ma)
    {
        ResetType(ma);
        new (this) CAllocStorageVariant(i);
    }
    short GetI2() const { return(iVal); }

    void SetUI2(USHORT ui, PMemoryAllocator &ma)
    {
        ResetType(ma);
        vt = VT_UI2;
        uiVal = ui;
    }
    ULONG GetUI2() const { return(uiVal); }

    void SetI4(long l, PMemoryAllocator &ma)
    {
        ResetType(ma);
        new (this) CAllocStorageVariant(l);
    }
    long GetI4() const { return(lVal); }

    void SetUI4(ULONG ul, PMemoryAllocator &ma)
    {
        ResetType(ma);
        vt = VT_UI4;
        ulVal = ul;
    }
    ULONG GetUI4() const { return(ulVal); }

    void SetR4(float f, PMemoryAllocator &ma)
    {
        ResetType(ma);
        new (this) CAllocStorageVariant(f);
    }
    float GetR4() const { return(fltVal); }

    void SetR8(double d, PMemoryAllocator &ma)
    {
        ResetType(ma);
        new (this) CAllocStorageVariant(d);
    }
    double GetR8() const { return(dblVal); }

    void SetI8(LARGE_INTEGER li, PMemoryAllocator &ma)
    {
        ResetType(ma);
        new (this) CAllocStorageVariant(li);
    }
    LARGE_INTEGER GetI8() const { return(hVal); }

    void SetUI8(ULARGE_INTEGER uli, PMemoryAllocator &ma)
    {
        ResetType(ma);
        vt = VT_UI8;
        uhVal = uli;
    }
    ULARGE_INTEGER GetUI8() const { return(uhVal); }

    void SetBOOL(VARIANT_BOOL b, PMemoryAllocator &ma)
    {
        ResetType(ma);
        vt = VT_BOOL;
        boolVal = b;
    }
    VARIANT_BOOL GetBOOL() const { return(boolVal); }

    void SetERROR(SCODE sc, PMemoryAllocator &ma)
    {
        ResetType(ma);
        vt = VT_ERROR;
        scode = sc;
    }
    SCODE GetERROR() const { return(scode); }

    void SetCY(CY cy, PMemoryAllocator &ma)
    {
        ResetType(ma);
        new (this) CAllocStorageVariant(cy);
    }
    CY GetCY() const { return(cyVal); }

    void SetDATE(DATE d, PMemoryAllocator &ma)
    {
        ResetType(ma);
        vt = VT_DATE;
        date = d;
    }
    DATE GetDATE() const { return(date); }

    void SetBSTR(BSTR b, PMemoryAllocator &ma);
    BSTR GetBSTR() const { return(bstrVal); }  // No ownership xfer!

    void SetLPSTR(char const *psz, PMemoryAllocator &ma)
    {
        ResetType(ma);
        new (this) CAllocStorageVariant(psz, ma);
    }
    char const *GetLPSTR() const { return(pszVal); }  // No ownership xfer!

    void SetLPWSTR(WCHAR const *pwsz, PMemoryAllocator &ma)
    {
        ResetType(ma);
        new (this) CAllocStorageVariant(pwsz, ma);
    }
    WCHAR const *GetLPWSTR() const { return(pwszVal); } // No owner xfer!

    void SetFILETIME(FILETIME ft, PMemoryAllocator &ma)
    {
        ResetType(ma);
        new (this) CAllocStorageVariant(ft);
    }
    FILETIME GetFILETIME() const { return(filetime); }

    void SetBLOB(BLOB b, PMemoryAllocator &ma)
    {
        ResetType(ma);
        new (this) CAllocStorageVariant(b, ma);
    }
    BLOB GetBLOB() const { return(blob); }              // No ownership xfer!

    void SetSTREAM(IStream *ps, PMemoryAllocator &ma)
    {
        ResetType(ma);
        vt = VT_STREAM;
        pStream = ps;
        ps->AddRef();
    }
    IStream *GetSTREAM() const { return(pStream); }

    void SetSTREAMED_OBJECT(IStream *ps, PMemoryAllocator &ma)
    {
        ResetType(ma);
        vt = VT_STREAMED_OBJECT;
        pStream = ps;
        ps->AddRef();
    }
    IStream *GetSTREAMED_OBJECT() const { return(pStream); }

    void SetSTORAGE(IStorage *ps, PMemoryAllocator &ma)
    {
        ResetType(ma);
        vt = VT_STORAGE;
        pStorage = ps;
        ps->AddRef();
    }
    IStorage *GetSTORAGE() const { return(pStorage); }

    void SetSTORED_OBJECT(IStorage *ps, PMemoryAllocator &ma)
    {
        ResetType(ma);
        vt = VT_STORED_OBJECT;
        pStorage = ps;
        ps->AddRef();
    }
    IStorage *GetSTORED_OBJECT() const { return(pStorage); }

    void SetCLSID(CLSID const *pc, PMemoryAllocator &ma)
    {
        ResetType(ma);
        new (this) CAllocStorageVariant(pc, ma);
    }
    CLSID const *GetCLSID() const { return(puuid); }    // No ownership xfer!

    //
    // Array access
    //

    inline ULONG Count() const;

    void  SetUI1(BYTE b, unsigned pos, PMemoryAllocator &ma);
    BYTE GetUI1(unsigned pos) const;

    void  SetI2(short i, unsigned pos, PMemoryAllocator &ma);
    short GetI2(unsigned pos) const;

    void  SetUI2(USHORT ui, unsigned pos, PMemoryAllocator &ma);
    USHORT GetUI2(unsigned pos) const;

    void SetI4(long l, unsigned pos, PMemoryAllocator &ma);
    long GetI4(unsigned pos) const;

    void SetUI4(ULONG ul, unsigned pos, PMemoryAllocator &ma);
    ULONG GetUI4(unsigned pos) const;

    void          SetI8(LARGE_INTEGER li, unsigned pos, PMemoryAllocator &ma);
    LARGE_INTEGER GetI8(unsigned pos) const;

    void           SetUI8(ULARGE_INTEGER uli, unsigned pos, PMemoryAllocator &ma);
    ULARGE_INTEGER GetUI8(unsigned pos) const;

    void  SetR4(float f, unsigned pos, PMemoryAllocator &ma);
    float GetR4(unsigned pos) const;

    void   SetR8(double d, unsigned pos, PMemoryAllocator &ma);
    double GetR8(unsigned pos) const;

    void         SetBOOL(VARIANT_BOOL b, unsigned pos, PMemoryAllocator &ma);
    VARIANT_BOOL GetBOOL(unsigned pos) const;

    void SetCY(CY c, unsigned pos, PMemoryAllocator &ma);
    CY   GetCY(unsigned pos) const;

    void SetDATE(DATE d, unsigned pos, PMemoryAllocator &ma);
    DATE GetDATE(unsigned pos) const;

    void SetBSTR(BSTR b, unsigned pos, PMemoryAllocator &ma);
    BSTR GetBSTR(unsigned pos) const { return cabstr.pElems[pos]; }

//    void SetVARIANT(CAllocStorageVariant var, unsigned pos, PMemoryAllocator &ma);
    inline CAllocStorageVariant & GetVARIANT(unsigned pos) const;

    void   SetLPSTR(char const *psz, unsigned pos, PMemoryAllocator &ma);
    char *GetLPSTR(unsigned pos) const;

    void    SetLPWSTR(WCHAR const *pwsz, unsigned pos, PMemoryAllocator &ma);
    WCHAR *GetLPWSTR(unsigned pos) const;

    void     SetFILETIME(FILETIME f, unsigned pos, PMemoryAllocator &ma);
    FILETIME GetFILETIME(unsigned pos) const;

    void  SetCLSID(CLSID c, unsigned pos, PMemoryAllocator &ma);
    CLSID GetCLSID(unsigned pos) const;

protected:

    //
    // Manual & Default Destructor
    //

    void ResetType(PMemoryAllocator &ma);

    ~CAllocStorageVariant();

    //
    // Memory allocation.  Returns passed parameter only.
    //

    void *operator new(size_t size, void *p)
    {
        return(p);
    }

private:
    BOOLEAN _AddStringToVector(
        unsigned pos,
        VOID *pv,
        ULONG cb,
        PMemoryAllocator &ma);
};


inline ULONG
CAllocStorageVariant::Count() const
{
    if (Type() & VT_VECTOR)
    {
        return( cai.cElems );
    }
    return( 0 );
}

inline CAllocStorageVariant & CAllocStorageVariant::GetVARIANT(unsigned pos) const
{
    return (CAllocStorageVariant &) capropvar.pElems[pos];
}

#endif // __STGVARA_HXX__