/*
* This file is part of the GROMACS molecular simulation package.
*
- * Copyright (c) 2009,2010,2011,2012, by the GROMACS development team, led by
- * David van der Spoel, Berk Hess, Erik Lindahl, and including many
- * others, as listed in the AUTHORS file in the top-level source
- * directory and at http://www.gromacs.org.
+ * Copyright (c) 2009,2010,2011,2012,2013,2014, by the GROMACS development team, led by
+ * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
+ * and including many others, as listed in the AUTHORS file in the
+ * top-level source directory and at http://www.gromacs.org.
*
* GROMACS is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* \author Teemu Murtola <teemu.murtola@gmail.com>
* \ingroup module_selection
*/
-#include "gromacs/legacyheaders/maths.h"
-#include "gromacs/legacyheaders/macros.h"
-#include "gromacs/legacyheaders/smalloc.h"
+#include "gmxpre.h"
+
+#include <cmath>
-#include "gromacs/selection/selmethod.h"
+#include "gromacs/legacyheaders/macros.h"
+#include "gromacs/math/utilities.h"
+#include "gromacs/utility/common.h"
#include "gromacs/utility/exceptions.h"
+#include "gromacs/utility/smalloc.h"
+
+#include "selmethod.h"
/** Defines the comparison operator for comparison expressions. */
typedef enum
t_compare_value right;
} t_methoddata_compare;
-/** Allocates data for comparison expression evaluation. */
+/*! \brief
+ * Allocates data for comparison expression evaluation.
+ *
+ * \param[in] npar Not used (should be 5).
+ * \param[in,out] param Method parameters (should point to a copy of
+ * \ref smparams_compare).
+ * \returns Pointer to the allocated data (\c t_methoddata_compare).
+ *
+ * Allocates memory for a \c t_methoddata_compare structure.
+ */
static void *
init_data_compare(int npar, gmx_ana_selparam_t *param);
-/** Initializes data for comparison expression evaluation. */
+/*! \brief
+ * Initializes data for comparison expression evaluation.
+ *
+ * \param[in] top Not used.
+ * \param[in] npar Not used (should be 5).
+ * \param[in] param Method parameters (should point to \ref smparams_compare).
+ * \param[in] data Should point to a \c t_methoddata_compare.
+ * \returns 0 if the input data is valid, -1 on error.
+ */
static void
init_compare(t_topology *top, int npar, gmx_ana_selparam_t *param, void *data);
/** Frees the memory allocated for comparison expression evaluation. */
static const char *
comparison_type_str(e_comparison_t cmpt)
{
+ const char *p = NULL;
switch (cmpt)
{
- case CMP_INVALID: return "INVALID"; break;
- case CMP_LESS: return "<"; break;
- case CMP_LEQ: return "<="; break;
- case CMP_GTR: return ">"; break;
- case CMP_GEQ: return ">="; break;
- case CMP_EQUAL: return "=="; break;
- case CMP_NEQ: return "!="; break;
+ case CMP_INVALID: p = "INVALID"; break;
+ case CMP_LESS: p = "<"; break;
+ case CMP_LEQ: p = "<="; break;
+ case CMP_GTR: p = ">"; break;
+ case CMP_GEQ: p = ">="; break;
+ case CMP_EQUAL: p = "=="; break;
+ case CMP_NEQ: p = "!="; break;
+ // No default clause so we intentionally get compiler errors
+ // if new selection choices are added later.
}
- return NULL;
+ return p;
}
/*!
fprintf(fp, "\"");
}
-/*!
- * \param[in] npar Not used (should be 5).
- * \param[in,out] param Method parameters (should point to a copy of
- * \ref smparams_compare).
- * \returns Pointer to the allocated data (\c t_methoddata_compare).
- *
- * Allocates memory for a \c t_methoddata_compare structure.
- */
static void *
-init_data_compare(int npar, gmx_ana_selparam_t *param)
+init_data_compare(int /* npar */, gmx_ana_selparam_t *param)
{
t_methoddata_compare *data;
{
case CMP_LESS:
case CMP_GEQ:
- iv[i] = (int)ceil(val->r[i]);
+ iv[i] = static_cast<int>(std::ceil(val->r[i]));
break;
case CMP_GTR:
case CMP_LEQ:
- iv[i] = (int)floor(val->r[i]);
+ iv[i] = static_cast<int>(std::floor(val->r[i]));
break;
case CMP_EQUAL:
case CMP_NEQ:
sfree(iv);
/* TODO: Implement, although it isn't typically very useful.
- * Implementation is only a matter or proper initialization,
+ * Implementation is only a matter of proper initialization,
* the evaluation function can already handle this case with
* proper preparations. */
GMX_THROW(gmx::NotImplementedError("Equality comparison between dynamic integer and static real expressions not implemented"));
val->flags |= CMP_ALLOCINT;
}
-/*!
- * \param[in] top Not used.
- * \param[in] npar Not used (should be 5).
- * \param[in] param Method parameters (should point to \ref smparams_compare).
- * \param[in] data Should point to a \c t_methoddata_compare.
- * \returns 0 if the input data is valid, -1 on error.
- */
static void
-init_compare(t_topology *top, int npar, gmx_ana_selparam_t *param, void *data)
+init_compare(t_topology * /* top */, int /* npar */, gmx_ana_selparam_t *param, void *data)
{
t_methoddata_compare *d = (t_methoddata_compare *)data;
int n1, n2;
/* Store the values */
n1 = init_comparison_value(&d->left, ¶m[0]);
n2 = init_comparison_value(&d->right, ¶m[3]);
- if (n1 == 0 || n2 == 0)
- {
- GMX_THROW(gmx::InternalError("One of the values for comparison missing"));
- }
/* Store the comparison type */
d->cmpt = comparison_type(d->cmpop);
if (d->cmpt == CMP_INVALID)
sfree(d);
}
-/*!
+/*! \brief
+ * Implementation for evaluate_compare() for integer values.
+ *
* \param[in] top Not used.
* \param[in] fr Not used.
* \param[in] pbc Not used.
int a, b;
bool bAccept;
+ GMX_UNUSED_VALUE(top);
+ GMX_UNUSED_VALUE(fr);
+ GMX_UNUSED_VALUE(pbc);
for (i = i1 = i2 = ig = 0; i < g->isize; ++i)
{
a = d->left.i[i1];
out->u.g->isize = ig;
}
-/*!
+/*! \brief
+ * Implementation for evaluate_compare() if either value is non-integer.
+ *
* \param[in] top Not used.
* \param[in] fr Not used.
* \param[in] pbc Not used.
* \param[in] g Evaluation index group.
* \param[out] out Output data structure (\p out->u.g is used).
* \param[in] data Should point to a \c t_methoddata_compare.
+ *
+ * Left value is assumed to be real-valued; right value can be either.
+ * This is ensured by the initialization method.
*/
static void
evaluate_compare_real(t_topology *top, t_trxframe *fr, t_pbc *pbc,
real a, b;
bool bAccept;
+ GMX_UNUSED_VALUE(top);
+ GMX_UNUSED_VALUE(fr);
+ GMX_UNUSED_VALUE(pbc);
for (i = i1 = i2 = ig = 0; i < g->isize; ++i)
{
a = d->left.r[i1];