VirtualBox

Changeset 15051 in vbox for trunk/include/VBox


Ignore:
Timestamp:
Dec 5, 2008 5:20:00 PM (16 years ago)
Author:
vboxsync
Message:

Main: Cleaned up the long standing const BSTR = const (OLECHAR *) on WIn32 vs (const PRunichar) * on XPCOM clash. Cleaned up BSTR/GUID macros (IN_BSTR replaces INPTR BSTR, IN_GUID replaces INPTR GUIDPARAM, OUT_GUID replaces GUIDPARAMOUT).

Location:
trunk/include/VBox/com
Files:
5 edited

Legend:

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

    r13624 r15051  
    119119    bool operator< (const GUID &guid) const { return ::RTUuidCompare (&uuid, (PRTUUID) &guid) < 0; }
    120120
    121     /* to pass instances as GUIDPARAM parameters to interface methods */
     121    /* to pass instances as IN_GUID parameters to interface methods */
    122122    operator const GUID &() const { return *(GUID *) &uuid; }
    123123
     
    133133#if !defined (VBOX_WITH_XPCOM)
    134134
    135     /* to assign instances to GUIDPARAMOUT parameters from within the
     135    /* to assign instances to OUT_GUID parameters from within the
    136136     *  interface method */
    137137    const Guid &cloneTo (GUID *pguid) const
     
    141141    }
    142142
    143     /* to pass instances as GUIDPARAMOUT parameters to interface methods */
     143    /* to pass instances as OUT_GUID parameters to interface methods */
    144144    GUID *asOutParam() { return (GUID *) &uuid; }
    145145
    146146#else
    147147
    148     /* to assign instances to GUIDPARAMOUT parameters from within the
     148    /* to assign instances to OUT_GUID parameters from within the
    149149     * interface method */
    150150    const Guid &cloneTo (nsID **ppguid) const
     
    171171    };
    172172
    173     /* to pass instances as GUIDPARAMOUT parameters to interface methods */
     173    /* to pass instances as OUT_GUID parameters to interface methods */
    174174    GuidOutParam asOutParam() { return GuidOutParam (*this); }
    175175
    176176#endif
    177177
    178     /* to directly test GUIDPARAM interface method's parameters */
     178    /* to directly test IN_GUID interface method's parameters */
    179179    static bool isEmpty (const GUID &guid)
    180180    {
  • trunk/include/VBox/com/VirtualBoxErrorInfo.h

    r13580 r15051  
    8686    // IVirtualBoxErrorInfo properties
    8787    STDMETHOD(COMGETTER(ResultCode)) (HRESULT *aResultCode);
    88     STDMETHOD(COMGETTER(InterfaceID)) (GUIDPARAMOUT aIID);
     88    STDMETHOD(COMGETTER(InterfaceID)) (OUT_GUID aIID);
    8989    STDMETHOD(COMGETTER(Component)) (BSTR *aComponent);
    9090    STDMETHOD(COMGETTER(Text)) (BSTR *aText);
  • trunk/include/VBox/com/array.h

    r15048 r15051  
    155155 *
    156156 * Also note that in order to pass input BSTR array parameters declared
    157  * using the ComSafeArrayIn (INPTR BSTR, aParam) macro to the SafeArray<>
    158  * constructor using the ComSafeArrayInArg() macro, you should use INPTR BSTR
     157 * using the ComSafeArrayIn (IN_BSTR, aParam) macro to the SafeArray<>
     158 * constructor using the ComSafeArrayInArg() macro, you should use IN_BSTR
    159159 * as the SafeArray<> template argument, not just BSTR.
    160160 *
  • trunk/include/VBox/com/defs.h

    r13908 r15051  
    9191#define SUCCEEDED_WARNING(rc)   (SUCCEEDED (rc) && (rc) != S_OK)
    9292
    93 /** Input pointer argument prefix in the interface method declaration. */
    94 #define INPTR
     93/** Immutable BSTR string */
     94typedef const OLECHAR *CBSTR;
     95
     96/** Input BSTR argument the interface method declaration. */
     97#define IN_BSTR BSTR
     98
     99/** Input GUID argument the interface method declaration. */
     100#define IN_GUID GUID
     101/** Output GUID argument the interface method declaration. */
     102#define OUT_GUID GUID*
    95103
    96104/** Makes the name of the getter interface function (n must be capitalized). */
     
    98106/** Makes the name of the setter interface function (n must be capitalized). */
    99107#define COMSETTER(n)    put_##n
    100 
    101 /** Type for an input GUID parameter in the interface method declaration. */
    102 #define GUIDPARAM           GUID
    103 /** Type for an output GUID parameter in the interface method declaration. */
    104 #define GUIDPARAMOUT        GUID*
    105108
    106109/**
     
    265268#define ULONG64 PRUint64
    266269
    267 #define BSTR    PRUnichar *
    268 #define LPBSTR  BSTR *
     270#define FALSE   PR_FALSE
     271#define TRUE    PR_TRUE
     272
    269273#define OLECHAR wchar_t
    270274
    271 #define FALSE PR_FALSE
    272 #define TRUE PR_TRUE
    273 
    274 /** Input pointer argument prefix in the interface method declaration. */
    275 #define INPTR const
     275/* note: typedef to semantically match BSTR on Win32 */
     276typedef PRUnichar *BSTR;
     277typedef const PRUnichar *CBSTR;
     278typedef BSTR *LPBSTR;
     279
     280/** Input BSTR argument the interface method declaration. */
     281#define IN_BSTR CBSTR
     282
     283/**
     284 * Type to define a raw GUID variable (for members use the com::Guid class
     285 * instead).
     286 */
     287#define GUID        nsID
     288/** Input GUID argument the interface method declaration. */
     289#define IN_GUID     const nsID &
     290/** Output GUID argument the interface method declaration. */
     291#define OUT_GUID    nsID **
    276292
    277293/** Makes the name of the getter interface function (n must be capitalized). */
     
    279295/** Makes the name of the setter interface function (n must be capitalized). */
    280296#define COMSETTER(n)    Set##n
    281 
    282 /**
    283  * Type to define a raw GUID variable (for members use the com::Guid class
    284  * instead).
    285  */
    286 #define GUID                nsID
    287 /** Type for an input GUID parameter in the interface method declaration. */
    288 #define GUIDPARAM           nsID &
    289 /** Type for an output GUID parameter in the interface method declaration.  */
    290 #define GUIDPARAMOUT        nsID **
    291297
    292298/* safearray input parameter macros */
  • trunk/include/VBox/com/string.h

    r13856 r15051  
    7676
    7777    typedef BSTR String;
    78     typedef const BSTR ConstString;
     78    typedef CBSTR ConstString;
    7979
    8080    Bstr () : bstr (NULL) {}
    8181
    8282    Bstr (const Bstr &that) : bstr (NULL) { raw_copy (bstr, that.bstr); }
    83     Bstr (const BSTR that) : bstr (NULL) { raw_copy (bstr, that); }
     83    Bstr (CBSTR that) : bstr (NULL) { raw_copy (bstr, that); }
     84
     85#if defined (VBOX_WITH_XPCOM)
    8486    Bstr (const wchar_t *that) : bstr (NULL)
    8587    {
    8688        AssertCompile (sizeof (wchar_t) == sizeof (OLECHAR));
    87         raw_copy (bstr, (const BSTR) that);
    88     }
     89        raw_copy (bstr, (CBSTR) that);
     90    }
     91#endif
    8992
    9093    Bstr (const Utf8Str &that);
     
    97100
    98101    Bstr &operator = (const Bstr &that) { safe_assign (that.bstr); return *this; }
    99     Bstr &operator = (const BSTR that) { safe_assign (that); return *this; }
     102    Bstr &operator = (CBSTR that) { safe_assign (that); return *this; }
    100103
    101104    Bstr &operator = (const Utf8Str &that);
     
    140143    }
    141144
    142     int compare (const BSTR str) const
     145    int compare (CBSTR str) const
     146    {
     147        return ::RTUtf16Cmp ((PRTUTF16) bstr, (PRTUTF16) str);
     148    }
     149
     150    int compare (BSTR str) const
    143151    {
    144152        return ::RTUtf16Cmp ((PRTUTF16) bstr, (PRTUTF16) str);
     
    147155    bool operator == (const Bstr &that) const { return !compare (that.bstr); }
    148156    bool operator != (const Bstr &that) const { return !!compare (that.bstr); }
    149     bool operator == (const BSTR that) const { return !compare (that); }
     157    bool operator == (CBSTR that) const { return !compare (that); }
     158    bool operator == (BSTR that) const { return !compare (that); }
     159
     160#if defined (VBOX_WITH_XPCOM)
    150161    bool operator != (const wchar_t *that) const
    151162    {
    152163        AssertCompile (sizeof (wchar_t) == sizeof (OLECHAR));
    153         return !!compare ((const BSTR) that);
     164        return !!compare ((CBSTR) that);
    154165    }
    155166    bool operator == (const wchar_t *that) const
    156167    {
    157168        AssertCompile (sizeof (wchar_t) == sizeof (OLECHAR));
    158         return !compare ((const BSTR) that);
    159     }
    160     bool operator != (const BSTR that) const { return !!compare (that); }
     169        return !compare ((CBSTR) that);
     170    }
     171#endif
     172
     173    bool operator != (CBSTR that) const { return !!compare (that); }
     174    bool operator != (BSTR that) const { return !!compare (that); }
    161175    bool operator < (const Bstr &that) const { return compare (that.bstr) < 0; }
    162     bool operator < (const BSTR that) const { return compare (that) < 0; }
     176    bool operator < (CBSTR that) const { return compare (that) < 0; }
     177    bool operator < (BSTR that) const { return compare (that) < 0; }
     178#if defined (VBOX_WITH_XPCOM)
    163179    bool operator < (const wchar_t *that) const
    164180    {
    165181        AssertCompile (sizeof (wchar_t) == sizeof (OLECHAR));
    166         return compare ((const BSTR) that) < 0;
    167     }
    168 
    169     int compareIgnoreCase (const BSTR str) const
     182        return compare ((CBSTR) that) < 0;
     183    }
     184#endif
     185
     186    int compareIgnoreCase (CBSTR str) const
    170187    {
    171188        return ::RTUtf16LocaleICmp (bstr, str);
     
    179196    size_t length() const { return isNull() ? 0 : ::RTUtf16Len ((PRTUTF16) bstr); }
    180197
    181     /** Intended to to pass instances as |BSTR| input parameters to methods. */
    182     operator const BSTR () const { return bstr; }
    183 
    184     /** The same as operator const BSTR(), but for situations where the compiler
    185         cannot typecast implicitly (for example, in printf() argument list). */
    186     const BSTR raw() const { return bstr; }
     198    /** Intended to to pass instances as |CBSTR| input parameters to methods. */
     199    operator CBSTR () const { return bstr; }
     200
     201    /**
     202     * Intended to to pass instances as |BSTR| input parameters to methods.
     203     * Note that we have to provide this mutable BSTR operator since in MS COM
     204     * input BSTR parameters of interface methods are not const.
     205     */
     206    operator BSTR () { return bstr; }
     207
     208    /**
     209     *  The same as operator CBSTR(), but for situations where the compiler
     210     *  cannot typecast implicitly (for example, in printf() argument list).
     211     */
     212    CBSTR raw() const { return bstr; }
    187213
    188214    /**
     
    245271protected:
    246272
    247     void safe_assign (const BSTR str)
     273    void safe_assign (CBSTR str)
    248274    {
    249275        if (bstr != str)
     
    254280    }
    255281
    256     inline static void raw_copy (BSTR &ls, const BSTR rs)
     282    inline static void raw_copy (BSTR &ls, CBSTR rs)
    257283    {
    258284        if (rs)
     
    277303
    278304/* symmetric compare operators */
    279 inline bool operator== (const BSTR l, const Bstr &r) { return r.operator== (l); }
    280 inline bool operator!= (const BSTR l, const Bstr &r) { return r.operator!= (l); }
     305inline bool operator== (CBSTR l, const Bstr &r) { return r.operator== (l); }
     306inline bool operator!= (CBSTR l, const Bstr &r) { return r.operator!= (l); }
     307inline bool operator== (BSTR l, const Bstr &r) { return r.operator== (l); }
     308inline bool operator!= (BSTR l, const Bstr &r) { return r.operator!= (l); }
    281309
    282310////////////////////////////////////////////////////////////////////////////////
     
    309337
    310338    Utf8Str (const Bstr &that) : str (NULL) { raw_copy (str, that); }
    311     Utf8Str (const BSTR that) : str (NULL) { raw_copy (str, that); }
     339    Utf8Str (CBSTR that) : str (NULL) { raw_copy (str, that); }
    312340
    313341    /** Shortcut that calls #alloc(aSize) right after object creation. */
     
    325353        return *this;
    326354    }
    327     Utf8Str &operator = (const BSTR that)
     355    Utf8Str &operator = (CBSTR that)
    328356    {
    329357        setNull();
     
    500528    }
    501529
    502     inline static void raw_copy (char *&ls, const BSTR rs)
     530    inline static void raw_copy (char *&ls, CBSTR rs)
    503531    {
    504532        if (rs)
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