2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 2010,2011,2012,2013,2014,2015,2016,2017, 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 virtual OptionInfo &optionInfo() { return info_; }
76 virtual std::string typeString() const { return "bool"; }
77 virtual std::string formatSingleValue(const bool &value) const;
79 //! \copydoc BooleanOptionInfo::defaultValue()
80 bool defaultValue() const { return valueCount() > 0 && values()[0]; }
83 virtual void initConverter(ConverterType *converter);
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 virtual OptionInfo &optionInfo() { return info_; }
101 virtual std::string typeString() const
102 { return isVector() ? "vector" : "int"; }
103 virtual std::string formatSingleValue(const int &value) const;
106 virtual void initConverter(ConverterType *converter);
107 virtual void processSetValues(ValueList *values);
109 IntegerOptionInfo info_;
113 * Converts, validates, and stores integer values.
115 class Int64OptionStorage : public OptionStorageTemplateSimple<gmx_int64_t>
118 //! \copydoc BooleanOptionStorage::BooleanOptionStorage()
119 explicit Int64OptionStorage(const Int64Option &settings)
120 : MyBase(settings), info_(this)
124 virtual OptionInfo &optionInfo() { return info_; }
125 virtual std::string typeString() const { return "int"; }
126 virtual std::string formatSingleValue(const gmx_int64_t &value) const;
129 virtual void initConverter(ConverterType *converter);
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 virtual OptionInfo &optionInfo() { return info_; }
144 virtual std::string typeString() const;
145 virtual std::string formatSingleValue(const double &value) const;
147 //! \copydoc DoubleOptionInfo::isTime()
148 bool isTime() const { return bTime_; }
149 //! \copydoc DoubleOptionInfo::setScaleFactor()
150 void setScaleFactor(double factor);
153 virtual void initConverter(ConverterType *converter);
154 virtual double processValue(const double &value) const;
155 virtual void processSetValues(ValueList *values);
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 virtual OptionInfo &optionInfo() { return info_; }
172 virtual std::string typeString() const;
173 virtual std::string formatSingleValue(const float &value) const;
175 //! \copydoc DoubleOptionStorage::isTime()
176 bool isTime() const { return bTime_; }
177 //! \copydoc DoubleOptionStorage::setScaleFactor()
178 void setScaleFactor(double factor);
181 virtual void initConverter(ConverterType *converter);
182 virtual float processValue(const float &value) const;
183 virtual void processSetValues(ValueList *values);
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 virtual OptionInfo &optionInfo() { return info_; }
200 virtual std::string typeString() const
201 { return allowed_.empty() ? "string" : "enum"; }
202 virtual std::string formatExtraDescription() const;
203 virtual std::string formatSingleValue(const std::string &value) const;
205 //! \copydoc StringOptionInfo::allowedValues()
206 const ValueList &allowedValues() const { return allowed_; }
209 virtual void initConverter(ConverterType *converter);
210 virtual std::string processValue(const std::string &value) const;
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 virtual OptionInfo &optionInfo() { return info_; }
244 virtual std::string typeString() const { return "enum"; }
245 virtual std::string formatExtraDescription() const;
246 virtual std::string formatSingleValue(const int &value) const;
247 virtual Variant normalizeValue(const int &value) const;
249 //! \copydoc EnumOptionInfo::allowedValues()
250 const std::vector<std::string> &allowedValues() const { return allowed_; }
253 virtual void initConverter(ConverterType *converter);
255 EnumOptionInfo info_;
256 std::vector<std::string> allowed_;