VirtualBox

Ignore:
Timestamp:
Jul 8, 2010 12:27:42 PM (15 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
63508
Message:

Main: remove VirtualBoxSupportTranslation template, add translation support to generic base class, clean up COM headers more, remove SupportErrorInfo.cpp|h

File:
1 moved

Legend:

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

    r30731 r30739  
    3333#include "VBox/com/string.h"
    3434
    35 #include <iprt/cdefs.h>
    36 
    3735#include <stdarg.h>
    3836
    39 #if !defined (VBOX_WITH_XPCOM)
    40 interface IVirtualBoxErrorInfo;
    41 #else
    42 class IVirtualBoxErrorInfo;
    43 #endif
    44 
    4537namespace com
    4638{
     39
     40/**
     41 * "First worst" result type.
     42 *
     43 * Variables of this class are used instead of HRESULT variables when it is
     44 * desirable to memorize the "first worst" result code instead of the last
     45 * assigned one. In other words, an assignment operation to a variable of this
     46 * class will succeed only if the result code to assign has worse severity. The
     47 * following table demonstrate this (the first column lists the previous result
     48 * code stored in the variable, the first row lists the new result code being
     49 * assigned, 'A' means the assignment will take place, '> S_OK' means a warning
     50 * result code):
     51 *
     52 * {{{
     53 *             FAILED    > S_OK    S_OK
     54 * FAILED        -         -         -
     55 * > S_OK        A         -         -
     56 * S_OK          A         A         -
     57 *
     58 * }}}
     59 *
     60 * In practice, you will need to use a FWResult variable when you call some COM
     61 * method B after another COM method A fails and want to return the result code
     62 * of A even if B also fails, but want to return the failed result code of B if
     63 * A issues a warning or succeeds.
     64 */
     65class FWResult
     66{
     67
     68public:
     69
     70    /**
     71     * Constructs a new variable. Note that by default this constructor sets the
     72     * result code to E_FAIL to make sure a failure is returned to the caller if
     73     * the variable is never assigned another value (which is considered as the
     74     * improper use of this class).
     75     */
     76    FWResult (HRESULT aRC = E_FAIL) : mRC (aRC) {}
     77
     78    FWResult &operator= (HRESULT aRC)
     79    {
     80        if ((FAILED (aRC) && !FAILED (mRC)) ||
     81            (mRC == S_OK && aRC != S_OK))
     82            mRC = aRC;
     83
     84        return *this;
     85    }
     86
     87    operator HRESULT() const { return mRC; }
     88
     89    HRESULT *operator&() { return &mRC; }
     90
     91private:
     92
     93    HRESULT mRC;
     94};
    4795
    4896/**
     
    164212private:
    165213
    166     DECLARE_CLS_NEW_DELETE_NOOP (MultiResult)
     214    DECLARE_CLS_NEW_DELETE_NOOP(MultiResult)
    167215
    168216    static void incCounter();
Note: See TracChangeset for help on using the changeset viewer.

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