BooleanValue.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 BooleanValue.hpp
36 
37  @author Jean-Christophe FABRE <jean-christophe.fabre@supagro.inra.fr>
38  */
39 
40 
41 #ifndef __OPENFLUID_CORE_BOOLEANVALUE_HPP__
42 #define __OPENFLUID_CORE_BOOLEANVALUE_HPP__
43 
45 #include <openfluid/dllexport.hpp>
46 
47 
48 namespace openfluid { namespace core {
49 
50 /**
51 BooleanValue is a container for a true/false value.\n
52 
53 \see Value
54 
55 \n
56 
57 <I>Example : declaration</I>
58 @code
59  // declaration of a BooleanValue, initialized to false by default
60  openfluid::core::BooleanValue Val1;
61 
62  // declaration of a BooleanValue, initialized to true
63  openfluid::core::BooleanValue Val2(true);
64 @endcode
65 
66 
67 <I>Example : getting the contained value</I>
68 @code
69  bool 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(true);
83 @endcode
84 
85 
86 <I>Example : conversion from string</I>
87 @code
88  openfluid::core::StringValue StringVal("true");
89 
90  // to BooleanValue
91  Val1 = StringVal.toBooleanValue();
92 
93  // to bool
94  bool BoolVal = StringVal.toBoolean();
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  bool m_Value;
108 
109  public:
110 
111  /**
112  Default constructor
113  */
114  BooleanValue() : SimpleValue(), m_Value(false)
115  { }
116 
117  /**
118  Copy constructor
119  */
120  BooleanValue(const BooleanValue& Val) : SimpleValue(), m_Value(Val.m_Value)
121  { }
122 
123  /**
124  Constructor from plain old type
125  */
126  BooleanValue(const bool& POD) : SimpleValue(), m_Value(POD)
127  { }
128 
129  virtual ~BooleanValue()
130  { }
131 
132  Value& operator =(const Value& Other);
133 
134  /**
135  * Cast operator
136  */
137  operator bool() const
138  { return m_Value; }
139 
140  inline Type getType() const
141  { return Value::BOOLEAN; }
142 
143  Value* clone() const
144  { return new BooleanValue(*this); }
145 
146  bool convert(Value& Val) const;
147 
148  /**
149  Returns the boolean value as plain old type
150  @return the boolean value
151  */
152  inline bool get() const
153  { return m_Value; }
154 
155  /**
156  Sets the plain old type boolean value
157  @param[in] Val the boolean value
158  */
159  inline void set(const bool& Val)
160  { m_Value = Val; }
161 
162  void writeToStream(std::ostream& OutStm) const;
163 
164  void writeQuotedToStream(std::ostream& OutStm) const
165  { writeToStream(OutStm); }
166 
167 };
168 
169 
170 } } // namespaces
171 
172 
173 
174 #endif /* __OPENFLUID_CORE_BOOLEANVALUE_HPP__ */
Type getType() const
Definition: BooleanValue.hpp:140
Definition: Value.hpp:64
void writeQuotedToStream(std::ostream &OutStm) const
Definition: BooleanValue.hpp:164
BooleanValue(const bool &POD)
Definition: BooleanValue.hpp:126
Definition: BooleanValue.hpp:103
Definition: Value.hpp:68
BooleanValue()
Definition: BooleanValue.hpp:114
BooleanValue(const BooleanValue &Val)
Definition: BooleanValue.hpp:120
virtual ~BooleanValue()
Definition: BooleanValue.hpp:129
Type
Definition: Value.hpp:68
Definition: ApplicationException.hpp:47
Value * clone() const
Definition: BooleanValue.hpp:143
#define OPENFLUID_API
Definition: dllexport.hpp:87
Definition: SimpleValue.hpp:50