Merge branch 'release-4-6' (incl. AdResS Patch)
[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 "optionfiletype.h"
45 #include "optionstoragetemplate.h"
46
47 namespace gmx
48 {
49
50 class BooleanOption;
51 class IntegerOption;
52 class DoubleOption;
53 class StringOption;
54 class FileNameOption;
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          * \param[in] options    Options object.
71          */
72         BooleanOptionStorage(const BooleanOption &settings, Options *options)
73             : MyBase(settings, options)
74         {
75         }
76
77         virtual const char *typeString() const { return "bool"; }
78         virtual std::string formatValue(int i) const;
79
80     private:
81         virtual void convertValue(const std::string &value);
82 };
83
84 /*! \internal \brief
85  * Converts, validates, and stores integer values.
86  */
87 class IntegerOptionStorage : public OptionStorageTemplate<int>
88 {
89     public:
90         //! \copydoc BooleanOptionStorage::BooleanOptionStorage()
91         IntegerOptionStorage(const IntegerOption &settings, Options *options)
92             : MyBase(settings, options)
93         {
94         }
95
96         virtual const char *typeString() const
97         { return hasFlag(efVector) ? "vector" : "int"; }
98         virtual std::string formatValue(int i) const;
99
100     private:
101         virtual void convertValue(const std::string &value);
102         virtual void processSetValues(ValueList *values);
103 };
104
105 /*! \internal \brief
106  * Converts, validates, and stores floating-point (double) values.
107  */
108 class DoubleOptionStorage : public OptionStorageTemplate<double>
109 {
110     public:
111         //! \copydoc IntegerOptionStorage::IntegerOptionStorage()
112         DoubleOptionStorage(const DoubleOption &settings, Options *options);
113
114         virtual const char *typeString() const;
115         virtual std::string formatValue(int i) const;
116
117     private:
118         virtual void convertValue(const std::string &value);
119         virtual void processSetValues(ValueList *values);
120         virtual void processAll();
121
122         bool                    _bTime;
123 };
124
125 /*! \internal \brief
126  * Converts, validates, and stores string values.
127  */
128 class StringOptionStorage : public OptionStorageTemplate<std::string>
129 {
130     public:
131         //! \copydoc DoubleOptionStorage::DoubleOptionStorage()
132         StringOptionStorage(const StringOption &settings, Options *options);
133
134         virtual const char *typeString() const { return _allowed.empty() ? "string" : "enum"; }
135         virtual std::string formatValue(int i) const;
136
137     private:
138         virtual void convertValue(const std::string &value);
139         virtual void refreshValues();
140
141         ValueList               _allowed;
142         int                    *_enumIndexStore;
143 };
144
145 /*! \internal \brief
146  * Converts, validates, and stores file names.
147  */
148 class FileNameOptionStorage : public OptionStorageTemplate<std::string>
149 {
150     public:
151         //! \copydoc StringOptionStorage::StringOptionStorage()
152         FileNameOptionStorage(const FileNameOption &settings, Options *options);
153
154         virtual const char *typeString() const { return "file"; }
155         virtual std::string formatValue(int i) const;
156
157     private:
158         virtual void convertValue(const std::string &value);
159
160         OptionFileType          _filetype;
161 };
162
163 /*!\}*/
164
165 } // namespace gmx
166
167 #endif