Gromacs  2024.3
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Functions
#include "gmxpre.h"
#include <algorithm>
#include <array>
#include <string>
#include "gromacs/math/units.h"
#include "gromacs/math/utilities.h"
#include "gromacs/math/vec.h"
#include "gromacs/selection/position.h"
#include "gromacs/utility/cstringutil.h"
#include "gromacs/utility/exceptions.h"
#include "gromacs/utility/gmxassert.h"
#include "gromacs/utility/smalloc.h"
#include "gromacs/utility/stringutil.h"
#include "gromacs/utility/unique_cptr.h"
#include "parsetree.h"
#include "scanner.h"
#include "selelem.h"
#include "selmethod.h"
#include "selparam.h"
+ Include dependency graph for params.cpp:

Description

Implements functions in selparam.h.

Author
Teemu Murtola teemu.nosp@m..mur.nosp@m.tola@.nosp@m.gmai.nosp@m.l.com

Functions

gmx_ana_selparam_tgmx_ana_selparam_find (const char *name, int nparam, gmx_ana_selparam_t *param)
 Finds a parameter from an array by name. More...
 
static void convert_value (SelectionParserValue *value, e_selvalue_t type, ExceptionInitializer *errors, void *scanner)
 Does a type conversion on a SelectionParserValue. More...
 
static void convert_values (SelectionParserValueList *values, e_selvalue_t type, void *scanner)
 Does a type conversion on a list of values. More...
 
static void place_child (const SelectionTreeElementPointer &root, const SelectionTreeElementPointer &child, gmx_ana_selparam_t *param)
 Adds a child element for a parameter, keeping the parameter order. More...
 
template<typename T >
static bool cmp_range (const std::array< T, 2 > &a, const std::array< T, 2 > &b)
 Comparison function for sorting ranges. More...
 
static void parse_values_range (const SelectionParserValueList &values, gmx_ana_selparam_t *param, void *scanner)
 Parses the values for a parameter that takes integer or real ranges. More...
 
static void parse_values_varnum (const SelectionParserValueList &values, gmx_ana_selparam_t *param, const SelectionTreeElementPointer &root, void *scanner)
 Parses the values for a parameter that takes a variable number of values. More...
 
static SelectionTreeElementPointer add_child (const SelectionTreeElementPointer &root, gmx_ana_selparam_t *param, const SelectionTreeElementPointer &expr, void *scanner)
 Adds a new subexpression reference to a selection element. More...
 
static void parse_values_varnum_expr (const SelectionParserValueList &values, gmx_ana_selparam_t *param, const SelectionTreeElementPointer &root, void *scanner)
 Parses an expression value for a parameter that takes a variable number of values. More...
 
static void set_expr_value_store (const SelectionTreeElementPointer &sel, gmx_ana_selparam_t *param, int i, void *scanner)
 Initializes the storage of an expression value. More...
 
static void parse_values_std (const SelectionParserValueList &values, gmx_ana_selparam_t *param, const SelectionTreeElementPointer &root, void *scanner)
 Parses the values for a parameter that takes a constant number of values. More...
 
static void parse_values_bool (const std::string &name, const SelectionParserValueList &values, gmx_ana_selparam_t *param, void *scanner)
 Parses the values for a boolean parameter. More...
 
static void parse_values_enum (const SelectionParserValueList &values, gmx_ana_selparam_t *param, void *scanner)
 Parses the values for an enumeration parameter. More...
 
static void convert_const_values (SelectionParserValueList *values)
 Replaces constant expressions with their values. More...
 
void _gmx_sel_parse_params (const gmx::SelectionParserParameterList &pparams, int nparam, gmx_ana_selparam_t *params, const gmx::SelectionTreeElementPointer &root, void *scanner)
 Initializes an array of parameters based on input from the selection parser. More...
 

Function Documentation

void _gmx_sel_parse_params ( const gmx::SelectionParserParameterList pparams,
int  nparam,
gmx_ana_selparam_t params,
const gmx::SelectionTreeElementPointer root,
void *  scanner 
)

Initializes an array of parameters based on input from the selection parser.

Parameters
pparamsList of parameters from the selection parser.
[in]nparamNumber of parameters in params.
paramsArray of parameters to parse.
rootSelection element to which child expressions are added.
[in]scannerScanner data structure.

Initializes the params array based on the parameters in pparams. See the documentation of gmx_ana_selparam_t for different options available for parsing.

The list pparams and any associated values are freed after the parameters have been processed, no matter is there was an error or not.

static SelectionTreeElementPointer add_child ( const SelectionTreeElementPointer root,
gmx_ana_selparam_t param,
const SelectionTreeElementPointer expr,
void *  scanner 
)
static

Adds a new subexpression reference to a selection element.

Parameters
[in,out]rootRoot element to which the subexpression is added.
[in]paramParameter for which this expression is a value.
[in]exprExpression to add.
[in]scannerScanner data structure.
Returns
The created child element.

