Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | // Windows/PropVariant.cpp |
michael@0 | 2 | |
michael@0 | 3 | #include "StdAfx.h" |
michael@0 | 4 | |
michael@0 | 5 | #include "PropVariant.h" |
michael@0 | 6 | |
michael@0 | 7 | #include "../Common/Defs.h" |
michael@0 | 8 | |
michael@0 | 9 | namespace NWindows { |
michael@0 | 10 | namespace NCOM { |
michael@0 | 11 | |
michael@0 | 12 | CPropVariant::CPropVariant(const PROPVARIANT& varSrc) |
michael@0 | 13 | { |
michael@0 | 14 | vt = VT_EMPTY; |
michael@0 | 15 | InternalCopy(&varSrc); |
michael@0 | 16 | } |
michael@0 | 17 | |
michael@0 | 18 | CPropVariant::CPropVariant(const CPropVariant& varSrc) |
michael@0 | 19 | { |
michael@0 | 20 | vt = VT_EMPTY; |
michael@0 | 21 | InternalCopy(&varSrc); |
michael@0 | 22 | } |
michael@0 | 23 | |
michael@0 | 24 | CPropVariant::CPropVariant(BSTR bstrSrc) |
michael@0 | 25 | { |
michael@0 | 26 | vt = VT_EMPTY; |
michael@0 | 27 | *this = bstrSrc; |
michael@0 | 28 | } |
michael@0 | 29 | |
michael@0 | 30 | CPropVariant::CPropVariant(LPCOLESTR lpszSrc) |
michael@0 | 31 | { |
michael@0 | 32 | vt = VT_EMPTY; |
michael@0 | 33 | *this = lpszSrc; |
michael@0 | 34 | } |
michael@0 | 35 | |
michael@0 | 36 | CPropVariant& CPropVariant::operator=(const CPropVariant& varSrc) |
michael@0 | 37 | { |
michael@0 | 38 | InternalCopy(&varSrc); |
michael@0 | 39 | return *this; |
michael@0 | 40 | } |
michael@0 | 41 | CPropVariant& CPropVariant::operator=(const PROPVARIANT& varSrc) |
michael@0 | 42 | { |
michael@0 | 43 | InternalCopy(&varSrc); |
michael@0 | 44 | return *this; |
michael@0 | 45 | } |
michael@0 | 46 | |
michael@0 | 47 | CPropVariant& CPropVariant::operator=(BSTR bstrSrc) |
michael@0 | 48 | { |
michael@0 | 49 | *this = (LPCOLESTR)bstrSrc; |
michael@0 | 50 | return *this; |
michael@0 | 51 | } |
michael@0 | 52 | |
michael@0 | 53 | CPropVariant& CPropVariant::operator=(LPCOLESTR lpszSrc) |
michael@0 | 54 | { |
michael@0 | 55 | InternalClear(); |
michael@0 | 56 | vt = VT_BSTR; |
michael@0 | 57 | bstrVal = ::SysAllocString(lpszSrc); |
michael@0 | 58 | if (bstrVal == NULL && lpszSrc != NULL) |
michael@0 | 59 | { |
michael@0 | 60 | vt = VT_ERROR; |
michael@0 | 61 | scode = E_OUTOFMEMORY; |
michael@0 | 62 | } |
michael@0 | 63 | return *this; |
michael@0 | 64 | } |
michael@0 | 65 | |
michael@0 | 66 | |
michael@0 | 67 | CPropVariant& CPropVariant::operator=(bool bSrc) |
michael@0 | 68 | { |
michael@0 | 69 | if (vt != VT_BOOL) |
michael@0 | 70 | { |
michael@0 | 71 | InternalClear(); |
michael@0 | 72 | vt = VT_BOOL; |
michael@0 | 73 | } |
michael@0 | 74 | boolVal = bSrc ? VARIANT_TRUE : VARIANT_FALSE; |
michael@0 | 75 | return *this; |
michael@0 | 76 | } |
michael@0 | 77 | |
michael@0 | 78 | CPropVariant& CPropVariant::operator=(UInt32 value) |
michael@0 | 79 | { |
michael@0 | 80 | if (vt != VT_UI4) |
michael@0 | 81 | { |
michael@0 | 82 | InternalClear(); |
michael@0 | 83 | vt = VT_UI4; |
michael@0 | 84 | } |
michael@0 | 85 | ulVal = value; |
michael@0 | 86 | return *this; |
michael@0 | 87 | } |
michael@0 | 88 | |
michael@0 | 89 | CPropVariant& CPropVariant::operator=(UInt64 value) |
michael@0 | 90 | { |
michael@0 | 91 | if (vt != VT_UI8) |
michael@0 | 92 | { |
michael@0 | 93 | InternalClear(); |
michael@0 | 94 | vt = VT_UI8; |
michael@0 | 95 | } |
michael@0 | 96 | uhVal.QuadPart = value; |
michael@0 | 97 | return *this; |
michael@0 | 98 | } |
michael@0 | 99 | |
michael@0 | 100 | CPropVariant& CPropVariant::operator=(const FILETIME &value) |
michael@0 | 101 | { |
michael@0 | 102 | if (vt != VT_FILETIME) |
michael@0 | 103 | { |
michael@0 | 104 | InternalClear(); |
michael@0 | 105 | vt = VT_FILETIME; |
michael@0 | 106 | } |
michael@0 | 107 | filetime = value; |
michael@0 | 108 | return *this; |
michael@0 | 109 | } |
michael@0 | 110 | |
michael@0 | 111 | CPropVariant& CPropVariant::operator=(Int32 value) |
michael@0 | 112 | { |
michael@0 | 113 | if (vt != VT_I4) |
michael@0 | 114 | { |
michael@0 | 115 | InternalClear(); |
michael@0 | 116 | vt = VT_I4; |
michael@0 | 117 | } |
michael@0 | 118 | lVal = value; |
michael@0 | 119 | |
michael@0 | 120 | return *this; |
michael@0 | 121 | } |
michael@0 | 122 | |
michael@0 | 123 | CPropVariant& CPropVariant::operator=(Byte value) |
michael@0 | 124 | { |
michael@0 | 125 | if (vt != VT_UI1) |
michael@0 | 126 | { |
michael@0 | 127 | InternalClear(); |
michael@0 | 128 | vt = VT_UI1; |
michael@0 | 129 | } |
michael@0 | 130 | bVal = value; |
michael@0 | 131 | return *this; |
michael@0 | 132 | } |
michael@0 | 133 | |
michael@0 | 134 | CPropVariant& CPropVariant::operator=(Int16 value) |
michael@0 | 135 | { |
michael@0 | 136 | if (vt != VT_I2) |
michael@0 | 137 | { |
michael@0 | 138 | InternalClear(); |
michael@0 | 139 | vt = VT_I2; |
michael@0 | 140 | } |
michael@0 | 141 | iVal = value; |
michael@0 | 142 | return *this; |
michael@0 | 143 | } |
michael@0 | 144 | |
michael@0 | 145 | /* |
michael@0 | 146 | CPropVariant& CPropVariant::operator=(LONG value) |
michael@0 | 147 | { |
michael@0 | 148 | if (vt != VT_I4) |
michael@0 | 149 | { |
michael@0 | 150 | InternalClear(); |
michael@0 | 151 | vt = VT_I4; |
michael@0 | 152 | } |
michael@0 | 153 | lVal = value; |
michael@0 | 154 | return *this; |
michael@0 | 155 | } |
michael@0 | 156 | */ |
michael@0 | 157 | |
michael@0 | 158 | static HRESULT MyPropVariantClear(PROPVARIANT *propVariant) |
michael@0 | 159 | { |
michael@0 | 160 | switch(propVariant->vt) |
michael@0 | 161 | { |
michael@0 | 162 | case VT_UI1: |
michael@0 | 163 | case VT_I1: |
michael@0 | 164 | case VT_I2: |
michael@0 | 165 | case VT_UI2: |
michael@0 | 166 | case VT_BOOL: |
michael@0 | 167 | case VT_I4: |
michael@0 | 168 | case VT_UI4: |
michael@0 | 169 | case VT_R4: |
michael@0 | 170 | case VT_INT: |
michael@0 | 171 | case VT_UINT: |
michael@0 | 172 | case VT_ERROR: |
michael@0 | 173 | case VT_FILETIME: |
michael@0 | 174 | case VT_UI8: |
michael@0 | 175 | case VT_R8: |
michael@0 | 176 | case VT_CY: |
michael@0 | 177 | case VT_DATE: |
michael@0 | 178 | propVariant->vt = VT_EMPTY; |
michael@0 | 179 | return S_OK; |
michael@0 | 180 | } |
michael@0 | 181 | return ::VariantClear((VARIANTARG *)propVariant); |
michael@0 | 182 | } |
michael@0 | 183 | |
michael@0 | 184 | HRESULT CPropVariant::Clear() |
michael@0 | 185 | { |
michael@0 | 186 | return MyPropVariantClear(this); |
michael@0 | 187 | } |
michael@0 | 188 | |
michael@0 | 189 | HRESULT CPropVariant::Copy(const PROPVARIANT* pSrc) |
michael@0 | 190 | { |
michael@0 | 191 | ::VariantClear((tagVARIANT *)this); |
michael@0 | 192 | switch(pSrc->vt) |
michael@0 | 193 | { |
michael@0 | 194 | case VT_UI1: |
michael@0 | 195 | case VT_I1: |
michael@0 | 196 | case VT_I2: |
michael@0 | 197 | case VT_UI2: |
michael@0 | 198 | case VT_BOOL: |
michael@0 | 199 | case VT_I4: |
michael@0 | 200 | case VT_UI4: |
michael@0 | 201 | case VT_R4: |
michael@0 | 202 | case VT_INT: |
michael@0 | 203 | case VT_UINT: |
michael@0 | 204 | case VT_ERROR: |
michael@0 | 205 | case VT_FILETIME: |
michael@0 | 206 | case VT_UI8: |
michael@0 | 207 | case VT_R8: |
michael@0 | 208 | case VT_CY: |
michael@0 | 209 | case VT_DATE: |
michael@0 | 210 | memmove((PROPVARIANT*)this, pSrc, sizeof(PROPVARIANT)); |
michael@0 | 211 | return S_OK; |
michael@0 | 212 | } |
michael@0 | 213 | return ::VariantCopy((tagVARIANT *)this, (tagVARIANT *)(pSrc)); |
michael@0 | 214 | } |
michael@0 | 215 | |
michael@0 | 216 | |
michael@0 | 217 | HRESULT CPropVariant::Attach(PROPVARIANT* pSrc) |
michael@0 | 218 | { |
michael@0 | 219 | HRESULT hr = Clear(); |
michael@0 | 220 | if (FAILED(hr)) |
michael@0 | 221 | return hr; |
michael@0 | 222 | memcpy(this, pSrc, sizeof(PROPVARIANT)); |
michael@0 | 223 | pSrc->vt = VT_EMPTY; |
michael@0 | 224 | return S_OK; |
michael@0 | 225 | } |
michael@0 | 226 | |
michael@0 | 227 | HRESULT CPropVariant::Detach(PROPVARIANT* pDest) |
michael@0 | 228 | { |
michael@0 | 229 | HRESULT hr = MyPropVariantClear(pDest); |
michael@0 | 230 | if (FAILED(hr)) |
michael@0 | 231 | return hr; |
michael@0 | 232 | memcpy(pDest, this, sizeof(PROPVARIANT)); |
michael@0 | 233 | vt = VT_EMPTY; |
michael@0 | 234 | return S_OK; |
michael@0 | 235 | } |
michael@0 | 236 | |
michael@0 | 237 | HRESULT CPropVariant::InternalClear() |
michael@0 | 238 | { |
michael@0 | 239 | HRESULT hr = Clear(); |
michael@0 | 240 | if (FAILED(hr)) |
michael@0 | 241 | { |
michael@0 | 242 | vt = VT_ERROR; |
michael@0 | 243 | scode = hr; |
michael@0 | 244 | } |
michael@0 | 245 | return hr; |
michael@0 | 246 | } |
michael@0 | 247 | |
michael@0 | 248 | void CPropVariant::InternalCopy(const PROPVARIANT* pSrc) |
michael@0 | 249 | { |
michael@0 | 250 | HRESULT hr = Copy(pSrc); |
michael@0 | 251 | if (FAILED(hr)) |
michael@0 | 252 | { |
michael@0 | 253 | vt = VT_ERROR; |
michael@0 | 254 | scode = hr; |
michael@0 | 255 | } |
michael@0 | 256 | } |
michael@0 | 257 | |
michael@0 | 258 | int CPropVariant::Compare(const CPropVariant &a) |
michael@0 | 259 | { |
michael@0 | 260 | if(vt != a.vt) |
michael@0 | 261 | return 0; // it's mean some bug |
michael@0 | 262 | switch (vt) |
michael@0 | 263 | { |
michael@0 | 264 | case VT_EMPTY: |
michael@0 | 265 | return 0; |
michael@0 | 266 | |
michael@0 | 267 | /* |
michael@0 | 268 | case VT_I1: |
michael@0 | 269 | return MyCompare(cVal, a.cVal); |
michael@0 | 270 | */ |
michael@0 | 271 | case VT_UI1: |
michael@0 | 272 | return MyCompare(bVal, a.bVal); |
michael@0 | 273 | |
michael@0 | 274 | case VT_I2: |
michael@0 | 275 | return MyCompare(iVal, a.iVal); |
michael@0 | 276 | case VT_UI2: |
michael@0 | 277 | return MyCompare(uiVal, a.uiVal); |
michael@0 | 278 | |
michael@0 | 279 | case VT_I4: |
michael@0 | 280 | return MyCompare(lVal, a.lVal); |
michael@0 | 281 | /* |
michael@0 | 282 | case VT_INT: |
michael@0 | 283 | return MyCompare(intVal, a.intVal); |
michael@0 | 284 | */ |
michael@0 | 285 | case VT_UI4: |
michael@0 | 286 | return MyCompare(ulVal, a.ulVal); |
michael@0 | 287 | /* |
michael@0 | 288 | case VT_UINT: |
michael@0 | 289 | return MyCompare(uintVal, a.uintVal); |
michael@0 | 290 | */ |
michael@0 | 291 | case VT_I8: |
michael@0 | 292 | return MyCompare(hVal.QuadPart, a.hVal.QuadPart); |
michael@0 | 293 | case VT_UI8: |
michael@0 | 294 | return MyCompare(uhVal.QuadPart, a.uhVal.QuadPart); |
michael@0 | 295 | |
michael@0 | 296 | case VT_BOOL: |
michael@0 | 297 | return -MyCompare(boolVal, a.boolVal); |
michael@0 | 298 | |
michael@0 | 299 | case VT_FILETIME: |
michael@0 | 300 | return ::CompareFileTime(&filetime, &a.filetime); |
michael@0 | 301 | case VT_BSTR: |
michael@0 | 302 | return 0; // Not implemented |
michael@0 | 303 | // return MyCompare(aPropVarint.cVal); |
michael@0 | 304 | |
michael@0 | 305 | default: |
michael@0 | 306 | return 0; |
michael@0 | 307 | } |
michael@0 | 308 | } |
michael@0 | 309 | |
michael@0 | 310 | }} |