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          */
73         explicit BooleanOptionStorage(const BooleanOption &settings)
74             : MyBase(settings), info_(this)
75         {
76         }
77
78         virtual OptionInfo &optionInfo() { return info_; }
79         virtual const char *typeString() const { return "bool"; }
80         virtual std::string formatValue(int i) const;
81
82     private:
83         virtual void convertValue(const std::string &value);
84
85         BooleanOptionInfo       info_;
86 };
87
88 /*! \internal \brief
89  * Converts, validates, and stores integer values.
90  */
91 class IntegerOptionStorage : public OptionStorageTemplate<int>
92 {
93     public:
94         //! \copydoc BooleanOptionStorage::BooleanOptionStorage()
95         explicit IntegerOptionStorage(const IntegerOption &settings)
96             : MyBase(settings), info_(this)
97         {
98         }
99
100         virtual OptionInfo &optionInfo() { return info_; }
101         virtual const char *typeString() const
102         { return hasFlag(efVector) ? "vector" : "int"; }
103         virtual std::string formatValue(int i) const;
104
105     private:
106         virtual void convertValue(const std::string &value);
107         virtual void processSetValues(ValueList *values);
108
109         IntegerOptionInfo       info_;
110 };
111
112 /*! \internal \brief
113  * Converts, validates, and stores floating-point (double) values.
114  */
115 class DoubleOptionStorage : public OptionStorageTemplate<double>
116 {
117     public:
118         //! \copydoc IntegerOptionStorage::IntegerOptionStorage()
119         explicit DoubleOptionStorage(const DoubleOption &settings);
120
121         virtual OptionInfo &optionInfo() { return info_; }
122         virtual const char *typeString() const;
123         virtual std::string formatValue(int i) const;
124
125         //! \copydoc DoubleOptionInfo::isTime()
126         bool isTime() const { return bTime_; }
127         //! \copydoc DoubleOptionInfo::setScaleFactor()
128         void setScaleFactor(double factor);
129
130     private:
131         virtual void convertValue(const std::string &value);
132         virtual void processSetValues(ValueList *values);
133         virtual void processAll();
134
135         DoubleOptionInfo        info_;
136         bool                    bTime_;
137         double                  factor_;
138 };
139
140 /*! \internal \brief
141  * Converts, validates, and stores string values.
142  */
143 class StringOptionStorage : public OptionStorageTemplate<std::string>
144 {
145     public:
146         //! \copydoc DoubleOptionStorage::DoubleOptionStorage()
147         explicit StringOptionStorage(const StringOption &settings);
148
149         virtual OptionInfo &optionInfo() { return _info; }
150         virtual const char *typeString() const { return _allowed.empty() ? "string" : "enum"; }
151         virtual std::string formatValue(int i) const;
152
153     private:
154         virtual void convertValue(const std::string &value);
155         virtual void refreshValues();
156
157         StringOptionInfo        _info;
158         ValueList               _allowed;
159         int                    *_enumIndexStore;
160 };
161
162 /*! \internal \brief
163  * Converts, validates, and stores file names.
164  */
165 class FileNameOptionStorage : public OptionStorageTemplate<std::string>
166 {
167     public:
168         //! \copydoc StringOptionStorage::StringOptionStorage()
169         explicit FileNameOptionStorage(const FileNameOption &settings);
170
171         virtual OptionInfo &optionInfo() { return info_; }
172         virtual const char *typeString() const { return "file"; }
173         virtual std::string formatValue(int i) const;
174
175         //! \copydoc FileNameOptionInfo::isInputFile()
176         bool isInputFile() const { return bRead_ && !bWrite_; }
177         //! \copydoc FileNameOptionInfo::isOutputFile()
178         bool isOutputFile() const { return !bRead_ && bWrite_; }
179         //! \copydoc FileNameOptionInfo::isInputOutputFile()
180         bool isInputOutputFile() const { return bRead_ && bWrite_; }
181         //! \copydoc FileNameOptionInfo::isLibraryFile()
182         bool isLibraryFile() const { return bLibrary_; }
183
184     private:
185         virtual void convertValue(const std::string &value);
186
187         FileNameOptionInfo      info_;
188         OptionFileType          filetype_;
189         bool                    bRead_;
190         bool                    bWrite_;
191         bool                    bLibrary_;
192 };
193
194 /*!\}*/
195
196 } // namespace gmx
197
198 #endif