Creates a new SEL_SUBEXPRREF element and adds it into the child list of root. If expr is already a SEL_SUBEXPRREF, it is used as it is. SEL_ALLOCVAL is cleared for the returned element.

template<typename T >
static bool cmp_range ( const std::array< T, 2 > &  a,
const std::array< T, 2 > &  b 
)
static

Comparison function for sorting ranges.

Parameters
[in]aFirst range.
[in]bSecond range.
Returns
return true if a < b

The ranges are primarily sorted based on their starting point, and secondarily based on length (longer ranges come first).

static void convert_const_values ( SelectionParserValueList values)
static

Replaces constant expressions with their values.

Parameters
[in,out]valuesFirst element in the value list to process.
static void convert_value ( SelectionParserValue value,
e_selvalue_t  type,
ExceptionInitializer errors,
void *  scanner 
)
static

Does a type conversion on a SelectionParserValue.

Parameters
[in,out]valueValue to convert.
[in]typeType to convert to.
[in]errorsErrors will be reported into this as nested exceptions.
[in]scannerScanner data structure.
static void convert_values ( SelectionParserValueList values,
e_selvalue_t  type,
void *  scanner 
)
static

Does a type conversion on a list of values.

Parameters
[in,out]valuesValues to convert.
[in]typeType to convert to.
[in]scannerScanner data structure.
gmx_ana_selparam_t* gmx_ana_selparam_find ( const char *  name,
int  nparam,
gmx_ana_selparam_t param 
)

Finds a parameter from an array by name.

Parameters
[in]nameName of the parameter to search.
[in]nparamNumber of parameters in the param array.
[in]paramParameter array to search.
Returns
Pointer to the parameter in the param or NULL if no parameter with name name was found.

The comparison is case-sensitive.

static void parse_values_bool ( const std::string &  name,
const SelectionParserValueList values,
gmx_ana_selparam_t param,
void *  scanner 
)
static

Parses the values for a boolean parameter.

Parameters
[in]nameName by which the parameter was given.
[in]valuesList of values.
paramParameter to parse.
[in]scannerScanner data structure.
static void parse_values_enum ( const SelectionParserValueList values,
gmx_ana_selparam_t param,
void *  scanner 
)
static

Parses the values for an enumeration parameter.

Parameters
[in]valuesList of values.
paramParameter to parse.
[in]scannerScanner data structure.
Returns
true if the values were parsed successfully, false otherwise.
static void parse_values_range ( const SelectionParserValueList values,
gmx_ana_selparam_t param,
void *  scanner 
)
static

Parses the values for a parameter that takes integer or real ranges.

Parameters
[in]valuesList of values.
paramParameter to parse.
[in]scannerScanner data structure.
static void parse_values_std ( const SelectionParserValueList values,
gmx_ana_selparam_t param,
const SelectionTreeElementPointer root,
void *  scanner 
)
static

Parses the values for a parameter that takes a constant number of values.

Parameters
[in]valuesList of values.
paramParameter to parse.
rootSelection element to which child expressions are added.
[in]scannerScanner data structure.

For integer ranges, the sequence of numbers from the first to second value is stored, each as a separate value.

static void parse_values_varnum ( const SelectionParserValueList values,
gmx_ana_selparam_t param,
const SelectionTreeElementPointer root,
void *  scanner 
)
static

Parses the values for a parameter that takes a variable number of values.

Parameters
[in]valuesList of values.
paramParameter to parse.
rootSelection element to which child expressions are added.
[in]scannerScanner data structure.

For integer ranges, the sequence of numbers from the first to second value is stored, each as a separate value.

static void parse_values_varnum_expr ( const SelectionParserValueList values,
gmx_ana_selparam_t param,
const SelectionTreeElementPointer root,
void *  scanner 
)
static

Parses an expression value for a parameter that takes a variable number of values.

Parameters
[in]valuesList of values.
paramParameter to parse.
rootSelection element to which child expressions are added.
[in]scannerScanner data structure.
static void place_child ( const SelectionTreeElementPointer root,
const SelectionTreeElementPointer child,
gmx_ana_selparam_t param 
)
static

Adds a child element for a parameter, keeping the parameter order.

Parameters
[in,out]rootRoot element to which the child is added.
[in]childChild to add.
[in]paramParameter for which this child is a value.

Puts child in the child list of root such that the list remains in the same order as the corresponding parameters.

static void set_expr_value_store ( const SelectionTreeElementPointer sel,
gmx_ana_selparam_t param,
int  i,
void *  scanner 
)
static

Initializes the storage of an expression value.

Parameters
[in,out]selSelection element that evaluates the value.
[in]paramParameter to receive the value.
[in]iThe value of sel evaluates the value i for param.
[in]scannerScanner data structure.

Initializes the data pointer of sel such that the result is stored as the value i of param. This function is used internally by parse_values_std().