DoubleValue.hpp
Go to the documentation of this file.
1 /*
2 
3  This file is part of OpenFLUID software
4  Copyright(c) 2007, INRA - Montpellier SupAgro
5 
6 
7  == GNU General Public License Usage ==
8 
9  OpenFLUID is free software: you can redistribute it and/or modify
10  it under the terms of the GNU General Public License as published by
11  the Free Software Foundation, either version 3 of the License, or
12  (at your option) any later version.
13 
14  OpenFLUID is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  GNU General Public License for more details.
18 
19  You should have received a copy of the GNU General Public License
20  along with OpenFLUID. If not, see <http://www.gnu.org/licenses/>.
21 
22 
23  == Other Usage ==
24 
25  Other Usage means a use of OpenFLUID that is inconsistent with the GPL
26  license, and requires a written agreement between You and INRA.
27  Licensees for Other Usage of OpenFLUID may use this file in accordance
28  with the terms contained in the written agreement between You and INRA.
29 
30 */
31 
32 
33 /**
34  @file DoubleValue.hpp
35 
36  @author Jean-Christophe FABRE <jean-christophe.fabre@inra.fr>
37 */
38 
39 
40 #ifndef __OPENFLUID_CORE_DOUBLEVALUE_HPP__
41 #define __OPENFLUID_CORE_DOUBLEVALUE_HPP__
42 
43 
45 #include <openfluid/dllexport.hpp>
46 
47 
48 namespace openfluid { namespace core {
49 /**
50 DoubleValue is a container for a signed double precision floating point value.\n
51 
52 \see Value
53 
54 \n
55 
56 <I>Example : declaration</I>
57 @code
58  // declaration of a DoubleValue, initialized to 0.0 by default
59  openfluid::core::DoubleValue Val1;
60 
61  // declaration of a DoubleValue, initialized to 1.357
62  openfluid::core::DoubleValue Val2(1.357);
63 @endcode
64 
65 
66 <I>Example : getting the contained value</I>
67 @code
68  double Tmp1;
69 
70  // using the get method
71  Tmp1 = Val1.get();
72 
73  // or using the cast operator
74  Tmp1 = Val1;
75 @endcode
76 
77 
78 <I>Example : setting the contained value</I>
79 @code
80  // using the set method
81  Val1.set(101.99);
82 @endcode
83 
84 
85 <I>Example : conversion from string</I>
86 @code
87  openfluid::core::StringValue StringVal("57.33");
88 
89  // to DoubleValue
90  Val1 = StringVal.toDoubleValue();
91 
92  // to double
93  double DblVal = StringVal.toDouble();
94 @endcode
95 
96 
97 <I>Example : conversion to string</I>
98 @code
99  std::string StdStrVal = Val1.toString();
100 @endcode
101 */
103 {
104  private:
105 
106  double m_Value;
107 
108  public:
109 
110  /**
111  Default constructor
112  */
113  DoubleValue() : SimpleValue(), m_Value(0.0)
114  { }
115 
116  /**
117  Copy constructor
118  */
119  DoubleValue(const DoubleValue& Val) : SimpleValue(), m_Value(Val.m_Value)
120  { }
121 
122  /**
123  Constructor from plain old type
124  */
125  DoubleValue(const double& POD) : SimpleValue(), m_Value(POD)
126  { }
127 
128  virtual ~DoubleValue()
129  { }
130 
131  Value& operator =(const Value& Other);
132 
133  /**
134  Cast operator
135  */
136  operator double() const
137  {
138  return m_Value;
139  }
140 
141  inline Type getType() const
142  {
143  return Value::DOUBLE;
144  }
145 
146  Value* clone() const
147  {
148  return new DoubleValue(*this);
149  }
150 
151  bool convert(Value& Val) const;
152 
153  /**
154  Returns the double value as plain old type
155  @return the double value
156  */
157  inline double get() const
158  {
159  return m_Value;
160  }
161 
162  /**
163  Sets the plain old type double value
164  @param[in] Val the double value
165  */
166  inline void set(const double& Val)
167  {
168  m_Value = Val;
169  }
170 
171  void writeToStream(std::ostream& OutStm) const;
172 
173  void writeQuotedToStream(std::ostream& OutStm) const
174  {
175  writeToStream(OutStm);
176  }
177 
178 };
179 
180 
181 } } // namespaces
182 
183 
184 #endif /* __OPENFLUID_CORE_DOUBLEVALUE_HPP__ */
Definition: Value.hpp:64
Type
Definition: Value.hpp:68
Definition: SimpleValue.hpp:51
DoubleValue(const double &POD)
Definition: DoubleValue.hpp:125
Definition: ApplicationException.hpp:47
void writeQuotedToStream(std::ostream &OutStm) const
Definition: DoubleValue.hpp:173
Type getType() const
Definition: DoubleValue.hpp:141
DoubleValue(const DoubleValue &Val)
Definition: DoubleValue.hpp:119
DoubleValue()
Definition: DoubleValue.hpp:113
Value * clone() const
Definition: DoubleValue.hpp:146
Definition: DoubleValue.hpp:102
virtual ~DoubleValue()
Definition: DoubleValue.hpp:128
#define OPENFLUID_API
Definition: dllexport.hpp:86
Definition: Value.hpp:68