VirtualBox

Ignore:
Timestamp:
Jun 27, 2007 2:58:18 PM (18 years ago)
Author:
vboxsync
Message:

Main/Glue: Useful enhancements to com::ErrorInfo[Keeper].

File:
1 edited

Legend:

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

    r3044 r3318  
    187187    bool isFullAvailable() const { return mIsFullAvailable; }
    188188
     189    /**
     190     *  Returns @c true if both isBasicAvailable() and isFullAvailable() are
     191     *  @c false.
     192     */
     193    bool isNull() const { return !mIsBasicAvailable && !mIsFullAvailable; }
     194
    189195    /**
    190196     *  Returns the COM result code of the failed operation.
     
    242248     */
    243249    void print (const char *aPrefix = NULL);
     250
     251    /**
     252     *  Resets all collected error information. #isNull() will
     253     *  return @c true after this method is called.
     254     */
     255    void setNull()
     256    {
     257        mIsBasicAvailable = false;
     258        mIsFullAvailable = false;
     259
     260        mResultCode = S_OK;
     261        mInterfaceID.clear();
     262        mComponent.setNull();
     263        mText.setNull();
     264        mNext.reset();
     265        mInterfaceName.setNull();
     266        mCalleeIID.clear();
     267        mCalleeName.setNull();
     268        mErrorInfo.setNull();
     269    }
    244270
    245271protected:
     
    327353public:
    328354
    329     /** Constructs a new instance that will fetch the current error info. */
    330     ErrorInfoKeeper() : ErrorInfo (false), mForgot (false)
    331         { init (true /* aKeepObj */); }
     355    /**
     356     *  Constructs a new instance that will fetch the current error info if
     357     *  @a aIsNull is @c false (by default) or remain uninitialized (null)
     358     *  otherwise.
     359     *
     360     *  @param aIsNull  @true to prevent fetching error info and leave
     361     *                  the instance uninitialized.
     362     */
     363    ErrorInfoKeeper (bool aIsNull = false)
     364        : ErrorInfo (false), mForgot (false)
     365    {
     366        if (!aIsNull)
     367            init (true /* aKeepObj */);
     368    }
    332369
    333370    /**
     
    337374    ~ErrorInfoKeeper() { if (!mForgot) restore(); }
    338375
     376    /**
     377     *  Tries to (re-)fetch error info set on the current thread.  On success,
     378     *  the previous error information, if any, will be overwritten with the
     379     *  new error information. On failure, or if there is no error information
     380     *  available, this instance will be reset to null.
     381     */
     382    void fetch()
     383    {
     384        setNull();
     385        init (true /* aKeepObj */);
     386    }
     387
    339388    /**
    340389     *  Restores error info fetched by the constructor and forgets it
     
    349398     *  being restored by #restore() or by the destructor.
    350399     */
    351     void forget() { mForgot = 0; }
     400    void forget() { mForgot = true; }
    352401
    353402    /**
     
    356405     *  stored error info object to the caller.
    357406     */
    358     ComPtr <IUnknown> takeError() { mForgot = 0; return mErrorInfo; }
     407    ComPtr <IUnknown> takeError() { mForgot = true; return mErrorInfo; }
    359408
    360409private:
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