File: value.h

package info (click to toggle)
gnome-chemistry-utils 0.14.9-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 17,836 kB
  • ctags: 7,337
  • sloc: cpp: 72,977; sh: 11,381; xml: 6,304; makefile: 1,663; ansic: 1,061
file content (228 lines) | stat: -rw-r--r-- 4,477 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
/*
 * Gnome Chemistry Utils
 * value.h
 *
 * Copyright (C) 2002-2008 Jean Bréfort <jean.brefort@normalesup.org>
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; either version 3 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301
 * USA
 */

#ifndef GCU_VALUE_H
#define GCU_VALUE_H

#include "chemistry.h"
#include <string>
#include <map>
#include <string>
#include <stdexcept>

/*!\file*/
namespace gcu
{

/*!\class Value gcu/value.h
Base class used for data storing.
*/
class Value
{
public:
/*!
Default constructor
*/
	Value ();
/*!
Default destructor
*/
	virtual ~Value ();

/*!
@return the value representation as a string.
*/
	virtual char const *GetAsString () const;

/*!
@return the value representation as a double or 0. if not a numeric value.
*/
	virtual double GetAsDouble () const;
};

/*!\class SimpleValue gcu/value.h
Used to store adimensional data.
*/
class SimpleValue: public Value
{
friend class Element;

public:
/*!
Default constructor
*/
	SimpleValue ();
/*!
@param value a GcuValue to embed.

Constructs a SimpleValue \a value.
*/
	SimpleValue (GcuValue value);
/*!
Default destructor
*/
	virtual ~SimpleValue ();

/*!
@return the literal representation of the embedded adimensional data
*/
	char const *GetAsString () const;
/*!
@return the embedded value.
*/
	double GetAsDouble () const;
/*!
@return the embedded GcuValue structure.
*/
	GcuValue const GetValue () {return val;}
/*!
@param value the value to add.

Adds two values.
@return the result of the addition.
*/
	SimpleValue operator+ (SimpleValue const &value) const;
/*!
@param n the number used to multiply.

Multiplies \a this by \a n.
@return the result of the multiplication.
*/
	SimpleValue operator* (int n) const;

private:
	GcuValue val;
	std::string str;
};
/*!\class DimensionalValue gcu/value.h
Used for data with a dimension e.g. a time interval expressed in days.
*/

class DimensionalValue: public Value
{
friend class Element;

public:
/*!
Default constructor
*/
	DimensionalValue ();
/*!
Default destructor
*/
	virtual ~DimensionalValue ();

/*!
@return the literal representation of the embedded dimensional data
*/
	char const *GetAsString () const;
/*!
@return the embedded value. Note that the unit is lost.
*/
	double GetAsDouble () const;
/*!
@param value the value to add.

Adds two values. They need to have the same dimension, otherwise an exception
will be thrown.
@return the result of the addition.
*/
	DimensionalValue operator+ (DimensionalValue const &value) const throw (std::invalid_argument);
/*!
@param n the number used to multiply.

Multiplies \a this by \a n.
@return the result of the multiplication.
*/
	DimensionalValue operator* (int n) const;
/*!
@return the embedded GcuDimensionalValue structure.
*/
	GcuDimensionalValue const GetValue () const {return val;}

private:
	GcuDimensionalValue val;
	std::string str;
};

/*!\class StringValue gcu/value.h
Used to store literal data.
*/
class StringValue: public Value
{
friend class Element;

public:
/*!
Default constructor
*/
	StringValue ();
/*!
Default destructor
*/
	virtual ~StringValue ();

/*!
@return the embedded string.
*/
	char const *GetAsString () const;

private:
	std::string val;
};

/*!\class LocalizedStringValue gcu/value.h
Used to store translatable strings.
*/
class LocalizedStringValue: public Value
{
friend class Element;

public:
/*!
Default constructor
*/
	LocalizedStringValue ();
/*!
Default destructor
*/
	virtual ~LocalizedStringValue ();

/*!
@return the string translated to the current locale if known, otherwise, the untranslated
string.
*/
	char const *GetAsString () const;
/*!
@param lang a locale name.
@return the string translated to the requested locale if known, otherwise, the untranslated
string.
*/
	char const *GetLocalizedString (char const *lang) const;

private:
	std::map <std::string, std::string> vals;
};

}	// namespace gcu

#endif	//	GCU_VALUE_H