IntegerValue.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 IntegerValue.hpp
36 
37  @author Jean-Christophe FABRE <jean-christophe.fabre@supagro.inra.fr>
38  */
39 
40 
41 #ifndef __OPENFLUID_CORE_INTEGERVALUE_HPP__
42 #define __OPENFLUID_CORE_INTEGERVALUE_HPP__
43 
44 
45 
47 #include <openfluid/dllexport.hpp>
48 
49 
50 namespace openfluid { namespace core {
51 
52 /**
53 IntegerValue is a container for a signed long integer value.\n
54 
55 \see Value
56 
57 \n
58 
59 <I>Example : declaration</I>
60 @code
61  // declaration of an IntegerValue, initialized to 0 by default
62  openfluid::core::IntegerValue Val1;
63 
64  // declaration of an IntegerValue, initialized to 35
65  openfluid::core::IntegerValue Val2(35);
66 @endcode
67 
68 
69 <I>Example : getting the contained value</I>
70 @code
71  long Tmp1;
72 
73  // using the get method
74  Tmp1 = Val1.get();
75 
76  // or using the cast operator
77  Tmp1 = Val1;
78 @endcode
79 
80 
81 <I>Example : setting the contained value</I>
82 @code
83  // using the set method
84  Val1.set(-10199);
85 @endcode
86 
87 
88 <I>Example : conversion from string</I>
89 @code
90  openfluid::core::StringValue StringVal("57");
91 
92  // to IntegerValue
93  Val1 = StringVal.toIntegerValue();
94 
95  // to long
96  long LongVal = StringVal.toInteger();
97 @endcode
98 
99 
100 <I>Example : conversion to string</I>
101 @code
102  std::string StdStrVal = Val1.toString();
103 @endcode
104 */
106 {
107  private:
108 
109  long m_Value;
110 
111  public:
112 
113  /**
114  Default constructor
115  */
116  IntegerValue() : SimpleValue(), m_Value(0)
117  { }
118 
119  /**
120  Copy constructor
121  */
122  IntegerValue(const IntegerValue& Val) : SimpleValue(), m_Value(Val.m_Value)
123  { }
124 
125  /**
126  Constructor from plain old type
127  */
128  IntegerValue(const long& POD) : SimpleValue(), m_Value(POD)
129  { }
130 
131  virtual ~IntegerValue()
132  { }
133 
134  Value& operator =(const Value& Other);
135 
136  /**
137  * Cast operator
138  */
139  operator long() const
140  { return m_Value; }
141 
142  inline Type getType() const
143  { return Value::INTEGER; }
144 
145  Value* clone() const
146  { return new IntegerValue(*this); };
147 
148  bool convert(Value& Val) const;
149 
150  /**
151  Returns the integer value as a plain old type
152  @return the integer value
153  */
154  inline long get() const
155  { return m_Value; }
156 
157  /**
158  Sets the plain old type long integer value
159  @param[in] Val the long integer value
160  */
161  inline void set(const long& Val)
162  { m_Value = Val; }
163 
164  void writeToStream(std::ostream& OutStm) const;
165 
166  void writeQuotedToStream(std::ostream& OutStm) const
167  { writeToStream(OutStm); }
168 
169 };
170 
171 
172 } } // namespaces
173 
174 
175 #endif /* __OPENFLUID_CORE_INTEGERVALUE_HPP__ */
#define OPENFLUID_API
Definition: dllexport.hpp:87
Value * clone() const
Definition: IntegerValue.hpp:145
Type
Definition: Value.hpp:68
IntegerValue(const IntegerValue &Val)
Definition: IntegerValue.hpp:122
IntegerValue(const long &POD)
Definition: IntegerValue.hpp:128
virtual ~IntegerValue()
Definition: IntegerValue.hpp:131
Definition: ApplicationException.hpp:47
Definition: IntegerValue.hpp:105
Type getType() const
Definition: IntegerValue.hpp:142
Definition: SimpleValue.hpp:50
Definition: Value.hpp:64
void writeQuotedToStream(std::ostream &OutStm) const
Definition: IntegerValue.hpp:166
Definition: Value.hpp:68
IntegerValue()
Definition: IntegerValue.hpp:116