Merge "Remove obsolete pointers in options handling."
[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         bool isTime() const { return bTime_; }
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 formatValue(int i) 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 /*! \internal \brief
161  * Converts, validates, and stores file names.
162  */
163 class FileNameOptionStorage : public OptionStorageTemplate<std::string>
164 {
165     public:
166         //! \copydoc StringOptionStorage::StringOptionStorage()
167         explicit FileNameOptionStorage(const FileNameOption &settings);
168
169         virtual OptionInfo &optionInfo() { return info_; }
170         virtual const char *typeString() const { return "file"; }
171         virtual std::string formatValue(int i) const;
172
173         bool isInputFile() const { return bRead_ && !bWrite_; }
174         bool isOutputFile() const { return !bRead_ && bWrite_; }
175         bool isInputOutputFile() const { return bRead_ && bWrite_; }
176         bool isLibraryFile() const { return bLibrary_; }
177
178     private:
179         virtual void convertValue(const std::string &value);
180
181         FileNameOptionInfo      info_;
182         OptionFileType          filetype_;
183         bool                    bRead_;
184         bool                    bWrite_;
185         bool                    bLibrary_;
186 };
187
188 /*!\}*/
189
190 } // namespace gmx
191
192 #endif