2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 2010-2018, The GROMACS development team.
5 * Copyright (c) 2019, by the GROMACS development team, led by
6 * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
7 * and including many others, as listed in the AUTHORS file in the
8 * top-level source directory and at http://www.gromacs.org.
10 * GROMACS is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public License
12 * as published by the Free Software Foundation; either version 2.1
13 * of the License, or (at your option) any later version.
15 * GROMACS is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Lesser General Public License for more details.
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with GROMACS; if not, see
22 * http://www.gnu.org/licenses, or write to the Free Software Foundation,
23 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25 * If you want to redistribute modifications to GROMACS, please
26 * consider that scientific software is very special. Version
27 * control is crucial - bugs must be traceable. We will be happy to
28 * consider code for inclusion in the official distribution, but
29 * derived work must not be called official GROMACS. Details are found
30 * in the README & COPYING files - if they are missing, get the
31 * official version at http://www.gromacs.org.
33 * To help us fund GROMACS development, we humbly ask that you cite
34 * the research papers on the package. Check out http://www.gromacs.org.
38 * Declares storage classes for basic option types.
40 * \author Teemu Murtola <teemu.murtola@gmail.com>
41 * \ingroup module_options
43 #ifndef GMX_OPTIONS_BASICOPTIONSTORAGE_H
44 #define GMX_OPTIONS_BASICOPTIONSTORAGE_H
50 #include "gromacs/options/basicoptions.h"
51 #include "gromacs/options/optionstoragetemplate.h"
56 /*! \addtogroup module_options
61 * Converts, validates, and stores boolean values.
63 class BooleanOptionStorage : public OptionStorageTemplateSimple<bool>
67 * Initializes the storage from option settings.
69 * \param[in] settings Storage settings.
71 explicit BooleanOptionStorage(const BooleanOption& settings) : MyBase(settings), info_(this) {}
73 OptionInfo& optionInfo() override { return info_; }
74 std::string typeString() const override { return "bool"; }
75 std::string formatSingleValue(const bool& value) const override;
77 //! \copydoc BooleanOptionInfo::defaultValue()
78 bool defaultValue() const { return valueCount() > 0 && values()[0]; }
81 void initConverter(ConverterType* converter) override;
83 BooleanOptionInfo info_;
87 * Converts, validates, and stores integer values.
89 class IntegerOptionStorage : public OptionStorageTemplateSimple<int>
92 //! \copydoc BooleanOptionStorage::BooleanOptionStorage()
93 explicit IntegerOptionStorage(const IntegerOption& settings) : MyBase(settings), info_(this) {}
95 OptionInfo& optionInfo() override { return info_; }
96 std::string typeString() const override { return isVector() ? "vector" : "int"; }
97 std::string formatSingleValue(const int& value) const override;
100 void initConverter(ConverterType* converter) override;
101 void processSetValues(ValueList* values) override;
103 IntegerOptionInfo info_;
107 * Converts, validates, and stores integer values.
109 class Int64OptionStorage : public OptionStorageTemplateSimple<int64_t>
112 //! \copydoc BooleanOptionStorage::BooleanOptionStorage()
113 explicit Int64OptionStorage(const Int64Option& settings) : MyBase(settings), info_(this) {}
115 OptionInfo& optionInfo() override { return info_; }
116 std::string typeString() const override { return "int"; }
117 std::string formatSingleValue(const int64_t& value) const override;
120 void initConverter(ConverterType* converter) override;
122 Int64OptionInfo info_;
126 * Converts, validates, and stores floating-point (double) values.
128 class DoubleOptionStorage : public OptionStorageTemplateSimple<double>
131 //! \copydoc IntegerOptionStorage::IntegerOptionStorage()
132 explicit DoubleOptionStorage(const DoubleOption& settings);
134 OptionInfo& optionInfo() override { return info_; }
135 std::string typeString() const override;
136 std::string formatSingleValue(const double& value) const override;
138 //! \copydoc DoubleOptionInfo::isTime()
139 bool isTime() const { return bTime_; }
140 //! \copydoc DoubleOptionInfo::setScaleFactor()
141 void setScaleFactor(double factor);
144 void initConverter(ConverterType* converter) override;
145 double processValue(const double& value) const override;
146 void processSetValues(ValueList* values) override;
148 DoubleOptionInfo info_;
154 * Converts, validates, and stores floating-point (float) values.
156 class FloatOptionStorage : public OptionStorageTemplateSimple<float>
159 //! \copydoc IntegerOptionStorage::IntegerOptionStorage()
160 explicit FloatOptionStorage(const FloatOption& settings);
162 OptionInfo& optionInfo() override { return info_; }
163 std::string typeString() const override;
164 std::string formatSingleValue(const float& value) const override;
166 //! \copydoc DoubleOptionStorage::isTime()
167 bool isTime() const { return bTime_; }
168 //! \copydoc DoubleOptionStorage::setScaleFactor()
169 void setScaleFactor(double factor);
172 void initConverter(ConverterType* converter) override;
173 float processValue(const float& value) const override;
174 void processSetValues(ValueList* values) override;
176 FloatOptionInfo info_;
182 * Converts, validates, and stores string values.
184 class StringOptionStorage : public OptionStorageTemplateSimple<std::string>
187 //! \copydoc DoubleOptionStorage::DoubleOptionStorage()
188 explicit StringOptionStorage(const StringOption& settings);
190 OptionInfo& optionInfo() override { return info_; }
191 std::string typeString() const override { return allowed_.empty() ? "string" : "enum"; }
192 std::string formatExtraDescription() const override;
193 std::string formatSingleValue(const std::string& value) const override;
195 //! \copydoc StringOptionInfo::allowedValues()
196 const ValueList& allowedValues() const { return allowed_; }
199 void initConverter(ConverterType* converter) override;
200 std::string processValue(const std::string& value) const override;
202 StringOptionInfo info_;
207 * Converts, validates, and stores enum values.
209 class EnumOptionStorage : public OptionStorageTemplateSimple<int>
213 * Initializes the storage from option settings.
215 * \param[in] settings Basic storage settings.
216 * \param[in] enumValues Allowed values.
217 * \param[in] count Number of elements in \p enumValues,
218 * or -1 if \p enumValues is `NULL`-terminated.
219 * \param[in] defaultValue Default value, or -1 if no default.
220 * \param[in] defaultValueIfSet Default value if set, or -1 if none.
221 * \param[in] store Storage to convert the values to/from `int`.
223 * This constructor takes more parameters than other storage parameters
224 * because the front-end option type is a template, and as such cannot
225 * be passed here without exposing also this header as an installed
228 EnumOptionStorage(const AbstractOption& settings,
229 const char* const* enumValues,
232 int defaultValueIfSet,
235 OptionInfo& optionInfo() override { return info_; }
236 std::string typeString() const override { return "enum"; }
237 std::string formatExtraDescription() const override;
238 std::string formatSingleValue(const int& value) const override;
239 Any normalizeValue(const int& value) const override;
241 //! \copydoc EnumOptionInfo::allowedValues()
242 const std::vector<std::string>& allowedValues() const { return allowed_; }
245 void initConverter(ConverterType* converter) override;
247 EnumOptionInfo info_;
248 std::vector<std::string> allowed_;