VirtualBox

Changeset 13580 in vbox for trunk/include


Ignore:
Timestamp:
Oct 27, 2008 2:04:18 PM (16 years ago)
Author:
vboxsync
Message:

Ported s2 branch (r37120:38456).

Location:
trunk/include
Files:
2 added
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/VBox/com/ErrorInfo.h

    r8309 r13580  
    362362     */
    363363    ErrorInfoKeeper (bool aIsNull = false)
    364         : ErrorInfo (false), mForgot (false)
     364        : ErrorInfo (false), mForgot (aIsNull)
    365365    {
    366366        if (!aIsNull)
     
    371371     *  Destroys this instance and automatically calls #restore() which will
    372372     *  either restore error info fetched by the constructor or do nothing
    373      *  if #forget() was called before destruction. */
     373     *  if #forget() was called before destruction.
     374     */
    374375    ~ErrorInfoKeeper() { if (!mForgot) restore(); }
    375376
     
    383384    {
    384385        setNull();
     386        mForgot = false;
    385387        init (true /* aKeepObj */);
    386388    }
     
    388390    /**
    389391     *  Restores error info fetched by the constructor and forgets it
    390      *  afterwards.
     392     *  afterwards. Does nothing if the error info was forgotten by #forget().
    391393     *
    392394     *  @return COM result of the restore operation.
  • trunk/include/VBox/com/Guid.h

    r9738 r13580  
    6565    Guid (const Guid &that) { uuid = that.uuid; }
    6666    Guid (const RTUUID &that) { uuid = that; }
    67     Guid (const GUID &that) { ::memcpy (&uuid, &that, sizeof (GUID)); }
     67
     68    Guid (const GUID &that)
     69    {
     70        AssertCompileSize (GUID, sizeof (RTUUID));
     71        ::memcpy (&uuid, &that, sizeof (GUID));
     72    }
     73
    6874    Guid (const char *that)
    6975    {
  • trunk/include/VBox/com/array.h

    r11379 r13580  
    153153 * supported and therefore cannot be used as element types.
    154154 *
    155  * In order to pass input BSTR array parameters delcared using the
    156  * ComSafeArrayIn (INPTR BSTR, aParam) macro to the SafeArray<> constructor
    157  * using the ComSafeArrayInArg() macro, you should use INPTR BSTR as the
    158  * SafeArray<> template argument, not just BSTR.
     155 * Note that for GUID arrays you should use SafeGUIDArray and
     156 * SafeConstGUIDArray, customized SafeArray<> specializations.
     157 *
     158 * Also note that in order to pass input BSTR array parameters delcared
     159 * using the ComSafeArrayIn (INPTR BSTR, aParam) macro to the SafeArray<>
     160 * constructor using the ComSafeArrayInArg() macro, you should use INPTR BSTR
     161 * as the SafeArray<> template argument, not just BSTR.
    159162 *
    160163 * Arrays of interface pointers are also supported but they require to use a
     
    183186 */
    184187#define ComSafeArrayAsInParam(aArray)   \
    185     (aArray).size(), (aArray).__asInParam_Arr (aArray.raw())
     188    (aArray).size(), (aArray).__asInParam_Arr ((aArray).raw())
    186189
    187190/**
     
    214217
    215218/**
    216  * Contains various helper constants for SafeArray.
     219 * Provides various helpers for SafeArray.
     220 *
     221 * @param T Type of array elements.
    217222 */
    218223template <typename T>
     
    221226protected:
    222227
     228    /** Initializes memory for aElem. */
    223229    static void Init (T &aElem) { aElem = 0; }
     230
     231    /** Initializes memory occupied by aElem. */
    224232    static void Uninit (T &aElem) { aElem = 0; }
     233
     234    /** Creates a deep copy of aFrom and stores it in aTo. */
    225235    static void Copy (const T &aFrom, T &aTo) { aTo = aFrom; }
    226236
     
    248258
    249259    static void Init (PRUnichar * &aElem) { aElem = NULL; }
     260
    250261    static void Uninit (PRUnichar * &aElem)
    251262    {
     
    300311};
    301312
     313template<>
     314struct SafeArrayTraits <nsID *>
     315{
     316protected:
     317
     318    static void Init (nsID * &aElem) { aElem = NULL; }
     319
     320    static void Uninit (nsID * &aElem)
     321    {
     322        if (aElem)
     323        {
     324            ::nsMemory::Free (aElem);
     325            aElem = NULL;
     326        }
     327    }
     328
     329    static void Copy (const nsID * aFrom, nsID * &aTo)
     330    {
     331        if (aFrom)
     332        {
     333            aTo = (nsID *) ::nsMemory::Alloc (sizeof (nsID));
     334            if (aTo)
     335                *aTo = *aFrom;
     336        }
     337        else
     338            aTo = NULL;
     339    }
     340
     341    /* This specification is also reused for SafeConstGUIDArray, so provide a
     342     * no-op Init() and Uninit() which are necessary for SafeArray<> but should
     343     * be never called in context of SafeConstGUIDArray. */
     344
     345    static void Init (const nsID * &aElem) { NOREF (aElem); AssertFailed(); }
     346    static void Uninit (const nsID * &aElem) { NOREF (aElem); AssertFailed(); }
     347
     348public:
     349
     350    /** Magic to workaround strict rules of par. 4.4.4 of the C++ standard. */
     351    static const nsID **__asInParam_Arr (nsID **aArr)
     352    {
     353        return const_cast <const nsID **> (aArr);
     354    }
     355    static const nsID **__asInParam_Arr (const nsID **aArr) { return aArr; }
     356};
     357
    302358#else /* defined (VBOX_WITH_XPCOM) */
    303359
     
    305361
    306362/**
    307  * Contains various helper constants for SafeArray.
     363 * Provides various helpers for SafeArray.
     364 *
     365 * @param T Type of array elements.
     366 *
     367 * Specializations of this template must provide the following methods:
     368 *
     369    // Returns the VARTYPE of COM SafeArray elements to be used for T
     370    static VARTYPE VarType();
     371
     372    // Returns the number of VarType() elements necessary for aSize
     373    // elements of T
     374    static ULONG VarCount (size_t aSize);
     375
     376    // Returns the number of elements of T that occupy the given number of
     377    // VarType() elements (opposite to VarCount (size_t aSize)).
     378    static size_t Size (ULONG aVarCount);
     379
     380    // Creates a deep copy of aFrom and stores it in aTo
     381    static void Copy (ULONG aFrom, ULONG &aTo);
    308382 */
    309383template <typename T>
    310384struct SafeArrayTraits
    311385{
    312     // Arbitrary types are not supported
     386    // Arbitrary types are not supported -- no helpers
    313387};
    314388
     
    319393
    320394    static VARTYPE VarType() { return VT_I4; }
     395    static ULONG VarCount (size_t aSize) { return (ULONG) aSize; }
     396    static size_t Size (ULONG aVarCount) { return (size_t) aVarCount; }
     397
    321398    static void Copy (LONG aFrom, LONG &aTo) { aTo = aFrom; }
    322399};
     
    328405
    329406    static VARTYPE VarType() { return VT_UI4; }
     407    static ULONG VarCount (size_t aSize) { return (ULONG) aSize; }
     408    static size_t Size (ULONG aVarCount) { return (size_t) aVarCount; }
     409
    330410    static void Copy (ULONG aFrom, ULONG &aTo) { aTo = aFrom; }
    331411};
     
    337417
    338418    static VARTYPE VarType() { return VT_I8; }
     419    static ULONG VarCount (size_t aSize) { return (ULONG) aSize; }
     420    static size_t Size (ULONG aVarCount) { return (size_t) aVarCount; }
     421
    339422    static void Copy (LONG64 aFrom, LONG64 &aTo) { aTo = aFrom; }
    340423};
     
    346429
    347430    static VARTYPE VarType() { return VT_UI8; }
     431    static ULONG VarCount (size_t aSize) { return (ULONG) aSize; }
     432    static size_t Size (ULONG aVarCount) { return (size_t) aVarCount; }
     433
    348434    static void Copy (ULONG64 aFrom, ULONG64 &aTo) { aTo = aFrom; }
    349435};
     
    355441
    356442    static VARTYPE VarType() { return VT_BSTR; }
     443    static ULONG VarCount (size_t aSize) { return (ULONG) aSize; }
     444    static size_t Size (ULONG aVarCount) { return (size_t) aVarCount; }
    357445
    358446    static void Copy (BSTR aFrom, BSTR &aTo)
     
    360448        aTo = aFrom ? ::SysAllocString ((const OLECHAR *) aFrom) : NULL;
    361449    }
     450};
     451
     452template<>
     453struct SafeArrayTraits <GUID>
     454{
     455protected:
     456
     457    /* Use the 64-bit unsigned integer type for GUID */
     458    static VARTYPE VarType() { return VT_UI8; }
     459
     460    /* GUID is 128 bit, so we need two VT_UI8 */
     461    static ULONG VarCount (size_t aSize)
     462    {
     463        AssertCompileSize (GUID, 16);
     464        return (ULONG) (aSize * 2);
     465    }
     466
     467    static size_t Size (ULONG aVarCount) { return (size_t) aVarCount / 2; }
     468
     469    static void Copy (GUID aFrom, GUID &aTo) { aTo = aFrom; }
    362470};
    363471
     
    418526     * Weakly attaches this instance to the existing array passed in a method
    419527     * parameter declared using the ComSafeArrayIn macro. When using this call,
    420      * always wrap the parameter name in the ComSafeArrayOutArg macro call like
     528     * always wrap the parameter name in the ComSafeArrayInArg macro call like
    421529     * this:
    422530     * <pre>
     
    460568        m.isWeak = true;
    461569
    462         AssertReturnVoid (accessRaw() != NULL);
     570        AssertReturnVoid (m.arr == NULL || accessRaw() != NULL);
    463571
    464572#endif /* defined (VBOX_WITH_XPCOM) */
     
    466574
    467575    /**
    468      * Creates a deep copy of the goven standard C++ container.
     576     * Creates a deep copy of the given standard C++ container.
    469577     *
    470578     * @param aCntr Container object to copy.
     
    479587        AssertReturnVoid (!isNull());
    480588
    481         int i = 0;
     589        size_t i = 0;
    482590        for (typename C <T>::const_iterator it = aCntr.begin();
    483591             it != aCntr.end(); ++ it, ++ i)
     
    526634#else
    527635        if (m.arr)
    528             return m.arr->rgsabound [0].cElements;
     636            return Size (m.arr->rgsabound [0].cElements);
    529637        return 0;
    530638#endif
     
    576684#else
    577685
    578         SAFEARRAYBOUND bound = { (ULONG)aNewSize, 0 };
     686        SAFEARRAYBOUND bound = { VarCount (aNewSize), 0 };
    579687        m.arr = SafeArrayCreate (VarType(), 1, &bound);
    580688        AssertReturn (m.arr != NULL, false);
     
    678786
    679787    /**
    680      * Transfers the ownership of this array's data to a method parameter
     788     * Transfers the ownership of this array's data to the specified location
    681789     * declared using the ComSafeArrayOut macro and makes this array a null
    682790     * array. When using this call, always wrap the parameter name in the
     
    686794     * </pre>
    687795     *
     796     * Detaching the null array is also possible in which case the location will
     797     * receive NULL.
     798     *
    688799     * @note Since the ownership of the array data is transferred to the
    689800     * caller of the method, he is responsible to free the array data when it is
    690801     * no more necessary.
    691802     *
    692      * @param aArg  Output method parameter to detach to.
     803     * @param aArg  Location to detach to.
    693804     */
    694805    virtual SafeArray &detachTo (ComSafeArrayOut (T, aArg))
     
    842953#if defined (VBOX_WITH_XPCOM)
    843954
     955/**
     956 * Version of com::SafeArray for arrays of GUID.
     957 *
     958 * In MS COM, GUID arrays store GUIDs by value and therefore input arrays are
     959 * represented using |GUID *| and out arrays -- using |GUID **|. In XPCOM,
     960 * GUID arrays store pointers to nsID so that input arrays are |const nsID **|
     961 * and out arrays are |nsID ***|. Due to this difference, it is impossible to
     962 * work with arrays of GUID on both platforms by simply using com::SafeArray
     963 * <GUID>. This class is intended to provide some leve of cross-platform
     964 * behavior.
     965 *
     966 * The basic usage pattern is basically similar to com::SafeArray<> except that
     967 * you use ComSafeGUIDArrayIn* and ComSafeGUIDArrayOut* macros instead of
     968 * ComSafeArrayIn* and ComSafeArrayOut*. Another important nuance is that the
     969 * raw() array type is different (nsID **, or GUID ** on XPCOM and GUID * on MS
     970 * COM) so it is recommended to use operator[] instead that always returns a
     971 * GUID by value.
     972 *
     973 * Note that due to const modifiers, you cannot use SafeGUIDArray for input GUID
     974 * arrays. Please use SafeConstGUIDArray for this instead.
     975 *
     976 * Other than mentioned above, the functionality of this class is equivalent to
     977 * com::SafeArray<>. See the description of that template and its methods for
     978 * more information.
     979 *
     980 * Output GUID arrays are handled by a separate class, SafeGUIDArrayOut, since
     981 * this class cannot handle them because of const modifiers.
     982 */
     983class SafeGUIDArray : public SafeArray <nsID *>
     984{
     985public:
     986
     987    typedef SafeArray <nsID *> Base;
     988
     989    class nsIDRef
     990    {
     991    public:
     992
     993        nsIDRef (nsID * &aVal) : mVal (aVal) {}
     994
     995        operator const nsID &() const { return mVal ? *mVal : *Empty; }
     996        operator nsID() const { return mVal ? *mVal : *Empty; }
     997
     998        const nsID *operator&() const { return mVal ? mVal : Empty; }
     999
     1000        nsIDRef &operator= (const nsID &aThat)
     1001        {
     1002            if (mVal == NULL)
     1003                Copy (&aThat, mVal);
     1004            else
     1005                *mVal = aThat;
     1006            return *this;
     1007        }
     1008
     1009    private:
     1010
     1011        nsID * &mVal;
     1012
     1013        static const nsID *Empty;
     1014
     1015        friend class SafeGUIDArray;
     1016    };
     1017
     1018    /** See SafeArray<>::SafeArray(). */
     1019    SafeGUIDArray() {}
     1020
     1021    /** See SafeArray<>::SafeArray (size_t). */
     1022    SafeGUIDArray (size_t aSize) : Base (aSize) {}
     1023
     1024    /**
     1025     * Array access operator that returns an array element by reference. As a
     1026     * special case, the return value of this operator on XPCOM is a nsID (GUID)
     1027     * reference, instead of a nsID pointer (the actual SafeArray template
     1028     * argument), for compatibility with the MS COM version.
     1029     *
     1030     * The rest is equivalent to SafeArray<>::operator[].
     1031     */
     1032    nsIDRef operator[] (size_t aIdx)
     1033    {
     1034        Assert (m.arr != NULL);
     1035        Assert (aIdx < size());
     1036        return nsIDRef (m.arr [aIdx]);
     1037    }
     1038
     1039    /**
     1040    * Const version of #operator[] that returns an array element by value.
     1041    */
     1042    const nsID &operator[] (size_t aIdx) const
     1043    {
     1044        Assert (m.arr != NULL);
     1045        Assert (aIdx < size());
     1046        return m.arr [aIdx] ? *m.arr [aIdx] : *nsIDRef::Empty;
     1047    }
     1048};
     1049
     1050/**
     1051 * Version of com::SafeArray for const arrays of GUID.
     1052 *
     1053 * This class is used to work with input GUID array parameters in method
     1054 * implementaitons. See SafeGUIDArray for more details.
     1055 */
     1056class SafeConstGUIDArray : public SafeArray <const nsID *,
     1057                                            SafeArrayTraits <nsID *> >
     1058{
     1059public:
     1060
     1061    typedef SafeArray <const nsID *, SafeArrayTraits <nsID *> > Base;
     1062
     1063    /** See SafeArray<>::SafeArray(). */
     1064    SafeConstGUIDArray() {}
     1065
     1066    /* See SafeArray<>::SafeArray (ComSafeArrayIn (T, aArg)). */
     1067    SafeConstGUIDArray (ComSafeGUIDArrayIn (aArg))
     1068        : Base (ComSafeGUIDArrayInArg (aArg)) {}
     1069
     1070    /**
     1071     * Array access operator that returns an array element by reference. As a
     1072     * special case, the return value of this operator on XPCOM is nsID (GUID)
     1073     * instead of nsID *, for compatibility with the MS COM version.
     1074     *
     1075     * The rest is equivalent to SafeArray<>::operator[].
     1076     */
     1077    const nsID &operator[] (size_t aIdx) const
     1078    {
     1079        AssertReturn (m.arr != NULL,  **((const nsID * *) NULL));
     1080        AssertReturn (aIdx < size(), **((const nsID * *) NULL));
     1081        return *m.arr [aIdx];
     1082    }
     1083
     1084private:
     1085
     1086    /* These are disabled because of const */
     1087    bool reset (size_t aNewSize) { NOREF (aNewSize); return false; }
     1088};
     1089
     1090#else /* defined (VBOX_WITH_XPCOM) */
     1091
     1092typedef SafeArray <GUID> SafeGUIDArray;
     1093typedef SafeArray <const GUID, SafeArrayTraits <GUID> > SafeConstGUIDArray;
     1094
     1095#endif /* defined (VBOX_WITH_XPCOM) */
     1096
     1097////////////////////////////////////////////////////////////////////////////////
     1098
     1099#if defined (VBOX_WITH_XPCOM)
     1100
    8441101template <class I>
    8451102struct SafeIfaceArrayTraits
     
    8831140
    8841141    static VARTYPE VarType() { return VT_UNKNOWN; }
     1142    static ULONG VarCount (size_t aSize) { return (ULONG) aSize; }
     1143    static size_t Size (ULONG aVarCount) { return (size_t) aVarCount; }
    8851144
    8861145    static void Copy (I * aFrom, I * &aTo)
  • trunk/include/VBox/com/defs.h

    r11390 r13580  
    7171#ifndef VBOX_COM_NO_ATL
    7272# include <atlbase.h>
     73#include <atlcom.h>
    7374#endif
    7475
     
    8586#define SUCCEEDED_WARNING(rc)   (SUCCEEDED (rc) && (rc) != S_OK)
    8687
    87 /* input pointer argument to method */
     88/** Input pointer argument prefix in the interface method declaration. */
    8889#define INPTR
    8990
    90 /* makes the name of the getter interface function (n must be capitalized) */
     91/** Makes the name of the getter interface function (n must be capitalized). */
    9192#define COMGETTER(n)    get_##n
    92 /* makes the name of the setter interface function (n must be capitalized) */
     93/** Makes the name of the setter interface function (n must be capitalized). */
    9394#define COMSETTER(n)    put_##n
    9495
    95 /* a type for an input GUID parameter in the interface method declaration */
     96/** Type for an input GUID parameter in the interface method declaration. */
    9697#define GUIDPARAM           GUID
    97 /* a type for an output GUID parameter in the interface method declaration */
     98/** Type for an output GUID parameter in the interface method declaration. */
    9899#define GUIDPARAMOUT        GUID*
    99100
     
    120121 * which makes it impossible to use it for reading safearray data.
    121122 */
    122 #define ComSafeArrayInIsNull(aArg)      (aArg == NULL || *aArg == NULL)
     123#define ComSafeArrayInIsNull(aArg)      ((aArg) == NULL || *(aArg) == NULL)
    123124
    124125/**
     
    155156 * which makes it impossible to use it for returning a safearray.
    156157 */
    157 #define ComSafeArrayOutIsNull(aArg)     (aArg == NULL)
     158#define ComSafeArrayOutIsNull(aArg)     ((aArg) == NULL)
    158159
    159160/**
     
    166167 */
    167168#define ComSafeArrayOutArg(aArg)        aArg
     169
     170/**
     171 * Version of ComSafeArrayIn for GUID.
     172 * @param aArg Parameter name to wrap.
     173 */
     174#define ComSafeGUIDArrayIn(aArg)        SAFEARRAY **aArg
     175
     176/**
     177 * Version of ComSafeArrayInIsNull for GUID.
     178 * @param aArg Parameter name to wrap.
     179 */
     180#define ComSafeGUIDArrayInIsNull(aArg)  ComSafeArrayInIsNull (aArg)
     181
     182/**
     183 * Version of ComSafeArrayInArg for GUID.
     184 * @param aArg Parameter name to wrap.
     185 */
     186#define ComSafeGUIDArrayInArg(aArg)     ComSafeArrayInArg (aArg)
     187
     188/**
     189 * Version of ComSafeArrayOut for GUID.
     190 * @param aArg Parameter name to wrap.
     191 */
     192#define ComSafeGUIDArrayOut(aArg)       SAFEARRAY **aArg
     193
     194/**
     195 * Version of ComSafeArrayOutIsNull for GUID.
     196 * @param aArg Parameter name to wrap.
     197 */
     198#define ComSafeGUIDArrayOutIsNull(aArg) ComSafeArrayOutIsNull (aArg)
     199
     200/**
     201 * Version of ComSafeArrayOutArg for GUID.
     202 * @param aArg Parameter name to wrap.
     203 */
     204#define ComSafeGUIDArrayOutArg(aArg)    ComSafeArrayOutArg (aArg)
    168205
    169206/**
     
    230267#define TRUE PR_TRUE
    231268
    232 /* makes the name of the getter interface function (n must be capitalized) */
     269/** Input pointer argument prefix in the interface method declaration. */
     270#define INPTR const
     271
     272/** Makes the name of the getter interface function (n must be capitalized). */
    233273#define COMGETTER(n)    Get##n
    234 /* makes the name of the setter interface function (n must be capitalized) */
     274/** Makes the name of the setter interface function (n must be capitalized). */
    235275#define COMSETTER(n)    Set##n
    236276
    237 /* a type to define a raw GUID variable (better to use the Guid class) */
     277/**
     278 * Type to define a raw GUID variable (for members use the com::Guid class
     279 * instead).
     280 */
    238281#define GUID                nsID
    239 /* a type for an input GUID parameter in the interface method declaration */
     282/** Type for an input GUID parameter in the interface method declaration. */
    240283#define GUIDPARAM           nsID &
    241 /* a type for an output GUID parameter in the interface method declaration */
     284/** Type for an output GUID parameter in the interface method declaration. */
    242285#define GUIDPARAMOUT        nsID **
    243286
    244287/* safearray input parameter macros */
    245288#define ComSafeArrayIn(aType, aArg)         PRUint32 aArg##Size, aType *aArg
    246 #define ComSafeArrayInIsNull(aArg)          (aArg == NULL)
     289#define ComSafeArrayInIsNull(aArg)          ((aArg) == NULL)
    247290#define ComSafeArrayInArg(aArg)             aArg##Size, aArg
    248291
    249292/* safearray output parameter macros */
    250293#define ComSafeArrayOut(aType, aArg)        PRUint32 *aArg##Size, aType **aArg
    251 #define ComSafeArrayOutIsNull(aArg)         (aArg == NULL)
     294#define ComSafeArrayOutIsNull(aArg)         ((aArg) == NULL)
    252295#define ComSafeArrayOutArg(aArg)            aArg##Size, aArg
     296
     297/* safearray input parameter macros for GUID */
     298#define ComSafeGUIDArrayIn(aArg)            PRUint32 aArg##Size, const nsID **aArg
     299#define ComSafeGUIDArrayInIsNull(aArg)      ComSafeArrayInIsNull (aArg)
     300#define ComSafeGUIDArrayInArg(aArg)         ComSafeArrayInArg (aArg)
     301
     302/* safearray output parameter macros for GUID */
     303#define ComSafeGUIDArrayOut(aArg)           PRUint32 *aArg##Size, nsID ***aArg
     304#define ComSafeGUIDArrayOutIsNull(aArg)     ComSafeArrayOutIsNull (aArg)
     305#define ComSafeGUIDArrayOutArg(aArg)        ComSafeArrayOutArg (aArg)
    253306
    254307/* CLSID and IID for compatibility with Win32 */
     
    257310
    258311/* OLE error codes */
    259 #define S_OK                NS_OK
     312#define S_OK                ((nsresult) NS_OK)
    260313#define E_UNEXPECTED        NS_ERROR_UNEXPECTED
    261314#define E_NOTIMPL           NS_ERROR_NOT_IMPLEMENTED
     
    290343    virtual ~CComObject() { this->FinalRelease(); }
    291344};
    292 
    293 /* input pointer argument to method */
    294 #define INPTR const
    295345
    296346/* helper functions */
     
    403453
    404454/**
     455 * "First worst" result type.
     456 *
     457 * Variables of this class are used instead of HRESULT variables when it is
     458 * desirable to memorize the "first worst" result code instead of the last
     459 * assigned one. In other words, an assignment operation to a variable of this
     460 * class will succeed only if the result code to assign has worse severity. The
     461 * following table demonstrate this (the first column lists the previous result
     462 * code stored in the variable, the first row lists the new result code being
     463 * assigned, 'A' means the assignment will take place, '> S_OK' means a warning
     464 * result code):
     465 *
     466 * {{{
     467 *             FAILED    > S_OK    S_OK
     468 * FAILED        -         -         -
     469 * > S_OK        A         -         -
     470 * S_OK          A         A         -
     471 *
     472 * }}}
     473 *
     474 * On practice, you will need to use a FWResult variable when you call some COM
     475 * method B after another COM method A fails and want to return the result code
     476 * of A even if B also fails, but want to return the failed result code of B if
     477 * A issues a warning or succeeds.
     478 */
     479class FWResult
     480{
     481
     482public:
     483
     484    /**
     485     * Constructs a new variable. Note that by default this constructor sets the
     486     * result code to E_FAIL to make sure a failure is returned to the caller if
     487     * the variable is never assigned another value (which is considered as the
     488     * improper use of this class).
     489     */
     490    FWResult (HRESULT aRC = E_FAIL) : mRC (aRC) {}
     491
     492    FWResult &operator= (HRESULT aRC)
     493    {
     494        if ((FAILED (aRC) && !FAILED (mRC)) ||
     495            (mRC == S_OK && aRC != S_OK))
     496            mRC = aRC;
     497
     498        return *this;
     499    }
     500
     501    operator HRESULT() const { return mRC; }
     502
     503    HRESULT *operator&() { return &mRC; }
     504
     505private:
     506
     507    HRESULT mRC;
     508};
     509
     510/**
    405511 * "Last worst" result type.
    406512 *
     
    411517 * severity. The following table demonstrate this (the first column lists the
    412518 * previous result code stored in the variable, the first row lists the new
    413  * result code being assigned, 'A' means the assignment will take place):
     519 * assigned, 'A' means the assignment will take place, '> S_OK' means a warning
     520 * result code):
    414521 *
    415522 * {{{
     
    420527 *
    421528 * }}}
     529 *
     530 * On practice, you will need to use a LWResult variable when you call some COM
     531 * method B after COM method A fails and want to return the result code of B
     532 * if B also fails, but still want to return the failed result code of A if B
     533 * issues a warning or succeeds.
    422534 */
    423535class LWResult
  • trunk/include/VBox/com/string.h

    r9332 r13580  
    243243    static const Bstr Null;
    244244
    245 private:
     245protected:
    246246
    247247    void safe_assign (const BSTR str)
     
    273273    BSTR bstr;
    274274
    275     friend class Utf8Str; // to access our raw_copy()
     275    friend class Utf8Str; /* to access our raw_copy() */
    276276};
    277277
    278 // symmetric compare operators
     278/* symmetric compare operators */
    279279inline bool operator== (const BSTR l, const Bstr &r) { return r.operator== (l); }
    280280inline bool operator!= (const BSTR l, const Bstr &r) { return r.operator!= (l); }
     
    479479    static const Utf8Str Null;
    480480
    481 private:
     481protected:
    482482
    483483    void safe_assign (const char *s)
     
    517517    char *str;
    518518
    519     friend class Bstr; // to access our raw_copy()
     519    friend class Bstr; /* to access our raw_copy() */
    520520};
    521521
     
    628628};
    629629
     630/**
     631 * THe BstrFmt class is a shortcut to <tt>Bstr (Utf8StrFmt (...))</tt>.
     632 */
     633class BstrFmt : public Bstr
     634{
     635public:
     636
     637    /**
     638     * Constructs a new string given the format string and the list of the
     639     * arguments for the format string.
     640     *
     641     * @param aFormat   printf-like format string (in UTF-8 encoding).
     642     * @param ...       List of the arguments for the format string.
     643     */
     644    explicit BstrFmt (const char *aFormat, ...)
     645    {
     646        va_list args;
     647        va_start (args, aFormat);
     648        raw_copy (bstr, Utf8StrFmtVA (aFormat, args));
     649        va_end (args);
     650    }
     651};
     652
     653/**
     654 * THe BstrFmtVA class is a shortcut to <tt>Bstr (Utf8StrFmtVA (...))</tt>.
     655 */
     656class BstrFmtVA : public Bstr
     657{
     658public:
     659
     660    /**
     661     * Constructs a new string given the format string and the list of the
     662     * arguments for the format string.
     663     *
     664     * @param aFormat   printf-like format string (in UTF-8 encoding).
     665     * @param aArgs     List of arguments for the format string
     666     */
     667    BstrFmtVA (const char *aFormat, va_list aArgs)
     668    {
     669        raw_copy (bstr, Utf8StrFmtVA (aFormat, aArgs));
     670    }
     671};
     672
    630673} /* namespace com */
    631674
  • trunk/include/VBox/settings.h

    r12653 r13580  
    250250 * Shut up MSVC complaining that auto_ptr[_ref] template instantiations (as a
    251251 * result of private data member declarations of some classes below) need to
    252  * be exported too to in order to be accessible by clients. I don't
     252 * be exported too to in order to be accessible by clients.
    253253 *
    254254 * The alternative is to instantiate a template before the data member
    255255 * declaration with the VBOXSETTINGS_CLASS prefix, but the standard disables
    256  * explicit instantiations in a foreign namespace. However, a declaration
     256 * explicit instantiations in a foreign namespace. In other words, a declaration
    257257 * like:
    258258 *
     
    261261 * right before the member declaration makes MSVC happy too, but this is not a
    262262 * valid C++ construct (and G++ spits it out). So, for now we just disable the
    263  * warning and will come back to this problem one dat later.
     263 * warning and will come back to this problem one day later.
    264264 *
    265265 * We also disable another warning (4275) saying that a DLL-exported class
  • trunk/include/iprt/log.h

    r12147 r13580  
    621621#ifdef LOG_USE_C99
    622622# define LogTraceMsg(a) \
    623     _LogIt(LOG_INSTANCE, RTLOGGRPFLAGS_FLOW, LOG_GROUP, ">>>>> %s (%d): %M" LOG_FN_FMT, __FILE__, __LINE__, __PRETTY_FUNCTION__, _LogRemoveParentheseis a )
     623    _LogIt(LOG_INSTANCE, RTLOGGRPFLAGS_FLOW, LOG_GROUP, ">>>>> %s (%d): " LOG_FN_FMT ": %M", __FILE__, __LINE__, __PRETTY_FUNCTION__, _LogRemoveParentheseis a )
    624624#else
    625625# define LogTraceMsg(a) \
    626     do {  LogFlow((">>>>> %s (%d): " LOG_FN_FMT, __FILE__, __LINE__, __PRETTY_FUNCTION__)); LogFlow(a); } while (0)
     626    do {  LogFlow((">>>>> %s (%d): " LOG_FN_FMT ": ", __FILE__, __LINE__, __PRETTY_FUNCTION__)); LogFlow(a); } while (0)
    627627#endif
    628628
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette