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