VirtualBox

Changeset 14588 in vbox for trunk/src


Ignore:
Timestamp:
Nov 25, 2008 6:01:22 PM (16 years ago)
Author:
vboxsync
Message:

Main: Added a bunch of CheckComArg macros.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/include/VirtualBoxBase.h

    r14579 r14588  
    356356    if (1)  { ComAssertComRC (rc); if (!SUCCEEDED (rc)) { throw rc; } } else do {} while (0)
    357357
     358////////////////////////////////////////////////////////////////////////////////
     359
     360/**
     361 * Checks that the pointer argument is not NULL and returns E_INVALIDARG +
     362 * extended error info on failure.
     363 * @param arg   Input pointer-type argument (strings, interace pointers...)
     364 */
     365#define CheckComArgNotNull(arg) \
     366    do { \
     367        if ((arg) == NULL) \
     368            return setError (E_INVALIDARG, tr ("Argument %s is NULL"), #arg); \
     369    } while (0)
     370
     371/**
     372 * Checks that safe array argument is not NULL and returns E_INVALIDARG +
     373 * extended error info on failure.
     374 * @param arg   Input safe array argument (strings, interace pointers...)
     375 */
     376#define CheckComArgSafeArrayNotNull(arg) \
     377    do { \
     378        if (ComSafeArrayInIsNull (arg)) \
     379            return setError (E_INVALIDARG, tr ("Argument %s is NULL"), #arg); \
     380    } while (0)
     381
     382/**
     383 * Checks that the string argument is not a NULL or empty string and returns
     384 * E_INVALIDARG + extended error info on failure.
     385 * @param arg   Input string argument (BSTR etc.).
     386 */
     387#define CheckComArgStrNotEmptyOrNull(arg) \
     388    do { \
     389        if ((arg) == NULL || *(arg) == '\0') \
     390            return setError (E_INVALIDARG, \
     391                tr ("Argument %s is emtpy or NULL"), #arg); \
     392    } while (0)
     393
     394/**
     395 * Checks that the given expression (that must involve the argument) is true and
     396 * returns E_INVALIDARG + extended error info on failure.
     397 * @param arg   Argument.
     398 * @param expr  Expression to evaluate.
     399 */
     400#define CheckComArgExpr(arg, expr) \
     401    do { \
     402        if (!(expr)) \
     403            return setError (E_INVALIDARG, \
     404                tr ("Argument %s is invalid (must be %s)"), #arg, #expr); \
     405    } while (0)
     406
     407/**
     408 * Checks that the given expression (that must involve the argument) is true and
     409 * returns E_INVALIDARG + extended error info on failure. The error message must
     410 * be customized.
     411 * @param arg   Argument.
     412 * @param expr  Expression to evaluate.
     413 * @param msg   Parenthesized printf-like expression (must start with a verb,
     414 *              like "must be one of...", "is not within...").
     415 */
     416#define CheckComArgExprMsg(arg, expr, msg) \
     417    do { \
     418        if (!(expr)) \
     419            return setError (E_INVALIDARG, tr ("Argument %s %s"), \
     420                             #arg, Utf8StrFmt msg .raw()); \
     421    } while (0)
     422
     423/**
     424 * Checks that the given pointer to an output argument is valid and returns
     425 * E_POINTER + extended error info otherwise.
     426 * @param arg   Pointer argument.
     427 */
     428#define CheckComArgOutPointerValid(arg) \
     429    do { \
     430        if (!VALID_PTR (arg)) \
     431            return setError (E_POINTER, \
     432                tr ("Output argument %s points to invalid memory location (%p)"), \
     433                #arg, (void *) (arg)); \
     434    } while (0)
     435
     436/**
     437 * Checks that the given pointer to an output safe array argument is valid and
     438 * returns E_POINTER + extended error info otherwise.
     439 * @param arg   Safe array argument.
     440 */
     441#define CheckComArgOutSafeArrayPointerValid(arg) \
     442    do { \
     443        if (ComSafeArrayOutIsNull (arg)) \
     444            return setError (E_POINTER, \
     445                tr ("Output argument %s points to invalid memory location (%p)"), \
     446                #arg, (void *) (arg)); \
     447    } while (0)
     448
     449/**
     450 * Sets the extended error info and returns E_NOTIMIL.
     451 * @param method    Method that is not implemented.
     452 */
     453#define ReturnComNotImplemented(method) \
     454    do { \
     455        return setError (E_NOTIMPL, tr ("Method %s is not implemented"), #method); \
     456    } while (0)
     457
     458////////////////////////////////////////////////////////////////////////////////
    358459
    359460/// @todo (dmik) remove after we switch to VirtualBoxBaseNEXT completely
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