void THANDLE_ASSIGN()

in common/inc/c_pal/thandle_ll.h [438:478]


void THANDLE_ASSIGN(C)(THANDLE(T) * t1, THANDLE(T) t2)                                                                                                              \
{                                                                                                                                                                   \
    /*Codes_SRS_THANDLE_02_006: [ If t1 is NULL then THANDLE_ASSIGN shall return. ]*/                                                                               \
    if (t1 == NULL)                                                                                                                                                 \
    {                                                                                                                                                               \
        LogError("invalid argument THANDLE(" MU_TOSTRING(T) ") * t1=%p, THANDLE(" MU_TOSTRING(T) ") t2=%p", t1, t2 );                                               \
    }                                                                                                                                                               \
    else                                                                                                                                                            \
    {                                                                                                                                                               \
        if (*t1 == NULL)                                                                                                                                            \
        {                                                                                                                                                           \
            if (t2 == NULL)                                                                                                                                         \
            {                                                                                                                                                       \
                /*Codes_SRS_THANDLE_02_007: [ If *t1 is NULL and t2 is NULL then THANDLE_ASSIGN shall return. ]*/                                                   \
                /*so nothing to do, leave them as they are*/                                                                                                        \
            }                                                                                                                                                       \
            else                                                                                                                                                    \
            {                                                                                                                                                       \
                /*Codes_SRS_THANDLE_02_008: [ If *t1 is NULL and t2 is not NULL then THANDLE_ASSIGN shall increment the reference count of t2 and store t2 in *t1. ]*/ \
                THANDLE_INC_REF(C)(t2);                                                                                                                             \
                *(T const**)t1 = t2;                                                                                                                                \
            }                                                                                                                                                       \
        }                                                                                                                                                           \
        else                                                                                                                                                        \
        {                                                                                                                                                           \
            if (t2 == NULL)                                                                                                                                         \
            {                                                                                                                                                       \
                /*Codes_SRS_THANDLE_02_009: [ If *t1 is not NULL and t2 is NULL then THANDLE_ASSIGN shall decrement the reference count of *t1 and store NULL in *t1. ]*/ \
                THANDLE_DEC_REF(C)(*t1);                                                                                                                            \
                *(T const**)t1 = t2;                                                                                                                                \
            }                                                                                                                                                       \
            else                                                                                                                                                    \
            {                                                                                                                                                       \
                /*Codes_SRS_THANDLE_02_010: [ If *t1 is not NULL and t2 is not NULL then THANDLE_ASSIGN shall increment the reference count of t2, shall decrement the reference count of *t1 and store t2 in *t1. ]*/ \
                THANDLE_INC_REF(C)(t2);                                                                                                                             \
                THANDLE_DEC_REF(C)(*t1);                                                                                                                            \
                *(T const**)t1 = t2;                                                                                                                                \
            }                                                                                                                                                       \
        }                                                                                                                                                           \
    }                                                                                                                                                               \
}                                                                                                                                                                   \