VirtualBox

Changeset 6963 in vbox


Ignore:
Timestamp:
Feb 14, 2008 6:11:54 PM (17 years ago)
Author:
vboxsync
Message:

Main/Glue: Added com::LWResult.

File:
1 edited

Legend:

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

    r6935 r6963  
    383383#endif
    384384
     385namespace com
     386{
     387
     388/**
     389 * "Last worst" result type.
     390 *
     391 * Variables of this class are used instead of HRESULT variables when it is
     392 * desirable to memorize the "last worst" result code instead of the last
     393 * assigned one. In other words, an assignment operation to a variable of this
     394 * class will succeed only if the result code to assign has the same or worse
     395 * severity. The following table demonstrate this (the first column lists the
     396 * previous result code stored in the variable, the first row lists the new
     397 * result code being assigned, 'A' means the assignment will take place):
     398 *
     399 * {{{
     400 *             FAILED    > S_OK    S_OK
     401 * FAILED        A         -         -
     402 * > S_OK        A         A         -
     403 * S_OK          A         A         -
     404 *
     405 * }}}
     406 */
     407class LWResult
     408{
     409
     410public:
     411
     412    /**
     413     * Constructs a new variable. Note that by default this constructor sets the
     414     * result code to E_FAIL to make sure a failure is returned to the caller if
     415     * the variable is never assigned another value (which is considered as the
     416     * improper use of this class).
     417     */
     418    LWResult (HRESULT aRC = E_FAIL) : mRC (aRC) {}
     419
     420    LWResult &operator= (HRESULT aRC)
     421    {
     422        if (FAILED (aRC) ||
     423            (SUCCEEDED (mRC) && aRC != S_OK))
     424            mRC = aRC;
     425
     426        return *this;
     427    }
     428
     429    operator HRESULT() const { return mRC; }
     430
     431    HRESULT *operator&() { return &mRC; }
     432
     433private:
     434
     435    HRESULT mRC;
     436};
     437
     438} /* namespace com */
     439
    385440#endif /* ___VBox_com_defs_h */
    386441
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