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 "optionfiletype.h"
47 #include "optionstoragetemplate.h"
48
49 namespace gmx
50 {
51
52 class BooleanOption;
53 class IntegerOption;
54 class DoubleOption;
55 class StringOption;
56 class FileNameOption;
57
58 /*! \addtogroup module_options
59  * \{
60  */
61
62 /*! \internal \brief
63  * Converts, validates, and stores boolean values.
64  */
65 class BooleanOptionStorage : public OptionStorageTemplate<bool>
66 {
67     public:
68         /*! \brief
69          * Initializes the storage from option settings.
70          *
71          * \param[in] settings   Storage settings.
72          * \param[in] options    Options object.
73          */
74         BooleanOptionStorage(const BooleanOption &settings, Options *options)
75             : MyBase(settings, options), info_(this)
76         {
77         }
78
79         virtual OptionInfo &optionInfo() { return info_; }
80         virtual const char *typeString() const { return "bool"; }
81         virtual std::string formatValue(int i) 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         IntegerOptionStorage(const IntegerOption &settings, Options *options)
97             : MyBase(settings, options), info_(this)
98         {
99         }
100
101         virtual OptionInfo &optionInfo() { return info_; }
102         virtual const char *typeString() const
103         { return hasFlag(efVector) ? "vector" : "int"; }
104         virtual std::string formatValue(int i) 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         DoubleOptionStorage(const DoubleOption &settings, Options *options);
121
122         virtual OptionInfo &optionInfo() { return info_; }
123         virtual const char *typeString() const;
124         virtual std::string formatValue(int i) const;
125
126         bool isTime() const { return bTime_; }
127         void setScaleFactor(double factor);
128
129     private:
130         virtual void convertValue(const std::string &value);
131         virtual void processSetValues(ValueList *values);
132         virtual void processAll();
133
134         DoubleOptionInfo        info_;
135         bool                    bTime_;
136         double                  factor_;
137 };
138
139 /*! \internal \brief
140  * Converts, validates, and stores string values.
141  */
142 class StringOptionStorage : public OptionStorageTemplate<std::string>
143 {
144     public:
145         //! \copydoc DoubleOptionStorage::DoubleOptionStorage()
146         StringOptionStorage(const StringOption &settings, Options *options);
147
148         virtual OptionInfo &optionInfo() { return _info; }
149         virtual const char *typeString() const { return _allowed.empty() ? "string" : "enum"; }
150         virtual std::string formatValue(int i) const;
151
152     private:
153         virtual void convertValue(const std::string &value);
154         virtual void refreshValues();
155
156         StringOptionInfo        _info;
157         ValueList               _allowed;
158         int                    *_enumIndexStore;
159 };
160
161 /*! \internal \brief
162  * Converts, validates, and stores file names.
163  */
164 class FileNameOptionStorage : public OptionStorageTemplate<std::string>
165 {
166     public:
167         //! \copydoc StringOptionStorage::StringOptionStorage()
168         FileNameOptionStorage(const FileNameOption &settings, Options *options);
169
170         virtual OptionInfo &optionInfo() { return info_; }
171         virtual const char *typeString() const { return "file"; }
172         virtual std::string formatValue(int i) const;
173
174         bool isInputFile() const { return bRead_ && !bWrite_; }
175         bool isOutputFile() const { return !bRead_ && bWrite_; }
176         bool isInputOutputFile() const { return bRead_ && bWrite_; }
177         bool isLibraryFile() const { return bLibrary_; }
178
179     private:
180         virtual void convertValue(const std::string &value);
181
182         FileNameOptionInfo      info_;
183         OptionFileType          filetype_;
184         bool                    bRead_;
185         bool                    bWrite_;
186         bool                    bLibrary_;
187 };
188
189 /*!\}*/
190
191 } // namespace gmx
192
193 #endif