]> git.sesse.net Git - vlc/blob - modules/gui/skins2/utils/var_bool.hpp
2b086cfc7aa2341643a969564d27b5dd280d4ad2
[vlc] / modules / gui / skins2 / utils / var_bool.hpp
1 /*****************************************************************************
2  * var_bool.hpp
3  *****************************************************************************
4  * Copyright (C) 2003 the VideoLAN team
5  * $Id$
6  *
7  * Authors: Cyril Deguet     <asmax@via.ecp.fr>
8  *          Olivier Teulière <ipkiss@via.ecp.fr>
9  *
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.
14  *
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.
19  *
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  *****************************************************************************/
24
25 #ifndef VAR_BOOL_HPP
26 #define VAR_BOOL_HPP
27
28 #include "variable.hpp"
29 #include "observer.hpp"
30
31
32 /// Interface for read-only boolean variable
33 class VarBool: public Variable, public Subject<VarBool, void *>
34 {
35     public:
36         /// Get the variable type
37         virtual const string &getType() const { return m_type; }
38
39         /// Get the boolean value
40         virtual bool get() const = 0;
41
42     protected:
43         VarBool( intf_thread_t *pIntf ): Variable( pIntf ) {}
44         virtual ~VarBool() {}
45
46     private:
47         /// Variable type
48         static const string m_type;
49 };
50
51
52 /// Constant true VarBool
53 class VarBoolTrue: public VarBool
54 {
55     public:
56         VarBoolTrue( intf_thread_t *pIntf ): VarBool( pIntf ) {}
57         virtual ~VarBoolTrue() {}
58         virtual bool get() const { return true; }
59 };
60
61
62 /// Constant false VarBool
63 class VarBoolFalse: public VarBool
64 {
65     public:
66         VarBoolFalse( intf_thread_t *pIntf ): VarBool( pIntf ) {}
67         virtual ~VarBoolFalse() {}
68         virtual bool get() const { return false; }
69 };
70
71
72 /// Boolean variable implementation (read/write)
73 class VarBoolImpl: public VarBool
74 {
75     public:
76         VarBoolImpl( intf_thread_t *pIntf );
77         virtual ~VarBoolImpl() {}
78
79         // Get the boolean value
80         virtual bool get() const { return m_value; }
81
82         /// Set the internal value
83         virtual void set( bool value );
84
85     private:
86         /// Boolean value
87         bool m_value;
88 };
89
90
91 /// Conjunction of two boolean variables (AND)
92 class VarBoolAndBool: public VarBool, public Observer<VarBool, void*>
93 {
94     public:
95         VarBoolAndBool( intf_thread_t *pIntf, VarBool &rVar1, VarBool &rVar2 );
96         virtual ~VarBoolAndBool();
97
98         // Get the boolean value
99         virtual bool get() const { return m_rVar1.get() && m_rVar2.get(); }
100
101         // Called when one of the observed variables is changed
102         void onUpdate( Subject<VarBool, void*> &rVariable, void* );
103
104     private:
105         /// Boolean variables
106         VarBool &m_rVar1, &m_rVar2;
107 };
108
109
110 /// Disjunction of two boolean variables (OR)
111 class VarBoolOrBool: public VarBool, public Observer<VarBool, void*>
112 {
113     public:
114         VarBoolOrBool( intf_thread_t *pIntf, VarBool &rVar1, VarBool &rVar2 );
115         virtual ~VarBoolOrBool();
116
117         // Get the boolean value
118         virtual bool get() const { return m_rVar1.get() || m_rVar2.get(); }
119
120         // Called when one of the observed variables is changed
121         void onUpdate( Subject<VarBool, void*> &rVariable, void* );
122
123     private:
124         /// Boolean variables
125         VarBool &m_rVar1, &m_rVar2;
126 };
127
128
129 /// Negation of a boolean variable (NOT)
130 class VarNotBool: public VarBool, public Observer<VarBool, void*>
131 {
132     public:
133         VarNotBool( intf_thread_t *pIntf, VarBool &rVar );
134         virtual ~VarNotBool();
135
136         // Get the boolean value
137         virtual bool get() const { return !m_rVar.get(); }
138
139         // Called when the observed variable is changed
140         void onUpdate( Subject<VarBool, void*> &rVariable, void* );
141
142     private:
143         /// Boolean variable
144         VarBool &m_rVar;
145 };
146
147
148 #endif