MythTV  0.27pre
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Groups Pages
Variables.h
Go to the documentation of this file.
1 /* Variables.h
2 
3  Copyright (C) David C. J. Matthews 2004 dm at prolingua.co.uk
4 
5  This program is free software; you can redistribute it and/or
6  modify it under the terms of the GNU General Public License
7  as published by the Free Software Foundation; either version 2
8  of the License, or (at your option) any later version.
9 
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with this program; if not, write to the Free Software
17  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18  Or, point your browser to http://www.gnu.org/copyleft/gpl.html
19 
20 */
21 
22 #if !defined(VARIABLES_H)
23 #define VARIABLES_H
24 
25 #include "Ingredients.h"
26 // Dependencies
27 #include "Root.h"
28 #include "BaseClasses.h"
29 #include "BaseActions.h"
30 
31 class MHVariable : public MHIngredient
32 {
33  public:
35  virtual ~MHVariable() {}
36 
37  // Internal behaviours.
38  virtual void Activation(MHEngine *engine);
39 };
40 
41 class MHBooleanVar : public MHVariable
42 {
43  public:
45  virtual const char *ClassName() { return "BooleanVariable"; }
46  virtual void Initialise(MHParseNode *p, MHEngine *engine);
47  virtual void PrintMe(FILE *fd, int nTabs) const;
48  virtual void Prepare() { m_fValue = m_fOriginalValue; }
49 
50  // Internal behaviours.
51  virtual void Preparation(MHEngine *engine);
52 
53  // Actions implemented
54  virtual void TestVariable(int nOp, const MHUnion &parm, MHEngine *engine);
55  virtual void GetVariableValue(MHUnion &value, MHEngine *);
56  virtual void SetVariableValue(const MHUnion &value);
57 
58  protected:
60 };
61 
62 class MHIntegerVar : public MHVariable
63 {
64  public:
66  virtual const char *ClassName() { return "IntegerVariable"; }
67  virtual void Initialise(MHParseNode *p, MHEngine *engine);
68  virtual void PrintMe(FILE *fd, int nTabs) const;
69  virtual void Prepare() { m_nValue = m_nOriginalValue; }
70 
71  // Internal behaviours.
72  virtual void Preparation(MHEngine *engine);
73 
74  // Actions implemented
75  virtual void TestVariable(int nOp, const MHUnion &parmm, MHEngine *engine);
76  virtual void GetVariableValue(MHUnion &value, MHEngine *);
77  virtual void SetVariableValue(const MHUnion &value);
78  protected:
80 };
81 
82 class MHOctetStrVar : public MHVariable
83 {
84  public:
86  virtual const char *ClassName() { return "OctetStringVariable"; }
87  virtual void Initialise(MHParseNode *p, MHEngine *engine);
88  virtual void PrintMe(FILE *fd, int nTabs) const;
89  virtual void Prepare() { m_Value.Copy(m_OriginalValue); }
90 
91  // Internal behaviours.
92  virtual void Preparation(MHEngine *engine);
93 
94  // Actions implemented
95  virtual void TestVariable(int nOp, const MHUnion &parm, MHEngine *engine);
96  virtual void GetVariableValue(MHUnion &value, MHEngine *);
97  virtual void SetVariableValue(const MHUnion &value);
98  protected:
100 };
101 
102 class MHObjectRefVar : public MHVariable
103 {
104  public:
106  virtual const char *ClassName() { return "ObjectRefVariable"; }
107  virtual void Initialise(MHParseNode *p, MHEngine *engine);
108  virtual void PrintMe(FILE *fd, int nTabs) const;
109  virtual void Prepare() { m_Value.Copy(m_OriginalValue); }
110 
111  // Internal behaviours.
112  virtual void Preparation(MHEngine *engine);
113 
114  // Actions implemented
115  virtual void TestVariable(int nOp, const MHUnion &parm, MHEngine *engine);
116  virtual void GetVariableValue(MHUnion &value, MHEngine *);
117  virtual void SetVariableValue(const MHUnion &value);
118  protected:
120 };
121 
123 {
124  public:
126  virtual const char *ClassName() { return "ContentRefVariable"; }
127  virtual void Initialise(MHParseNode *p, MHEngine *engine);
128  virtual void PrintMe(FILE *fd, int nTabs) const;
129  virtual void Prepare() { m_Value.Copy(m_OriginalValue); }
130 
131  // Internal behaviours.
132  virtual void Preparation(MHEngine *engine);
133 
134  // Actions implemented
135  virtual void TestVariable(int nOp, const MHUnion &parm, MHEngine *engine);
136  virtual void GetVariableValue(MHUnion &value, MHEngine *);
137  virtual void SetVariableValue(const MHUnion &value);
138  protected:
140 };
141 
142 
143 // Set a variable to a value.
145 {
146  public:
147  MHSetVariable():MHElemAction(":SetVariable") {}
148  virtual void Initialise(MHParseNode *p, MHEngine *engine);
149  virtual void Perform(MHEngine *engine);
150  protected:
151  virtual void PrintArgs(FILE *fd, int /*nTabs*/) const { m_NewValue.PrintMe(fd, 0); }
152  MHParameter m_NewValue; // New value to store.
153 };
154 
155 // Compare a variable with a value and generate a TestEvent event on the result.
157 {
158  public:
159  MHTestVariable(): MHElemAction(":TestVariable"), m_nOperator(0) {}
160  virtual void Initialise(MHParseNode *p, MHEngine *engine);
161  virtual void Perform(MHEngine *engine);
162  protected:
163  virtual void PrintArgs(FILE *fd, int nTabs) const;
165  MHParameter m_Comparison; // Value to compare with.
166 };
167 
168 // Integer actions.
169 
170 // Integer operations.
172 {
173  public:
174  MHIntegerAction(const char *name): MHElemAction(name) {}
175  virtual void Initialise(MHParseNode *p, MHEngine *engine);
176  virtual void Perform(MHEngine *engine);
177  protected:
178  virtual void PrintArgs(FILE *fd, int /*nTabs*/) const { m_Operand.PrintMe(fd, 0); }
179  virtual int DoOp(int arg1, int arg2) = 0; // Do the operation.
180  MHGenericInteger m_Operand; // Value to add, subtract etc.
181 };
182 
183 class MHAdd: public MHIntegerAction {
184  public:
185  MHAdd(): MHIntegerAction(":Add") {}
186  protected:
187  virtual int DoOp(int arg1, int arg2) { return arg1+arg2; }
188 };
189 
191  public:
192  MHSubtract(): MHIntegerAction(":Subtract") {}
193  protected:
194  virtual int DoOp(int arg1, int arg2) { return arg1-arg2; }
195 };
196 
198  public:
199  MHMultiply(): MHIntegerAction(":Multiply") {}
200  protected:
201  virtual int DoOp(int arg1, int arg2) { return arg1*arg2; }
202 };
203 
204 class MHDivide: public MHIntegerAction {
205  public:
206  MHDivide(): MHIntegerAction(":Divide") {}
207  protected:
208  virtual int DoOp(int arg1, int arg2) {
209  if (arg2 == 0) throw "Divide by 0";
210  return arg1/arg2;
211  }
212 };
213 
214 class MHModulo: public MHIntegerAction {
215  public:
216  MHModulo(): MHIntegerAction(":Modulo") {}
217  protected:
218  virtual int DoOp(int arg1, int arg2) { return arg2 ? arg1%arg2 : 0; }
219 };
220 
221 // Append -
222 class MHAppend: public MHElemAction
223 {
224  public:
225  MHAppend(): MHElemAction(":Append") {}
226  virtual void Initialise(MHParseNode *p, MHEngine *engine);
227  virtual void Perform(MHEngine *engine);
228  protected:
229  virtual void PrintArgs(FILE *fd, int /*nTabs*/) const { m_Operand.PrintMe(fd, 0); }
230  MHGenericOctetString m_Operand; // Value to append.
231 };
232 
233 #endif