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