VirtualBox

Changeset 24446 in vbox


Ignore:
Timestamp:
Nov 6, 2009 2:38:35 PM (15 years ago)
Author:
vboxsync
Message:

Main: add a debugging member to com::Guid so the UUID can be easily looked at in the debugger (only in debug code)

File:
1 edited

Legend:

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

    r19239 r24446  
    6262public:
    6363
    64     Guid () { ::RTUuidClear (&uuid); }
    65     Guid (const Guid &that) { uuid = that.uuid; }
    66     Guid (const RTUUID &that) { uuid = that; }
    67 
    68     Guid (const GUID &that)
    69     {
    70         AssertCompileSize (GUID, sizeof (RTUUID));
    71         ::memcpy (&uuid, &that, sizeof (GUID));
    72     }
    73 
    74     Guid (const char *that)
    75     {
    76         ::RTUuidClear (&uuid);
    77         ::RTUuidFromStr (&uuid, that);
    78     }
    79 
    80     Guid (const Bstr &that)
     64    Guid()
     65    {
     66        ::RTUuidClear(&uuid);
     67        refresh();
     68    }
     69
     70    Guid(const Guid &that)
     71    {
     72        uuid = that.uuid;
     73        refresh();
     74    }
     75
     76    Guid(const RTUUID &that)
     77    {
     78        uuid = that;
     79        refresh();
     80    }
     81
     82    Guid(const GUID &that)
     83    {
     84        AssertCompileSize(GUID, sizeof(RTUUID));
     85        ::memcpy(&uuid, &that, sizeof(GUID));
     86        refresh();
     87    }
     88
     89    Guid(const char *that)
     90    {
     91        ::RTUuidClear(&uuid);
     92        ::RTUuidFromStr(&uuid, that);
     93        refresh();
     94    }
     95
     96    Guid(const Bstr &that)
    8197    {
    8298        ::RTUuidClear (&uuid);
    8399        if (!that.isNull())
    84100           ::RTUuidFromUtf16(&uuid, that.raw());
    85     }
    86 
    87     Guid &operator= (const Guid &that)
    88     {
    89         ::memcpy (&uuid, &that.uuid, sizeof (RTUUID));
    90         return *this;
    91     }
    92     Guid &operator= (const GUID &guid)
    93     {
    94         ::memcpy (&uuid, &guid, sizeof (GUID));
    95         return *this;
    96     }
    97     Guid &operator= (const RTUUID &guid)
    98     {
    99         ::memcpy (&uuid, &guid, sizeof (RTUUID));
    100         return *this;
    101     }
    102     Guid &operator= (const char *str)
    103     {
    104         ::RTUuidFromStr (&uuid, str);
    105         return *this;
    106     }
    107 
    108     void create() { ::RTUuidCreate (&uuid); }
    109     void clear() { ::RTUuidClear (&uuid); }
    110 
    111     Utf8Str toString () const
    112     {
    113         char buf [RTUUID_STR_LENGTH];
    114         ::RTUuidToStr (&uuid, buf, RTUUID_STR_LENGTH);
    115         return Utf8Str (buf);
     101        refresh();
     102    }
     103
     104    Guid &operator=(const Guid &that)
     105    {
     106        ::memcpy(&uuid, &that.uuid, sizeof (RTUUID));
     107        refresh();
     108        return *this;
     109    }
     110    Guid &operator=(const GUID &guid)
     111    {
     112        ::memcpy(&uuid, &guid, sizeof (GUID));
     113        refresh();
     114        return *this;
     115    }
     116    Guid &operator=(const RTUUID &guid)
     117    {
     118        ::memcpy(&uuid, &guid, sizeof (RTUUID));
     119        refresh();
     120        return *this;
     121    }
     122    Guid &operator=(const char *str)
     123    {
     124        ::RTUuidFromStr(&uuid, str);
     125        refresh();
     126        return *this;
     127    }
     128
     129    void create()
     130    {
     131        ::RTUuidCreate(&uuid);
     132        refresh();
     133    }
     134    void clear()
     135    {
     136        ::RTUuidClear(&uuid);
     137        refresh();
     138    }
     139
     140    Utf8Str toString() const
     141    {
     142        char buf[RTUUID_STR_LENGTH];
     143        ::RTUuidToStr(&uuid, buf, RTUUID_STR_LENGTH);
     144        return Utf8Str(buf);
    116145    }
    117146
     
    121150          return Bstr();
    122151
    123         RTUTF16 buf [RTUUID_STR_LENGTH];
    124         ::RTUuidToUtf16 (&uuid, buf, RTUUID_STR_LENGTH);
    125         return Bstr (buf);
    126     }
    127 
    128     bool isEmpty() const { return ::RTUuidIsNull (&uuid); }
    129     operator bool() const { return !isEmpty(); }
    130 
    131     bool operator== (const Guid &that) const { return ::RTUuidCompare (&uuid, &that.uuid) == 0; }
    132     bool operator== (const GUID &guid) const { return ::RTUuidCompare (&uuid, (PRTUUID) &guid) == 0; }
    133     bool operator!= (const Guid &that) const { return !operator==(that); }
    134     bool operator!= (const GUID &guid) const { return !operator==(guid); }
    135     bool operator< (const Guid &that) const { return ::RTUuidCompare (&uuid, &that.uuid) < 0; }
    136     bool operator< (const GUID &guid) const { return ::RTUuidCompare (&uuid, (PRTUUID) &guid) < 0; }
     152        RTUTF16 buf[RTUUID_STR_LENGTH];
     153        ::RTUuidToUtf16(&uuid, buf, RTUUID_STR_LENGTH);
     154        return Bstr(buf);
     155    }
     156
     157    bool isEmpty() const
     158    {
     159        return ::RTUuidIsNull (&uuid);
     160    }
     161
     162    operator bool() const
     163    {
     164        return !isEmpty();
     165    }
     166
     167    bool operator==(const Guid &that) const { return ::RTUuidCompare (&uuid, &that.uuid) == 0; }
     168    bool operator==(const GUID &guid) const { return ::RTUuidCompare (&uuid, (PRTUUID) &guid) == 0; }
     169    bool operator!=(const Guid &that) const { return !operator==(that); }
     170    bool operator!=(const GUID &guid) const { return !operator==(guid); }
     171    bool operator<(const Guid &that) const { return ::RTUuidCompare (&uuid, &that.uuid) < 0; }
     172    bool operator<(const GUID &guid) const { return ::RTUuidCompare (&uuid, (PRTUUID) &guid) < 0; }
    137173
    138174    /* to pass instances as IN_GUID parameters to interface methods */
    139     operator const GUID &() const { return *(GUID *) &uuid; }
     175    operator const GUID&() const
     176    {
     177        return *(GUID *) &uuid;
     178    }
    140179
    141180    /* to directly pass instances to RTPrintf("%Vuuid") */
    142     PRTUUID ptr() { return &uuid; }
     181    PRTUUID ptr()
     182    {
     183        return &uuid;
     184    }
    143185
    144186    /* to pass instances to printf-like functions */
    145     PCRTUUID raw() const { return &uuid; }
     187    PCRTUUID raw() const
     188    {
     189        return &uuid;
     190    }
    146191
    147192    /* to pass instances to RTUuid*() as a constant argument */
    148     operator const RTUUID * () const { return &uuid; }
     193    operator const RTUUID*() const
     194    {
     195        return &uuid;
     196    }
    149197
    150198#if !defined (VBOX_WITH_XPCOM)
     
    154202    const Guid &cloneTo (GUID *pguid) const
    155203    {
    156         if (pguid) { ::memcpy (pguid, &uuid, sizeof (GUID)); }
     204        if (pguid)
     205            ::memcpy(pguid, &uuid, sizeof(GUID));
    157206        return *this;
    158207    }
    159208
    160209    /* to pass instances as OUT_GUID parameters to interface methods */
    161     GUID *asOutParam() { return (GUID *) &uuid; }
     210    GUID *asOutParam()
     211    {
     212        return (GUID*)&uuid;
     213    }
    162214
    163215#else
     
    171223    }
    172224
    173     /* internal helper class for asOutParam() */
     225    // internal helper class for asOutParam(); this takes a GUID refrence
     226    // in the constructor and copies the uuid from the method to that instance
     227    // in its destructor
    174228    class GuidOutParam
    175229    {
    176         GuidOutParam (Guid &guid) : ptr (0), outer (guid) { outer.clear(); }
     230        GuidOutParam(Guid &guid)
     231            : ptr(0),
     232              outer(guid)
     233        {
     234            outer.clear();
     235        }
     236
    177237        nsID *ptr;
    178238        Guid &outer;
    179         GuidOutParam (const GuidOutParam &that); // disabled
    180         GuidOutParam &operator= (const GuidOutParam &that); // disabled
     239        GuidOutParam(const GuidOutParam &that); // disabled
     240        GuidOutParam &operator=(const GuidOutParam &that); // disabled
    181241    public:
    182         operator nsID **() { return &ptr; }
     242        operator nsID**() { return &ptr; }
    183243        ~GuidOutParam()
    184244        {
    185             if (ptr && outer.isEmpty()) { outer = *ptr; nsMemory::Free (ptr); }
     245            if (ptr && outer.isEmpty())
     246            {
     247                outer = *ptr;
     248                outer.refresh();
     249                nsMemory::Free(ptr);
     250            }
    186251        }
    187252        friend class Guid;
     
    189254
    190255    /* to pass instances as OUT_GUID parameters to interface methods */
    191     GuidOutParam asOutParam() { return GuidOutParam (*this); }
     256    GuidOutParam asOutParam() { return GuidOutParam(*this); }
    192257
    193258#endif
    194259
    195260    /* to directly test IN_GUID interface method's parameters */
    196     static bool isEmpty (const GUID &guid)
    197     {
    198         return ::RTUuidIsNull ((PRTUUID) &guid);
     261    static bool isEmpty(const GUID &guid)
     262    {
     263        return ::RTUuidIsNull((PRTUUID)&guid);
    199264    }
    200265
     
    205270
    206271private:
     272    // in debug code, refresh the UUID string representatino for
     273    // debugging; must be called every time the internal uuid
     274    // changes; compiles to nothing in release code
     275    inline void refresh()
     276    {
     277#ifdef DEBUG
     278        ::RTUuidToStr(&uuid, szUUID, RTUUID_STR_LENGTH);
     279        pcszUUID = szUUID;
     280#endif
     281    }
    207282
    208283    RTUUID uuid;
     284
     285#ifdef DEBUG
     286    // in debug builds, have a Utf8Str representation of the UUID so we can look
     287    // at it in the debugger more easily
     288    char szUUID[RTUUID_STR_LENGTH];
     289    const char *pcszUUID;
     290#endif
    209291};
    210292
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