core/BooleanValue.hpp
Go to the documentation of this file.
00001 /*
00002 
00003   This file is part of OpenFLUID software
00004   Copyright(c) 2007, INRA - Montpellier SupAgro
00005 
00006 
00007  == GNU General Public License Usage ==
00008 
00009   OpenFLUID is free software: you can redistribute it and/or modify
00010   it under the terms of the GNU General Public License as published by
00011   the Free Software Foundation, either version 3 of the License, or
00012   (at your option) any later version.
00013 
00014   OpenFLUID is distributed in the hope that it will be useful,
00015   but WITHOUT ANY WARRANTY; without even the implied warranty of
00016   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017   GNU General Public License for more details.
00018 
00019   You should have received a copy of the GNU General Public License
00020   along with OpenFLUID. If not, see <http://www.gnu.org/licenses/>.
00021 
00022 
00023  == Other Usage ==
00024 
00025   Other Usage means a use of OpenFLUID that is inconsistent with the GPL
00026   license, and requires a written agreement between You and INRA.
00027   Licensees for Other Usage of OpenFLUID may use this file in accordance
00028   with the terms contained in the written agreement between You and INRA.
00029   
00030 */
00031 
00032 
00033 
00034 /**
00035   \file BooleanValue.hpp
00036   \brief Header of ...
00037 
00038   \author Jean-Christophe FABRE <fabrejc@supagro.inra.fr>
00039  */
00040 
00041 
00042 #ifndef __BOOLEANVALUE_HPP___
00043 #define __BOOLEANVALUE_HPP___
00044 
00045 #include <openfluid/core/SimpleValue.hpp>
00046 #include <openfluid/dllexport.hpp>
00047 
00048 
00049 namespace openfluid { namespace core {
00050 
00051 /**
00052 BooleanValue is a container for a true/false value.\n
00053 
00054 \see Value
00055 
00056 \n
00057 
00058 <I>Example : declaration</I>
00059 @code
00060   // declaration of a BooleanValue, initialized to false by default
00061   openfluid::core::BooleanValue Val1;
00062 
00063   // declaration of a BooleanValue, initialized to true
00064   openfluid::core::BooleanValue Val2(true);
00065 @endcode
00066 
00067 
00068 <I>Example : getting the contained value</I>
00069 @code
00070   bool Tmp1;
00071 
00072   // using the get method
00073   Tmp1 = Val1.get();
00074 
00075   // or using the cast operator
00076   Tmp1 = Val1;
00077 @endcode
00078 
00079 
00080 <I>Example : setting the contained value</I>
00081 @code
00082   // using the set method
00083   Val1.set(true);
00084 @endcode
00085 
00086 
00087 <I>Example : conversion from string</I>
00088 @code
00089   openfluid::core::StringValue StringVal("true");
00090 
00091   // to BooleanValue
00092   Val1 = StringVal.toBooleanValue();
00093 
00094   // to bool
00095   bool BoolVal = StringVal.toBoolean();
00096 @endcode
00097 
00098 
00099 <I>Example : conversion to string</I>
00100 @code
00101   std::string StdStrVal = Val1.toString();
00102 @endcode
00103 */
00104 class DLLEXPORT BooleanValue : public SimpleValue
00105 {
00106   private:
00107 
00108     bool m_Value;
00109 
00110   public:
00111 
00112     /**
00113       Default constructor
00114     */
00115     BooleanValue() : m_Value(false) {};
00116 
00117     /**
00118       Copy constructor
00119     */
00120     BooleanValue(const BooleanValue& Val) : SimpleValue(Val), m_Value(Val.m_Value) {};
00121 
00122     /**
00123       Constructor from plain old type
00124     */
00125     BooleanValue(const bool& POD) : SimpleValue(), m_Value(POD) {};
00126 
00127     Value& operator =(const Value& Other);
00128 
00129     /**
00130     * Cast operator
00131     */
00132     operator bool() const { return m_Value; };
00133 
00134     virtual ~BooleanValue() {};
00135 
00136     inline Type getType() const { return Value::BOOLEAN; };
00137 
00138     Value* clone() const { return new BooleanValue(*this); };
00139 
00140     /**
00141       Returns the boolean value as plain old type
00142       @return the boolean value
00143     */
00144     inline bool& get() { return m_Value; };
00145 
00146     /**
00147       Returns the boolean value as a const plain old type
00148       @return the boolean value
00149     */
00150     inline const bool& get() const { return m_Value; };
00151 
00152     /**
00153       Sets the plain old type boolean value
00154       @param[in] Val the boolean value
00155     */
00156     inline void set(const bool& Val) { m_Value = Val; };
00157 
00158     void writeToStream(std::ostream& OutStm) const;
00159 
00160 };
00161 
00162 
00163 } }  // namespaces
00164 
00165 
00166 
00167 #endif /* __BOOLEANVALUE_HPP___ */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines