Exemplo n.º 1
0
/*!
 * \param[in] sel Selection to free.
 */
void
_gmx_selelem_free_values(t_selelem *sel)
{
    int   i, n;

    _gmx_selelem_mempool_release(sel);
    if ((sel->flags & SEL_ALLOCDATA) && sel->v.u.ptr)
    {
        /* The number of position/group structures is constant, so the
         * backup of using sel->v.nr should work for them.
         * For strings, we report an error if we don't know the allocation
         * size here. */
        n = (sel->v.nalloc > 0) ? sel->v.nalloc : sel->v.nr;
        switch (sel->v.type)
        {
            case STR_VALUE:
                if (sel->v.nalloc == 0)
                {
                    gmx_bug("SEL_ALLOCDATA should only be set for allocated STR_VALUE values");
                    break;
                }
                for (i = 0; i < n; ++i)
                {
                    sfree(sel->v.u.s[i]);
                }
                break;
            case POS_VALUE:
                for (i = 0; i < n; ++i)
                {
                    gmx_ana_pos_deinit(&sel->v.u.p[i]);
                }
                break;
            case GROUP_VALUE:
                for (i = 0; i < n; ++i)
                {
                    gmx_ana_index_deinit(&sel->v.u.g[i]);
                }
                break;
            default: /* No special handling for other types */
                break;
        }
    }
    if (sel->flags & SEL_ALLOCVAL)
    {
        sfree(sel->v.u.ptr);
    }
    _gmx_selvalue_setstore(&sel->v, NULL);
    if (sel->type == SEL_SUBEXPRREF && sel->u.param)
    {
        sel->u.param->val.u.ptr = NULL;
    }
}
Exemplo n.º 2
0
/*!
 * \param[in] sel  Selection to free.
 *
 * After the call, the pointer \p sel is invalid.
 */
void
gmx_ana_selection_free(gmx_ana_selection_t *sel)
{
    sfree(sel->name);
    gmx_ana_pos_deinit(&sel->p);
    if (sel->m != sel->orgm)
    {
        sfree(sel->m);
    }
    if (sel->q != sel->orgq)
    {
        sfree(sel->q);
    }
    sfree(sel->orgm);
    sfree(sel->orgq);
    sfree(sel);
}
Exemplo n.º 3
0
/*!
 * \param[in,out] pos   Position data structure.
 *
 * Frees any memory allocated for \p pos.
 * The pointer \p pos is also freed, and is invalid after the call.
 *
 * \see gmx_ana_pos_deinit()
 */
void
gmx_ana_pos_free(gmx_ana_pos_t *pos)
{
    gmx_ana_pos_deinit(pos);
    sfree(pos);
}
Exemplo n.º 4
0
/*!
 * \param[in] method Method to free.
 * \param[in] mdata  Method data to free.
 */
void
_gmx_selelem_free_method(gmx_ana_selmethod_t *method, void *mdata)
{
    sel_freefunc free_func = NULL;

    /* Save the pointer to the free function. */
    if (method && method->free)
    {
        free_func = method->free;
    }

    /* Free the method itself.
     * Has to be done before freeing the method data, because parameter
     * values are typically stored in the method data, and here we may
     * access them. */
    if (method)
    {
        int  i, j;

        /* Free the memory allocated for the parameters that are not managed
         * by the selection method itself. */
        for (i = 0; i < method->nparams; ++i)
        {
            gmx_ana_selparam_t *param = &method->param[i];

            if (param->val.u.ptr)
            {
                if (param->val.type == GROUP_VALUE)
                {
                    for (j = 0; j < param->val.nr; ++j)
                    {
                        gmx_ana_index_deinit(&param->val.u.g[j]);
                    }
                }
                else if (param->val.type == POS_VALUE)
                {
                    for (j = 0; j < param->val.nr; ++j)
                    {
                        gmx_ana_pos_deinit(&param->val.u.p[j]);
                    }
                }

                if (param->val.nalloc > 0)
                {
                    sfree(param->val.u.ptr);
                }
            }
        }
        sfree(method->param);
        sfree(method);
    }
    /* Free method data. */
    if (mdata)
    {
        if (free_func)
        {
            free_func(mdata);
        }
        sfree(mdata);
    }
}
Exemplo n.º 5
0
SelectionData::~SelectionData()
{
    gmx_ana_pos_deinit(&rawPositions_);
}