/*
+ * This file is part of the GROMACS molecular simulation package.
*
- * This source code is part of
+ * 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.
*
- * G R O M A C S
+ * GROMACS is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 2.1
+ * of the License, or (at your option) any later version.
*
- * GROningen MAchine for Chemical Simulations
+ * GROMACS is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
*
- * Written by David van der Spoel, Erik Lindahl, Berk Hess, and others.
- * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
- * Copyright (c) 2001-2009, The GROMACS development team,
- * check out http://www.gromacs.org for more information.
-
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with GROMACS; if not, see
+ * http://www.gnu.org/licenses, or write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
- * If you want to redistribute modifications, please consider that
- * scientific software is very special. Version control is crucial -
- * bugs must be traceable. We will be happy to consider code for
- * inclusion in the official distribution, but derived work must not
- * be called official GROMACS. Details are found in the README & COPYING
- * files - if they are missing, get the official version at www.gromacs.org.
+ * If you want to redistribute modifications to GROMACS, please
+ * consider that scientific software is very special. Version
+ * control is crucial - bugs must be traceable. We will be happy to
+ * consider code for inclusion in the official distribution, but
+ * derived work must not be called official GROMACS. Details are found
+ * in the README & COPYING files - if they are missing, get the
+ * official version at http://www.gromacs.org.
*
* To help us fund GROMACS development, we humbly ask that you cite
- * the papers on the package - you can find them in the top README file.
- *
- * For more info, check our website at http://www.gromacs.org
+ * the research papers on the package. Check out http://www.gromacs.org.
*/
/*! \internal \file
* \brief
* Implements internal selection methods for numeric and string keyword
* evaluation.
*
- * \author Teemu Murtola <teemu.murtola@cbr.su.se>
+ * \author Teemu Murtola <teemu.murtola@gmail.com>
* \ingroup module_selection
*/
+#include "gmxpre.h"
+
#include <cctype>
#include <cstring>
#include <boost/shared_ptr.hpp>
#include "gromacs/legacyheaders/macros.h"
-#include "gromacs/legacyheaders/smalloc.h"
-#include "gromacs/legacyheaders/string2.h"
-
-#include "gromacs/selection/selmethod.h"
+#include "gromacs/utility/cstringutil.h"
#include "gromacs/utility/exceptions.h"
#include "gromacs/utility/gmxregex.h"
#include "gromacs/utility/messagestringcollector.h"
+#include "gromacs/utility/smalloc.h"
#include "gromacs/utility/stringutil.h"
#include "keywords.h"
#include "parsetree.h"
#include "scanner.h"
#include "selelem.h"
+#include "selmethod.h"
-/** Allocates data for integer keyword evaluation. */
+/*! \brief
+ * Allocates data for integer keyword evaluation.
+ *
+ * \param[in] npar Not used.
+ * \param param Not used.
+ * \returns Pointer to the allocated data (\ref t_methoddata_kwint).
+ *
+ * Allocates memory for a \ref t_methoddata_kwint structure.
+ */
static void *
-init_data_kwint(int npar, gmx_ana_selparam_t *param);
-/** Allocates data for real keyword evaluation. */
+init_data_kwint(int npar, gmx_ana_selparam_t * param);
+/*! \brief
+ * Allocates data for real keyword evaluation.
+ *
+ * \param[in] npar Not used.
+ * \param param Not used.
+ * \returns Pointer to the allocated data (\ref t_methoddata_kwreal).
+ *
+ * Allocates memory for a \ref t_methoddata_kwreal structure.
+ */
static void *
-init_data_kwreal(int npar, gmx_ana_selparam_t *param);
-/** Allocates data for string keyword evaluation. */
+init_data_kwreal(int npar, gmx_ana_selparam_t * param);
+/*! \brief
+ * Allocates data for string keyword evaluation.
+ *
+ * \param[in] npar Not used.
+ * \param param Not used.
+ * \returns Pointer to the allocated data (t_methoddata_kwstr).
+ *
+ * Allocates memory for a t_methoddata_kwstr structure.
+ */
static void *
-init_data_kwstr(int npar, gmx_ana_selparam_t *param);
-/** Initializes data for integer keyword evaluation. */
+init_data_kwstr(int npar, gmx_ana_selparam_t * param);
+/** /brief Initializes data for integer keyword evaluation.
+ *
+ * \param[in] top Not used.
+ * \param[in] npar Not used (should be 2).
+ * \param[in] param Method parameters (should point to \ref smparams_keyword_int).
+ * \param[in] data Should point to \ref t_methoddata_kwint.
+ */
static void
init_kwint(t_topology *top, int npar, gmx_ana_selparam_t *param, void *data);
-/** Initializes data for real keyword evaluation. */
+/*! \brief
+ * Initializes data for real keyword evaluation.
+ *
+ * \param[in] top Not used.
+ * \param[in] npar Not used (should be 2).
+ * \param[in] param Method parameters (should point to \ref smparams_keyword_real).
+ * \param[in] data Should point to \ref t_methoddata_kwreal.
+ * \returns 0 (the initialization always succeeds).
+ */
static void
init_kwreal(t_topology *top, int npar, gmx_ana_selparam_t *param, void *data);
-/** Initializes data for string keyword evaluation. */
+/*! \brief
+ * Initializes data for string keyword evaluation.
+ *
+ * \param[in] top Not used.
+ * \param[in] npar Not used (should be 2).
+ * \param[in] param Method parameters (should point to \ref smparams_keyword_str).
+ * \param[in] data Should point to t_methoddata_kwstr.
+ */
static void
init_kwstr(t_topology *top, int npar, gmx_ana_selparam_t *param, void *data);
/** Frees the memory allocated for string keyword evaluation. */
free_data_kwstr(void *data);
/** Evaluates integer selection keywords. */
static void
-evaluate_keyword_int(t_topology *top, t_trxframe *fr, t_pbc *pbc,
+evaluate_keyword_int(t_topology * /* top */, t_trxframe * /* fr */, t_pbc * /* pbc */,
gmx_ana_index_t *g, gmx_ana_selvalue_t *out, void *data);
/** Evaluates real selection keywords. */
static void
-evaluate_keyword_real(t_topology *top, t_trxframe *fr, t_pbc *pbc,
+evaluate_keyword_real(t_topology * /* top */, t_trxframe * /* fr */, t_pbc * /* pbc */,
gmx_ana_index_t *g, gmx_ana_selvalue_t *out, void *data);
/** Evaluates string selection keywords. */
static void
-evaluate_keyword_str(t_topology *top, t_trxframe *fr, t_pbc *pbc,
+evaluate_keyword_str(t_topology * /* top */, t_trxframe * /* fr */, t_pbc * /* pbc */,
gmx_ana_index_t *g, gmx_ana_selvalue_t *out, void *data);
/*! \internal \brief
* \param[in] str String to use for matching.
*/
StringKeywordMatchItem(gmx::SelectionStringMatchType matchType,
- const char *str)
+ const char *str)
: str_(str)
{
bool bRegExp = (matchType == gmx::eStringMatchType_RegularExpression);
if (!gmx::Regex::isSupported())
{
GMX_THROW(gmx::InvalidInputError(gmx::formatString(
- "No regular expression support, "
- "cannot match \"%s\"", str)));
+ "No regular expression support, "
+ "cannot match \"%s\"", str)));
}
regex_.reset(new gmx::Regex(str));
}
* \returns true if this item matches \p value.
*/
bool match(gmx::SelectionStringMatchType matchType,
- const char *value) const
+ const char *value) const
{
if (matchType == gmx::eStringMatchType_Exact)
{
/** Matching type for the strings. */
gmx::SelectionStringMatchType matchType;
/** Array of values for the keyword. */
- char **v;
+ char **v;
/** Array of strings/regular expressions to match against.*/
std::vector<StringKeywordMatchItem> matches;
};
{NULL, {STR_VALUE, -1, {NULL}}, NULL, SPAR_VARNUM},
};
-/** \internal Selection method data for integer keyword evaluation. */
+/** Selection method data for integer keyword evaluation. */
gmx_ana_selmethod_t sm_keyword_int = {
"kw_int", GROUP_VALUE, SMETH_SINGLEVAL,
asize(smparams_keyword_int), smparams_keyword_int,
&init_data_kwint,
- NULL,
+ NULL,
&init_kwint,
- NULL,
- NULL,
- NULL,
+ NULL,
+ NULL,
+ NULL,
&evaluate_keyword_int,
- NULL,
+ NULL,
{NULL, 0, NULL},
};
-/** \internal Selection method data for real keyword evaluation. */
+/** Selection method data for real keyword evaluation. */
gmx_ana_selmethod_t sm_keyword_real = {
"kw_real", GROUP_VALUE, SMETH_SINGLEVAL,
asize(smparams_keyword_real), smparams_keyword_real,
&init_data_kwreal,
- NULL,
+ NULL,
&init_kwreal,
- NULL,
- NULL,
- NULL,
+ NULL,
+ NULL,
+ NULL,
&evaluate_keyword_real,
- NULL,
+ NULL,
{NULL, 0, NULL},
};
-/** \internal Selection method data for string keyword evaluation. */
+/** Selection method data for string keyword evaluation. */
gmx_ana_selmethod_t sm_keyword_str = {
"kw_str", GROUP_VALUE, SMETH_SINGLEVAL,
asize(smparams_keyword_str), smparams_keyword_str,
&init_data_kwstr,
- NULL,
+ NULL,
&init_kwstr,
- NULL,
+ NULL,
&free_data_kwstr,
- NULL,
+ NULL,
&evaluate_keyword_str,
- NULL,
+ NULL,
{NULL, 0, NULL},
};
-/** Initializes keyword evaluation for an arbitrary group. */
+/*! \brief
+ * Initializes keyword evaluation for an arbitrary group.
+ *
+ * \param[in] top Not used.
+ * \param[in] npar Not used.
+ * \param[in] param Not used.
+ * \param[in] data Should point to \ref t_methoddata_kweval.
+ * \returns 0 on success, a non-zero error code on return.
+ *
+ * Calls the initialization method of the wrapped keyword.
+ */
static void
-init_kweval(t_topology *top, int npar, gmx_ana_selparam_t *param, void *data);
-/** Initializes output for keyword evaluation in an arbitrary group. */
+init_kweval(t_topology *top, int npar, gmx_ana_selparam_t * param, void *data);
+/*! \brief
+ * Initializes output for keyword evaluation in an arbitrary group.
+ *
+ * \param[in] top Not used.
+ * \param[in,out] out Pointer to output data structure.
+ * \param[in,out] data Should point to \c t_methoddata_kweval.
+ * \returns 0 for success.
+ */
static void
init_output_kweval(t_topology *top, gmx_ana_selvalue_t *out, void *data);
/** Frees the data allocated for keyword evaluation in an arbitrary group. */
init_frame_kweval(t_topology *top, t_trxframe *fr, t_pbc *pbc, void *data);
/** Evaluates keywords in an arbitrary group. */
static void
-evaluate_kweval(t_topology *top, t_trxframe *fr, t_pbc *pbc,
- gmx_ana_index_t *g, gmx_ana_selvalue_t *out, void *data);
+evaluate_kweval(t_topology *top, t_trxframe *fr, t_pbc *pbc, gmx_ana_index_t * /* g */, gmx_ana_selvalue_t *out, void *data);
/*! \internal \brief
* Data structure for keyword evaluation in arbitrary groups.
* INTEGER KEYWORD EVALUATION
********************************************************************/
-/*!
- * \param[in] npar Not used.
- * \param param Not used.
- * \returns Pointer to the allocated data (\ref t_methoddata_kwint).
- *
- * Allocates memory for a \ref t_methoddata_kwint structure.
- */
static void *
-init_data_kwint(int npar, gmx_ana_selparam_t *param)
+init_data_kwint(int /* npar */, gmx_ana_selparam_t * /* param */)
{
t_methoddata_kwint *data;
return data;
}
-/*!
- * \param[in] top Not used.
- * \param[in] npar Not used (should be 2).
- * \param[in] param Method parameters (should point to \ref smparams_keyword_int).
- * \param[in] data Should point to \ref t_methoddata_kwint.
- */
static void
-init_kwint(t_topology *top, int npar, gmx_ana_selparam_t *param, void *data)
+init_kwint(t_topology * /* top */, int /* npar */, gmx_ana_selparam_t *param, void *data)
{
t_methoddata_kwint *d = (t_methoddata_kwint *)data;
* Matching atoms are stored in \p out->u.g.
*/
static void
-evaluate_keyword_int(t_topology *top, t_trxframe *fr, t_pbc *pbc,
+evaluate_keyword_int(t_topology * /* top */, t_trxframe * /* fr */, t_pbc * /* pbc */,
gmx_ana_index_t *g, gmx_ana_selvalue_t *out, void *data)
{
t_methoddata_kwint *d = (t_methoddata_kwint *)data;
int val;
out->u.g->isize = 0;
- n = d->n;
+ n = d->n;
for (i = 0; i < g->isize; ++i)
{
val = d->v[i];
* REAL KEYWORD EVALUATION
********************************************************************/
-/*!
- * \param[in] npar Not used.
- * \param param Not used.
- * \returns Pointer to the allocated data (\ref t_methoddata_kwreal).
- *
- * Allocates memory for a \ref t_methoddata_kwreal structure.
- */
static void *
-init_data_kwreal(int npar, gmx_ana_selparam_t *param)
+init_data_kwreal(int /* npar */, gmx_ana_selparam_t * /* param */)
{
t_methoddata_kwreal *data;
return data;
}
-/*!
- * \param[in] top Not used.
- * \param[in] npar Not used (should be 2).
- * \param[in] param Method parameters (should point to \ref smparams_keyword_real).
- * \param[in] data Should point to \ref t_methoddata_kwreal.
- * \returns 0 (the initialization always succeeds).
- */
static void
-init_kwreal(t_topology *top, int npar, gmx_ana_selparam_t *param, void *data)
+init_kwreal(t_topology * /* top */, int /* npar */, gmx_ana_selparam_t *param, void *data)
{
t_methoddata_kwreal *d = (t_methoddata_kwreal *)data;
* Matching atoms are stored in \p out->u.g.
*/
static void
-evaluate_keyword_real(t_topology *top, t_trxframe *fr, t_pbc *pbc,
- gmx_ana_index_t *g, gmx_ana_selvalue_t *out, void *data)
+evaluate_keyword_real(t_topology * /* top */, t_trxframe * /* fr */, t_pbc * /* pbc */,
+ gmx_ana_index_t *g, gmx_ana_selvalue_t *out, void *data)
{
t_methoddata_kwreal *d = (t_methoddata_kwreal *)data;
int n, i, j, jmin, jmax;
real val;
out->u.g->isize = 0;
- n = d->n;
+ n = d->n;
for (i = 0; i < g->isize; ++i)
{
val = d->v[i];
* STRING KEYWORD EVALUATION
********************************************************************/
-/*!
- * \param[in] npar Not used.
- * \param param Not used.
- * \returns Pointer to the allocated data (t_methoddata_kwstr).
- *
- * Allocates memory for a t_methoddata_kwstr structure.
- */
static void *
-init_data_kwstr(int npar, gmx_ana_selparam_t *param)
+init_data_kwstr(int /* npar */, gmx_ana_selparam_t * /* param */)
{
t_methoddata_kwstr *data = new t_methoddata_kwstr();
data->matchType = gmx::eStringMatchType_Auto;
*/
void
_gmx_selelem_set_kwstr_match_type(const gmx::SelectionTreeElementPointer &sel,
- gmx::SelectionStringMatchType matchType)
+ gmx::SelectionStringMatchType matchType)
{
- t_methoddata_kwstr *d = (t_methoddata_kwstr *)sel->u.expr.mdata;
+ t_methoddata_kwstr *d = static_cast<t_methoddata_kwstr *>(sel->u.expr.mdata);
if (sel->type != SEL_EXPRESSION || !sel->u.expr.method
|| sel->u.expr.method->name != sm_keyword_str.name)
d->matchType = matchType;
}
-/*!
- * \param[in] top Not used.
- * \param[in] npar Not used (should be 2).
- * \param[in] param Method parameters (should point to \ref smparams_keyword_str).
- * \param[in] data Should point to t_methoddata_kwstr.
- */
static void
-init_kwstr(t_topology *top, int npar, gmx_ana_selparam_t *param, void *data)
+init_kwstr(t_topology * /* top */, int /* npar */, gmx_ana_selparam_t *param, void *data)
{
- t_methoddata_kwstr *d = (t_methoddata_kwstr *)data;
+ t_methoddata_kwstr *d = static_cast<t_methoddata_kwstr *>(data);
d->v = param[0].val.u.s;
/* Return if this is not the first time */
static void
free_data_kwstr(void *data)
{
- t_methoddata_kwstr *d = (t_methoddata_kwstr *)data;
+ t_methoddata_kwstr *d = static_cast<t_methoddata_kwstr *>(data);
delete d;
}
* Matching atoms are stored in \p out->u.g.
*/
static void
-evaluate_keyword_str(t_topology *top, t_trxframe *fr, t_pbc *pbc,
+evaluate_keyword_str(t_topology * /* top */, t_trxframe * /* fr */, t_pbc * /* pbc */,
gmx_ana_index_t *g, gmx_ana_selvalue_t *out, void *data)
{
- t_methoddata_kwstr *d = (t_methoddata_kwstr *)data;
+ t_methoddata_kwstr *d = static_cast<t_methoddata_kwstr *>(data);
out->u.g->isize = 0;
for (int i = 0; i < g->isize; ++i)
* KEYWORD EVALUATION FOR ARBITRARY GROUPS
********************************************************************/
-/*!
- * \param[in] top Not used.
- * \param[in] npar Not used.
- * \param[in] param Not used.
- * \param[in] data Should point to \ref t_methoddata_kweval.
- * \returns 0 on success, a non-zero error code on return.
- *
- * Calls the initialization method of the wrapped keyword.
- */
static void
-init_kweval(t_topology *top, int npar, gmx_ana_selparam_t *param, void *data)
+init_kweval(t_topology *top, int /* npar */, gmx_ana_selparam_t * /* param */, void *data)
{
t_methoddata_kweval *d = (t_methoddata_kweval *)data;
d->kwmethod->init(top, 0, NULL, d->kwmdata);
}
-/*!
- * \param[in] top Not used.
- * \param[in,out] out Pointer to output data structure.
- * \param[in,out] data Should point to \c t_methoddata_kweval.
- * \returns 0 for success.
- */
static void
-init_output_kweval(t_topology *top, gmx_ana_selvalue_t *out, void *data)
+init_output_kweval(t_topology * /* top */, gmx_ana_selvalue_t *out, void *data)
{
t_methoddata_kweval *d = (t_methoddata_kweval *)data;
*/
static void
evaluate_kweval(t_topology *top, t_trxframe *fr, t_pbc *pbc,
- gmx_ana_index_t *g, gmx_ana_selvalue_t *out, void *data)
+ gmx_ana_index_t * /* g */, gmx_ana_selvalue_t *out, void *data)
{
t_methoddata_kweval *d = (t_methoddata_kweval *)data;
* The name of \p param should be empty.
*/
gmx::SelectionTreeElementPointer
-_gmx_sel_init_keyword_evaluator(gmx_ana_selmethod_t *method,
+_gmx_sel_init_keyword_evaluator(gmx_ana_selmethod_t *method,
const gmx::SelectionParserParameterList ¶ms,
- void *scanner)
+ void *scanner)
{
gmx::MessageStringCollector *errors = _gmx_sel_lexer_error_reporter(scanner);
char buf[1024];
|| method->outinit || method->pupdate)
{
GMX_THROW(gmx::InternalError(
- "Unsupported keyword method for arbitrary group evaluation"));
+ "Unsupported keyword method for arbitrary group evaluation"));
}
gmx::SelectionTreeElementPointer sel(