/*****************************************************************************
* var_bool.hpp
*****************************************************************************
- * Copyright (C) 2003 VideoLAN
- * $Id: var_bool.hpp,v 1.2 2004/01/11 17:12:17 asmax Exp $
+ * Copyright (C) 2003 the VideoLAN team
+ * $Id$
*
* Authors: Cyril Deguet <asmax@via.ecp.fr>
- * Olivier Teulière <ipkiss@via.ecp.fr>
+ * Olivier Teulière <ipkiss@via.ecp.fr>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
#ifndef VAR_BOOL_HPP
#include "observer.hpp"
-/// Percentage variable
+/// Interface for read-only boolean variable
class VarBool: public Variable, public Subject<VarBool>
{
public:
- VarBool( intf_thread_t *pIntf );
- virtual ~VarBool() {}
-
/// Get the variable type
virtual const string &getType() const { return m_type; }
- /// Set the internal value
- virtual void set( bool value );
- virtual bool get() const { return m_value; }
+ /// Get the boolean value
+ virtual bool get() const = 0;
+
+ protected:
+ VarBool( intf_thread_t *pIntf ): Variable( pIntf ) {}
+ virtual ~VarBool() {}
private:
/// Variable type
static const string m_type;
+};
+
+
+/// Constant true VarBool
+class VarBoolTrue: public VarBool
+{
+ public:
+ VarBoolTrue( intf_thread_t *pIntf ): VarBool( pIntf ) {}
+ virtual ~VarBoolTrue() {}
+ virtual bool get() const { return true; }
+};
+
+
+/// Constant false VarBool
+class VarBoolFalse: public VarBool
+{
+ public:
+ VarBoolFalse( intf_thread_t *pIntf ): VarBool( pIntf ) {}
+ virtual ~VarBoolFalse() {}
+ virtual bool get() const { return false; }
+};
+
+
+/// Boolean variable implementation (read/write)
+class VarBoolImpl: public VarBool
+{
+ public:
+ VarBoolImpl( intf_thread_t *pIntf );
+ virtual ~VarBoolImpl() {}
+
+ // Get the boolean value
+ virtual bool get() const { return m_value; }
+
+ /// Set the internal value
+ virtual void set( bool value );
+
+ private:
/// Boolean value
bool m_value;
};
+
+/// Conjunction of two boolean variables (AND)
+class VarBoolAndBool: public VarBool, public Observer<VarBool>
+{
+ public:
+ VarBoolAndBool( intf_thread_t *pIntf, VarBool &rVar1, VarBool &rVar2 );
+ virtual ~VarBoolAndBool();
+
+ // Get the boolean value
+ virtual bool get() const { return m_rVar1.get() && m_rVar2.get(); }
+
+ // Called when one of the observed variables is changed
+ void onUpdate( Subject<VarBool> &rVariable, void* );
+
+ private:
+ /// Boolean variables
+ VarBool &m_rVar1, &m_rVar2;
+};
+
+
+/// Disjunction of two boolean variables (OR)
+class VarBoolOrBool: public VarBool, public Observer<VarBool>
+{
+ public:
+ VarBoolOrBool( intf_thread_t *pIntf, VarBool &rVar1, VarBool &rVar2 );
+ virtual ~VarBoolOrBool();
+
+ // Get the boolean value
+ virtual bool get() const { return m_rVar1.get() || m_rVar2.get(); }
+
+ // Called when one of the observed variables is changed
+ void onUpdate( Subject<VarBool> &rVariable, void* );
+
+ private:
+ /// Boolean variables
+ VarBool &m_rVar1, &m_rVar2;
+};
+
+
+/// Negation of a boolean variable (NOT)
+class VarNotBool: public VarBool, public Observer<VarBool>
+{
+ public:
+ VarNotBool( intf_thread_t *pIntf, VarBool &rVar );
+ virtual ~VarNotBool();
+
+ // Get the boolean value
+ virtual bool get() const { return !m_rVar.get(); }
+
+ // Called when the observed variable is changed
+ void onUpdate( Subject<VarBool> &rVariable, void* );
+
+ private:
+ /// Boolean variable
+ VarBool &m_rVar;
+};
+
+
#endif