Changeset 36186 in vbox for trunk/include/VBox
- Timestamp:
- Mar 7, 2011 1:14:34 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/VBox/com/array.h
r35913 r36186 5 5 6 6 /* 7 * Copyright (C) 2006-20 07Oracle Corporation7 * Copyright (C) 2006-2011 Oracle Corporation 8 8 * 9 9 * This file is part of VirtualBox Open Source Edition (OSE), as … … 56 56 * @code 57 57 58 STDMETHOD(TestArrays) (ComSafeArrayIn(LONG, aIn),59 ComSafeArrayOut(LONG, aOut),60 ComSafeArrayOut(LONG, aRet));58 STDMETHOD(TestArrays)(ComSafeArrayIn(LONG, aIn), 59 ComSafeArrayOut(LONG, aOut), 60 ComSafeArrayOut(LONG, aRet)); 61 61 62 62 * @endcode … … 65 65 * @code 66 66 67 STDMETHODIMP Component::TestArrays (ComSafeArrayIn(LONG, aIn),68 ComSafeArrayOut(LONG, aOut),69 ComSafeArrayOut(LONG, aRet))70 { 71 if (ComSafeArrayInIsNull 67 STDMETHODIMP Component::TestArrays(ComSafeArrayIn(LONG, aIn), 68 ComSafeArrayOut(LONG, aOut), 69 ComSafeArrayOut(LONG, aRet)) 70 { 71 if (ComSafeArrayInIsNull(aIn)) 72 72 return E_INVALIDARG; 73 if (ComSafeArrayOutIsNull 73 if (ComSafeArrayOutIsNull(aOut)) 74 74 return E_POINTER; 75 if (ComSafeArrayOutIsNull 75 if (ComSafeArrayOutIsNull(aRet)) 76 76 return E_POINTER; 77 77 78 78 // Use SafeArray to access the input array parameter 79 79 80 com::SafeArray <LONG> in (ComSafeArrayInArg(aIn));80 com::SafeArray<LONG> in(ComSafeArrayInArg(aIn)); 81 81 82 82 for (size_t i = 0; i < in.size(); ++ i) 83 LogFlow (("*** in[%u]=%d\n", i, in[i]));83 LogFlow(("*** in[%u]=%d\n", i, in[i])); 84 84 85 85 // Use SafeArray to create the return array (the same technique is used 86 86 // for output array parameters) 87 87 88 SafeArray <LONG> ret(in.size() * 2);88 SafeArray<LONG> ret(in.size() * 2); 89 89 for (size_t i = 0; i < in.size(); ++ i) 90 90 { 91 ret [i] = in[i];92 ret [i + in.size()] = in[i] * 10;93 } 94 95 ret.detachTo (ComSafeArrayOutArg(aRet));91 ret[i] = in[i]; 92 ret[i + in.size()] = in[i] * 10; 93 } 94 95 ret.detachTo(ComSafeArrayOutArg(aRet)); 96 96 97 97 return S_OK; … … 103 103 * @code 104 104 105 ComPtr 105 ComPtr<ISomething> component; 106 106 107 107 // ... 108 108 109 com::SafeArray <LONG> in(3);110 in 111 in 112 in 113 114 com::SafeArray 115 com::SafeArray 116 117 HRESULT rc = component->TestArrays (ComSafeArrayAsInParam(in),118 ComSafeArrayAsOutParam(out),119 ComSafeArrayAsOutParam(ret));120 121 if (SUCCEEDED 109 com::SafeArray<LONG> in(3); 110 in[0] = -1; 111 in[1] = -2; 112 in[2] = -3; 113 114 com::SafeArray<LONG> out; 115 com::SafeArray<LONG> ret; 116 117 HRESULT rc = component->TestArrays(ComSafeArrayAsInParam(in), 118 ComSafeArrayAsOutParam(out), 119 ComSafeArrayAsOutParam(ret)); 120 121 if (SUCCEEDED(rc)) 122 122 for (size_t i = 0; i < ret.size(); ++ i) 123 printf ("*** ret[%u]=%d\n", i, ret[i]);123 printf("*** ret[%u]=%d\n", i, ret[i]); 124 124 125 125 * @endcode … … 130 130 * @code 131 131 132 STDMETHODIMP Component::COMGETTER(Values) (ComSafeArrayOut(int, aValues))133 { 134 // ... assume there is a |std::list 135 136 com::SafeArray <int> values(mValues);137 values.detachTo (ComSafeArrayOutArg(aValues));132 STDMETHODIMP Component::COMGETTER(Values)(ComSafeArrayOut(int, aValues)) 133 { 134 // ... assume there is a |std::list<int> mValues| data member 135 136 com::SafeArray<int> values(mValues); 137 values.detachTo(ComSafeArrayOutArg(aValues)); 138 138 139 139 return S_OK; … … 151 151 * 152 152 * Also note that in order to pass input BSTR array parameters declared 153 * using the ComSafeArrayIn 153 * using the ComSafeArrayIn(IN_BSTR, aParam) macro to the SafeArray<> 154 154 * constructor using the ComSafeArrayInArg() macro, you should use IN_BSTR 155 155 * as the SafeArray<> template argument, not just BSTR. … … 161 161 */ 162 162 163 #if defined (VBOX_WITH_XPCOM)163 #ifdef VBOX_WITH_XPCOM 164 164 # include <nsMemory.h> 165 165 #endif … … 169 169 #include "VBox/com/assert.h" 170 170 171 #if defined (VBOX_WITH_XPCOM)171 #ifdef VBOX_WITH_XPCOM 172 172 173 173 /** … … 179 179 */ 180 180 #define ComSafeArrayAsInParam(aArray) \ 181 (aArray).size(), (aArray).__asInParam_Arr 181 (aArray).size(), (aArray).__asInParam_Arr((aArray).raw()) 182 182 183 183 /** … … 191 191 (aArray).__asOutParam_Size(), (aArray).__asOutParam_Arr() 192 192 193 #else /* defined (VBOX_WITH_XPCOM)*/193 #else /* !VBOX_WITH_XPCOM */ 194 194 195 195 #define ComSafeArrayAsInParam(aArray) (aArray).__asInParam() … … 197 197 #define ComSafeArrayAsOutParam(aArray) (aArray).__asOutParam() 198 198 199 #endif /* defined (VBOX_WITH_XPCOM)*/199 #endif /* !VBOX_WITH_XPCOM */ 200 200 201 201 /** … … 205 205 { 206 206 207 #if defined (VBOX_WITH_XPCOM)207 #ifdef VBOX_WITH_XPCOM 208 208 209 209 //////////////////////////////////////////////////////////////////////////////// … … 214 214 * @param T Type of array elements. 215 215 */ 216 template 216 template<typename T> 217 217 struct SafeArrayTraits 218 218 { … … 220 220 221 221 /** Initializes memory for aElem. */ 222 static void Init 222 static void Init(T &aElem) { aElem = 0; } 223 223 224 224 /** Initializes memory occupied by aElem. */ 225 static void Uninit 225 static void Uninit(T &aElem) { aElem = 0; } 226 226 227 227 /** Creates a deep copy of aFrom and stores it in aTo. */ 228 static void Copy 228 static void Copy(const T &aFrom, T &aTo) { aTo = aFrom; } 229 229 230 230 public: … … 235 235 * (char/PRUnichar pointers) as const but doesn't do so for pointers to 236 236 * arrays. */ 237 static T *__asInParam_Arr 238 static T *__asInParam_Arr (const T *aArr) { return const_cast <T *>(aArr); }239 }; 240 241 template 242 struct SafeArrayTraits 237 static T *__asInParam_Arr(T *aArr) { return aArr; } 238 static T *__asInParam_Arr(const T *aArr) { return const_cast<T *>(aArr); } 239 }; 240 241 template<typename T> 242 struct SafeArrayTraits<T *> 243 243 { 244 244 // Arbitrary pointers are not supported … … 246 246 247 247 template<> 248 struct SafeArrayTraits 248 struct SafeArrayTraits<PRUnichar *> 249 249 { 250 250 protected: 251 251 252 static void Init 253 254 static void Uninit 252 static void Init(PRUnichar * &aElem) { aElem = NULL; } 253 254 static void Uninit(PRUnichar * &aElem) 255 255 { 256 256 if (aElem) 257 257 { 258 ::SysFreeString 258 ::SysFreeString(aElem); 259 259 aElem = NULL; 260 260 } 261 261 } 262 262 263 static void Copy 264 { 265 AssertCompile (sizeof (PRUnichar) == sizeof(OLECHAR));266 aTo = aFrom ? ::SysAllocString ((const OLECHAR *)aFrom) : NULL;263 static void Copy(const PRUnichar * aFrom, PRUnichar * &aTo) 264 { 265 AssertCompile(sizeof(PRUnichar) == sizeof(OLECHAR)); 266 aTo = aFrom ? ::SysAllocString((const OLECHAR *)aFrom) : NULL; 267 267 } 268 268 … … 270 270 271 271 /* Magic to workaround strict rules of par. 4.4.4 of the C++ standard */ 272 static const PRUnichar **__asInParam_Arr 273 { 274 return const_cast <const PRUnichar **>(aArr);275 } 276 static const PRUnichar **__asInParam_Arr 272 static const PRUnichar **__asInParam_Arr(PRUnichar **aArr) 273 { 274 return const_cast<const PRUnichar **>(aArr); 275 } 276 static const PRUnichar **__asInParam_Arr(const PRUnichar **aArr) { return aArr; } 277 277 }; 278 278 279 279 template<> 280 struct SafeArrayTraits 280 struct SafeArrayTraits<const PRUnichar *> 281 281 { 282 282 protected: 283 283 284 static void Init 285 static void Uninit 284 static void Init(const PRUnichar * &aElem) { aElem = NULL; } 285 static void Uninit(const PRUnichar * &aElem) 286 286 { 287 287 if (aElem) 288 288 { 289 ::SysFreeString (const_cast <PRUnichar *>(aElem));289 ::SysFreeString(const_cast<PRUnichar *>(aElem)); 290 290 aElem = NULL; 291 291 } 292 292 } 293 293 294 static void Copy 295 { 296 AssertCompile (sizeof (PRUnichar) == sizeof(OLECHAR));297 aTo = aFrom ? ::SysAllocString ((const OLECHAR *)aFrom) : NULL;294 static void Copy(const PRUnichar * aFrom, const PRUnichar * &aTo) 295 { 296 AssertCompile(sizeof(PRUnichar) == sizeof(OLECHAR)); 297 aTo = aFrom ? ::SysAllocString((const OLECHAR *)aFrom) : NULL; 298 298 } 299 299 … … 301 301 302 302 /* Magic to workaround strict rules of par. 4.4.4 of the C++ standard */ 303 static const PRUnichar **__asInParam_Arr 303 static const PRUnichar **__asInParam_Arr(const PRUnichar **aArr) { return aArr; } 304 304 }; 305 305 306 306 template<> 307 struct SafeArrayTraits 307 struct SafeArrayTraits<nsID *> 308 308 { 309 309 protected: 310 310 311 static void Init 312 313 static void Uninit 311 static void Init(nsID * &aElem) { aElem = NULL; } 312 313 static void Uninit(nsID * &aElem) 314 314 { 315 315 if (aElem) 316 316 { 317 ::nsMemory::Free 317 ::nsMemory::Free(aElem); 318 318 aElem = NULL; 319 319 } 320 320 } 321 321 322 static void Copy 322 static void Copy(const nsID * aFrom, nsID * &aTo) 323 323 { 324 324 if (aFrom) 325 325 { 326 aTo = (nsID *) ::nsMemory::Alloc (sizeof(nsID));326 aTo = (nsID *) ::nsMemory::Alloc(sizeof(nsID)); 327 327 if (aTo) 328 328 *aTo = *aFrom; … … 336 336 * be never called in context of SafeConstGUIDArray. */ 337 337 338 static void Init (const nsID * &aElem) { NOREF(aElem); AssertFailed(); }339 static void Uninit (const nsID * &aElem) { NOREF(aElem); AssertFailed(); }338 static void Init(const nsID * &aElem) { NOREF(aElem); AssertFailed(); } 339 static void Uninit(const nsID * &aElem) { NOREF(aElem); AssertFailed(); } 340 340 341 341 public: 342 342 343 343 /** Magic to workaround strict rules of par. 4.4.4 of the C++ standard. */ 344 static const nsID **__asInParam_Arr 345 { 346 return const_cast <const nsID **>(aArr);347 } 348 static const nsID **__asInParam_Arr 349 }; 350 351 #else /* defined (VBOX_WITH_XPCOM)*/344 static const nsID **__asInParam_Arr(nsID **aArr) 345 { 346 return const_cast<const nsID **>(aArr); 347 } 348 static const nsID **__asInParam_Arr(const nsID **aArr) { return aArr; } 349 }; 350 351 #else /* !VBOX_WITH_XPCOM */ 352 352 353 353 //////////////////////////////////////////////////////////////////////////////// … … 357 357 protected: 358 358 359 static SAFEARRAY *CreateSafeArray 360 { return SafeArrayCreate 359 static SAFEARRAY *CreateSafeArray(VARTYPE aVarType, SAFEARRAYBOUND *aBound) 360 { return SafeArrayCreate(aVarType, 1, aBound); } 361 361 }; 362 362 … … 373 373 // Returns the number of VarType() elements necessary for aSize 374 374 // elements of T 375 static ULONG VarCount 375 static ULONG VarCount(size_t aSize); 376 376 377 377 // Returns the number of elements of T that fit into the given number of 378 // VarType() elements (opposite to VarCount 379 static size_t Size 378 // VarType() elements (opposite to VarCount(size_t aSize)). 379 static size_t Size(ULONG aVarCount); 380 380 381 381 // Creates a deep copy of aFrom and stores it in aTo 382 static void Copy 382 static void Copy(ULONG aFrom, ULONG &aTo); 383 383 */ 384 template 384 template<typename T> 385 385 struct SafeArrayTraits : public SafeArrayTraitsBase 386 386 { … … 394 394 static VARTYPE VarType() 395 395 { 396 if (sizeof 397 if (sizeof 398 if (sizeof 396 if (sizeof(T) % 8 == 0) return VT_I8; 397 if (sizeof(T) % 4 == 0) return VT_I4; 398 if (sizeof(T) % 2 == 0) return VT_I2; 399 399 return VT_I1; 400 400 } 401 401 402 static ULONG VarCount 403 { 404 if (sizeof (T) % 8 == 0) return (ULONG) ((sizeof(T) / 8) * aSize);405 if (sizeof (T) % 4 == 0) return (ULONG) ((sizeof(T) / 4) * aSize);406 if (sizeof (T) % 2 == 0) return (ULONG) ((sizeof(T) / 2) * aSize);407 return (ULONG) (sizeof(T) * aSize);408 } 409 410 static size_t Size 411 { 412 if (sizeof (T) % 8 == 0) return (size_t) (aVarCount * 8) / sizeof(T);413 if (sizeof (T) % 4 == 0) return (size_t) (aVarCount * 4) / sizeof(T);414 if (sizeof (T) % 2 == 0) return (size_t) (aVarCount * 2) / sizeof(T);415 return (size_t) aVarCount / sizeof 416 } 417 418 static void Copy 419 }; 420 421 template 422 struct SafeArrayTraits 402 static ULONG VarCount(size_t aSize) 403 { 404 if (sizeof(T) % 8 == 0) return (ULONG)((sizeof(T) / 8) * aSize); 405 if (sizeof(T) % 4 == 0) return (ULONG)((sizeof(T) / 4) * aSize); 406 if (sizeof(T) % 2 == 0) return (ULONG)((sizeof(T) / 2) * aSize); 407 return (ULONG)(sizeof(T) * aSize); 408 } 409 410 static size_t Size(ULONG aVarCount) 411 { 412 if (sizeof(T) % 8 == 0) return (size_t)(aVarCount * 8) / sizeof(T); 413 if (sizeof(T) % 4 == 0) return (size_t)(aVarCount * 4) / sizeof(T); 414 if (sizeof(T) % 2 == 0) return (size_t)(aVarCount * 2) / sizeof(T); 415 return (size_t) aVarCount / sizeof(T); 416 } 417 418 static void Copy(T aFrom, T &aTo) { aTo = aFrom; } 419 }; 420 421 template<typename T> 422 struct SafeArrayTraits<T *> 423 423 { 424 424 // Arbitrary pointer types are not supported … … 429 429 430 430 template<> 431 struct SafeArrayTraits 431 struct SafeArrayTraits<LONG> : public SafeArrayTraitsBase 432 432 { 433 433 protected: 434 434 435 435 static VARTYPE VarType() { return VT_I4; } 436 static ULONG VarCount (size_t aSize) { return (ULONG)aSize; }437 static size_t Size (ULONG aVarCount) { return (size_t)aVarCount; }438 439 static void Copy 436 static ULONG VarCount(size_t aSize) { return (ULONG)aSize; } 437 static size_t Size(ULONG aVarCount) { return (size_t)aVarCount; } 438 439 static void Copy(LONG aFrom, LONG &aTo) { aTo = aFrom; } 440 440 }; 441 441 442 442 template<> 443 struct SafeArrayTraits 443 struct SafeArrayTraits<ULONG> : public SafeArrayTraitsBase 444 444 { 445 445 protected: 446 446 447 447 static VARTYPE VarType() { return VT_UI4; } 448 static ULONG VarCount (size_t aSize) { return (ULONG)aSize; }449 static size_t Size (ULONG aVarCount) { return (size_t)aVarCount; }450 451 static void Copy 448 static ULONG VarCount(size_t aSize) { return (ULONG)aSize; } 449 static size_t Size(ULONG aVarCount) { return (size_t)aVarCount; } 450 451 static void Copy(ULONG aFrom, ULONG &aTo) { aTo = aFrom; } 452 452 }; 453 453 454 454 template<> 455 struct SafeArrayTraits 455 struct SafeArrayTraits<LONG64> : public SafeArrayTraitsBase 456 456 { 457 457 protected: 458 458 459 459 static VARTYPE VarType() { return VT_I8; } 460 static ULONG VarCount (size_t aSize) { return (ULONG)aSize; }461 static size_t Size (ULONG aVarCount) { return (size_t)aVarCount; }462 463 static void Copy 460 static ULONG VarCount(size_t aSize) { return (ULONG)aSize; } 461 static size_t Size(ULONG aVarCount) { return (size_t)aVarCount; } 462 463 static void Copy(LONG64 aFrom, LONG64 &aTo) { aTo = aFrom; } 464 464 }; 465 465 466 466 template<> 467 struct SafeArrayTraits 467 struct SafeArrayTraits<ULONG64> : public SafeArrayTraitsBase 468 468 { 469 469 protected: 470 470 471 471 static VARTYPE VarType() { return VT_UI8; } 472 static ULONG VarCount (size_t aSize) { return (ULONG)aSize; }473 static size_t Size (ULONG aVarCount) { return (size_t)aVarCount; }474 475 static void Copy 472 static ULONG VarCount(size_t aSize) { return (ULONG)aSize; } 473 static size_t Size(ULONG aVarCount) { return (size_t)aVarCount; } 474 475 static void Copy(ULONG64 aFrom, ULONG64 &aTo) { aTo = aFrom; } 476 476 }; 477 477 478 478 template<> 479 struct SafeArrayTraits 479 struct SafeArrayTraits<BSTR> : public SafeArrayTraitsBase 480 480 { 481 481 protected: 482 482 483 483 static VARTYPE VarType() { return VT_BSTR; } 484 static ULONG VarCount (size_t aSize) { return (ULONG)aSize; }485 static size_t Size (ULONG aVarCount) { return (size_t)aVarCount; }486 487 static void Copy 488 { 489 aTo = aFrom ? ::SysAllocString ((const OLECHAR *)aFrom) : NULL;484 static ULONG VarCount(size_t aSize) { return (ULONG)aSize; } 485 static size_t Size(ULONG aVarCount) { return (size_t)aVarCount; } 486 487 static void Copy(BSTR aFrom, BSTR &aTo) 488 { 489 aTo = aFrom ? ::SysAllocString((const OLECHAR *)aFrom) : NULL; 490 490 } 491 491 }; 492 492 493 493 template<> 494 struct SafeArrayTraits 494 struct SafeArrayTraits<GUID> : public SafeArrayTraitsBase 495 495 { 496 496 protected: … … 500 500 501 501 /* GUID is 128 bit, so we need two VT_UI8 */ 502 static ULONG VarCount 503 { 504 AssertCompileSize 505 return (ULONG) 506 } 507 508 static size_t Size (ULONG aVarCount) { return (size_t)aVarCount / 2; }509 510 static void Copy 502 static ULONG VarCount(size_t aSize) 503 { 504 AssertCompileSize(GUID, 16); 505 return (ULONG)(aSize * 2); 506 } 507 508 static size_t Size(ULONG aVarCount) { return (size_t)aVarCount / 2; } 509 510 static void Copy(GUID aFrom, GUID &aTo) { aTo = aFrom; } 511 511 }; 512 512 … … 517 517 class OutSafeArrayDipper 518 518 { 519 OutSafeArrayDipper 520 : arr (aArr), raw (aRaw) { Assert(*aArr == NULL && *aRaw == NULL); }519 OutSafeArrayDipper(SAFEARRAY **aArr, void **aRaw) 520 : arr(aArr), raw(aRaw) { Assert(*aArr == NULL && *aRaw == NULL); } 521 521 522 522 SAFEARRAY **arr; 523 523 void **raw; 524 524 525 template 525 template<class, class> friend class SafeArray; 526 526 527 527 public: … … 531 531 if (*arr != NULL) 532 532 { 533 HRESULT rc = SafeArrayAccessData 534 AssertComRC 533 HRESULT rc = SafeArrayAccessData(*arr, raw); 534 AssertComRC(rc); 535 535 } 536 536 } … … 539 539 }; 540 540 541 #endif /* defined (VBOX_WITH_XPCOM)*/541 #endif /* !VBOX_WITH_XPCOM */ 542 542 543 543 //////////////////////////////////////////////////////////////////////////////// … … 569 569 * @note This class is not thread-safe. 570 570 */ 571 template <typename T, class Traits = SafeArrayTraits<T> >571 template<typename T, class Traits = SafeArrayTraits<T> > 572 572 class SafeArray : public Traits 573 573 { … … 589 589 * The constructor will also assert in this case. 590 590 */ 591 SafeArray (size_t aSize) { resize(aSize); }591 SafeArray(size_t aSize) { resize(aSize); } 592 592 593 593 /** … … 597 597 * this: 598 598 * <pre> 599 * SafeArray safeArray (ComSafeArrayInArg(aArg));599 * SafeArray safeArray(ComSafeArrayInArg(aArg)); 600 600 * </pre> 601 601 * … … 606 606 * @param aArg Input method parameter to attach to. 607 607 */ 608 SafeArray (ComSafeArrayIn(T, aArg))609 { 610 #if defined (VBOX_WITH_XPCOM)611 612 AssertReturnVoid 608 SafeArray(ComSafeArrayIn(T, aArg)) 609 { 610 #ifdef VBOX_WITH_XPCOM 611 612 AssertReturnVoid(aArg != NULL); 613 613 614 614 m.size = aArgSize; … … 616 616 m.isWeak = true; 617 617 618 #else /* defined (VBOX_WITH_XPCOM)*/619 620 AssertReturnVoid 618 #else /* !VBOX_WITH_XPCOM */ 619 620 AssertReturnVoid(aArg != NULL); 621 621 SAFEARRAY *arg = aArg; 622 622 623 623 if (arg) 624 624 { 625 AssertReturnVoid 625 AssertReturnVoid(arg->cDims == 1); 626 626 627 627 VARTYPE vt; 628 HRESULT rc = SafeArrayGetVartype 629 AssertComRCReturnVoid 630 AssertMsgReturnVoid 631 632 633 634 rc = SafeArrayAccessData (arg, (void HUGEP **)&m.raw);635 AssertComRCReturnVoid 628 HRESULT rc = SafeArrayGetVartype(arg, &vt); 629 AssertComRCReturnVoid(rc); 630 AssertMsgReturnVoid(vt == VarType(), 631 ("Expected vartype %d, got %d.\n", 632 VarType(), vt)); 633 634 rc = SafeArrayAccessData(arg, (void HUGEP **)&m.raw); 635 AssertComRCReturnVoid(rc); 636 636 } 637 637 … … 639 639 m.isWeak = true; 640 640 641 #endif /* defined (VBOX_WITH_XPCOM)*/641 #endif /* !VBOX_WITH_XPCOM */ 642 642 } 643 643 … … 651 651 * @c aCntr). 652 652 */ 653 template <template<typename, typename> class C, class A>654 SafeArray (const C<T, A> & aCntr)655 { 656 resize 657 AssertReturnVoid 653 template<template<typename, typename> class C, class A> 654 SafeArray(const C<T, A> & aCntr) 655 { 656 resize(aCntr.size()); 657 AssertReturnVoid(!isNull()); 658 658 659 659 size_t i = 0; 660 for (typename C 660 for (typename C<T, A>::const_iterator it = aCntr.begin(); 661 661 it != aCntr.end(); ++ it, ++ i) 662 #if defined (VBOX_WITH_XPCOM)663 Copy (*it, m.arr[i]);664 #else 665 Copy (*it, m.raw[i]);662 #ifdef VBOX_WITH_XPCOM 663 Copy(*it, m.arr[i]); 664 #else 665 Copy(*it, m.raw[i]); 666 666 #endif 667 667 } … … 679 679 * @param K Map key class (deduced from @c aCntr). 680 680 */ 681 template <template<typename, typename, typename, typename>681 template<template<typename, typename, typename, typename> 682 682 class C, class L, class A, class K> 683 SafeArray (const C<K, T, L, A> & aMap)684 { 685 typedef C 686 687 resize 688 AssertReturnVoid 683 SafeArray(const C<K, T, L, A> & aMap) 684 { 685 typedef C<K, T, L, A> Map; 686 687 resize(aMap.size()); 688 AssertReturnVoid(!isNull()); 689 689 690 690 int i = 0; 691 691 for (typename Map::const_iterator it = aMap.begin(); 692 692 it != aMap.end(); ++ it, ++ i) 693 #if defined (VBOX_WITH_XPCOM)694 Copy (it->second, m.arr[i]);695 #else 696 Copy (it->second, m.raw[i]);693 #ifdef VBOX_WITH_XPCOM 694 Copy(it->second, m.arr[i]); 695 #else 696 Copy(it->second, m.raw[i]); 697 697 #endif 698 698 } … … 734 734 size_t size() const 735 735 { 736 #if defined (VBOX_WITH_XPCOM)736 #ifdef VBOX_WITH_XPCOM 737 737 if (m.arr) 738 738 return m.size; … … 740 740 #else 741 741 if (m.arr) 742 return Size (m.arr->rgsabound[0].cElements);742 return Size(m.arr->rgsabound[0].cElements); 743 743 return 0; 744 744 #endif … … 753 753 * This method is handy in cases where you want to assign a copy of the 754 754 * existing value to the array element, for example: 755 * <tt>Bstr string; array.push_back 755 * <tt>Bstr string; array.push_back(string);</tt>. If you create a string 756 756 * just to put it in the array, you may find #appendedRaw() more useful. 757 757 * … … 761 761 * memory for resizing. 762 762 */ 763 bool push_back 764 { 765 if (!ensureCapacity 763 bool push_back(const T &aElement) 764 { 765 if (!ensureCapacity(size() + 1)) 766 766 return false; 767 767 768 #if defined (VBOX_WITH_XPCOM)769 Copy (aElement, m.arr[m.size]);768 #ifdef VBOX_WITH_XPCOM 769 Copy(aElement, m.arr[m.size]); 770 770 ++ m.size; 771 771 #else 772 Copy (aElement, m.raw[size() - 1]);772 Copy(aElement, m.raw[size() - 1]); 773 773 #endif 774 774 return true; … … 788 788 * 789 789 * This method is handy for operations like 790 * <tt>Bstr ("foo").detachTo(array.appendedRaw());</tt>. Don't use it as791 * an l-value (<tt>array.appendedRaw() = SysAllocString 790 * <tt>Bstr("foo").detachTo(array.appendedRaw());</tt>. Don't use it as 791 * an l-value (<tt>array.appendedRaw() = SysAllocString(L"tralala");</tt>) 792 792 * since this doesn't check for a NULL condition; use #resize() and 793 793 * #setRawAt() instead. If you need to assign a copy of the existing value … … 798 798 T *appendedRaw() 799 799 { 800 if (!ensureCapacity 800 if (!ensureCapacity(size() + 1)) 801 801 return NULL; 802 802 803 #if defined (VBOX_WITH_XPCOM)804 Init (m.arr[m.size]);803 #ifdef VBOX_WITH_XPCOM 804 Init(m.arr[m.size]); 805 805 ++ m.size; 806 return &m.arr 806 return &m.arr[m.size - 1]; 807 807 #else 808 808 /* nothing to do here, SafeArrayCreate() has performed element 809 809 * initialization */ 810 return &m.raw 810 return &m.raw[size() - 1]; 811 811 #endif 812 812 } … … 822 822 * memory for resizing. 823 823 */ 824 bool resize 825 { 826 if (!ensureCapacity 824 bool resize(size_t aNewSize) 825 { 826 if (!ensureCapacity(aNewSize)) 827 827 return false; 828 828 829 #if defined (VBOX_WITH_XPCOM)829 #ifdef VBOX_WITH_XPCOM 830 830 831 831 if (m.size < aNewSize) … … 833 833 /* initialize the new elements */ 834 834 for (size_t i = m.size; i < aNewSize; ++ i) 835 Init (m.arr[i]);835 Init(m.arr[i]); 836 836 } 837 837 … … 852 852 * memory for resizing. 853 853 */ 854 bool reset 854 bool reset(size_t aNewSize) 855 855 { 856 856 m.uninit(); 857 return resize 857 return resize(aNewSize); 858 858 } 859 859 … … 867 867 T *raw() 868 868 { 869 #if defined (VBOX_WITH_XPCOM)869 #ifdef VBOX_WITH_XPCOM 870 870 return m.arr; 871 871 #else … … 879 879 const T *raw() const 880 880 { 881 #if defined (VBOX_WITH_XPCOM)881 #ifdef VBOX_WITH_XPCOM 882 882 return m.arr; 883 883 #else … … 897 897 T &operator[] (size_t aIdx) 898 898 { 899 AssertReturn (m.arr != NULL, *((T *)NULL));900 AssertReturn (aIdx < size(), *((T *)NULL));901 #if defined (VBOX_WITH_XPCOM)902 return m.arr 903 #else 904 AssertReturn (m.raw != NULL, *((T *)NULL));905 return m.raw 899 AssertReturn(m.arr != NULL, *((T *)NULL)); 900 AssertReturn(aIdx < size(), *((T *)NULL)); 901 #ifdef VBOX_WITH_XPCOM 902 return m.arr[aIdx]; 903 #else 904 AssertReturn(m.raw != NULL, *((T *)NULL)); 905 return m.raw[aIdx]; 906 906 #endif 907 907 } … … 912 912 const T operator[] (size_t aIdx) const 913 913 { 914 AssertReturn (m.arr != NULL, *((T *)NULL));915 AssertReturn (aIdx < size(), *((T *)NULL));916 #if defined (VBOX_WITH_XPCOM)917 return m.arr 918 #else 919 AssertReturn (m.raw != NULL, *((T *)NULL));920 return m.raw 914 AssertReturn(m.arr != NULL, *((T *)NULL)); 915 AssertReturn(aIdx < size(), *((T *)NULL)); 916 #ifdef VBOX_WITH_XPCOM 917 return m.arr[aIdx]; 918 #else 919 AssertReturn(m.raw != NULL, *((T *)NULL)); 920 return m.raw[aIdx]; 921 921 #endif 922 922 } … … 927 927 * parameter name in the ComSafeArrayOutArg macro call like this: 928 928 * <pre> 929 * safeArray.cloneTo (ComSafeArrayOutArg(aArg));929 * safeArray.cloneTo(ComSafeArrayOutArg(aArg)); 930 930 * </pre> 931 931 * … … 936 936 * @param aArg Output method parameter to clone to. 937 937 */ 938 virtual const SafeArray &cloneTo (ComSafeArrayOut(T, aArg)) const938 virtual const SafeArray &cloneTo(ComSafeArrayOut(T, aArg)) const 939 939 { 940 940 /// @todo Implement me! 941 #if defined (VBOX_WITH_XPCOM)942 NOREF 943 NOREF 944 #else 945 NOREF 946 #endif 947 AssertFailedReturn 948 } 949 950 void cloneTo 941 #ifdef VBOX_WITH_XPCOM 942 NOREF(aArgSize); 943 NOREF(aArg); 944 #else 945 NOREF(aArg); 946 #endif 947 AssertFailedReturn(*this); 948 } 949 950 void cloneTo(SafeArray<T>& aOther) const 951 951 { 952 952 aOther.reset(size()); … … 961 961 * ComSafeArrayOutArg macro call like this: 962 962 * <pre> 963 * safeArray.detachTo (ComSafeArrayOutArg(aArg));963 * safeArray.detachTo(ComSafeArrayOutArg(aArg)); 964 964 * </pre> 965 965 * … … 973 973 * @param aArg Location to detach to. 974 974 */ 975 virtual SafeArray &detachTo (ComSafeArrayOut(T, aArg))976 { 977 AssertReturn 978 979 #if defined (VBOX_WITH_XPCOM)980 981 AssertReturn 982 AssertReturn 975 virtual SafeArray &detachTo(ComSafeArrayOut(T, aArg)) 976 { 977 AssertReturn(m.isWeak == false, *this); 978 979 #ifdef VBOX_WITH_XPCOM 980 981 AssertReturn(aArgSize != NULL, *this); 982 AssertReturn(aArg != NULL, *this); 983 983 984 984 *aArgSize = m.size; … … 989 989 m.arr = NULL; 990 990 991 #else /* defined (VBOX_WITH_XPCOM)*/992 993 AssertReturn 991 #else /* !VBOX_WITH_XPCOM */ 992 993 AssertReturn(aArg != NULL, *this); 994 994 *aArg = m.arr; 995 995 996 996 if (m.raw) 997 997 { 998 HRESULT rc = SafeArrayUnaccessData 999 AssertComRCReturn 998 HRESULT rc = SafeArrayUnaccessData(m.arr); 999 AssertComRCReturn(rc, *this); 1000 1000 m.raw = NULL; 1001 1001 } … … 1004 1004 m.arr = NULL; 1005 1005 1006 #endif /* defined (VBOX_WITH_XPCOM)*/1006 #endif /* !VBOX_WITH_XPCOM */ 1007 1007 1008 1008 return *this; … … 1014 1014 // Public methods for internal purposes only. 1015 1015 1016 #if defined (VBOX_WITH_XPCOM)1016 #ifdef VBOX_WITH_XPCOM 1017 1017 1018 1018 /** Internal function. Never call it directly. */ … … 1020 1020 1021 1021 /** Internal function Never call it directly. */ 1022 T **__asOutParam_Arr() { Assert 1023 1024 #else /* defined (VBOX_WITH_XPCOM)*/1022 T **__asOutParam_Arr() { Assert(isNull()); return &m.arr; } 1023 1024 #else /* !VBOX_WITH_XPCOM */ 1025 1025 1026 1026 /** Internal function Never call it directly. */ … … 1029 1029 /** Internal function Never call it directly. */ 1030 1030 OutSafeArrayDipper __asOutParam() 1031 { setNull(); return OutSafeArrayDipper (&m.arr, (void **)&m.raw); }1032 1033 #endif /* defined (VBOX_WITH_XPCOM)*/1031 { setNull(); return OutSafeArrayDipper(&m.arr, (void **)&m.raw); } 1032 1033 #endif /* !VBOX_WITH_XPCOM */ 1034 1034 1035 1035 static const SafeArray Null; … … 1058 1058 * @return @c true on success and @c false if not enough memory. 1059 1059 */ 1060 bool ensureCapacity 1061 { 1062 AssertReturn 1063 1064 #if defined (VBOX_WITH_XPCOM)1060 bool ensureCapacity(size_t aNewSize) 1061 { 1062 AssertReturn(!m.isWeak, false); 1063 1064 #ifdef VBOX_WITH_XPCOM 1065 1065 1066 1066 /* Note: we distinguish between a null array and an empty (zero … … 1072 1072 1073 1073 /* Allocate in 16-byte pieces. */ 1074 size_t newCapacity = RT_MAX 1074 size_t newCapacity = RT_MAX((aNewSize + 15) / 16 * 16, 16); 1075 1075 1076 1076 if (m.capacity != newCapacity) 1077 1077 { 1078 T *newArr = (T *) nsMemory::Alloc (RT_MAX (newCapacity, 1) * sizeof(T));1079 AssertReturn 1078 T *newArr = (T *)nsMemory::Alloc(RT_MAX(newCapacity, 1) * sizeof(T)); 1079 AssertReturn(newArr != NULL, false); 1080 1080 1081 1081 if (m.arr != NULL) … … 1086 1086 * shrink the size. */ 1087 1087 for (size_t i = aNewSize; i < m.size; ++ i) 1088 Uninit (m.arr[i]);1088 Uninit(m.arr[i]); 1089 1089 1090 1090 m.size = aNewSize; … … 1092 1092 1093 1093 /* Copy the old contents. */ 1094 memcpy (newArr, m.arr, m.size * sizeof(T));1095 nsMemory::Free ((void *)m.arr);1094 memcpy(newArr, m.arr, m.size * sizeof(T)); 1095 nsMemory::Free((void *)m.arr); 1096 1096 } 1097 1097 … … 1105 1105 * shrink the size. */ 1106 1106 for (size_t i = aNewSize; i < m.size; ++ i) 1107 Uninit (m.arr[i]);1107 Uninit(m.arr[i]); 1108 1108 1109 1109 m.size = aNewSize; … … 1115 1115 #else 1116 1116 1117 SAFEARRAYBOUND bound = { VarCount 1117 SAFEARRAYBOUND bound = { VarCount(aNewSize), 0 }; 1118 1118 HRESULT rc; 1119 1119 1120 1120 if (m.arr == NULL) 1121 1121 { 1122 m.arr = CreateSafeArray 1123 AssertReturn 1122 m.arr = CreateSafeArray(VarType(), &bound); 1123 AssertReturn(m.arr != NULL, false); 1124 1124 } 1125 1125 else 1126 1126 { 1127 SafeArrayUnaccessData 1128 1129 rc = SafeArrayRedim 1130 AssertComRCReturn 1131 } 1132 1133 rc = SafeArrayAccessData (m.arr, (void HUGEP **)&m.raw);1134 AssertComRCReturn 1127 SafeArrayUnaccessData(m.arr); 1128 1129 rc = SafeArrayRedim(m.arr, &bound); 1130 AssertComRCReturn(rc == S_OK, false); 1131 } 1132 1133 rc = SafeArrayAccessData(m.arr, (void HUGEP **)&m.raw); 1134 AssertComRCReturn(rc, false); 1135 1135 1136 1136 #endif … … 1141 1141 { 1142 1142 Data() 1143 : isWeak 1144 #if defined (VBOX_WITH_XPCOM)1145 , capacity (0), size (0), arr(NULL)1146 #else 1147 , arr (NULL), raw(NULL)1143 : isWeak(false) 1144 #ifdef VBOX_WITH_XPCOM 1145 , capacity(0), size(0), arr(NULL) 1146 #else 1147 , arr(NULL), raw(NULL) 1148 1148 #endif 1149 1149 {} … … 1153 1153 void uninit() 1154 1154 { 1155 #if defined (VBOX_WITH_XPCOM)1155 #ifdef VBOX_WITH_XPCOM 1156 1156 1157 1157 if (arr) … … 1160 1160 { 1161 1161 for (size_t i = 0; i < size; ++ i) 1162 Uninit (arr[i]);1163 1164 nsMemory::Free ((void *)arr);1162 Uninit(arr[i]); 1163 1164 nsMemory::Free((void *)arr); 1165 1165 } 1166 1166 else … … 1172 1172 size = capacity = 0; 1173 1173 1174 #else /* defined (VBOX_WITH_XPCOM)*/1174 #else /* !VBOX_WITH_XPCOM */ 1175 1175 1176 1176 if (arr) … … 1178 1178 if (raw) 1179 1179 { 1180 SafeArrayUnaccessData 1180 SafeArrayUnaccessData(arr); 1181 1181 raw = NULL; 1182 1182 } … … 1184 1184 if (!isWeak) 1185 1185 { 1186 HRESULT rc = SafeArrayDestroy 1187 AssertComRCReturnVoid 1186 HRESULT rc = SafeArrayDestroy(arr); 1187 AssertComRCReturnVoid(rc); 1188 1188 } 1189 1189 else … … 1193 1193 } 1194 1194 1195 #endif /* defined (VBOX_WITH_XPCOM)*/1195 #endif /* !VBOX_WITH_XPCOM */ 1196 1196 } 1197 1197 1198 1198 bool isWeak : 1; 1199 1199 1200 #if defined (VBOX_WITH_XPCOM)1200 #ifdef VBOX_WITH_XPCOM 1201 1201 PRUint32 capacity; 1202 1202 PRUint32 size; … … 1244 1244 //////////////////////////////////////////////////////////////////////////////// 1245 1245 1246 #if defined (VBOX_WITH_XPCOM)1246 #ifdef VBOX_WITH_XPCOM 1247 1247 1248 1248 /** … … 1274 1274 * this class cannot handle them because of const modifiers. 1275 1275 */ 1276 class SafeGUIDArray : public SafeArray 1276 class SafeGUIDArray : public SafeArray<nsID *> 1277 1277 { 1278 1278 public: 1279 1279 1280 typedef SafeArray 1280 typedef SafeArray<nsID *> Base; 1281 1281 1282 1282 class nsIDRef … … 1284 1284 public: 1285 1285 1286 nsIDRef (nsID * &aVal) : mVal(aVal) {}1286 nsIDRef(nsID * &aVal) : mVal(aVal) {} 1287 1287 1288 1288 operator const nsID &() const { return mVal ? *mVal : *Empty; } … … 1294 1294 { 1295 1295 if (mVal == NULL) 1296 Copy 1296 Copy(&aThat, mVal); 1297 1297 else 1298 1298 *mVal = aThat; … … 1312 1312 SafeGUIDArray() {} 1313 1313 1314 /** See SafeArray<>::SafeArray 1315 SafeGUIDArray (size_t aSize) : Base(aSize) {}1314 /** See SafeArray<>::SafeArray(size_t). */ 1315 SafeGUIDArray(size_t aSize) : Base(aSize) {} 1316 1316 1317 1317 /** … … 1325 1325 nsIDRef operator[] (size_t aIdx) 1326 1326 { 1327 Assert 1328 Assert 1329 return nsIDRef (m.arr[aIdx]);1327 Assert(m.arr != NULL); 1328 Assert(aIdx < size()); 1329 return nsIDRef(m.arr[aIdx]); 1330 1330 } 1331 1331 … … 1335 1335 const nsID &operator[] (size_t aIdx) const 1336 1336 { 1337 Assert 1338 Assert 1339 return m.arr [aIdx] ? *m.arr[aIdx] : *nsIDRef::Empty;1337 Assert(m.arr != NULL); 1338 Assert(aIdx < size()); 1339 return m.arr[aIdx] ? *m.arr[aIdx] : *nsIDRef::Empty; 1340 1340 } 1341 1341 }; … … 1347 1347 * implementations. See SafeGUIDArray for more details. 1348 1348 */ 1349 class SafeConstGUIDArray : public SafeArray 1350 SafeArrayTraits 1349 class SafeConstGUIDArray : public SafeArray<const nsID *, 1350 SafeArrayTraits<nsID *> > 1351 1351 { 1352 1352 public: 1353 1353 1354 typedef SafeArray <const nsID *, SafeArrayTraits<nsID *> > Base;1354 typedef SafeArray<const nsID *, SafeArrayTraits<nsID *> > Base; 1355 1355 1356 1356 /** See SafeArray<>::SafeArray(). */ 1357 1357 SafeConstGUIDArray() {} 1358 1358 1359 /* See SafeArray<>::SafeArray (ComSafeArrayIn(T, aArg)). */1360 SafeConstGUIDArray (ComSafeGUIDArrayIn(aArg))1361 : Base (ComSafeGUIDArrayInArg(aArg)) {}1359 /* See SafeArray<>::SafeArray(ComSafeArrayIn(T, aArg)). */ 1360 SafeConstGUIDArray(ComSafeGUIDArrayIn(aArg)) 1361 : Base(ComSafeGUIDArrayInArg(aArg)) {} 1362 1362 1363 1363 /** … … 1370 1370 const nsID &operator[] (size_t aIdx) const 1371 1371 { 1372 AssertReturn (m.arr != NULL, **((const nsID * *)NULL));1373 AssertReturn (aIdx < size(), **((const nsID * *)NULL));1374 return *m.arr 1372 AssertReturn(m.arr != NULL, **((const nsID * *)NULL)); 1373 AssertReturn(aIdx < size(), **((const nsID * *)NULL)); 1374 return *m.arr[aIdx]; 1375 1375 } 1376 1376 … … 1378 1378 1379 1379 /* These are disabled because of const. */ 1380 bool reset (size_t aNewSize) { NOREF(aNewSize); return false; }1381 }; 1382 1383 #else /* defined (VBOX_WITH_XPCOM)*/1384 1385 typedef SafeArray 1386 typedef SafeArray <const GUID, SafeArrayTraits<GUID> > SafeConstGUIDArray;1387 1388 #endif /* defined (VBOX_WITH_XPCOM)*/1380 bool reset(size_t aNewSize) { NOREF(aNewSize); return false; } 1381 }; 1382 1383 #else /* !VBOX_WITH_XPCOM */ 1384 1385 typedef SafeArray<GUID> SafeGUIDArray; 1386 typedef SafeArray<const GUID, SafeArrayTraits<GUID> > SafeConstGUIDArray; 1387 1388 #endif /* !VBOX_WITH_XPCOM */ 1389 1389 1390 1390 //////////////////////////////////////////////////////////////////////////////// 1391 1391 1392 #if defined (VBOX_WITH_XPCOM)1393 1394 template 1392 #ifdef VBOX_WITH_XPCOM 1393 1394 template<class I> 1395 1395 struct SafeIfaceArrayTraits 1396 1396 { 1397 1397 protected: 1398 1398 1399 static void Init 1400 static void Uninit 1399 static void Init(I * &aElem) { aElem = NULL; } 1400 static void Uninit(I * &aElem) 1401 1401 { 1402 1402 if (aElem) … … 1407 1407 } 1408 1408 1409 static void Copy 1409 static void Copy(I * aFrom, I * &aTo) 1410 1410 { 1411 1411 if (aFrom != NULL) … … 1421 1421 1422 1422 /* Magic to workaround strict rules of par. 4.4.4 of the C++ standard. */ 1423 static I **__asInParam_Arr 1424 static I **__asInParam_Arr (const I **aArr) { return const_cast <I **>(aArr); }1425 }; 1426 1427 #else /* defined (VBOX_WITH_XPCOM)*/1428 1429 template 1423 static I **__asInParam_Arr(I **aArr) { return aArr; } 1424 static I **__asInParam_Arr(const I **aArr) { return const_cast<I **>(aArr); } 1425 }; 1426 1427 #else /* !VBOX_WITH_XPCOM */ 1428 1429 template<class I> 1430 1430 struct SafeIfaceArrayTraits 1431 1431 { … … 1433 1433 1434 1434 static VARTYPE VarType() { return VT_DISPATCH; } 1435 static ULONG VarCount (size_t aSize) { return (ULONG)aSize; }1436 static size_t Size (ULONG aVarCount) { return (size_t)aVarCount; }1437 1438 static void Copy 1435 static ULONG VarCount(size_t aSize) { return (ULONG)aSize; } 1436 static size_t Size(ULONG aVarCount) { return (size_t)aVarCount; } 1437 1438 static void Copy(I * aFrom, I * &aTo) 1439 1439 { 1440 1440 if (aFrom != NULL) … … 1447 1447 } 1448 1448 1449 static SAFEARRAY *CreateSafeArray 1450 { 1451 NOREF 1452 return SafeArrayCreateEx (VT_DISPATCH, 1, aBound, (PVOID) &_ATL_IIDOF(I));1453 } 1454 }; 1455 1456 #endif /* defined (VBOX_WITH_XPCOM)*/1449 static SAFEARRAY *CreateSafeArray(VARTYPE aVarType, SAFEARRAYBOUND *aBound) 1450 { 1451 NOREF(aVarType); 1452 return SafeArrayCreateEx(VT_DISPATCH, 1, aBound, (PVOID)&_ATL_IIDOF(I)); 1453 } 1454 }; 1455 1456 #endif /* !VBOX_WITH_XPCOM */ 1457 1457 1458 1458 //////////////////////////////////////////////////////////////////////////////// … … 1466 1466 * @param I Interface class (no asterisk). 1467 1467 */ 1468 template 1469 class SafeIfaceArray : public SafeArray <I *, SafeIfaceArrayTraits<I> >1468 template<class I> 1469 class SafeIfaceArray : public SafeArray<I *, SafeIfaceArrayTraits<I> > 1470 1470 { 1471 1471 public: 1472 1472 1473 typedef SafeArray <I *, SafeIfaceArrayTraits<I> > Base;1473 typedef SafeArray<I *, SafeIfaceArrayTraits<I> > Base; 1474 1474 1475 1475 /** … … 1489 1489 * The constructor will also assert in this case. 1490 1490 */ 1491 SafeIfaceArray (size_t aSize) { Base::resize(aSize); }1491 SafeIfaceArray(size_t aSize) { Base::resize(aSize); } 1492 1492 1493 1493 /** … … 1497 1497 * this: 1498 1498 * <pre> 1499 * SafeArray safeArray (ComSafeArrayInArg(aArg));1499 * SafeArray safeArray(ComSafeArrayInArg(aArg)); 1500 1500 * </pre> 1501 1501 * … … 1506 1506 * @param aArg Input method parameter to attach to. 1507 1507 */ 1508 SafeIfaceArray (ComSafeArrayIn(I *, aArg))1509 { 1510 #if defined (VBOX_WITH_XPCOM)1511 1512 AssertReturnVoid 1508 SafeIfaceArray(ComSafeArrayIn(I *, aArg)) 1509 { 1510 #ifdef VBOX_WITH_XPCOM 1511 1512 AssertReturnVoid(aArg != NULL); 1513 1513 1514 1514 Base::m.size = aArgSize; … … 1516 1516 Base::m.isWeak = true; 1517 1517 1518 #else /* defined (VBOX_WITH_XPCOM)*/1519 1520 AssertReturnVoid 1518 #else /* !VBOX_WITH_XPCOM */ 1519 1520 AssertReturnVoid(aArg != NULL); 1521 1521 SAFEARRAY *arg = aArg; 1522 1522 1523 1523 if (arg) 1524 1524 { 1525 AssertReturnVoid 1525 AssertReturnVoid(arg->cDims == 1); 1526 1526 1527 1527 VARTYPE vt; 1528 HRESULT rc = SafeArrayGetVartype 1529 AssertComRCReturnVoid 1530 AssertMsgReturnVoid 1531 1532 1528 HRESULT rc = SafeArrayGetVartype(arg, &vt); 1529 AssertComRCReturnVoid(rc); 1530 AssertMsgReturnVoid(vt == VT_UNKNOWN || vt == VT_DISPATCH, 1531 ("Expected vartype VT_UNKNOWN, got %d.\n", 1532 VarType(), vt)); 1533 1533 GUID guid; 1534 rc = SafeArrayGetIID 1535 AssertComRCReturnVoid 1536 AssertMsgReturnVoid (InlineIsEqualGUID (_ATL_IIDOF(I), guid),1537 1538 &_ATL_IIDOF(I), &guid));1539 1540 rc = SafeArrayAccessData (arg, (void HUGEP **)&m.raw);1541 AssertComRCReturnVoid 1534 rc = SafeArrayGetIID(arg, &guid); 1535 AssertComRCReturnVoid(rc); 1536 AssertMsgReturnVoid(InlineIsEqualGUID(_ATL_IIDOF(I), guid), 1537 ("Expected IID {%RTuuid}, got {%RTuuid}.\n", 1538 &_ATL_IIDOF(I), &guid)); 1539 1540 rc = SafeArrayAccessData(arg, (void HUGEP **)&m.raw); 1541 AssertComRCReturnVoid(rc); 1542 1542 } 1543 1543 … … 1545 1545 m.isWeak = true; 1546 1546 1547 #endif /* defined (VBOX_WITH_XPCOM)*/1547 #endif /* !VBOX_WITH_XPCOM */ 1548 1548 } 1549 1549 1550 1550 /** 1551 1551 * Creates a deep copy of the given standard C++ container that stores 1552 * interface pointers as objects of the ComPtr 1552 * interface pointers as objects of the ComPtr<I> class. 1553 1553 * 1554 1554 * @param aCntr Container object to copy. … … 1559 1559 * @param OI Argument to the ComPtr template (deduced from @c aCntr). 1560 1560 */ 1561 template <template<typename, typename> class C, class A, class OI>1562 SafeIfaceArray (const C <ComPtr<OI>, A> & aCntr)1563 { 1564 typedef C <ComPtr<OI>, A> List;1565 1566 Base::resize 1567 AssertReturnVoid 1561 template<template<typename, typename> class C, class A, class OI> 1562 SafeIfaceArray(const C<ComPtr<OI>, A> & aCntr) 1563 { 1564 typedef C<ComPtr<OI>, A> List; 1565 1566 Base::resize(aCntr.size()); 1567 AssertReturnVoid(!Base::isNull()); 1568 1568 1569 1569 int i = 0; 1570 1570 for (typename List::const_iterator it = aCntr.begin(); 1571 1571 it != aCntr.end(); ++ it, ++ i) 1572 #if defined (VBOX_WITH_XPCOM)1573 Copy (*it, Base::m.arr[i]);1574 #else 1575 Copy (*it, Base::m.raw[i]);1572 #ifdef VBOX_WITH_XPCOM 1573 Copy(*it, Base::m.arr[i]); 1574 #else 1575 Copy(*it, Base::m.raw[i]); 1576 1576 #endif 1577 1577 } … … 1579 1579 /** 1580 1580 * Creates a deep copy of the given standard C++ container that stores 1581 * interface pointers as objects of the ComObjPtr 1581 * interface pointers as objects of the ComObjPtr<I> class. 1582 1582 * 1583 1583 * @param aCntr Container object to copy. … … 1588 1588 * @param OI Argument to the ComObjPtr template (deduced from @c aCntr). 1589 1589 */ 1590 template <template<typename, typename> class C, class A, class OI>1591 SafeIfaceArray (const C <ComObjPtr<OI>, A> & aCntr)1592 { 1593 typedef C <ComObjPtr<OI>, A> List;1594 1595 Base::resize 1596 AssertReturnVoid 1590 template<template<typename, typename> class C, class A, class OI> 1591 SafeIfaceArray(const C<ComObjPtr<OI>, A> & aCntr) 1592 { 1593 typedef C<ComObjPtr<OI>, A> List; 1594 1595 Base::resize(aCntr.size()); 1596 AssertReturnVoid(!Base::isNull()); 1597 1597 1598 1598 int i = 0; 1599 1599 for (typename List::const_iterator it = aCntr.begin(); 1600 1600 it != aCntr.end(); ++ it, ++ i) 1601 #if defined (VBOX_WITH_XPCOM)1602 Copy (*it, Base::m.arr[i]);1603 #else 1604 Copy (*it, Base::m.raw[i]);1601 #ifdef VBOX_WITH_XPCOM 1602 Copy(*it, Base::m.arr[i]); 1603 #else 1604 Copy(*it, Base::m.raw[i]); 1605 1605 #endif 1606 1606 } … … 1608 1608 /** 1609 1609 * Creates a deep copy of the given standard C++ map whose values are 1610 * interface pointers stored as objects of the ComPtr 1610 * interface pointers stored as objects of the ComPtr<I> class. 1611 1611 * 1612 1612 * @param aMap Map object to copy. … … 1619 1619 * @param OI Argument to the ComPtr template (deduced from @c aCntr). 1620 1620 */ 1621 template <template<typename, typename, typename, typename>1621 template<template<typename, typename, typename, typename> 1622 1622 class C, class L, class A, class K, class OI> 1623 SafeIfaceArray (const C <K, ComPtr<OI>, L, A> & aMap)1624 { 1625 typedef C <K, ComPtr<OI>, L, A> Map;1626 1627 Base::resize 1628 AssertReturnVoid 1623 SafeIfaceArray(const C<K, ComPtr<OI>, L, A> & aMap) 1624 { 1625 typedef C<K, ComPtr<OI>, L, A> Map; 1626 1627 Base::resize(aMap.size()); 1628 AssertReturnVoid(!Base::isNull()); 1629 1629 1630 1630 int i = 0; 1631 1631 for (typename Map::const_iterator it = aMap.begin(); 1632 1632 it != aMap.end(); ++ it, ++ i) 1633 #if defined (VBOX_WITH_XPCOM)1634 Copy (it->second, Base::m.arr[i]);1635 #else 1636 Copy (it->second, Base::m.raw[i]);1633 #ifdef VBOX_WITH_XPCOM 1634 Copy(it->second, Base::m.arr[i]); 1635 #else 1636 Copy(it->second, Base::m.raw[i]); 1637 1637 #endif 1638 1638 } … … 1640 1640 /** 1641 1641 * Creates a deep copy of the given standard C++ map whose values are 1642 * interface pointers stored as objects of the ComObjPtr 1642 * interface pointers stored as objects of the ComObjPtr<I> class. 1643 1643 * 1644 1644 * @param aMap Map object to copy. … … 1651 1651 * @param OI Argument to the ComObjPtr template (deduced from @c aCntr). 1652 1652 */ 1653 template <template<typename, typename, typename, typename>1653 template<template<typename, typename, typename, typename> 1654 1654 class C, class L, class A, class K, class OI> 1655 SafeIfaceArray (const C <K, ComObjPtr<OI>, L, A> & aMap)1656 { 1657 typedef C <K, ComObjPtr<OI>, L, A> Map;1658 1659 Base::resize 1660 AssertReturnVoid 1655 SafeIfaceArray(const C<K, ComObjPtr<OI>, L, A> & aMap) 1656 { 1657 typedef C<K, ComObjPtr<OI>, L, A> Map; 1658 1659 Base::resize(aMap.size()); 1660 AssertReturnVoid(!Base::isNull()); 1661 1661 1662 1662 int i = 0; 1663 1663 for (typename Map::const_iterator it = aMap.begin(); 1664 1664 it != aMap.end(); ++ it, ++ i) 1665 #if defined (VBOX_WITH_XPCOM)1666 Copy (it->second, Base::m.arr[i]);1667 #else 1668 Copy (it->second, Base::m.raw[i]);1665 #ifdef VBOX_WITH_XPCOM 1666 Copy(it->second, Base::m.arr[i]); 1667 #else 1668 Copy(it->second, Base::m.raw[i]); 1669 1669 #endif 1670 1670 } … … 1672 1672 void setElement(size_t iIdx, I* obj) 1673 1673 { 1674 #if defined (VBOX_WITH_XPCOM)1675 Copy (obj, Base::m.arr[iIdx]);1676 #else 1677 Copy (obj, Base::m.raw[iIdx]);1674 #ifdef VBOX_WITH_XPCOM 1675 Copy(obj, Base::m.arr[iIdx]); 1676 #else 1677 Copy(obj, Base::m.raw[iIdx]); 1678 1678 #endif 1679 1679 }
Note:
See TracChangeset
for help on using the changeset viewer.