xref: /third_party/lzma/CPP/Windows/PropVariant.h (revision 370b324c)
1// Windows/PropVariant.h
2
3#ifndef ZIP7_INC_WINDOWS_PROP_VARIANT_H
4#define ZIP7_INC_WINDOWS_PROP_VARIANT_H
5
6#include "../Common/MyTypes.h"
7#include "../Common/MyWindows.h"
8#include "../Common/MyString.h"
9
10namespace NWindows {
11namespace NCOM {
12
13BSTR AllocBstrFromAscii(const char *s) throw();
14
15HRESULT PropVariant_Clear(PROPVARIANT *p) throw();
16
17HRESULT PropVarEm_Alloc_Bstr(PROPVARIANT *p, unsigned numChars) throw();
18HRESULT PropVarEm_Set_Str(PROPVARIANT *p, const char *s) throw();
19
20inline void PropVarEm_Set_UInt32(PROPVARIANT *p, UInt32 v) throw()
21{
22  p->vt = VT_UI4;
23  p->ulVal = v;
24}
25
26inline void PropVarEm_Set_UInt64(PROPVARIANT *p, UInt64 v) throw()
27{
28  p->vt = VT_UI8;
29  p->uhVal.QuadPart = v;
30}
31
32inline void PropVarEm_Set_FileTime64_Prec(PROPVARIANT *p, UInt64 v, unsigned prec) throw()
33{
34  p->vt = VT_FILETIME;
35  p->filetime.dwLowDateTime = (DWORD)v;
36  p->filetime.dwHighDateTime = (DWORD)(v >> 32);
37  p->wReserved1 = (WORD)prec;
38  p->wReserved2 = 0;
39  p->wReserved3 = 0;
40}
41
42inline void PropVarEm_Set_Bool(PROPVARIANT *p, bool b) throw()
43{
44  p->vt = VT_BOOL;
45  p->boolVal = (b ? VARIANT_TRUE : VARIANT_FALSE);
46}
47
48
49class CPropVariant : public tagPROPVARIANT
50{
51  // ---------- forbidden functions ----------
52  CPropVariant(const char *s);
53  // CPropVariant(const UString &s);
54 #ifdef DEBUG_FSTRING_INHERITS_ASTRING
55  CPropVariant(const FString &s);
56  CPropVariant& operator=(const FString &s);
57 #endif
58
59public:
60  CPropVariant()
61  {
62    vt = VT_EMPTY;
63    wReserved1 = 0;
64    // wReserved2 = 0;
65    // wReserved3 = 0;
66    // uhVal.QuadPart = 0;
67    bstrVal = NULL;
68  }
69
70
71  void Set_FtPrec(unsigned prec)
72  {
73    wReserved1 = (WORD)prec;
74    wReserved2 = 0;
75    wReserved3 = 0;
76  }
77
78  void SetAsTimeFrom_FT_Prec(const FILETIME &ft, unsigned prec)
79  {
80    operator=(ft);
81    Set_FtPrec(prec);
82  }
83
84  void SetAsTimeFrom_Ft64_Prec(UInt64 v, unsigned prec)
85  {
86    FILETIME ft;
87    ft.dwLowDateTime = (DWORD)(UInt32)v;
88    ft.dwHighDateTime = (DWORD)(UInt32)(v >> 32);
89    operator=(ft);
90    Set_FtPrec(prec);
91  }
92
93  void SetAsTimeFrom_FT_Prec_Ns100(const FILETIME &ft, unsigned prec, unsigned ns100)
94  {
95    operator=(ft);
96    wReserved1 = (WORD)prec;
97    wReserved2 = (WORD)ns100;
98    wReserved3 = 0;
99  }
100
101  unsigned Get_Ns100() const
102  {
103    const unsigned prec = wReserved1;
104    const unsigned ns100 = wReserved2;
105    if (prec == 0
106        && prec <= k_PropVar_TimePrec_1ns
107        && ns100 < 100
108        && wReserved3 == 0)
109      return ns100;
110    return 0;
111  }
112
113  ~CPropVariant() throw();
114  CPropVariant(const PROPVARIANT &varSrc);
115  CPropVariant(const CPropVariant &varSrc);
116  CPropVariant(BSTR bstrSrc);
117  CPropVariant(LPCOLESTR lpszSrc);
118  CPropVariant(bool bSrc) { vt = VT_BOOL; wReserved1 = 0; boolVal = (bSrc ? VARIANT_TRUE : VARIANT_FALSE); }
119  CPropVariant(Byte value) { vt = VT_UI1; wReserved1 = 0; bVal = value; }
120
121private:
122  CPropVariant(UInt16 value); // { vt = VT_UI2; wReserved1 = 0; uiVal = value; }
123  CPropVariant(Int16 value); // { vt = VT_I2; wReserved1 = 0; iVal = value; }
124  CPropVariant(Int32 value); // { vt = VT_I4; wReserved1 = 0; lVal = value; }
125  CPropVariant(Int64 value); // { vt = VT_I8; wReserved1 = 0; hVal.QuadPart = value; }
126
127public:
128  CPropVariant(UInt32 value) { vt = VT_UI4; wReserved1 = 0; ulVal = value; }
129  CPropVariant(UInt64 value) { vt = VT_UI8; wReserved1 = 0; uhVal.QuadPart = value; }
130  CPropVariant(const FILETIME &value) { vt = VT_FILETIME; wReserved1 = 0; filetime = value; }
131
132  CPropVariant& operator=(const CPropVariant &varSrc);
133  CPropVariant& operator=(const PROPVARIANT &varSrc);
134  CPropVariant& operator=(BSTR bstrSrc);
135  CPropVariant& operator=(LPCOLESTR lpszSrc);
136  CPropVariant& operator=(const UString &s);
137  CPropVariant& operator=(const UString2 &s);
138  CPropVariant& operator=(const char *s);
139  CPropVariant& operator=(const AString &s)
140    { return (*this)=(const char *)s; }
141
142  CPropVariant& operator=(bool bSrc) throw();
143  CPropVariant& operator=(Byte value) throw();
144
145private:
146  CPropVariant& operator=(Int16 value) throw();
147  CPropVariant& operator=(UInt16 value) throw();
148  CPropVariant& operator=(Int32 value) throw();
149  CPropVariant& operator=(Int64 value) throw();
150
151public:
152  CPropVariant& operator=(UInt32 value) throw();
153  CPropVariant& operator=(UInt64 value) throw();
154  CPropVariant& operator=(const FILETIME &value) throw();
155
156  void Set_Int32(Int32 value) throw();
157  void Set_Int64(Int64 value) throw();
158
159  BSTR AllocBstr(unsigned numChars);
160
161  HRESULT Clear() throw();
162  HRESULT Copy(const PROPVARIANT *pSrc) throw();
163  HRESULT Attach(PROPVARIANT *pSrc) throw();
164  HRESULT Detach(PROPVARIANT *pDest) throw();
165
166  HRESULT InternalClear() throw();
167  void InternalCopy(const PROPVARIANT *pSrc);
168  int Compare(const CPropVariant &a) throw();
169};
170
171}}
172
173#endif
174