Changeset 30739 in vbox for trunk/include/VBox/com/MultiResult.h
- Timestamp:
- Jul 8, 2010 12:27:42 PM (15 years ago)
- svn:sync-xref-src-repo-rev:
- 63508
- File:
-
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/VBox/com/MultiResult.h
r30731 r30739 33 33 #include "VBox/com/string.h" 34 34 35 #include <iprt/cdefs.h>36 37 35 #include <stdarg.h> 38 36 39 #if !defined (VBOX_WITH_XPCOM)40 interface IVirtualBoxErrorInfo;41 #else42 class IVirtualBoxErrorInfo;43 #endif44 45 37 namespace com 46 38 { 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 */ 65 class FWResult 66 { 67 68 public: 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 91 private: 92 93 HRESULT mRC; 94 }; 47 95 48 96 /** … … 164 212 private: 165 213 166 DECLARE_CLS_NEW_DELETE_NOOP 214 DECLARE_CLS_NEW_DELETE_NOOP(MultiResult) 167 215 168 216 static void incCounter();
Note:
See TracChangeset
for help on using the changeset viewer.