1 /*****************************************************************************
3 *****************************************************************************
4 * Copyright (C) 2003 the VideoLAN team
7 * Authors: Cyril Deguet <asmax@via.ecp.fr>
8 * Olivier Teulière <ipkiss@via.ecp.fr>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23 *****************************************************************************/
28 #include "variable.hpp"
29 #include "observer.hpp"
32 /// Interface for read-only boolean variable
33 class VarBool: public Variable, public Subject<VarBool, void *>
36 /// Get the variable type
37 virtual const string &getType() const { return m_type; }
39 /// Get the boolean value
40 virtual bool get() const = 0;
43 VarBool( intf_thread_t *pIntf ): Variable( pIntf ) {}
48 static const string m_type;
52 /// Constant true VarBool
53 class VarBoolTrue: public VarBool
56 VarBoolTrue( intf_thread_t *pIntf ): VarBool( pIntf ) {}
57 virtual ~VarBoolTrue() {}
58 virtual bool get() const { return true; }
62 /// Constant false VarBool
63 class VarBoolFalse: public VarBool
66 VarBoolFalse( intf_thread_t *pIntf ): VarBool( pIntf ) {}
67 virtual ~VarBoolFalse() {}
68 virtual bool get() const { return false; }
72 /// Boolean variable implementation (read/write)
73 class VarBoolImpl: public VarBool
76 VarBoolImpl( intf_thread_t *pIntf );
77 virtual ~VarBoolImpl() {}
79 // Get the boolean value
80 virtual bool get() const { return m_value; }
82 /// Set the internal value
83 virtual void set( bool value );
91 /// Conjunction of two boolean variables (AND)
92 class VarBoolAndBool: public VarBool, public Observer<VarBool, void*>
95 VarBoolAndBool( intf_thread_t *pIntf, VarBool &rVar1, VarBool &rVar2 );
96 virtual ~VarBoolAndBool();
98 // Get the boolean value
99 virtual bool get() const { return m_rVar1.get() && m_rVar2.get(); }
101 // Called when one of the observed variables is changed
102 void onUpdate( Subject<VarBool, void*> &rVariable, void* );
105 /// Boolean variables
106 VarBool &m_rVar1, &m_rVar2;
110 /// Disjunction of two boolean variables (OR)
111 class VarBoolOrBool: public VarBool, public Observer<VarBool, void*>
114 VarBoolOrBool( intf_thread_t *pIntf, VarBool &rVar1, VarBool &rVar2 );
115 virtual ~VarBoolOrBool();
117 // Get the boolean value
118 virtual bool get() const { return m_rVar1.get() || m_rVar2.get(); }
120 // Called when one of the observed variables is changed
121 void onUpdate( Subject<VarBool, void*> &rVariable, void* );
124 /// Boolean variables
125 VarBool &m_rVar1, &m_rVar2;
129 /// Negation of a boolean variable (NOT)
130 class VarNotBool: public VarBool, public Observer<VarBool, void*>
133 VarNotBool( intf_thread_t *pIntf, VarBool &rVar );
134 virtual ~VarNotBool();
136 // Get the boolean value
137 virtual bool get() const { return !m_rVar.get(); }
139 // Called when the observed variable is changed
140 void onUpdate( Subject<VarBool, void*> &rVariable, void* );