Sort all includes in src/gromacs
[alexxy/gromacs.git] / src / gromacs / options / basicoptionstorage.h
1 /*
2  * This file is part of the GROMACS molecular simulation package.
3  *
4  * Copyright (c) 2010,2011,2012,2013,2014, 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.
8  *
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.
13  *
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.
18  *
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.
23  *
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.
31  *
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.
34  */
35 /*! \internal \file
36  * \brief
37  * Declares storage classes for basic option types.
38  *
39  * \author Teemu Murtola <teemu.murtola@gmail.com>
40  * \ingroup module_options
41  */
42 #ifndef GMX_OPTIONS_BASICOPTIONSTORAGE_H
43 #define GMX_OPTIONS_BASICOPTIONSTORAGE_H
44
45 #include <string>
46 #include <vector>
47
48 #include "gromacs/options/basicoptions.h"
49 #include "gromacs/options/optionstoragetemplate.h"
50
51 namespace gmx
52 {
53
54 /*! \addtogroup module_options
55  * \{
56  */
57
58 /*! \internal \brief
59  * Converts, validates, and stores boolean values.
60  */
61 class BooleanOptionStorage : public OptionStorageTemplate<bool>
62 {
63     public:
64         /*! \brief
65          * Initializes the storage from option settings.
66          *
67          * \param[in] settings   Storage settings.
68          */
69         explicit BooleanOptionStorage(const BooleanOption &settings)
70             : MyBase(settings), info_(this)
71         {
72         }
73
74         virtual OptionInfo &optionInfo() { return info_; }
75         virtual std::string typeString() const { return "bool"; }
76         virtual std::string formatSingleValue(const bool &value) const;
77
78         //! \copydoc BooleanOptionInfo::defaultValue()
79         bool defaultValue() const { return valueCount() > 0 && values()[0]; }
80
81     private:
82         virtual void convertValue(const std::string &value);
83
84         BooleanOptionInfo       info_;
85 };
86
87 /*! \internal \brief
88  * Converts, validates, and stores integer values.
89  */
90 class IntegerOptionStorage : public OptionStorageTemplate<int>
91 {
92     public:
93         //! \copydoc BooleanOptionStorage::BooleanOptionStorage()
94         explicit IntegerOptionStorage(const IntegerOption &settings)
95             : MyBase(settings), info_(this)
96         {
97         }
98
99         virtual OptionInfo &optionInfo() { return info_; }
100         virtual std::string typeString() const
101         { return isVector() ? "vector" : "int"; }
102         virtual std::string formatSingleValue(const int &value) const;
103
104     private:
105         virtual void convertValue(const std::string &value);
106         virtual void processSetValues(ValueList *values);
107
108         IntegerOptionInfo       info_;
109 };
110
111 /*! \internal \brief
112  * Converts, validates, and stores integer values.
113  */
114 class Int64OptionStorage : public OptionStorageTemplate<gmx_int64_t>
115 {
116     public:
117         //! \copydoc BooleanOptionStorage::BooleanOptionStorage()
118         explicit Int64OptionStorage(const Int64Option &settings)
119             : MyBase(settings), info_(this)
120         {
121         }
122
123         virtual OptionInfo &optionInfo() { return info_; }
124         virtual std::string typeString() const { return "int"; }
125         virtual std::string formatSingleValue(const gmx_int64_t &value) const;
126
127     private:
128         virtual void convertValue(const std::string &value);
129
130         Int64OptionInfo       info_;
131 };
132
133 /*! \internal \brief
134  * Converts, validates, and stores floating-point (double) values.
135  */
136 class DoubleOptionStorage : public OptionStorageTemplate<double>
137 {
138     public:
139         //! \copydoc IntegerOptionStorage::IntegerOptionStorage()
140         explicit DoubleOptionStorage(const DoubleOption &settings);
141
142         virtual OptionInfo &optionInfo() { return info_; }
143         virtual std::string typeString() const;
144         virtual std::string formatSingleValue(const double &value) const;
145
146         //! \copydoc DoubleOptionInfo::isTime()
147         bool isTime() const { return bTime_; }
148         //! \copydoc DoubleOptionInfo::setScaleFactor()
149         void setScaleFactor(double factor);
150
151     private:
152         virtual void convertValue(const std::string &value);
153         virtual void processSetValues(ValueList *values);
154
155         DoubleOptionInfo        info_;
156         bool                    bTime_;
157         double                  factor_;
158 };
159
160 /*! \internal \brief
161  * Converts, validates, and stores floating-point (float) values.
162  */
163 class FloatOptionStorage : public OptionStorageTemplate<float>
164 {
165     public:
166         //! \copydoc IntegerOptionStorage::IntegerOptionStorage()
167         explicit FloatOptionStorage(const FloatOption &settings);
168
169         virtual OptionInfo &optionInfo() { return info_; }
170         virtual std::string typeString() const;
171         virtual std::string formatSingleValue(const float &value) const;
172
173         //! \copydoc DoubleOptionStorage::isTime()
174         bool isTime() const { return bTime_; }
175         //! \copydoc DoubleOptionStorage::setScaleFactor()
176         void setScaleFactor(double factor);
177
178     private:
179         virtual void convertValue(const std::string &value);
180         virtual void processSetValues(ValueList *values);
181
182         FloatOptionInfo         info_;
183         bool                    bTime_;
184         double                  factor_;
185 };
186
187 /*! \internal \brief
188  * Converts, validates, and stores string values.
189  */
190 class StringOptionStorage : public OptionStorageTemplate<std::string>
191 {
192     public:
193         //! \copydoc DoubleOptionStorage::DoubleOptionStorage()
194         explicit StringOptionStorage(const StringOption &settings);
195
196         virtual OptionInfo &optionInfo() { return info_; }
197         virtual std::string typeString() const
198         { return allowed_.empty() ? "string" : "enum"; }
199         virtual std::string formatExtraDescription() const;
200         virtual std::string formatSingleValue(const std::string &value) const;
201
202         //! \copydoc StringOptionInfo::allowedValues()
203         const ValueList &allowedValues() const { return allowed_; }
204
205     private:
206         virtual void convertValue(const std::string &value);
207         virtual void refreshValues();
208
209         void refreshEnumIndexStore();
210
211         StringOptionInfo        info_;
212         ValueList               allowed_;
213         int                    *enumIndexStore_;
214 };
215
216 /*!\}*/
217
218 } // namespace gmx
219
220 #endif