Merge remote-tracking branch 'gerrit/release-4-6'
[alexxy/gromacs.git] / src / gromacs / options / basicoptionstorage.h
1 /*
2  *
3  *                This source code is part of
4  *
5  *                 G   R   O   M   A   C   S
6  *
7  *          GROningen MAchine for Chemical Simulations
8  *
9  * Written by David van der Spoel, Erik Lindahl, Berk Hess, and others.
10  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
11  * Copyright (c) 2001-2009, The GROMACS development team,
12  * check out http://www.gromacs.org for more information.
13
14  * This program is free software; you can redistribute it and/or
15  * modify it under the terms of the GNU General Public License
16  * as published by the Free Software Foundation; either version 2
17  * of the License, or (at your option) any later version.
18  *
19  * If you want to redistribute modifications, please consider that
20  * scientific software is very special. Version control is crucial -
21  * bugs must be traceable. We will be happy to consider code for
22  * inclusion in the official distribution, but derived work must not
23  * be called official GROMACS. Details are found in the README & COPYING
24  * files - if they are missing, get the official version at www.gromacs.org.
25  *
26  * To help us fund GROMACS development, we humbly ask that you cite
27  * the papers on the package - you can find them in the top README file.
28  *
29  * For more info, check our website at http://www.gromacs.org
30  */
31 /*! \internal \file
32  * \brief
33  * Declares storage classes for basic option types.
34  *
35  * \author Teemu Murtola <teemu.murtola@cbr.su.se>
36  * \ingroup module_options
37  */
38 #ifndef GMX_OPTIONS_BASICOPTIONSTORAGE_H
39 #define GMX_OPTIONS_BASICOPTIONSTORAGE_H
40
41 #include <string>
42 #include <vector>
43
44 #include "basicoptions.h"
45 #include "basicoptioninfo.h"
46 #include "optionstoragetemplate.h"
47
48 namespace gmx
49 {
50
51 class BooleanOption;
52 class IntegerOption;
53 class DoubleOption;
54 class StringOption;
55
56 /*! \addtogroup module_options
57  * \{
58  */
59
60 /*! \internal \brief
61  * Converts, validates, and stores boolean values.
62  */
63 class BooleanOptionStorage : public OptionStorageTemplate<bool>
64 {
65     public:
66         /*! \brief
67          * Initializes the storage from option settings.
68          *
69          * \param[in] settings   Storage settings.
70          */
71         explicit BooleanOptionStorage(const BooleanOption &settings)
72             : MyBase(settings), info_(this)
73         {
74         }
75
76         virtual OptionInfo &optionInfo() { return info_; }
77         virtual const char *typeString() const { return "bool"; }
78         virtual std::string formatSingleValue(const bool &value) const;
79
80     private:
81         virtual void convertValue(const std::string &value);
82
83         BooleanOptionInfo       info_;
84 };
85
86 /*! \internal \brief
87  * Converts, validates, and stores integer values.
88  */
89 class IntegerOptionStorage : public OptionStorageTemplate<int>
90 {
91     public:
92         //! \copydoc BooleanOptionStorage::BooleanOptionStorage()
93         explicit IntegerOptionStorage(const IntegerOption &settings)
94             : MyBase(settings), info_(this)
95         {
96         }
97
98         virtual OptionInfo &optionInfo() { return info_; }
99         virtual const char *typeString() const
100         { return isVector() ? "vector" : "int"; }
101         virtual std::string formatSingleValue(const int &value) const;
102
103     private:
104         virtual void convertValue(const std::string &value);
105         virtual void processSetValues(ValueList *values);
106
107         IntegerOptionInfo       info_;
108 };
109
110 /*! \internal \brief
111  * Converts, validates, and stores floating-point (double) values.
112  */
113 class DoubleOptionStorage : public OptionStorageTemplate<double>
114 {
115     public:
116         //! \copydoc IntegerOptionStorage::IntegerOptionStorage()
117         explicit DoubleOptionStorage(const DoubleOption &settings);
118
119         virtual OptionInfo &optionInfo() { return info_; }
120         virtual const char *typeString() const;
121         virtual std::string formatSingleValue(const double &value) const;
122
123         //! \copydoc DoubleOptionInfo::isTime()
124         bool isTime() const { return bTime_; }
125         //! \copydoc DoubleOptionInfo::setScaleFactor()
126         void setScaleFactor(double factor);
127
128     private:
129         virtual void convertValue(const std::string &value);
130         virtual void processSetValues(ValueList *values);
131         virtual void processAll();
132
133         DoubleOptionInfo        info_;
134         bool                    bTime_;
135         double                  factor_;
136 };
137
138 /*! \internal \brief
139  * Converts, validates, and stores string values.
140  */
141 class StringOptionStorage : public OptionStorageTemplate<std::string>
142 {
143     public:
144         //! \copydoc DoubleOptionStorage::DoubleOptionStorage()
145         explicit StringOptionStorage(const StringOption &settings);
146
147         virtual OptionInfo &optionInfo() { return info_; }
148         virtual const char *typeString() const { return allowed_.empty() ? "string" : "enum"; }
149         virtual std::string formatSingleValue(const std::string &value) const;
150
151     private:
152         virtual void convertValue(const std::string &value);
153         virtual void refreshValues();
154
155         StringOptionInfo        info_;
156         ValueList               allowed_;
157         int                    *enumIndexStore_;
158 };
159
160 /*!\}*/
161
162 } // namespace gmx
163
164 #endif