All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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 /**
35  @file DoubleValue.hpp
36 
37  @author Jean-Christophe FABRE <jean-christophe.fabre@supagro.inra.fr>
38  */
39 
40 
41 #ifndef __OPENFLUID_CORE_DOUBLEVALUE_HPP__
42 #define __OPENFLUID_CORE_DOUBLEVALUE_HPP__
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() : m_Value(0.0) {};
114 
115  /**
116  Copy constructor
117  */
118  DoubleValue(const DoubleValue& Val) : SimpleValue(Val), m_Value(Val.m_Value)
119  { };
120 
121 
122  /**
123  Constructor from plain old type
124  */
125  DoubleValue(const double& POD) : SimpleValue(), m_Value(POD)
126  { };
127 
128  Value& operator =(const Value& Other);
129 
130  /**
131  Cast operator
132  */
133  operator double() const
134  { return m_Value; };
135 
136  virtual ~DoubleValue()
137  { };
138 
139  inline Type getType() const
140  { return Value::DOUBLE; };
141 
142  Value* clone() const
143  { return new DoubleValue(*this); };
144 
145  bool convert(Value& Val) const;
146 
147  /**
148  Returns the double value as plain old type
149  @return the double value
150  */
151  inline double get() const
152  { return m_Value; };
153 
154  /**
155  Sets the plain old type double value
156  @param[in] Val the double value
157  */
158  inline void set(const double& Val)
159  { m_Value = Val; };
160 
161  void writeToStream(std::ostream& OutStm) const;
162 
163  void writeQuotedToStream(std::ostream& OutStm) const
164  { writeToStream(OutStm); }
165 
166 };
167 
168 
169 } } // namespaces
170 
171 
172 #endif /* __OPENFLUID_CORE_DOUBLEVALUE_HPP__ */
DoubleValue(const double &POD)
Definition: DoubleValue.hpp:125
Definition: SimpleValue.hpp:50
virtual ~DoubleValue()
Definition: DoubleValue.hpp:136
Type getType() const
Definition: DoubleValue.hpp:139
Definition: Value.hpp:64
Definition: Value.hpp:68
Definition: DoubleValue.hpp:102
Value * clone() const
Definition: DoubleValue.hpp:142
DoubleValue(const DoubleValue &Val)
Definition: DoubleValue.hpp:118
DoubleValue()
Definition: DoubleValue.hpp:113
Type
Definition: Value.hpp:68
void set(const double &Val)
Definition: DoubleValue.hpp:158
#define OPENFLUID_API
Definition: dllexport.hpp:87
void writeQuotedToStream(std::ostream &OutStm) const
Definition: DoubleValue.hpp:163