array.h revision a49dafa13549ac5db76a3c7f5e44ba83485a1971
/** @file
* MS COM / XPCOM Abstraction Layer - Safe array helper class declaration.
*/
/*
* Copyright (C) 2006-2014 Oracle Corporation
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* General Public License (GPL) as published by the Free Software
* Foundation, in version 2 as it comes in the "COPYING" file of the
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
*
* The contents of this file may alternatively be used under the terms
* of the Common Development and Distribution License Version 1.0
* (CDDL) only, as it comes in the "COPYING.CDDL" file of the
* VirtualBox OSE distribution, in which case the provisions of the
* CDDL are applicable instead of those of the GPL.
*
* You may elect to license modified versions of this file under the
* terms and conditions of either the GPL or the CDDL or both.
*/
#ifndef ___VBox_com_array_h
#define ___VBox_com_array_h
* @{
*
* arrays to and from COM interface methods and consists of the com::SafeArray
* template and a set of ComSafeArray* macros part of which is defined in
*
* This layer works with interface attributes and method parameters that have
* the 'safearray="yes"' attribute in the XIDL definition:
* @code
<interface name="ISomething" ...>
<method name="testArrays">
<param name="inArr" type="long" dir="in" safearray="yes"/>
<param name="outArr" type="long" dir="out" safearray="yes"/>
<param name="retArr" type="long" dir="return" safearray="yes"/>
</method>
</interface>
* @endcode
*
* Methods generated from this and similar definitions are implemented in
* component classes using the following declarations:
* @code
STDMETHOD(TestArrays)(ComSafeArrayIn(LONG, aIn),
ComSafeArrayOut(LONG, aOut),
ComSafeArrayOut(LONG, aRet));
* @endcode
*
* And the following function bodies:
* @code
STDMETHODIMP Component::TestArrays(ComSafeArrayIn(LONG, aIn),
ComSafeArrayOut(LONG, aOut),
ComSafeArrayOut(LONG, aRet))
{
if (ComSafeArrayInIsNull(aIn))
return E_INVALIDARG;
if (ComSafeArrayOutIsNull(aOut))
return E_POINTER;
if (ComSafeArrayOutIsNull(aRet))
return E_POINTER;
// Use SafeArray to access the input array parameter
com::SafeArray<LONG> in(ComSafeArrayInArg(aIn));
for (size_t i = 0; i < in.size(); ++ i)
LogFlow(("*** in[%u]=%d\n", i, in[i]));
// Use SafeArray to create the return array (the same technique is used
// for output array parameters)
SafeArray<LONG> ret(in.size() * 2);
for (size_t i = 0; i < in.size(); ++ i)
{
ret[i] = in[i];
ret[i + in.size()] = in[i] * 10;
}
ret.detachTo(ComSafeArrayOutArg(aRet));
return S_OK;
}
* @endcode
*
* Such methods can be called from the client code using the following pattern:
* @code
ComPtr<ISomething> component;
// ...
com::SafeArray<LONG> in(3);
in[0] = -1;
in[1] = -2;
in[2] = -3;
com::SafeArray<LONG> out;
com::SafeArray<LONG> ret;
HRESULT rc = component->TestArrays(ComSafeArrayAsInParam(in),
ComSafeArrayAsOutParam(out),
ComSafeArrayAsOutParam(ret));
if (SUCCEEDED(rc))
for (size_t i = 0; i < ret.size(); ++ i)
printf("*** ret[%u]=%d\n", i, ret[i]);
* @endcode
*
* For interoperability with standard C++ containers, there is a template
* constructor that takes such a container as argument and performs a deep copy
* of its contents. This can be used in method implementations like this:
* @code
STDMETHODIMP Component::COMGETTER(Values)(ComSafeArrayOut(int, aValues))
{
// ... assume there is a |std::list<int> mValues| data member
com::SafeArray<int> values(mValues);
values.detachTo(ComSafeArrayOutArg(aValues));
return S_OK;
}
* @endcode
*
* The current implementation of the SafeArray layer supports all types normally
* allowed in XIDL as array element types (including 'wstring' and 'uuid').
* However, 'pointer-to-...' types (e.g. 'long *', 'wstring *') are not
* supported and therefore cannot be used as element types.
*
* Note that for GUID arrays you should use SafeGUIDArray and
* SafeConstGUIDArray, customized SafeArray<> specializations.
*
* Also note that in order to pass input BSTR array parameters declared
* using the ComSafeArrayIn(IN_BSTR, aParam) macro to the SafeArray<>
* constructor using the ComSafeArrayInArg() macro, you should use IN_BSTR
* as the SafeArray<> template argument, not just BSTR.
*
* Arrays of interface pointers are also supported but they require to use a
* special SafeArray implementation, com::SafeIfacePointer, which takes the
* interface class name as a template argument (e.g. com::SafeIfacePointer
* <IUnknown>). This implementation functions identically to com::SafeArray.
*/
#ifdef VBOX_WITH_XPCOM
# include <nsMemory.h>
#endif
/* Type traits are a C++ 11 feature, so not available everywhere (yet). */
/* Only GCC 4.6 or newer. */
/* Only MSVC++ 16.0 (Visual Studio 2010) or newer. */ \
#define VBOX_WITH_TYPE_TRAITS
#endif
#ifdef VBOX_WITH_TYPE_TRAITS
# include <type_traits>
#endif
#ifdef VBOX_WITH_XPCOM
/**
* Wraps the given com::SafeArray instance to generate an expression that is
* suitable for passing it to functions that take input safearray parameters
* declared using the ComSafeArrayIn macro.
*
* @param aArray com::SafeArray instance to pass as an input parameter.
*/
#define ComSafeArrayAsInParam(aArray) \
/**
* Wraps the given com::SafeArray instance to generate an expression that is
* suitable for passing it to functions that take output safearray parameters
* declared using the ComSafeArrayOut macro.
*
* @param aArray com::SafeArray instance to pass as an output parameter.
*/
#define ComSafeArrayAsOutParam(aArray) \
#else /* !VBOX_WITH_XPCOM */
#endif /* !VBOX_WITH_XPCOM */
/**
*
*/
{
#ifdef VBOX_WITH_XPCOM
////////////////////////////////////////////////////////////////////////////////
/**
* Provides various helpers for SafeArray.
*
* @param T Type of array elements.
*/
struct SafeArrayTraits
{
/** Initializes memory for aElem. */
/** Initializes memory occupied by aElem. */
/** Creates a deep copy of aFrom and stores it in aTo. */
/* Magic to workaround strict rules of par. 4.4.4 of the C++ standard (that
* in particular forbid casts of 'char **' to 'const char **'). Then initial
* reason for this magic is that XPIDL declares input strings
* arrays. */
};
struct SafeArrayTraits<T *>
{
// Arbitrary pointers are not supported
};
template<>
struct SafeArrayTraits<PRUnichar *>
{
{
if (aElem)
{
::SysFreeString(aElem);
}
}
{
}
/* Magic to workaround strict rules of par. 4.4.4 of the C++ standard */
{
}
};
template<>
struct SafeArrayTraits<const PRUnichar *>
{
{
if (aElem)
{
}
}
{
}
/* Magic to workaround strict rules of par. 4.4.4 of the C++ standard */
};
template<>
struct SafeArrayTraits<nsID *>
{
{
if (aElem)
{
}
}
{
if (aFrom)
{
if (aTo)
}
else
}
/* This specification is also reused for SafeConstGUIDArray, so provide a
* no-op Init() and Uninit() which are necessary for SafeArray<> but should
* be never called in context of SafeConstGUIDArray. */
/** Magic to workaround strict rules of par. 4.4.4 of the C++ standard. */
{
}
};
#else /* !VBOX_WITH_XPCOM */
////////////////////////////////////////////////////////////////////////////////
struct SafeArrayTraitsBase
{
};
/**
* Provides various helpers for SafeArray.
*
* @param T Type of array elements.
*
* Specializations of this template must provide the following methods:
*
// Returns the VARTYPE of COM SafeArray elements to be used for T
static VARTYPE VarType();
// Returns the number of VarType() elements necessary for aSize
// elements of T
static ULONG VarCount(size_t aSize);
// Returns the number of elements of T that fit into the given number of
// VarType() elements (opposite to VarCount(size_t aSize)).
static size_t Size(ULONG aVarCount);
// Creates a deep copy of aFrom and stores it in aTo
static void Copy(ULONG aFrom, ULONG &aTo);
*/
{
// Arbitrary types are treated as passed by value and each value is
// represented by a number of VT_Ix type elements where VT_Ix has the
// biggest possible bitness necessary to represent T w/o a gap. COM enums
// fall into this category.
{
#ifdef VBOX_WITH_TYPE_TRAITS
{
if (sizeof(T) % 8 == 0) return VT_UI8;
if (sizeof(T) % 4 == 0) return VT_UI4;
if (sizeof(T) % 2 == 0) return VT_UI2;
return VT_UI1;
}
#endif
if (sizeof(T) % 8 == 0) return VT_I8;
if (sizeof(T) % 4 == 0) return VT_I4;
if (sizeof(T) % 2 == 0) return VT_I2;
return VT_I1;
}
/*
* Fallback method in case type traits (VBOX_WITH_TYPE_TRAITS)
* are not available. Always returns unsigned types.
*/
static VARTYPE VarTypeUnsigned()
{
if (sizeof(T) % 8 == 0) return VT_UI8;
if (sizeof(T) % 4 == 0) return VT_UI4;
if (sizeof(T) % 2 == 0) return VT_UI2;
return VT_UI1;
}
{
}
{
}
};
struct SafeArrayTraits<T *>
{
// Arbitrary pointer types are not supported
};
/* Although the generic SafeArrayTraits template would work for all integers,
* we specialize it for some of them in order to use the correct VT_ type */
template<>
{
};
template<>
{
};
template<>
{
};
template<>
{
};
template<>
{
{
}
};
template<>
{
/* Use the 64-bit unsigned integer type for GUID */
/* GUID is 128 bit, so we need two VT_UI8 */
{
}
};
/**
* Helper for SafeArray::__asOutParam() that automatically updates m.raw after a
* non-NULL m.arr assignment.
*/
{
void **raw;
{
{
}
}
};
#endif /* !VBOX_WITH_XPCOM */
////////////////////////////////////////////////////////////////////////////////
/**
* The SafeArray class represents the safe array type used in COM to pass arrays
*
* together with ComSafeArrayIn, ComSafeArrayOut and ComSafeArrayRet macros,
* provides a platform-neutral way to handle safe arrays in the method
* implementation.
*
* When an instance of this class is destroyed, it automatically frees all
* resources occupied by individual elements of the array as well as by the
* array itself. However, when the value of an element is manually changed
* using #operator[] or by accessing array data through the #raw() pointer, it is
* the caller's responsibility to free resources occupied by the previous
* element's value.
*
* Also, objects of this class do not support copy and assignment operations and
* therefore cannot be returned from functions by value. In other words, this
* class is just a temporary storage for handling interface method calls and not
* intended to be used to store arrays as data members and such -- you should
*
* @note The current implementation supports only one-dimensional arrays.
*
* @note This class is not thread-safe.
*/
{
/**
* Creates a null array.
*/
SafeArray() {}
/**
* Creates a new array of the given size. All elements of the newly created
* array initialized with null values.
*
* @param aSize Initial number of elements in the array.
*
* @note If this object remains null after construction it means that there
* was not enough memory for creating an array of the requested size.
* The constructor will also assert in this case.
*/
/**
* Weakly attaches this instance to the existing array passed in a method
* parameter declared using the ComSafeArrayIn macro. When using this call,
* always wrap the parameter name in the ComSafeArrayInArg macro call like
* this:
* <pre>
* SafeArray safeArray(ComSafeArrayInArg(aArg));
* </pre>
*
* Note that this constructor doesn't take the ownership of the array. In
* particular, it means that operations that operate on the ownership (e.g.
* #detachTo()) are forbidden and will assert.
*
* @param aArg Input method parameter to attach to.
*/
{
if (aArg)
{
#ifdef VBOX_WITH_XPCOM
m.isWeak = true;
#else /* !VBOX_WITH_XPCOM */
# ifndef VBOX_WITH_TYPE_TRAITS
|| vt == VarTypeUnsigned(),
("Expected vartype %d or %d, got %d.\n",
# else /* !VBOX_WITH_TYPE_TRAITS */
("Expected vartype %d, got %d.\n",
# endif
m.isWeak = true;
#endif /* !VBOX_WITH_XPCOM */
}
}
/**
* Creates a deep copy of the given standard C++ container that stores
* T objects.
*
* @param aCntr Container object to copy.
*
* @param C Standard C++ container template class (normally deduced from
* @c aCntr).
*/
{
AssertReturnVoid(!isNull());
size_t i = 0;
#ifdef VBOX_WITH_XPCOM
#else
#endif
}
/**
* Creates a deep copy of the given standard C++ map that stores T objects
* as values.
*
* @param aMap Map object to copy.
*
* @param C Standard C++ map template class (normally deduced from
* @c aCntr).
* @param L Standard C++ compare class (deduced from @c aCntr).
* @param A Standard C++ allocator class (deduced from @c aCntr).
* @param K Map key class (deduced from @c aCntr).
*/
{
typedef C<K, T, L, A> Map;
AssertReturnVoid(!isNull());
int i = 0;
#ifdef VBOX_WITH_XPCOM
#else
#endif
}
/**
* Destroys this instance after calling #setNull() to release allocated
* resources. See #setNull() for more details.
*/
/**
* Returns @c true if this instance represents a null array.
*/
/**
* Returns @c true if this instance does not represents a null array.
*/
/**
* Resets this instance to null and, if this instance is not a weak one,
* releases any resources occupied by the array data.
*
* @note This method destroys (cleans up) all elements of the array using
* the corresponding cleanup routine for the element type before the
* array itself is destroyed.
*/
/**
* Returns @c true if this instance is weak. A weak instance doesn't own the
* array data and therefore operations manipulating the ownership (e.g.
* #detachTo()) are forbidden and will assert.
*/
/** Number of elements in the array. */
{
#ifdef VBOX_WITH_XPCOM
if (m.arr)
return m.size;
return 0;
#else
if (m.arr)
return 0;
#endif
}
/**
* Appends a copy of the given element at the end of the array.
*
* The array size is increased by one by this method and the additional
* space is allocated as needed.
*
* This method is handy in cases where you want to assign a copy of the
* existing value to the array element, for example:
* <tt>Bstr string; array.push_back(string);</tt>. If you create a string
* just to put it in the array, you may find #appendedRaw() more useful.
*
* @param aElement Element to append.
*
* @return @c true on success and @c false if there is not enough
* memory for resizing.
*/
{
return false;
#ifdef VBOX_WITH_XPCOM
++ m.size;
#else
#endif
return true;
}
/**
* Appends an empty element at the end of the array and returns a raw
* pointer to it suitable for assigning a raw value (w/o constructing a
* copy).
*
* The array size is increased by one by this method and the additional
* space is allocated as needed.
*
* Note that in case of raw assignment, value ownership (for types with
* dynamically allocated data and for interface pointers) is transferred to
* the safe array object.
*
* This method is handy for operations like
* <tt>Bstr("foo").detachTo(array.appendedRaw());</tt>. Don't use it as
* an l-value (<tt>array.appendedRaw() = SysAllocString(L"tralala");</tt>)
* since this doesn't check for a NULL condition; use #resize() and
* #setRawAt() instead. If you need to assign a copy of the existing value
* instead of transferring the ownership, look at #push_back().
*
* @return Raw pointer to the added element or NULL if no memory.
*/
T *appendedRaw()
{
return NULL;
#ifdef VBOX_WITH_XPCOM
++ m.size;
#else
/* nothing to do here, SafeArrayCreate() has performed element
* initialization */
#endif
}
/**
* Resizes the array preserving its contents when possible. If the new size
* is larger than the old size, new elements are initialized with null
* values. If the new size is less than the old size, the contents of the
* array beyond the new size is lost.
*
* @param aNewSize New number of elements in the array.
* @return @c true on success and @c false if there is not enough
* memory for resizing.
*/
{
if (!ensureCapacity(aNewSize))
return false;
#ifdef VBOX_WITH_XPCOM
{
/* initialize the new elements */
}
#else
/* nothing to do here, SafeArrayCreate() has performed element
* initialization */
#endif
return true;
}
/**
* Reinitializes this instance by preallocating space for the given number
* of elements. The previous array contents is lost.
*
* @param aNewSize New number of elements in the array.
* @return @c true on success and @c false if there is not enough
* memory for resizing.
*/
{
m.uninit();
}
/**
* Returns a pointer to the raw array data. Use this raw pointer with care
* as no type or bound checking is done for you in this case.
*
* @note This method returns @c NULL when this instance is null.
* @see #operator[]
*/
T *raw()
{
#ifdef VBOX_WITH_XPCOM
return m.arr;
#else
return m.raw;
#endif
}
/**
* Const version of #raw().
*/
const T *raw() const
{
#ifdef VBOX_WITH_XPCOM
return m.arr;
#else
return m.raw;
#endif
}
/**
* Array access operator that returns an array element by reference. A bit
* safer than #raw(): asserts and returns an invalid reference if this
* instance is null or if the index is out of bounds.
*
* @note For weak instances, this call will succeed but the behavior of
* changing the contents of an element of the weak array instance is
* undefined and may lead to a program crash on some platforms.
*/
{
#ifdef VBOX_WITH_XPCOM
#else
#endif
}
/**
* Const version of #operator[] that returns an array element by value.
*/
{
#ifdef VBOX_WITH_XPCOM
#else
#endif
}
/**
* Creates a copy of this array and stores it in a method parameter declared
* using the ComSafeArrayOut macro. When using this call, always wrap the
* parameter name in the ComSafeArrayOutArg macro call like this:
* <pre>
* safeArray.cloneTo(ComSafeArrayOutArg(aArg));
* </pre>
*
* @note It is assumed that the ownership of the returned copy is
* transferred to the caller of the method and he is responsible to free the
* array data when it is no longer needed.
*
* @param aArg Output method parameter to clone to.
*/
{
/// @todo Implement me!
#ifdef VBOX_WITH_XPCOM
#else
#endif
}
{
}
/**
* Transfers the ownership of this array's data to the specified location
* declared using the ComSafeArrayOut macro and makes this array a null
* array. When using this call, always wrap the parameter name in the
* ComSafeArrayOutArg macro call like this:
* <pre>
* safeArray.detachTo(ComSafeArrayOutArg(aArg));
* </pre>
*
* Detaching the null array is also possible in which case the location will
* receive NULL.
*
* @note Since the ownership of the array data is transferred to the
* caller of the method, he is responsible to free the array data when it is
* no longer needed.
*
* @param aArg Location to detach to.
*/
{
#ifdef VBOX_WITH_XPCOM
m.isWeak = false;
m.size = 0;
#else /* !VBOX_WITH_XPCOM */
if (m.raw)
{
}
m.isWeak = false;
#endif /* !VBOX_WITH_XPCOM */
return *this;
}
/**
* Returns a copy of this SafeArray as RTCList<T>.
*/
{
#ifdef VBOX_WITH_XPCOM
#else
#endif
return list;
}
// Public methods for internal purposes only.
#ifdef VBOX_WITH_XPCOM
/** Internal function. Never call it directly. */
/** Internal function Never call it directly. */
#else /* !VBOX_WITH_XPCOM */
/** Internal function Never call it directly. */
/** Internal function Never call it directly. */
#endif /* !VBOX_WITH_XPCOM */
/**
* Ensures that the array is big enough to contain aNewSize elements.
*
* If the new size is greater than the current capacity, a new array is
* allocated and elements from the old array are copied over. The size of
* the array doesn't change, only the capacity increases (which is always
* greater than the size). Note that the additionally allocated elements are
* left uninitialized by this method.
*
* If the new size is less than the current size, the existing array is
* truncated to the specified size and the elements outside the new array
* boundary are freed.
*
* If the new size is the same as the current size, nothing happens.
*
* @param aNewSize New size of the array.
*
* @return @c true on success and @c false if not enough memory.
*/
{
AssertReturn(!m.isWeak, false);
#ifdef VBOX_WITH_XPCOM
/* Note: we distinguish between a null array and an empty (zero
* elements) array. Therefore we never use zero in malloc (even if
* aNewSize is zero) to make sure we get a non-null pointer. */
return true;
/* Allocate in 16-byte pieces. */
if (m.capacity != newCapacity)
{
{
{
/* Truncation takes place, uninit exceeding elements and
* shrink the size. */
}
/* Copy the old contents. */
}
}
else
{
{
/* Truncation takes place, uninit exceeding elements and
* shrink the size. */
}
}
m.capacity = newCapacity;
#else
{
}
else
{
}
AssertComRCReturn(rc, false);
#endif
return true;
}
struct Data
{
Data()
: isWeak(false)
#ifdef VBOX_WITH_XPCOM
#else
#endif
{}
void uninit()
{
#ifdef VBOX_WITH_XPCOM
if (arr)
{
if (!isWeak)
{
}
else
isWeak = false;
}
#else /* !VBOX_WITH_XPCOM */
if (arr)
{
if (raw)
{
}
if (!isWeak)
{
}
else
isWeak = false;
}
#endif /* !VBOX_WITH_XPCOM */
}
bool isWeak : 1;
#ifdef VBOX_WITH_XPCOM
T *arr;
#else
T *raw;
#endif
};
Data m;
};
/* Few fast specializations for primitive array types */
template<>
{
}
template<>
{
}
template<>
{
}
template<>
{
}
template<>
{
}
template<>
{
}
template<>
{
}
template<>
{
}
////////////////////////////////////////////////////////////////////////////////
#ifdef VBOX_WITH_XPCOM
/**
* Version of com::SafeArray for arrays of GUID.
*
* In MS COM, GUID arrays store GUIDs by value and therefore input arrays are
* represented using |GUID *| and out arrays -- using |GUID **|. In XPCOM,
* GUID arrays store pointers to nsID so that input arrays are |const nsID **|
* and out arrays are |nsID ***|. Due to this difference, it is impossible to
* work with arrays of GUID on both platforms by simply using com::SafeArray
* <GUID>. This class is intended to provide some level of cross-platform
* behavior.
*
* The basic usage pattern is basically similar to com::SafeArray<> except that
* you use ComSafeGUIDArrayIn* and ComSafeGUIDArrayOut* macros instead of
* ComSafeArrayIn* and ComSafeArrayOut*. Another important nuance is that the
* raw() array type is different (nsID **, or GUID ** on XPCOM and GUID * on MS
* COM) so it is recommended to use operator[] instead which always returns a
* GUID by value.
*
* Note that due to const modifiers, you cannot use SafeGUIDArray for input GUID
* arrays. Please use SafeConstGUIDArray for this instead.
*
* Other than mentioned above, the functionality of this class is equivalent to
* com::SafeArray<>. See the description of that template and its methods for
* more information.
*
* Output GUID arrays are handled by a separate class, SafeGUIDArrayOut, since
* this class cannot handle them because of const modifiers.
*/
{
{
{
else
return *this;
}
};
/** See SafeArray<>::SafeArray(). */
SafeGUIDArray() {}
/** See SafeArray<>::SafeArray(size_t). */
/**
* Array access operator that returns an array element by reference. As a
* special case, the return value of this operator on XPCOM is an nsID (GUID)
* reference, instead of an nsID pointer (the actual SafeArray template
* argument), for compatibility with the MS COM version.
*
* The rest is equivalent to SafeArray<>::operator[].
*/
{
}
/**
* Const version of #operator[] that returns an array element by value.
*/
{
}
};
/**
* Version of com::SafeArray for const arrays of GUID.
*
* This class is used to work with input GUID array parameters in method
* implementations. See SafeGUIDArray for more details.
*/
SafeArrayTraits<nsID *> >
{
/** See SafeArray<>::SafeArray(). */
SafeConstGUIDArray() {}
/* See SafeArray<>::SafeArray(ComSafeArrayIn(T, aArg)). */
/**
* Array access operator that returns an array element by reference. As a
* special case, the return value of this operator on XPCOM is nsID (GUID)
* instead of nsID *, for compatibility with the MS COM version.
*
* The rest is equivalent to SafeArray<>::operator[].
*/
{
}
/* These are disabled because of const. */
};
#else /* !VBOX_WITH_XPCOM */
#endif /* !VBOX_WITH_XPCOM */
////////////////////////////////////////////////////////////////////////////////
#ifdef VBOX_WITH_XPCOM
struct SafeIfaceArrayTraits
{
{
if (aElem)
{
}
}
{
{
}
else
}
/* Magic to workaround strict rules of par. 4.4.4 of the C++ standard. */
};
#else /* !VBOX_WITH_XPCOM */
struct SafeIfaceArrayTraits
{
{
{
}
else
}
{
}
};
#endif /* !VBOX_WITH_XPCOM */
////////////////////////////////////////////////////////////////////////////////
/**
* Version of com::SafeArray for arrays of interface pointers.
*
* Except that it manages arrays of interface pointers, the usage of this class
* is identical to com::SafeArray.
*
* @param I Interface class (no asterisk).
*/
{
/**
* Creates a null array.
*/
SafeIfaceArray() {}
/**
* Creates a new array of the given size. All elements of the newly created
* array initialized with null values.
*
* @param aSize Initial number of elements in the array. Must be greater
* than 0.
*
* @note If this object remains null after construction it means that there
* was not enough memory for creating an array of the requested size.
* The constructor will also assert in this case.
*/
/**
* Weakly attaches this instance to the existing array passed in a method
* parameter declared using the ComSafeArrayIn macro. When using this call,
* always wrap the parameter name in the ComSafeArrayOutArg macro call like
* this:
* <pre>
* SafeArray safeArray(ComSafeArrayInArg(aArg));
* </pre>
*
* Note that this constructor doesn't take the ownership of the array. In
* particular, this means that operations that operate on the ownership
* (e.g. #detachTo()) are forbidden and will assert.
*
* @param aArg Input method parameter to attach to.
*/
{
if (aArg)
{
#ifdef VBOX_WITH_XPCOM
#else /* !VBOX_WITH_XPCOM */
("Expected vartype VT_UNKNOWN or VT_DISPATCH, got %d.\n",
vt));
("Expected IID {%RTuuid}, got {%RTuuid}.\n",
&_ATL_IIDOF(I), &guid));
m.isWeak = true;
#endif /* !VBOX_WITH_XPCOM */
}
}
/**
* Creates a deep copy of the given standard C++ container that stores
* interface pointers as objects of the ComPtr<I> class.
*
* @param aCntr Container object to copy.
*
* @param C Standard C++ container template class (normally deduced from
* @c aCntr).
* @param A Standard C++ allocator class (deduced from @c aCntr).
* @param OI Argument to the ComPtr template (deduced from @c aCntr).
*/
{
int i = 0;
#ifdef VBOX_WITH_XPCOM
#else
#endif
}
/**
* Creates a deep copy of the given standard C++ container that stores
* interface pointers as objects of the ComObjPtr<I> class.
*
* @param aCntr Container object to copy.
*
* @param C Standard C++ container template class (normally deduced from
* @c aCntr).
* @param A Standard C++ allocator class (deduced from @c aCntr).
* @param OI Argument to the ComObjPtr template (deduced from @c aCntr).
*/
{
int i = 0;
#ifdef VBOX_WITH_XPCOM
#else
#endif
}
/**
* Creates a deep copy of the given standard C++ map whose values are
* interface pointers stored as objects of the ComPtr<I> class.
*
* @param aMap Map object to copy.
*
* @param C Standard C++ map template class (normally deduced from
* @c aCntr).
* @param L Standard C++ compare class (deduced from @c aCntr).
* @param A Standard C++ allocator class (deduced from @c aCntr).
* @param K Map key class (deduced from @c aCntr).
* @param OI Argument to the ComPtr template (deduced from @c aCntr).
*/
{
int i = 0;
#ifdef VBOX_WITH_XPCOM
#else
#endif
}
/**
* Creates a deep copy of the given standard C++ map whose values are
* interface pointers stored as objects of the ComObjPtr<I> class.
*
* @param aMap Map object to copy.
*
* @param C Standard C++ map template class (normally deduced from
* @c aCntr).
* @param L Standard C++ compare class (deduced from @c aCntr).
* @param A Standard C++ allocator class (deduced from @c aCntr).
* @param K Map key class (deduced from @c aCntr).
* @param OI Argument to the ComObjPtr template (deduced from @c aCntr).
*/
{
int i = 0;
#ifdef VBOX_WITH_XPCOM
#else
#endif
}
{
#ifdef VBOX_WITH_XPCOM
#else
#endif
}
};
} /* namespace com */
/** @} */
#endif /* !___VBox_com_array_h */