annotate src/win32/7zip/7z/CPP/Windows/PropVariant.cpp @ 5:8fe0c57e53d2

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