Merge branch release-4-6 into master
[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, by the GROMACS development team, led by
5  * David van der Spoel, Berk Hess, Erik Lindahl, and including many
6  * others, as listed in the AUTHORS file in the top-level source
7  * 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 "basicoptions.h"
49 #include "optionstoragetemplate.h"
50
51 namespace gmx
52 {
53
54 class BooleanOption;
55 class IntegerOption;
56 class DoubleOption;
57 class StringOption;
58
59 /*! \addtogroup module_options
60  * \{
61  */
62
63 /*! \internal \brief
64  * Converts, validates, and stores boolean values.
65  */
66 class BooleanOptionStorage : public OptionStorageTemplate<bool>
67 {
68     public:
69         /*! \brief
70          * Initializes the storage from option settings.
71          *
72          * \param[in] settings   Storage settings.
73          */
74         explicit BooleanOptionStorage(const BooleanOption &settings)
75             : MyBase(settings), info_(this)
76         {
77         }
78
79         virtual OptionInfo &optionInfo() { return info_; }
80         virtual const char *typeString() const { return "bool"; }
81         virtual std::string formatSingleValue(const bool &value) const;
82
83     private:
84         virtual void convertValue(const std::string &value);
85
86         BooleanOptionInfo       info_;
87 };
88
89 /*! \internal \brief
90  * Converts, validates, and stores integer values.
91  */
92 class IntegerOptionStorage : public OptionStorageTemplate<int>
93 {
94     public:
95         //! \copydoc BooleanOptionStorage::BooleanOptionStorage()
96         explicit IntegerOptionStorage(const IntegerOption &settings)
97             : MyBase(settings), info_(this)
98         {
99         }
100
101         virtual OptionInfo &optionInfo() { return info_; }
102         virtual const char *typeString() const
103         { return isVector() ? "vector" : "int"; }
104         virtual std::string formatSingleValue(const int &value) const;
105
106     private:
107         virtual void convertValue(const std::string &value);
108         virtual void processSetValues(ValueList *values);
109
110         IntegerOptionInfo       info_;
111 };
112
113 /*! \internal \brief
114  * Converts, validates, and stores floating-point (double) values.
115  */
116 class DoubleOptionStorage : public OptionStorageTemplate<double>
117 {
118     public:
119         //! \copydoc IntegerOptionStorage::IntegerOptionStorage()
120         explicit DoubleOptionStorage(const DoubleOption &settings);
121
122         virtual OptionInfo &optionInfo() { return info_; }
123         virtual const char *typeString() const;
124         virtual std::string formatSingleValue(const double &value) const;
125
126         //! \copydoc DoubleOptionInfo::isTime()
127         bool isTime() const { return bTime_; }
128         //! \copydoc DoubleOptionInfo::setScaleFactor()
129         void setScaleFactor(double factor);
130
131     private:
132         virtual void convertValue(const std::string &value);
133         virtual void processSetValues(ValueList *values);
134         virtual void processAll();
135
136         DoubleOptionInfo        info_;
137         bool                    bTime_;
138         double                  factor_;
139 };
140
141 /*! \internal \brief
142  * Converts, validates, and stores string values.
143  */
144 class StringOptionStorage : public OptionStorageTemplate<std::string>
145 {
146     public:
147         //! \copydoc DoubleOptionStorage::DoubleOptionStorage()
148         explicit StringOptionStorage(const StringOption &settings);
149
150         virtual OptionInfo &optionInfo() { return info_; }
151         virtual const char *typeString() const { return allowed_.empty() ? "string" : "enum"; }
152         virtual std::string formatSingleValue(const std::string &value) const;
153
154         //! \copydoc StringOptionInfo::allowedValues()
155         const ValueList &allowedValues() const { return allowed_; }
156
157     private:
158         virtual void convertValue(const std::string &value);
159         virtual void refreshValues();
160
161         StringOptionInfo        info_;
162         ValueList               allowed_;
163         int                    *enumIndexStore_;
164 };
165
166 /*!\}*/
167
168 } // namespace gmx
169
170 #endif