2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 2010,2011,2012,2013,2014,2015,2016,2017,2018,2019, by the GROMACS development team, led by
5 * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
6 * and including many others, as listed in the AUTHORS file in the
7 * top-level source directory and at http://www.gromacs.org.
9 * GROMACS is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public License
11 * as published by the Free Software Foundation; either version 2.1
12 * of the License, or (at your option) any later version.
14 * GROMACS is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with GROMACS; if not, see
21 * http://www.gnu.org/licenses, or write to the Free Software Foundation,
22 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 * If you want to redistribute modifications to GROMACS, please
25 * consider that scientific software is very special. Version
26 * control is crucial - bugs must be traceable. We will be happy to
27 * consider code for inclusion in the official distribution, but
28 * derived work must not be called official GROMACS. Details are found
29 * in the README & COPYING files - if they are missing, get the
30 * official version at http://www.gromacs.org.
32 * To help us fund GROMACS development, we humbly ask that you cite
33 * the research papers on the package. Check out http://www.gromacs.org.
37 * Declares storage classes for basic option types.
39 * \author Teemu Murtola <teemu.murtola@gmail.com>
40 * \ingroup module_options
42 #ifndef GMX_OPTIONS_BASICOPTIONSTORAGE_H
43 #define GMX_OPTIONS_BASICOPTIONSTORAGE_H
49 #include "gromacs/options/basicoptions.h"
50 #include "gromacs/options/optionstoragetemplate.h"
55 /*! \addtogroup module_options
60 * Converts, validates, and stores boolean values.
62 class BooleanOptionStorage : public OptionStorageTemplateSimple<bool>
66 * Initializes the storage from option settings.
68 * \param[in] settings Storage settings.
70 explicit BooleanOptionStorage(const BooleanOption &settings)
71 : MyBase(settings), info_(this)
75 OptionInfo &optionInfo() override { return info_; }
76 std::string typeString() const override { return "bool"; }
77 std::string formatSingleValue(const bool &value) const override;
79 //! \copydoc BooleanOptionInfo::defaultValue()
80 bool defaultValue() const { return valueCount() > 0 && values()[0]; }
83 void initConverter(ConverterType *converter) override;
85 BooleanOptionInfo info_;
89 * Converts, validates, and stores integer values.
91 class IntegerOptionStorage : public OptionStorageTemplateSimple<int>
94 //! \copydoc BooleanOptionStorage::BooleanOptionStorage()
95 explicit IntegerOptionStorage(const IntegerOption &settings)
96 : MyBase(settings), info_(this)
100 OptionInfo &optionInfo() override { return info_; }
101 std::string typeString() const override
102 { return isVector() ? "vector" : "int"; }
103 std::string formatSingleValue(const int &value) const override;
106 void initConverter(ConverterType *converter) override;
107 void processSetValues(ValueList *values) override;
109 IntegerOptionInfo info_;
113 * Converts, validates, and stores integer values.
115 class Int64OptionStorage : public OptionStorageTemplateSimple<int64_t>
118 //! \copydoc BooleanOptionStorage::BooleanOptionStorage()
119 explicit Int64OptionStorage(const Int64Option &settings)
120 : MyBase(settings), info_(this)
124 OptionInfo &optionInfo() override { return info_; }
125 std::string typeString() const override { return "int"; }
126 std::string formatSingleValue(const int64_t &value) const override;
129 void initConverter(ConverterType *converter) override;
131 Int64OptionInfo info_;
135 * Converts, validates, and stores floating-point (double) values.
137 class DoubleOptionStorage : public OptionStorageTemplateSimple<double>
140 //! \copydoc IntegerOptionStorage::IntegerOptionStorage()
141 explicit DoubleOptionStorage(const DoubleOption &settings);
143 OptionInfo &optionInfo() override { return info_; }
144 std::string typeString() const override;
145 std::string formatSingleValue(const double &value) const override;
147 //! \copydoc DoubleOptionInfo::isTime()
148 bool isTime() const { return bTime_; }
149 //! \copydoc DoubleOptionInfo::setScaleFactor()
150 void setScaleFactor(double factor);
153 void initConverter(ConverterType *converter) override;
154 double processValue(const double &value) const override;
155 void processSetValues(ValueList *values) override;
157 DoubleOptionInfo info_;
163 * Converts, validates, and stores floating-point (float) values.
165 class FloatOptionStorage : public OptionStorageTemplateSimple<float>
168 //! \copydoc IntegerOptionStorage::IntegerOptionStorage()
169 explicit FloatOptionStorage(const FloatOption &settings);
171 OptionInfo &optionInfo() override { return info_; }
172 std::string typeString() const override;
173 std::string formatSingleValue(const float &value) const override;
175 //! \copydoc DoubleOptionStorage::isTime()
176 bool isTime() const { return bTime_; }
177 //! \copydoc DoubleOptionStorage::setScaleFactor()
178 void setScaleFactor(double factor);
181 void initConverter(ConverterType *converter) override;
182 float processValue(const float &value) const override;
183 void processSetValues(ValueList *values) override;
185 FloatOptionInfo info_;
191 * Converts, validates, and stores string values.
193 class StringOptionStorage : public OptionStorageTemplateSimple<std::string>
196 //! \copydoc DoubleOptionStorage::DoubleOptionStorage()
197 explicit StringOptionStorage(const StringOption &settings);
199 OptionInfo &optionInfo() override { return info_; }
200 std::string typeString() const override
201 { return allowed_.empty() ? "string" : "enum"; }
202 std::string formatExtraDescription() const override;
203 std::string formatSingleValue(const std::string &value) const override;
205 //! \copydoc StringOptionInfo::allowedValues()
206 const ValueList &allowedValues() const { return allowed_; }
209 void initConverter(ConverterType *converter) override;
210 std::string processValue(const std::string &value) const override;
212 StringOptionInfo info_;
217 * Converts, validates, and stores enum values.
219 class EnumOptionStorage : public OptionStorageTemplateSimple<int>
223 * Initializes the storage from option settings.
225 * \param[in] settings Basic storage settings.
226 * \param[in] enumValues Allowed values.
227 * \param[in] count Number of elements in \p enumValues,
228 * or -1 if \p enumValues is `NULL`-terminated.
229 * \param[in] defaultValue Default value, or -1 if no default.
230 * \param[in] defaultValueIfSet Default value if set, or -1 if none.
231 * \param[in] store Storage to convert the values to/from `int`.
233 * This constructor takes more parameters than other storage parameters
234 * because the front-end option type is a template, and as such cannot
235 * be passed here without exposing also this header as an installed
238 EnumOptionStorage(const AbstractOption &settings,
239 const char *const *enumValues, int count,
240 int defaultValue, int defaultValueIfSet,
243 OptionInfo &optionInfo() override { return info_; }
244 std::string typeString() const override { return "enum"; }
245 std::string formatExtraDescription() const override;
246 std::string formatSingleValue(const int &value) const override;
247 Any normalizeValue(const int &value) const override;
249 //! \copydoc EnumOptionInfo::allowedValues()
250 const std::vector<std::string> &allowedValues() const { return allowed_; }
253 void initConverter(ConverterType *converter) override;
255 EnumOptionInfo info_;
256 std::vector<std::string> allowed_;