gmx_ana_poscalc_set_flags(sel->u.expr.pc, cflags);
}
gmx_ana_poscalc_set_maxindex(sel->u.expr.pc, sel->cdata->gmax);
- snew(sel->u.expr.pos, 1);
+ sel->u.expr.pos = new gmx_ana_pos_t();
gmx_ana_poscalc_init_pos(sel->u.expr.pc, sel->u.expr.pos);
}
}
base = pc->coll->createCalculation(pc->type, flags);
set_poscalc_maxindex(base, &pc->gmax, true);
- snew(base->p, 1);
+ base->p = new gmx_ana_pos_t();
pc->sbase = base;
pc->coll->removeCalculation(base);
{
gmx_ana_index_deinit(&pc->gmax);
}
- if (pc->p)
- {
- gmx_ana_pos_free(pc->p);
- }
+ delete pc->p;
if (pc->sbase)
{
gmx_ana_poscalc_free(pc->sbase);
* \author Teemu Murtola <teemu.murtola@gmail.com>
* \ingroup module_selection
*/
+#include "gromacs/selection/position.h"
+
#include <string.h>
#include "gromacs/legacyheaders/smalloc.h"
#include "gromacs/legacyheaders/vec.h"
#include "gromacs/selection/indexutil.h"
-#include "gromacs/selection/position.h"
#include "gromacs/utility/gmxassert.h"
-/*!
- * \param[out] pos Output structure.
- *
- * Any contents of \p pos are discarded without freeing.
- */
-void
-gmx_ana_pos_clear(gmx_ana_pos_t *pos)
+gmx_ana_pos_t::gmx_ana_pos_t()
{
- pos->x = NULL;
- pos->v = NULL;
- pos->f = NULL;
- gmx_ana_indexmap_clear(&pos->m);
- pos->nalloc_x = 0;
+ x = NULL;
+ v = NULL;
+ f = NULL;
+ gmx_ana_indexmap_clear(&m);
+ nalloc_x = 0;
+}
+
+gmx_ana_pos_t::~gmx_ana_pos_t()
+{
+ sfree(x);
+ sfree(v);
+ sfree(f);
+ gmx_ana_indexmap_deinit(&m);
}
/*!
void
gmx_ana_pos_init_const(gmx_ana_pos_t *pos, const rvec x)
{
- gmx_ana_pos_clear(pos);
snew(pos->x, 1);
snew(pos->v, 1);
snew(pos->f, 1);
gmx_ana_indexmap_init(&pos->m, NULL, NULL, INDEX_UNKNOWN);
}
-/*!
- * \param[in,out] pos Position data structure.
- *
- * Frees any memory allocated within \p pos.
- * The pointer \p pos itself is not freed.
- *
- * \see gmx_ana_pos_free()
- */
-void
-gmx_ana_pos_deinit(gmx_ana_pos_t *pos)
-{
- sfree(pos->x); pos->x = NULL;
- sfree(pos->v); pos->v = NULL;
- sfree(pos->f); pos->f = NULL;
- pos->nalloc_x = 0;
- gmx_ana_indexmap_deinit(&pos->m);
-}
-
-/*!
- * \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);
-}
-
/*!
* \param[in,out] dest Destination positions.
* \param[in] src Source positions.
/*! \brief
* Stores a set of positions together with their origins.
*/
-typedef struct gmx_ana_pos_t
+struct gmx_ana_pos_t
{
+ //! Initializes an empty position structure.
+ gmx_ana_pos_t();
+ ~gmx_ana_pos_t();
+
//! Returns the number of positions.
int count() const { return m.mapb.nr; }
* Number of elements allocated for \c x.
*/
int nalloc_x;
-} gmx_ana_pos_t;
+};
-/** Initializes an empty position structure. */
-void
-gmx_ana_pos_clear(gmx_ana_pos_t *pos);
/** Ensures that enough memory has been allocated to store positions. */
void
gmx_ana_pos_reserve(gmx_ana_pos_t *pos, int n, int isize);
/** Initializes a \c gmx_ana_pos_t to represent a constant position. */
void
gmx_ana_pos_init_const(gmx_ana_pos_t *pos, const rvec x);
-/** Frees the memory allocated for position storage. */
-void
-gmx_ana_pos_deinit(gmx_ana_pos_t *pos);
-/** Frees the memory allocated for positions. */
-void
-gmx_ana_pos_free(gmx_ana_pos_t *pos);
/** Copies the evaluated positions to a preallocated data structure. */
void
gmx_ana_pos_copy(gmx_ana_pos_t *dest, gmx_ana_pos_t *src, bool bFirst);
coveredFraction_(1.0), averageCoveredFraction_(1.0),
bDynamic_(false), bDynamicCoveredFraction_(false)
{
- gmx_ana_pos_clear(&rawPositions_);
-
if (elem->child->type == SEL_CONST)
{
// TODO: This is not exception-safe if any called function throws.
SelectionData::~SelectionData()
{
- gmx_ana_pos_deinit(&rawPositions_);
}
sfree(v.u.s[i]);
}
break;
- case POS_VALUE:
- for (int i = 0; i < n; ++i)
- {
- gmx_ana_pos_deinit(&v.u.p[i]);
- }
- break;
case GROUP_VALUE:
for (int i = 0; i < n; ++i)
{
break;
}
}
- if (flags & SEL_ALLOCVAL)
+ if (v.nalloc > 0)
{
- sfree(v.u.ptr);
+ if (v.type == POS_VALUE)
+ {
+ delete [] v.u.p;
+ }
+ else
+ {
+ sfree(v.u.ptr);
+ }
}
_gmx_selvalue_setstore(&v, NULL);
if (type == SEL_SUBEXPRREF && u.param)
u.expr.mdata = NULL;
u.expr.method = NULL;
/* Free position data */
- if (u.expr.pos)
- {
- gmx_ana_pos_free(u.expr.pos);
- u.expr.pos = NULL;
- }
+ delete u.expr.pos;
+ u.expr.pos = NULL;
/* Free position calculation data */
if (u.expr.pc)
{
}
else if (param->val.type == POS_VALUE)
{
- for (j = 0; j < param->val.nr; ++j)
+ if (param->val.nalloc > 0)
{
- gmx_ana_pos_deinit(¶m->val.u.p[j]);
+ delete[] param->val.u.p;
+ _gmx_selvalue_setstore(¶m->val, NULL);
}
}
#include "gromacs/selection/indexutil.h"
#include "gromacs/selection/position.h"
#include "gromacs/selection/selvalue.h"
+#include "gromacs/utility/gmxassert.h"
/*!
* \param[out] val Output structure
}
break;
case POS_VALUE:
- srenew(val->u.p, n);
- for (i = val->nalloc; i < n; ++i)
- {
- gmx_ana_pos_clear(&val->u.p[i]);
- }
+ GMX_RELEASE_ASSERT(val->u.ptr == NULL,
+ "Reallocation of position values not supported");
+ val->u.p = new gmx_ana_pos_t[n];
break;
case GROUP_VALUE:
srenew(val->u.g, n);
{
t_methoddata_distance() : cutoff(-1.0)
{
- gmx_ana_pos_clear(&p);
}
/** Cutoff distance. */
static void *
init_data_insolidangle(int npar, gmx_ana_selparam_t *param)
{
- t_methoddata_insolidangle *data;
+ t_methoddata_insolidangle *data = new t_methoddata_insolidangle();
+ data->angcut = 5.0;
+ data->cfrac = 0.0;
+
+ data->distccut = 0.0;
+ data->targetbinsize = 0.0;
+
+ data->ntbins = 0;
+ data->tbinsize = 0.0;
+ data->tbin = NULL;
+ data->maxbins = 0;
+ data->nbins = 0;
+ data->bin = NULL;
- snew(data, 1);
- data->angcut = 5.0;
param[0].val.u.p = &data->center;
param[1].val.u.p = &data->span;
param[2].val.u.r = &data->angcut;
}
free_surface_points(d);
sfree(d->bin);
- sfree(d);
+ delete d;
}
/*!
static void *
init_data_merge(int npar, gmx_ana_selparam_t *param)
{
- t_methoddata_merge *data;
-
- snew(data, 1);
+ t_methoddata_merge *data = new t_methoddata_merge();
data->stride = 0;
param[0].val.u.p = &data->p1;
param[1].val.u.p = &data->p2;
free_data_merge(void *data)
{
t_methoddata_merge *d = (t_methoddata_merge *)data;
-
- sfree(d);
+ delete d;
}
/*!
static void *
init_data_permute(int npar, gmx_ana_selparam_t *param)
{
- t_methoddata_permute *data;
-
- snew(data, 1);
+ t_methoddata_permute *data = new t_methoddata_permute();
+ data->n = 0;
+ data->perm = NULL;
+ data->rperm = NULL;
param[0].val.u.p = &data->p;
return data;
}
t_methoddata_permute *d = (t_methoddata_permute *)data;
sfree(d->rperm);
- sfree(d);
+ delete d;
}
/*!
#include "gromacs/selection/indexutil.h"
#include "gromacs/selection/poscalc.h"
#include "gromacs/selection/position.h"
+#include "gromacs/utility/uniqueptr.h"
#include "testutils/refdata.h"
gmx::PositionCalculationCollection pcc_;
private:
+ typedef gmx::gmx_unique_ptr<gmx_ana_pos_t>::type PositionPointer;
+
struct PositionTest
{
- PositionTest() : pos(NULL), pc(NULL), name(NULL) {}
- PositionTest(gmx_ana_pos_t *pos, gmx_ana_poscalc_t *pc,
+ PositionTest(PositionPointer pos, gmx_ana_poscalc_t *pc,
const char *name)
- : pos(pos), pc(pc), name(name)
+ : pos(gmx::move(pos)), pc(pc), name(name)
{
}
- gmx_ana_pos_t *pos;
+ PositionPointer pos;
gmx_ana_poscalc_t *pc;
const char *name;
};
{
gmx_ana_poscalc_free(*pci);
}
-
- PositionTestList::iterator pi;
- for (pi = posList_.begin(); pi != posList_.end(); ++pi)
- {
- gmx_ana_pos_free(pi->pos);
- }
}
void PositionCalculationTest::generateCoordinates()
PositionCalculationTest::initPositions(gmx_ana_poscalc_t *pc, const char *name)
{
posList_.reserve(posList_.size() + 1);
- gmx_ana_pos_t *p;
- snew(p, 1);
- posList_.push_back(PositionTest(p, pc, name));
- gmx_ana_poscalc_init_pos(pc, p);
- return p;
+ PositionPointer p(new gmx_ana_pos_t());
+ gmx_ana_pos_t *result = p.get();
+ posList_.push_back(PositionTest(gmx::move(p), pc, name));
+ gmx_ana_poscalc_init_pos(pc, result);
+ return result;
}
void PositionCalculationTest::checkInitialized()
PositionTestList::const_iterator pi;
for (pi = posList_.begin(); pi != posList_.end(); ++pi)
{
- checkPositions(&compound, pi->name, pi->pos, false);
+ checkPositions(&compound, pi->name, pi->pos.get(), false);
}
}