var_bool.hpp

Go to the documentation of this file.
00001 /*****************************************************************************
00002  * var_bool.hpp
00003  *****************************************************************************
00004  * Copyright (C) 2003 the VideoLAN team
00005  * $Id: 4b0618ff57ee80e1beafdfc9fcabcd98bff147b4 $
00006  *
00007  * Authors: Cyril Deguet     <asmax@via.ecp.fr>
00008  *          Olivier Teulière <ipkiss@via.ecp.fr>
00009  *
00010  * This program is free software; you can redistribute it and/or modify
00011  * it under the terms of the GNU General Public License as published by
00012  * the Free Software Foundation; either version 2 of the License, or
00013  * (at your option) any later version.
00014  *
00015  * This program is distributed in the hope that it will be useful,
00016  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018  * GNU General Public License for more details.
00019  *
00020  * You should have received a copy of the GNU General Public License along
00021  * with this program; if not, write to the Free Software Foundation, Inc.,
00022  * 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
00023  *****************************************************************************/
00024 
00025 #ifndef VAR_BOOL_HPP
00026 #define VAR_BOOL_HPP
00027 
00028 #include "variable.hpp"
00029 #include "observer.hpp"
00030 
00031 
00032 /// Interface for read-only boolean variable
00033 class VarBool: public Variable, public Subject<VarBool>
00034 {
00035 public:
00036     /// Get the variable type
00037     virtual const string &getType() const { return m_type; }
00038 
00039     /// Get the boolean value
00040     virtual bool get() const = 0;
00041 
00042 protected:
00043     VarBool( intf_thread_t *pIntf ): Variable( pIntf ) { }
00044     virtual ~VarBool() { }
00045 
00046 private:
00047     /// Variable type
00048     static const string m_type;
00049 };
00050 
00051 
00052 /// Constant true VarBool
00053 class VarBoolTrue: public VarBool
00054 {
00055 public:
00056     VarBoolTrue( intf_thread_t *pIntf ): VarBool( pIntf ) { }
00057     virtual ~VarBoolTrue() { }
00058     virtual bool get() const { return true; }
00059 };
00060 
00061 
00062 /// Constant false VarBool
00063 class VarBoolFalse: public VarBool
00064 {
00065 public:
00066     VarBoolFalse( intf_thread_t *pIntf ): VarBool( pIntf ) { }
00067     virtual ~VarBoolFalse() { }
00068     virtual bool get() const { return false; }
00069 };
00070 
00071 
00072 /// Boolean variable implementation (read/write)
00073 class VarBoolImpl: public VarBool
00074 {
00075 public:
00076     VarBoolImpl( intf_thread_t *pIntf );
00077     virtual ~VarBoolImpl() { }
00078 
00079     // Get the boolean value
00080     virtual bool get() const { return m_value; }
00081 
00082     /// Set the internal value
00083     virtual void set( bool value );
00084 
00085 private:
00086     /// Boolean value
00087     bool m_value;
00088 };
00089 
00090 
00091 /// Conjunction of two boolean variables (AND)
00092 class VarBoolAndBool: public VarBool, public Observer<VarBool>
00093 {
00094 public:
00095     VarBoolAndBool( intf_thread_t *pIntf, VarBool &rVar1, VarBool &rVar2 );
00096     virtual ~VarBoolAndBool();
00097     virtual bool get() const { return m_rVar1.get() && m_rVar2.get(); }
00098 
00099     // Called when one of the observed variables is changed
00100     void onUpdate( Subject<VarBool> &rVariable, void* );
00101 
00102 private:
00103     /// Boolean variables
00104     VarBool &m_rVar1, &m_rVar2;
00105 };
00106 
00107 
00108 /// Disjunction of two boolean variables (OR)
00109 class VarBoolOrBool: public VarBool, public Observer<VarBool>
00110 {
00111 public:
00112     VarBoolOrBool( intf_thread_t *pIntf, VarBool &rVar1, VarBool &rVar2 );
00113     virtual ~VarBoolOrBool();
00114     virtual bool get() const { return m_rVar1.get() || m_rVar2.get(); }
00115 
00116     // Called when one of the observed variables is changed
00117     void onUpdate( Subject<VarBool> &rVariable, void* );
00118 
00119 private:
00120     /// Boolean variables
00121     VarBool &m_rVar1, &m_rVar2;
00122 };
00123 
00124 
00125 /// Negation of a boolean variable (NOT)
00126 class VarNotBool: public VarBool, public Observer<VarBool>
00127 {
00128 public:
00129     VarNotBool( intf_thread_t *pIntf, VarBool &rVar );
00130     virtual ~VarNotBool();
00131     virtual bool get() const { return !m_rVar.get(); }
00132 
00133     // Called when the observed variable is changed
00134     void onUpdate( Subject<VarBool> &rVariable, void* );
00135 
00136 private:
00137     /// Boolean variable
00138     VarBool &m_rVar;
00139 };
00140 
00141 
00142 #endif

Generated on Tue May 25 08:04:58 2010 for VLC by  doxygen 1.5.6