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