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