MythTV  master
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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  void Activation(MHEngine *engine) override; // MHRoot
39 };
40 
41 class MHBooleanVar : public MHVariable
42 {
43  public:
44  MHBooleanVar() = default;
45  const char *ClassName() override // MHRoot
46  { return "BooleanVariable"; }
47  void Initialise(MHParseNode *p, MHEngine *engine) override; // MHIngredient
48  void PrintMe(FILE *fd, int nTabs) const override; // MHIngredient
49  virtual void Prepare() { m_fValue = m_fOriginalValue; }
50 
51  // Internal behaviours.
52  void Preparation(MHEngine *engine) override; // MHIngredient
53 
54  // Actions implemented
55  void TestVariable(int nOp, const MHUnion &parm, MHEngine *engine) override; // MHRoot
56  void GetVariableValue(MHUnion &value, MHEngine *) override; // MHRoot
57  void SetVariableValue(const MHUnion &value) override; // MHRoot
58 
59  protected:
60  bool m_fOriginalValue {false};
61  bool m_fValue {false};
62 };
63 
64 class MHIntegerVar : public MHVariable
65 {
66  public:
67  MHIntegerVar() = default;
68  const char *ClassName() override // MHRoot
69  { return "IntegerVariable"; }
70  void Initialise(MHParseNode *p, MHEngine *engine) override; // MHIngredient
71  void PrintMe(FILE *fd, int nTabs) const override; // MHIngredient
72  virtual void Prepare() { m_nValue = m_nOriginalValue; }
73 
74  // Internal behaviours.
75  void Preparation(MHEngine *engine) override; // MHIngredient
76 
77  // Actions implemented
78  void TestVariable(int nOp, const MHUnion &parmm, MHEngine *engine) override; // MHRoot
79  void GetVariableValue(MHUnion &value, MHEngine *) override; // MHRoot
80  void SetVariableValue(const MHUnion &value) override; // MHRoot
81  protected:
83  int m_nValue {0};
84 };
85 
86 class MHOctetStrVar : public MHVariable
87 {
88  public:
90  const char *ClassName() override // MHRoot
91  { return "OctetStringVariable"; }
92  void Initialise(MHParseNode *p, MHEngine *engine) override; // MHIngredient
93  void PrintMe(FILE *fd, int nTabs) const override; // MHIngredient
94  virtual void Prepare() { m_Value.Copy(m_OriginalValue); }
95 
96  // Internal behaviours.
97  void Preparation(MHEngine *engine) override; // MHIngredient
98 
99  // Actions implemented
100  void TestVariable(int nOp, const MHUnion &parm, MHEngine *engine) override; // MHRoot
101  void GetVariableValue(MHUnion &value, MHEngine *) override; // MHRoot
102  void SetVariableValue(const MHUnion &value) override; // MHRoot
103  protected:
105 };
106 
107 class MHObjectRefVar : public MHVariable
108 {
109  public:
111  const char *ClassName() override // MHRoot
112  { return "ObjectRefVariable"; }
113  void Initialise(MHParseNode *p, MHEngine *engine) override; // MHIngredient
114  void PrintMe(FILE *fd, int nTabs) const override; // MHIngredient
115  virtual void Prepare() { m_Value.Copy(m_OriginalValue); }
116 
117  // Internal behaviours.
118  void Preparation(MHEngine *engine) override; // MHIngredient
119 
120  // Actions implemented
121  void TestVariable(int nOp, const MHUnion &parm, MHEngine *engine) override; // MHRoot
122  void GetVariableValue(MHUnion &value, MHEngine *) override; // MHRoot
123  void SetVariableValue(const MHUnion &value) override; // MHRoot
124  protected:
126 };
127 
129 {
130  public:
132  const char *ClassName() override // MHRoot
133  { return "ContentRefVariable"; }
134  void Initialise(MHParseNode *p, MHEngine *engine) override; // MHIngredient
135  void PrintMe(FILE *fd, int nTabs) const override; // MHIngredient
136  virtual void Prepare() { m_Value.Copy(m_OriginalValue); }
137 
138  // Internal behaviours.
139  void Preparation(MHEngine *engine) override; // MHIngredient
140 
141  // Actions implemented
142  void TestVariable(int nOp, const MHUnion &parm, MHEngine *engine) override; // MHRoot
143  void GetVariableValue(MHUnion &value, MHEngine *) override; // MHRoot
144  void SetVariableValue(const MHUnion &value) override; // MHRoot
145  protected:
147 };
148 
149 
150 // Set a variable to a value.
152 {
153  public:
154  MHSetVariable():MHElemAction(":SetVariable") {}
155  void Initialise(MHParseNode *p, MHEngine *engine) override; // MHElemAction
156  void Perform(MHEngine *engine) override; // MHElemAction
157  protected:
158  void PrintArgs(FILE *fd, int /*nTabs*/) const override // MHElemAction
159  { m_NewValue.PrintMe(fd, 0); }
160  MHParameter m_NewValue; // New value to store.
161 };
162 
163 // Compare a variable with a value and generate a TestEvent event on the result.
165 {
166  public:
167  MHTestVariable(): MHElemAction(":TestVariable"), m_nOperator(0) {}
168  void Initialise(MHParseNode *p, MHEngine *engine) override; // MHElemAction
169  void Perform(MHEngine *engine) override; // MHElemAction
170  protected:
171  void PrintArgs(FILE *fd, int nTabs) const override; // MHElemAction
173  MHParameter m_Comparison; // Value to compare with.
174 };
175 
176 // Integer actions.
177 
178 // Integer operations.
180 {
181  public:
183  void Initialise(MHParseNode *p, MHEngine *engine) override; // MHElemAction
184  void Perform(MHEngine *engine) override; // MHElemAction
185  protected:
186  void PrintArgs(FILE *fd, int /*nTabs*/) const override // MHElemAction
187  { m_Operand.PrintMe(fd, 0); }
188  virtual int DoOp(int arg1, int arg2) = 0; // Do the operation.
189  MHGenericInteger m_Operand; // Value to add, subtract etc.
190 };
191 
192 class MHAdd: public MHIntegerAction {
193  public:
194  MHAdd(): MHIntegerAction(":Add") {}
195  protected:
196  int DoOp(int arg1, int arg2) override // MHIntegerAction
197  { return arg1+arg2; }
198 };
199 
201  public:
202  MHSubtract(): MHIntegerAction(":Subtract") {}
203  protected:
204  int DoOp(int arg1, int arg2) override // MHIntegerAction
205  { return arg1-arg2; }
206 };
207 
209  public:
210  MHMultiply(): MHIntegerAction(":Multiply") {}
211  protected:
212  int DoOp(int arg1, int arg2) override // MHIntegerAction
213  { return arg1*arg2; }
214 };
215 
216 class MHDivide: public MHIntegerAction {
217  public:
218  MHDivide(): MHIntegerAction(":Divide") {}
219  protected:
220  int DoOp(int arg1, int arg2) override { // MHIntegerAction
221  if (arg2 == 0) throw "Divide by 0";
222  return arg1/arg2;
223  }
224 };
225 
226 class MHModulo: public MHIntegerAction {
227  public:
228  MHModulo(): MHIntegerAction(":Modulo") {}
229  protected:
230  int DoOp(int arg1, int arg2) override // MHIntegerAction
231  { return arg2 ? arg1%arg2 : 0; }
232 };
233 
234 // Append -
235 class MHAppend: public MHElemAction
236 {
237  public:
238  MHAppend(): MHElemAction(":Append") {}
239  void Initialise(MHParseNode *p, MHEngine *engine) override; // MHElemAction
240  void Perform(MHEngine *engine) override; // MHElemAction
241  protected:
242  void PrintArgs(FILE *fd, int /*nTabs*/) const override // MHElemAction
243  { m_Operand.PrintMe(fd, 0); }
244  MHGenericOctetString m_Operand; // Value to append.
245 };
246 
247 #endif
MHModulo()
Definition: Variables.h:228
const char * ClassName() override
Definition: Variables.h:45
virtual void Prepare()
Definition: Variables.h:115
int DoOp(int arg1, int arg2) override
Definition: Variables.h:230
void PrintMe(FILE *fd, int nTabs) const override
Definition: Variables.cpp:379
void TestVariable(int nOp, const MHUnion &parm, MHEngine *engine) override
Definition: Variables.cpp:302
void Initialise(MHParseNode *p, MHEngine *engine) override
Definition: Variables.cpp:580
void SetVariableValue(const MHUnion &value) override
Definition: Variables.cpp:218
virtual void Prepare()
Definition: Variables.h:136
void TestVariable(int nOp, const MHUnion &parm, MHEngine *engine) override
Definition: Variables.cpp:404
void Initialise(MHParseNode *p, MHEngine *engine) override
Definition: Variables.cpp:557
void GetVariableValue(MHUnion &value, MHEngine *) override
Definition: Variables.cpp:425
void PrintMe(FILE *fd, int nTabs) const
void Initialise(MHParseNode *p, MHEngine *engine) override
Definition: Variables.cpp:361
void SetVariableValue(const MHUnion &value) override
Definition: Variables.cpp:511
int DoOp(int arg1, int arg2) override
Definition: Variables.h:196
void Preparation(MHEngine *engine) override
Definition: Variables.cpp:392
MHVariable()
Definition: Variables.h:34
virtual void Prepare()
Definition: Variables.h:94
void Preparation(MHEngine *engine) override
Definition: Variables.cpp:91
MHAppend()
Definition: Variables.h:238
void PrintMe(FILE *fd, int nTabs) const override
Definition: Variables.cpp:277
MHContentRef m_OriginalValue
Definition: Variables.h:146
void PrintMe(FILE *fd, int nTabs) const override
Definition: Variables.cpp:153
MHContentRef m_Value
Definition: Variables.h:146
const char * ClassName() override
Definition: Variables.h:90
void GetVariableValue(MHUnion &value, MHEngine *) override
Definition: Variables.cpp:211
void Copy(const MHObjectRef &objr)
MHObjectRef m_OriginalValue
Definition: Variables.h:125
const char * ClassName() override
Definition: Variables.h:132
void PrintArgs(FILE *fd, int) const override
Definition: Variables.h:242
const char * ClassName() override
Definition: Variables.h:111
void TestVariable(int nOp, const MHUnion &parmm, MHEngine *engine) override
Definition: Variables.cpp:176
void GetVariableValue(MHUnion &value, MHEngine *) override
Definition: Variables.cpp:504
void TestVariable(int nOp, const MHUnion &parm, MHEngine *engine) override
Definition: Variables.cpp:103
void Activation(MHEngine *engine) override
Definition: Variables.cpp:56
int DoOp(int arg1, int arg2) override
Definition: Variables.h:220
MHOctetString m_Value
Definition: Variables.h:104
void Initialise(MHParseNode *p, MHEngine *engine) override
Definition: Variables.cpp:68
void Preparation(MHEngine *engine) override
Definition: Variables.cpp:290
void Copy(const MHContentRef &cr)
Definition: BaseClasses.h:180
void TestVariable(int nOp, const MHUnion &parm, MHEngine *engine) override
Definition: Variables.cpp:483
void PrintMe(FILE *fd, int nTabs) const override
Definition: Variables.cpp:458
int DoOp(int arg1, int arg2) override
Definition: Variables.h:212
void PrintMe(FILE *fd, int nTabs) const override
Definition: Variables.cpp:80
void Initialise(MHParseNode *p, MHEngine *engine) override
Definition: Variables.cpp:519
void SetVariableValue(const MHUnion &value) override
Definition: Variables.cpp:339
void Copy(const MHOctetString &str)
void Initialise(MHParseNode *p, MHEngine *engine) override
Definition: Variables.cpp:535
virtual void Prepare()
Definition: Variables.h:72
virtual ~MHVariable()
Definition: Variables.h:35
int m_nValue
Definition: Variables.h:83
void Perform(MHEngine *engine) override
Definition: Variables.cpp:564
MHIntegerAction(const char *name)
Definition: Variables.h:182
void GetVariableValue(MHUnion &value, MHEngine *) override
Definition: Variables.cpp:332
MHDivide()
Definition: Variables.h:218
void Initialise(MHParseNode *p, MHEngine *engine) override
Definition: Variables.cpp:440
bool m_fOriginalValue
Definition: Variables.h:60
const char * name
Definition: ParseText.cpp:328
void PrintMe(FILE *fd, int nTabs) const
int FILE
Definition: mythburn.py:110
void PrintArgs(FILE *fd, int) const override
Definition: Variables.h:158
MHBooleanVar()=default
MHIntegerVar()=default
MHGenericInteger m_Operand
Definition: Variables.h:189
int m_nOriginalValue
Definition: Variables.h:82
MHParameter m_NewValue
Definition: Variables.h:160
virtual void Prepare()
Definition: Variables.h:49
MHParameter m_Comparison
Definition: Variables.h:173
MHGenericOctetString m_Operand
Definition: Variables.h:244
void PrintArgs(FILE *fd, int nTabs) const override
Definition: Variables.cpp:542
void PrintArgs(FILE *fd, int) const override
Definition: Variables.h:186
const char * ClassName() override
Definition: Variables.h:68
void Perform(MHEngine *engine) override
Definition: Variables.cpp:586
int DoOp(int arg1, int arg2) override
Definition: Variables.h:204
void SetVariableValue(const MHUnion &value) override
Definition: Variables.cpp:432
bool m_fValue
Definition: Variables.h:61
MHObjectRef m_Value
Definition: Variables.h:125
void Preparation(MHEngine *engine) override
Definition: Variables.cpp:164
void Initialise(MHParseNode *p, MHEngine *engine) override
Definition: Variables.cpp:141
virtual int DoOp(int arg1, int arg2)=0
void Preparation(MHEngine *engine) override
Definition: Variables.cpp:471
void Perform(MHEngine *engine) override
Definition: Variables.cpp:548
void PrintMe(FILE *fd, int nTabs) const
MHOctetString m_OriginalValue
Definition: Variables.h:104
MHAdd()
Definition: Variables.h:194
void Initialise(MHParseNode *p, MHEngine *engine) override
Definition: Variables.cpp:265
void GetVariableValue(MHUnion &value, MHEngine *) override
Definition: Variables.cpp:126
void SetVariableValue(const MHUnion &value) override
Definition: Variables.cpp:133
void Perform(MHEngine *engine) override
Definition: Variables.cpp:525