IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jun 3, 2005, 2:49:48 PM (21 years ago)
Author:
gusciora
Message:

PS_ASSERT_

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psLib/src/math/psConstants.h

    r4051 r4108  
    66 *  @author GLG, MHPCC
    77 *
    8  *  @version $Revision: 1.71 $ $Name: not supported by cvs2svn $
    9  *  @date $Date: 2005-05-31 21:48:13 $
     8 *  @version $Revision: 1.72 $ $Name: not supported by cvs2svn $
     9 *  @date $Date: 2005-06-04 00:49:48 $
    1010 *
    1111 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    6060
    6161#define PS_ASSERT_INT_UNEQUAL(NAME1, NAME2, RVAL) \
    62 if (NAME1 == NAME2) { \
     62if ((NAME1) == (NAME2)) { \
    6363    psError(PS_ERR_BAD_PARAMETER_VALUE, true, \
    6464            "Error: %s and %s are equal.", \
     
    6868
    6969#define PS_ASSERT_INT_EQUAL(NAME1, NAME2, RVAL) \
    70 if (NAME1 != NAME2) { \
     70if ((NAME1) != (NAME2)) { \
    7171    psError(PS_ERR_BAD_PARAMETER_VALUE, true, \
    7272            "Error: %s and %s are not equal.", \
     
    7676
    7777#define PS_ASSERT_INT_NONNEGATIVE(NAME, RVAL) \
    78 if (NAME < 0) { \
     78if ((NAME) < 0) { \
    7979    psError(PS_ERR_BAD_PARAMETER_VALUE, true, \
    8080            "Error: %s is less than 0.", #NAME); \
     
    8383
    8484#define PS_ASSERT_INT_POSITIVE(NAME, RVAL) \
    85 if (NAME < 1) { \
     85if ((NAME) < 1) { \
    8686    psError(PS_ERR_BAD_PARAMETER_VALUE, true, \
    8787            "Error: %s is 0 or less.", #NAME); \
     
    9090
    9191#define PS_ASSERT_INT_ZERO(NAME, RVAL) \
    92 if (NAME != 0) { \
     92if ((NAME) != 0) { \
    9393    psError(PS_ERR_BAD_PARAMETER_VALUE, true, \
    9494            "Error: %s is 0.", #NAME); \
     
    9797
    9898#define PS_ASSERT_INT_NONZERO(NAME, RVAL) \
    99 if (NAME == 0) { \
     99if ((NAME) == 0) { \
    100100    psError(PS_ERR_BAD_PARAMETER_VALUE, true, \
    101101            "Error: %s is 0.", #NAME); \
     
    103103}
    104104
     105// XXX: Where did these int casts come from?
    105106#define PS_ASSERT_INT_WITHIN_RANGE(NAME, LOWER, UPPER, RVAL) \
    106 if ((int)NAME < LOWER || (int)NAME > UPPER) { \
     107if ((int)(NAME) < LOWER || (int)(NAME) > UPPER) { \
    107108    psError(PS_ERR_BAD_PARAMETER_VALUE, true, \
    108109            "Error: %s, %d, is out of range.  Must be between %d and %d.", \
     
    111112}
    112113
     114#define PS_ASSERT_INT_LARGER_THAN(NAME1, NAME2, RVAL) \
     115if (!((NAME1) > (NAME2))) { \
     116    psError(PS_ERR_BAD_PARAMETER_VALUE, true, \
     117            "Error: !(%s > %s) (%d %d).", \
     118            #NAME1, #NAME2, NAME1, NAME2); \
     119    return(RVAL); \
     120}
     121
     122#define PS_ASSERT_INT_LARGER_THAN_OR_EQUAL(NAME1, NAME2, RVAL) \
     123if (!((NAME1) >= (NAME2))) { \
     124    psError(PS_ERR_BAD_PARAMETER_VALUE, true, \
     125            "Error: !(%s >= %s) (%d %d).", \
     126            #NAME1, #NAME2, NAME1, NAME2); \
     127    return(RVAL); \
     128}
     129#define PS_ASSERT_FLOAT_LARGER_THAN(NAME1, NAME2, RVAL) \
     130if (!((NAME1) > (NAME2))) { \
     131    psError(PS_ERR_BAD_PARAMETER_VALUE, true, \
     132            "Error: !(%s > %s) (%f %f).", \
     133            #NAME1, #NAME2, NAME1, NAME2); \
     134    return(RVAL); \
     135}
     136
     137#define PS_ASSERT_FLOAT_LARGER_THAN_OR_EQUAL(NAME1, NAME2, RVAL) \
     138if (!((NAME1) >= (NAME2))) { \
     139    psError(PS_ERR_BAD_PARAMETER_VALUE, true, \
     140            "Error: !(%s >= %s) (%f %f).", \
     141            #NAME1, #NAME2, NAME1, NAME2); \
     142    return(RVAL); \
     143}
     144
    113145// Produce an error if (NAME1 > NAME2)
    114 // XXX: rename: ASSERT
     146// XXX: Get rid of this, use above macros.
    115147#define PS_INT_COMPARE(NAME1, NAME2, RVAL) \
    116 if (NAME1 > NAME2) { \
     148if ((NAME1) > (NAME2)) { \
    117149    psError(PS_ERR_BAD_PARAMETER_VALUE, true, \
    118150            "Error: (%s > %s) (%d %d).", \
     
    122154
    123155// Produce an error if ((NAME1 > NAME2)
    124 // XXX: rename: ASSERT
     156// XXX: Get rid of this, use above macros.
    125157#define PS_FLOAT_COMPARE(NAME1, NAME2, RVAL) \
    126 if (NAME1 > NAME2) { \
     158if ((NAME1) > (NAME2)) { \
    127159    psError(PS_ERR_BAD_PARAMETER_VALUE, true, \
    128160            "Error: (%s > %s) (%f %f)", \
     
    131163}
    132164
    133 // Generate an error if the two floats are equal.
    134 // XXX: Inconsistent naming.
    135165#define PS_ASSERT_FLOAT_NON_EQUAL(NAME1, NAME2, RVAL) \
    136 if (fabs(NAME2 - NAME1) < FLT_EPSILON) { \
     166if (fabs((NAME2) - (NAME1)) < FLT_EPSILON) { \
    137167    psError(PS_ERR_BAD_PARAMETER_VALUE, true, \
    138168            "Error: %s and %s are equal.", \
     169            #NAME1, #NAME2); \
     170    return(RVAL); \
     171}
     172
     173#define PS_ASSERT_FLOAT_EQUAL(NAME1, NAME2, RVAL) \
     174if (fabs((NAME2) - (NAME1)) > FLT_EPSILON) { \
     175    psError(PS_ERR_BAD_PARAMETER_VALUE, true, \
     176            "Error: %s and %s are not equal.", \
    139177            #NAME1, #NAME2); \
    140178    return(RVAL); \
     
    165203#define PS_ASSERT_PTR_NON_NULL(NAME, RVAL) PS_ASSERT_GENERAL_PTR_NON_NULL(NAME, return RVAL)
    166204#define PS_ASSERT_GENERAL_PTR_NON_NULL(NAME, CLEANUP) \
    167 if (NAME == NULL) { \
     205if ((NAME) == NULL) { \
    168206    psError(PS_ERR_BAD_PARAMETER_NULL, true, \
    169207            "Unallowable operation: %s is NULL.", \
     
    173211
    174212#define PS_ASSERT_PTR_TYPE(NAME, TYPE, RVAL) \
    175 if (NAME->type.type != TYPE) { \
     213if ((NAME)->type.type != TYPE) { \
    176214    psError(PS_ERR_BAD_PARAMETER_TYPE, true, \
    177215            "Unallowable operation: %s has incorrect type.", \
     
    182220#define PS_ASSERT_PTR_DIMEN(NAME, DIMEN, RVAL) PS_ASSERT_GENERAL_PTR_DIMEN(NAME, DIMEN, return RVAL)
    183221#define PS_ASSERT_GENERAL_PTR_DIMEN(NAME, DIMEN, CLEANUP) \
    184 if (NAME->type.dimen != DIMEN) { \
     222if ((NAME)->type.dimen != DIMEN) { \
    185223    psError(PS_ERR_BAD_PARAMETER_TYPE, true, \
    186224            "Unallowable operation: %s has incorrect dimensionality.", \
     
    190228
    191229#define PS_ASSERT_PTR_DIMEN_GENERAL_NOT(NAME, DIMEN, CLEANUP) \
    192 if (NAME->type.dimen == DIMEN) { \
     230if ((NAME)->type.dimen == DIMEN) { \
    193231    psError(PS_ERR_BAD_PARAMETER_TYPE, true, \
    194232            "Unallowable operation: %s has incorrect dimensionality.", \
     
    221259#define PS_ASSERT_VECTOR_NON_NULL(NAME, RVAL) PS_ASSERT_GENERAL_VECTOR_NON_NULL(NAME, return RVAL)
    222260#define PS_ASSERT_GENERAL_VECTOR_NON_NULL(NAME, CLEANUP) \
    223 if (NAME == NULL || NAME->data.U8 == NULL) { \
     261if ((NAME) == NULL || (NAME)->data.U8 == NULL) { \
    224262    psError(PS_ERR_BAD_PARAMETER_NULL, true, \
    225263            "Unallowable operation: psVector %s or its data is NULL.", \
     
    230268#define PS_ASSERT_VECTOR_NON_EMPTY(NAME, RVAL) PS_ASSERT_GENERAL_VECTOR_NON_EMPTY(NAME, return RVAL)
    231269#define PS_ASSERT_GENERAL_VECTOR_NON_EMPTY(NAME, CLEANUP) \
    232 if (NAME->n < 1) { \
     270if ((NAME)->n < 1) { \
    233271    psError(PS_ERR_BAD_PARAMETER_SIZE, true, \
    234272            "Unallowable operation: psVector %s has no elements.", \
     
    238276
    239277#define PS_ASSERT_VECTOR_TYPE_F32_OR_F64(NAME, RVAL) \
    240 if ((NAME->type.type != PS_TYPE_F32) && (NAME->type.type != PS_TYPE_F64)) { \
     278if (((NAME)->type.type != PS_TYPE_F32) && ((NAME)->type.type != PS_TYPE_F64)) { \
    241279    psError(PS_ERR_BAD_PARAMETER_TYPE, true, \
    242280            "psVector %s: bad type(%d)", \
     
    246284
    247285#define PS_ASSERT_VECTOR_TYPE_S16_S32_F32(NAME, RVAL) \
    248 if ((NAME->type.type != PS_TYPE_S16) && (NAME->type.type != PS_TYPE_S32) && (NAME->type.type != PS_TYPE_F32)) { \
     286if (((NAME)->type.type != PS_TYPE_S16) && ((NAME)->type.type != PS_TYPE_S32) && ((NAME)->type.type != PS_TYPE_F32)) { \
    249287    psError(PS_ERR_BAD_PARAMETER_TYPE, true, \
    250288            "psVector %s: bad type(%d)", \
     
    254292
    255293#define PS_ASSERT_VECTOR_TYPE(NAME, TYPE, RVAL) \
    256 if (NAME->type.type != TYPE) { \
     294if ((NAME)->type.type != TYPE) { \
    257295    psError(PS_ERR_BAD_PARAMETER_TYPE, true, \
    258296            "Unallowable operation: psVector %s has incorrect type.", \
     
    298336
    299337#define PS_VECTOR_PRINT_F32(NAME) \
    300 for (int my_i=0;my_i<NAME->n;my_i++) { \
    301     printf("%s->data.F32[%d] is %f\n", #NAME, my_i, NAME->data.F32[my_i]); \
     338for (int my_i=0;my_i<(NAME)->n;my_i++) { \
     339    printf("%s->data.F32[%d] is %f\n", #NAME, my_i, (NAME)->data.F32[my_i]); \
    302340} \
    303341printf("\n"); \
     
    364402#define PS_VECTOR_GEN_STATIC_RECYCLED(NAME, SIZE, TYPE) \
    365403static psVector *NAME = NULL; \
    366 NAME = psVectorRecycle(NAME, SIZE, TYPE); \
    367 p_psMemSetPersistent(NAME, true); \
    368 p_psMemSetPersistent(NAME->data.U8, true); \
     404(NAME) = psVectorRecycle((NAME), SIZE, TYPE); \
     405p_psMemSetPersistent((NAME), true); \
     406p_psMemSetPersistent((NAME)->data.U8, true); \
    369407
    370408#define PS_VECTOR_DECLARE_ALLOC_STATIC(NAME, SIZE, TYPE) \
    371 static psVector *NAME = NULL; \
    372 if (NAME == NULL) { \
    373     NAME = psVectorAlloc(SIZE, TYPE); \
    374     p_psMemSetPersistent(NAME, true); \
     409static psVector *(NAME) = NULL; \
     410if ((NAME) == NULL) { \
     411    (NAME) = psVectorAlloc(SIZE, TYPE); \
     412    p_psMemSetPersistent((NAME), true); \
    375413} \
    376414
     
    430468*****************************************************************************/
    431469#define PS_ASSERT_POLY_NON_NULL(NAME, RVAL) \
    432 if (NAME == NULL || NAME->coeff == NULL) { \
     470if ((NAME) == NULL || (NAME)->coeff == NULL) { \
    433471    psError(PS_ERR_BAD_PARAMETER_NULL, true, \
    434472            "Unallowable operation: polynomial %s or its coeffs is NULL.", \
     
    438476
    439477#define PS_ASSERT_POLY_TYPE(NAME, TYPE, RVAL) \
    440 if (NAME->type != TYPE) { \
     478if ((NAME)->type != TYPE) { \
    441479    psError(PS_ERR_BAD_PARAMETER_TYPE, true, \
    442480            "Unallowable operation: polynomial %s has wrong type.", #NAME); \
     
    448486
    449487#define PS_POLY_1D_DECLARE_ALLOC_STATIC(NAME, ORDER, TYPE) \
    450 static psPolynomial1D *NAME = NULL; \
    451 if (NAME == NULL) { \
    452     NAME = psPolynomial1DAlloc(ORDER, TYPE); \
    453     p_psMemSetPersistent(NAME, true); \
    454     p_psMemSetPersistent(NAME->coeff, true); \
    455     p_psMemSetPersistent(NAME->coeffErr, true); \
    456     p_psMemSetPersistent(NAME->mask, true); \
     488static psPolynomial1D *(NAME) = NULL; \
     489if ((NAME) == NULL) { \
     490    (NAME) = psPolynomial1DAlloc(ORDER, TYPE); \
     491    p_psMemSetPersistent((NAME), true); \
     492    p_psMemSetPersistent((NAME)->coeff, true); \
     493    p_psMemSetPersistent((NAME)->coeffErr, true); \
     494    p_psMemSetPersistent((NAME)->mask, true); \
    457495} \
    458496
    459497#define PS_POLY_2D_DECLARE_ALLOC_STATIC(NAME, ORDER, TYPE) \
    460 static psPolynomial2D *NAME = NULL; \
    461 if (NAME == NULL) { \
    462     NAME = psPolynomial2DAlloc(ORDER, TYPE); \
    463     p_psMemSetPersistent(NAME, true); \
     498static psPolynomial2D *(NAME) = NULL; \
     499if ((NAME) == NULL) { \
     500    (NAME) = psPolynomial2DAlloc(ORDER, TYPE); \
     501    p_psMemSetPersistent((NAME), true); \
    464502} \
    465503
    466504#define PS_POLY_3D_DECLARE_ALLOC_STATIC(NAME, ORDER, TYPE) \
    467 static psPolynomial3D *NAME = NULL; \
    468 if (NAME == NULL) { \
    469     NAME = psPolynomial3DAlloc(ORDER, TYPE); \
    470     p_psMemSetPersistent(NAME, true); \
     505static psPolynomial3D *(NAME) = NULL; \
     506if ((NAME) == NULL) { \
     507    (NAME) = psPolynomial3DAlloc(ORDER, TYPE); \
     508    p_psMemSetPersistent((NAME), true); \
    471509} \
    472510
    473511#define PS_POLY_4D_DECLARE_ALLOC_STATIC(NAME, ORDER, TYPE) \
    474 static psPolynomial4D *NAME = NULL; \
    475 if (NAME == NULL) { \
    476     NAME = psPolynomial4DAlloc(ORDER, TYPE); \
    477     p_psMemSetPersistent(NAME, true); \
     512static psPolynomial4D *(NAME) = NULL; \
     513if ((NAME) == NULL) { \
     514    (NAME) = psPolynomial4DAlloc(ORDER, TYPE); \
     515    p_psMemSetPersistent((NAME), true); \
    478516} \
    479517
    480518#define PS_POLY_1D_D_DECLARE_ALLOC_STATIC(NAME, ORDER, TYPE) \
    481 static psPolynomial1D *NAME = NULL; \
    482 if (NAME == NULL) { \
    483     NAME = psPolynomial1DAlloc(ORDER, TYPE); \
    484     p_psMemSetPersistent(NAME, true); \
     519static psPolynomial1D *(NAME) = NULL; \
     520if ((NAME) == NULL) { \
     521    (NAME) = psPolynomial1DAlloc(ORDER, TYPE); \
     522    p_psMemSetPersistent((NAME), true); \
    485523} \
    486524
    487525#define PS_POLY_2D_D_DECLARE_ALLOC_STATIC(NAME, ORDER, TYPE) \
    488 static psPolynomial2D *NAME = NULL; \
    489 if (NAME == NULL) { \
    490     NAME = psPolynomial2DAlloc(ORDER, TYPE); \
    491     p_psMemSetPersistent(NAME, true); \
     526static psPolynomial2D *(NAME) = NULL; \
     527if ((NAME) == NULL) { \
     528    (NAME) = psPolynomial2DAlloc(ORDER, TYPE); \
     529    p_psMemSetPersistent((NAME), true); \
    492530} \
    493531
    494532#define PS_POLY_3D_D_DECLARE_ALLOC_STATIC(NAME, ORDER, TYPE) \
    495 static psPolynomial3D *NAME = NULL; \
    496 if (NAME == NULL) { \
    497     NAME = psPolynomial3DAlloc(ORDER, TYPE); \
    498     p_psMemSetPersistent(NAME, true); \
     533static psPolynomial3D *(NAME) = NULL; \
     534if ((NAME) == NULL) { \
     535    (NAME) = psPolynomial3DAlloc(ORDER, TYPE); \
     536    p_psMemSetPersistent((NAME), true); \
    499537} \
    500538
    501539#define PS_POLY_4D_D_DECLARE_ALLOC_STATIC(NAME, ORDER, TYPE) \
    502 static psPolynomial4D *NAME = NULL; \
    503 if (NAME == NULL) { \
    504     NAME = psPolynomial4DAlloc(ORDER, TYPE); \
    505     p_psMemSetPersistent(NAME, true); \
     540static psPolynomial4D *(NAME) = NULL; \
     541if ((NAME) == NULL) { \
     542    (NAME) = psPolynomial4DAlloc(ORDER, TYPE); \
     543    p_psMemSetPersistent((NAME), true); \
    506544} \
    507545
     
    511549#define PS_ASSERT_IMAGE_NON_NULL(NAME, RVAL) PS_ASSERT_GENERAL_IMAGE_NON_NULL(NAME, return RVAL)
    512550#define PS_ASSERT_GENERAL_IMAGE_NON_NULL(NAME, CLEANUP) \
    513 if (NAME == NULL || NAME->data.V == NULL) { \
     551if ((NAME) == NULL || (NAME)->data.V == NULL) { \
    514552    psError(PS_ERR_BAD_PARAMETER_NULL, true, \
    515553            "Unallowable operation: psImage %s or its data is NULL.", \
     
    520558#define PS_ASSERT_IMAGE_NON_EMPTY(NAME, RVAL) PS_ASSERT_GENERAL_IMAGE_NON_EMPTY(NAME, return RVAL)
    521559#define PS_ASSERT_GENERAL_IMAGE_NON_EMPTY(NAME, CLEANUP) \
    522 if (NAME->numCols < 1 || NAME->numRows < 1) { \
     560if ((NAME)->numCols < 1 || (NAME)->numRows < 1) { \
    523561    psError(PS_ERR_BAD_PARAMETER_SIZE, true, \
    524562            "Unallowable operation: psImage %s has zero rows or columns (%dx%d).", \
    525             #NAME, NAME->numCols, NAME->numRows); \
     563            #NAME, (NAME)->numCols, (NAME)->numRows); \
    526564    CLEANUP; \
    527565}
    528566
    529567#define PS_ASSERT_IMAGE_TYPE(NAME, TYPE, RVAL) \
    530 if (NAME->type.type != TYPE) { \
     568if ((NAME)->type.type != TYPE) { \
    531569    psError(PS_ERR_BAD_PARAMETER_TYPE, true, \
    532570            "Unallowable operation: psImage %s has incorrect type.", \
     
    536574
    537575#define PS_ASSERT_IMAGES_SIZE_EQUAL(NAME1, NAME2, RVAL) \
    538 if ((NAME1->numCols != NAME2->numCols) || \
    539         (NAME1->numRows != NAME2->numRows)) { \
     576if (((NAME1)->numCols != (NAME2)->numCols) || \
     577        ((NAME1)->numRows != (NAME2)->numRows)) { \
    540578    psError(PS_ERR_BAD_PARAMETER_SIZE, true, \
    541579            "Unallowable operation: psImages %s and %s are not the same size.", \
     
    545583
    546584#define PS_ASSERT_IMAGE_SIZE(NAME1, NUM_COLS, NUM_ROWS, RVAL) \
    547 if ((NAME1->numCols != NUM_COLS) || \
    548         (NAME1->numRows != NUM_ROWS)) { \
     585if (((NAME1)->numCols != NUM_COLS) || \
     586        ((NAME1)->numRows != NUM_ROWS)) { \
    549587    psError(PS_ERR_BAD_PARAMETER_SIZE, true, \
    550588            "Unallowable operation: psImages %s is not the correct size.", \
     
    555593#define PS_IMAGE_PRINT_F32(NAME) \
    556594printf("======== printing %s ========\n", #NAME); \
    557 for (int i = 0 ; i < NAME->numRows ; i++) { \
    558     for (int j = 0 ; j < NAME->numCols ; j++) { \
    559         printf("%.2f ", NAME->data.F32[i][j]); \
     595for (int i = 0 ; i < (NAME)->numRows ; i++) { \
     596    for (int j = 0 ; j < (NAME)->numCols ; j++) { \
     597        printf("%.2f ", (NAME)->data.F32[i][j]); \
    560598    } \
    561599    printf("\n"); \
     
    636674*****************************************************************************/
    637675#define PS_ASSERT_READOUT_NON_NULL(NAME, RVAL) \
    638 if (NAME == NULL || NAME->image == NULL) { \
     676if ((NAME) == NULL || (NAME)->image == NULL) { \
    639677    psError(PS_ERR_BAD_PARAMETER_NULL, true, \
    640678            "Unallowable operation: psReadout %s or its data is NULL.", \
     
    644682
    645683#define PS_ASSERT_READOUT_NON_EMPTY(NAME, RVAL) \
    646 if (NAME->image->numCols < 1 || NAME->image->numRows < 1) { \
     684if ((NAME)->image->numCols < 1 || (NAME)->image->numRows < 1) { \
    647685    psError(PS_ERR_BAD_PARAMETER_SIZE, true, \
    648686            "Unallowable operation: psReadout %s or its data is NULL.", #NAME); \
     
    651689
    652690#define PS_ASSERT_READOUT_TYPE(NAME, TYPE, RVAL) \
    653 if (NAME->image->type.type != TYPE) { \
     691if ((NAME)->image->type.type != TYPE) { \
    654692    psError(PS_ERR_BAD_PARAMETER_TYPE, true, \
    655693            "Unallowable operation: psImage %s has incorrect type.", #NAME); \
Note: See TracChangeset for help on using the changeset viewer.