A bit more modular selection position handling.
[gromacs/qmmm-gamess-us.git] / src / gmxlib / selection / parsetree.h
blob37573eba191576786c34a364f615b1313d42d934
1 /*
3 * This source code is part of
5 * G R O M A C S
7 * GROningen MAchine for Chemical Simulations
9 * Written by David van der Spoel, Erik Lindahl, Berk Hess, and others.
10 * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
11 * Copyright (c) 2001-2009, The GROMACS development team,
12 * check out http://www.gromacs.org for more information.
14 * This program is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU General Public License
16 * as published by the Free Software Foundation; either version 2
17 * of the License, or (at your option) any later version.
19 * If you want to redistribute modifications, please consider that
20 * scientific software is very special. Version control is crucial -
21 * bugs must be traceable. We will be happy to consider code for
22 * inclusion in the official distribution, but derived work must not
23 * be called official GROMACS. Details are found in the README & COPYING
24 * files - if they are missing, get the official version at www.gromacs.org.
26 * To help us fund GROMACS development, we humbly ask that you cite
27 * the papers on the package - you can find them in the top README file.
29 * For more info, check our website at http://www.gromacs.org
31 /*! \internal \file
32 * \brief Handling of intermediate selection parser data.
34 * The data types declared in this header are used by the parser to store
35 * intermediate data when constructing method expressions.
36 * In particular, the parameters for the method are stored.
37 * The intermediate data is freed once a \c t_selelem object can be
38 * constructed.
40 * This is an implementation header: there should be no need to use it outside
41 * this directory.
43 #ifndef SELECTION_PARSETREE_H
44 #define SELECTION_PARSETREE_H
46 #include <typedefs.h>
48 #include <selvalue.h>
50 struct t_selelem;
51 struct gmx_ana_indexgrps_t;
52 struct gmx_ana_selmethod_t;
53 struct gmx_ana_selparam_t;
55 /*! \internal \brief
56 * Describes a parsed value, possibly resulting from expression evaluation.
58 typedef struct t_selexpr_value
60 /** Type of the value. */
61 e_selvalue_t type;
62 /** TRUE if the value is the result of an expression. */
63 bool bExpr;
64 union {
65 /** The integer value/range (\p type INT_VALUE); */
66 struct {
67 /** Beginning of the range. */
68 int i1;
69 /** End of the range; equals \p i1 for a single integer. */
70 int i2;
71 } i;
72 /** The real value/range (\p type REAL_VALUE); */
73 struct {
74 /** Beginning of the range. */
75 real r1;
76 /** End of the range; equals \p r1 for a single number. */
77 real r2;
78 } r;
79 /** The string value (\p type STR_VALUE); */
80 char *s;
81 /** The position value (\p type POS_VALUE); */
82 rvec x;
83 /** The expression if \p bExpr is TRUE. */
84 struct t_selelem *expr;
85 } u;
86 /** Pointer to the next value. */
87 struct t_selexpr_value *next;
88 } t_selexpr_value;
90 /*! \internal \brief
91 * Describes a parsed method parameter.
93 typedef struct t_selexpr_param
95 /** Name of the parameter. */
96 char *name;
97 /** Number of values given for this parameter. */
98 int nval;
99 /** Pointer to the first value. */
100 struct t_selexpr_value *value;
101 /** Pointer to the next parameter. */
102 struct t_selexpr_param *next;
103 } t_selexpr_param;
105 /** Error reporting function for the selection parser. */
106 void
107 _gmx_selparser_error(const char *fmt, ...);
109 /** Allocates and initializes a constant \c t_selexpr_value. */
110 t_selexpr_value *
111 _gmx_selexpr_create_value(e_selvalue_t type);
112 /** Allocates and initializes an expression \c t_selexpr_value. */
113 t_selexpr_value *
114 _gmx_selexpr_create_value_expr(struct t_selelem *expr);
115 /** Allocates and initializes a \c t_selexpr_param. */
116 t_selexpr_param *
117 _gmx_selexpr_create_param(char *name);
119 /** Frees the memory allocated for a chain of values. */
120 void
121 _gmx_selexpr_free_values(t_selexpr_value *value);
122 /** Frees the memory allocated for a chain of parameters. */
123 void
124 _gmx_selexpr_free_params(t_selexpr_param *param);
126 /** Propagates the flags for selection elements. */
128 _gmx_selelem_update_flags(struct t_selelem *sel);
130 /** Creates a \c t_selelem for comparsion expression evaluation. */
131 struct t_selelem *
132 _gmx_sel_init_comparison(struct t_selelem *left, struct t_selelem *right,
133 char *cmpop, void *scanner);
134 /** Creates a \c t_selelem for a keyword expression from the parsed data. */
135 struct t_selelem *
136 _gmx_sel_init_keyword(struct gmx_ana_selmethod_t *method,
137 t_selexpr_value *args, const char *rpost, void *scanner);
138 /** Creates a \c t_selelem for a method expression from the parsed data. */
139 struct t_selelem *
140 _gmx_sel_init_method(struct gmx_ana_selmethod_t *method,
141 t_selexpr_param *params, const char *rpost,
142 void *scanner);
143 /** Creates a \c t_selelem for a modifier expression from the parsed data. */
144 struct t_selelem *
145 _gmx_sel_init_modifier(struct gmx_ana_selmethod_t *mod, t_selexpr_param *params,
146 struct t_selelem *sel, void *scanner);
147 /** Creates a \c t_selelem for evaluation of reference positions. */
148 struct t_selelem *
149 _gmx_sel_init_position(struct t_selelem *expr, const char *type, void *scanner);
151 /** Creates a \c t_selelem for a constant position. */
152 struct t_selelem *
153 _gmx_sel_init_const_position(real x, real y, real z);
154 /** Creates a \c t_selelem for a index group expression using group name. */
155 struct t_selelem *
156 _gmx_sel_init_group_by_name(const char *name, void *scanner);
157 /** Creates a \c t_selelem for a index group expression using group index. */
158 struct t_selelem *
159 _gmx_sel_init_group_by_id(int id, void *scanner);
160 /** Creates a \c t_selelem for a variable reference */
161 struct t_selelem *
162 _gmx_sel_init_variable_ref(struct t_selelem *sel);
164 /** Creates a root \c t_selelem for a selection. */
165 struct t_selelem *
166 _gmx_sel_init_selection(char *name, struct t_selelem *sel, void *scanner);
167 /** Creates a root \c t_selelem elements for a variable assignment. */
168 struct t_selelem *
169 _gmx_sel_assign_variable(char *name, struct t_selelem *expr, void *scanner);
170 /** Appends a root \c t_selelem to a selection collection. */
171 struct t_selelem *
172 _gmx_sel_append_selection(struct t_selelem *sel, struct t_selelem *last,
173 void *scanner);
174 /** Check whether the parser should finish. */
175 bool
176 _gmx_sel_parser_should_finish(void *scanner);
178 /** Handle empty commands. */
179 void
180 _gmx_sel_handle_empty_cmd(void *scanner);
181 /** Process help commands. */
182 void
183 _gmx_sel_handle_help_cmd(char *topic, void *scanner);
185 /* In params.c */
186 /** Initializes an array of parameters based on input from the selection parser. */
187 bool
188 _gmx_sel_parse_params(t_selexpr_param *pparams, int nparam,
189 struct gmx_ana_selparam_t *param, struct t_selelem *root,
190 void *scanner);
192 #endif