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:
34  MHVariable() = default;
35  ~MHVariable() override = default;
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 *engine) 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 *engine) 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:
89  MHOctetStrVar() = default;
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 *engine) override; // MHRoot
102  void SetVariableValue(const MHUnion &value) override; // MHRoot
103  protected:
105 };
106 
107 class MHObjectRefVar : public MHVariable
108 {
109  public:
110  MHObjectRefVar() = default;
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 *engine) override; // MHRoot
123  void SetVariableValue(const MHUnion &value) override; // MHRoot
124  protected:
126 };
127 
129 {
130  public:
131  MHContentRefVar() = default;
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 *engine) 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") {}
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
172  int m_nOperator {0};
173  MHParameter m_comparison; // Value to compare with.
174 };
175 
176 // Integer actions.
177 
178 // Integer operations.
180 {
181  public:
182  explicit MHIntegerAction(const char *name): MHElemAction(name) {}
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
MHContentRefVar::Preparation
void Preparation(MHEngine *engine) override
Definition: Variables.cpp:475
MHObjectRef
Definition: BaseClasses.h:153
MHObjectRef::Copy
void Copy(const MHObjectRef &objr)
Definition: BaseClasses.cpp:308
MHGenericOctetString
Definition: BaseClasses.h:224
MHSetVariable::m_newValue
MHParameter m_newValue
Definition: Variables.h:160
MHTestVariable::m_comparison
MHParameter m_comparison
Definition: Variables.h:173
MHVariable::Activation
void Activation(MHEngine *engine) override
Definition: Variables.cpp:57
MHAppend
Definition: Variables.h:235
MHOctetStrVar::GetVariableValue
void GetVariableValue(MHUnion &value, MHEngine *engine) override
Definition: Variables.cpp:338
MHParameter
Definition: BaseClasses.h:258
MHVariable
Definition: Variables.h:31
MHAdd
Definition: Variables.h:192
MHSetVariable::Perform
void Perform(MHEngine *engine) override
Definition: Variables.cpp:530
MHSetVariable::Initialise
void Initialise(MHParseNode *p, MHEngine *engine) override
Definition: Variables.cpp:524
MHObjectRefVar::MHObjectRefVar
MHObjectRefVar()=default
MHObjectRefVar::m_value
MHObjectRef m_value
Definition: Variables.h:125
MHParameter::PrintMe
void PrintMe(FILE *fd, int nTabs) const
Definition: BaseClasses.cpp:719
MHEngine
Definition: Engine.h:72
MHBooleanVar::TestVariable
void TestVariable(int nOp, const MHUnion &parm, MHEngine *engine) override
Definition: Variables.cpp:104
MHIntegerVar::MHIntegerVar
MHIntegerVar()=default
MHBooleanVar::GetVariableValue
void GetVariableValue(MHUnion &value, MHEngine *engine) override
Definition: Variables.cpp:130
MHBooleanVar::Initialise
void Initialise(MHParseNode *p, MHEngine *engine) override
Definition: Variables.cpp:69
MHIntegerAction::PrintArgs
void PrintArgs(FILE *fd, int) const override
Definition: Variables.h:186
MHBooleanVar::MHBooleanVar
MHBooleanVar()=default
MHGenericInteger
Definition: BaseClasses.h:213
MHIntegerAction::Initialise
void Initialise(MHParseNode *p, MHEngine *engine) override
Definition: Variables.cpp:562
MHMultiply::MHMultiply
MHMultiply()
Definition: Variables.h:210
MHIntegerAction::MHIntegerAction
MHIntegerAction(const char *name)
Definition: Variables.h:182
MHSetVariable::MHSetVariable
MHSetVariable()
Definition: Variables.h:154
MHIntegerVar::ClassName
const char * ClassName() override
Definition: Variables.h:68
MHOctetString
Definition: BaseClasses.h:107
MHObjectRefVar::PrintMe
void PrintMe(FILE *fd, int nTabs) const override
Definition: Variables.cpp:382
mythburn.FILE
int FILE
Definition: mythburn.py:139
MHSubtract::DoOp
int DoOp(int arg1, int arg2) override
Definition: Variables.h:204
MHModulo::MHModulo
MHModulo()
Definition: Variables.h:228
MHBooleanVar::m_fValue
bool m_fValue
Definition: Variables.h:61
MHVariable::MHVariable
MHVariable()=default
MHIntegerVar::Initialise
void Initialise(MHParseNode *p, MHEngine *engine) override
Definition: Variables.cpp:146
MHAppend::Initialise
void Initialise(MHParseNode *p, MHEngine *engine) override
Definition: Variables.cpp:585
MHIntegerVar::m_nValue
int m_nValue
Definition: Variables.h:83
MHContentRefVar::Prepare
virtual void Prepare()
Definition: Variables.h:136
MHOctetStrVar
Definition: Variables.h:86
MHAdd::DoOp
int DoOp(int arg1, int arg2) override
Definition: Variables.h:196
MHTestVariable::Initialise
void Initialise(MHParseNode *p, MHEngine *engine) override
Definition: Variables.cpp:540
MHUnion
Definition: BaseClasses.h:283
MHBooleanVar::m_fOriginalValue
bool m_fOriginalValue
Definition: Variables.h:60
hardwareprofile.config.p
p
Definition: config.py:33
MHAppend::m_operand
MHGenericOctetString m_operand
Definition: Variables.h:244
MHBooleanVar
Definition: Variables.h:41
MHOctetStrVar::m_value
MHOctetString m_value
Definition: Variables.h:104
MHContentRefVar::SetVariableValue
void SetVariableValue(const MHUnion &value) override
Definition: Variables.cpp:515
MHContentRefVar::Initialise
void Initialise(MHParseNode *p, MHEngine *engine) override
Definition: Variables.cpp:444
MHOctetStrVar::Initialise
void Initialise(MHParseNode *p, MHEngine *engine) override
Definition: Variables.cpp:270
MHVariable::~MHVariable
~MHVariable() override=default
MHBooleanVar::SetVariableValue
void SetVariableValue(const MHUnion &value) override
Definition: Variables.cpp:137
MHModulo::DoOp
int DoOp(int arg1, int arg2) override
Definition: Variables.h:230
MHBooleanVar::Prepare
virtual void Prepare()
Definition: Variables.h:49
MHOctetStrVar::m_originalValue
MHOctetString m_originalValue
Definition: Variables.h:104
MHObjectRefVar::Initialise
void Initialise(MHParseNode *p, MHEngine *engine) override
Definition: Variables.cpp:364
MHTestVariable::m_nOperator
int m_nOperator
Definition: Variables.h:172
MHOctetStrVar::Prepare
virtual void Prepare()
Definition: Variables.h:94
MHObjectRefVar::Preparation
void Preparation(MHEngine *engine) override
Definition: Variables.cpp:395
MHOctetStrVar::MHOctetStrVar
MHOctetStrVar()=default
MHContentRefVar::PrintMe
void PrintMe(FILE *fd, int nTabs) const override
Definition: Variables.cpp:462
MHAppend::PrintArgs
void PrintArgs(FILE *fd, int) const override
Definition: Variables.h:242
MHIntegerAction::Perform
void Perform(MHEngine *engine) override
Definition: Variables.cpp:569
MHObjectRefVar::m_originalValue
MHObjectRef m_originalValue
Definition: Variables.h:125
MHSetVariable::PrintArgs
void PrintArgs(FILE *fd, int) const override
Definition: Variables.h:158
MHIntegerVar::Prepare
virtual void Prepare()
Definition: Variables.h:72
MHContentRefVar::m_originalValue
MHContentRef m_originalValue
Definition: Variables.h:146
MHGenericOctetString::PrintMe
void PrintMe(FILE *fd, int nTabs) const
Definition: BaseClasses.cpp:476
MHDivide
Definition: Variables.h:216
MHBooleanVar::ClassName
const char * ClassName() override
Definition: Variables.h:45
Ingredients.h
MHSubtract
Definition: Variables.h:200
MHIntegerAction::m_operand
MHGenericInteger m_operand
Definition: Variables.h:189
MHDivide::DoOp
int DoOp(int arg1, int arg2) override
Definition: Variables.h:220
MHDivide::MHDivide
MHDivide()
Definition: Variables.h:218
MHIntegerVar::m_nOriginalValue
int m_nOriginalValue
Definition: Variables.h:82
MHIngredient
Definition: Ingredients.h:33
MHIntegerAction::DoOp
virtual int DoOp(int arg1, int arg2)=0
MHObjectRefVar::Prepare
virtual void Prepare()
Definition: Variables.h:115
MHObjectRefVar::ClassName
const char * ClassName() override
Definition: Variables.h:111
Root.h
MHContentRefVar::GetVariableValue
void GetVariableValue(MHUnion &value, MHEngine *engine) override
Definition: Variables.cpp:508
MHContentRefVar::TestVariable
void TestVariable(int nOp, const MHUnion &parm, MHEngine *engine) override
Definition: Variables.cpp:487
MHAdd::MHAdd
MHAdd()
Definition: Variables.h:194
MHContentRef
Definition: BaseClasses.h:174
MHContentRefVar::MHContentRefVar
MHContentRefVar()=default
MHOctetStrVar::PrintMe
void PrintMe(FILE *fd, int nTabs) const override
Definition: Variables.cpp:282
MHContentRefVar::m_value
MHContentRef m_value
Definition: Variables.h:146
MHMultiply
Definition: Variables.h:208
BaseClasses.h
MHSetVariable
Definition: Variables.h:151
MHTestVariable::PrintArgs
void PrintArgs(FILE *fd, int nTabs) const override
Definition: Variables.cpp:547
MHIntegerVar::PrintMe
void PrintMe(FILE *fd, int nTabs) const override
Definition: Variables.cpp:158
MHIntegerVar::TestVariable
void TestVariable(int nOp, const MHUnion &parmm, MHEngine *engine) override
Definition: Variables.cpp:181
MHContentRefVar
Definition: Variables.h:128
MHParseNode
Definition: ParseNode.h:38
MHTestVariable
Definition: Variables.h:164
MHBooleanVar::PrintMe
void PrintMe(FILE *fd, int nTabs) const override
Definition: Variables.cpp:81
MHGenericInteger::PrintMe
void PrintMe(FILE *fd, int nTabs) const
Definition: BaseClasses.cpp:397
MHModulo
Definition: Variables.h:226
MHAppend::Perform
void Perform(MHEngine *engine) override
Definition: Variables.cpp:591
MHOctetStrVar::Preparation
void Preparation(MHEngine *engine) override
Definition: Variables.cpp:295
MHElemAction
Definition: BaseActions.h:34
MHObjectRefVar
Definition: Variables.h:107
MHAppend::MHAppend
MHAppend()
Definition: Variables.h:238
MHObjectRefVar::TestVariable
void TestVariable(int nOp, const MHUnion &parm, MHEngine *engine) override
Definition: Variables.cpp:407
MHSubtract::MHSubtract
MHSubtract()
Definition: Variables.h:202
MHObjectRefVar::GetVariableValue
void GetVariableValue(MHUnion &value, MHEngine *engine) override
Definition: Variables.cpp:428
MHContentRef::Copy
void Copy(const MHContentRef &cr)
Definition: BaseClasses.h:183
MHIntegerVar::GetVariableValue
void GetVariableValue(MHUnion &value, MHEngine *engine) override
Definition: Variables.cpp:216
MHMultiply::DoOp
int DoOp(int arg1, int arg2) override
Definition: Variables.h:212
MHIntegerVar::SetVariableValue
void SetVariableValue(const MHUnion &value) override
Definition: Variables.cpp:223
MHOctetStrVar::TestVariable
void TestVariable(int nOp, const MHUnion &parm, MHEngine *engine) override
Definition: Variables.cpp:307
MHTestVariable::Perform
void Perform(MHEngine *engine) override
Definition: Variables.cpp:553
MHOctetStrVar::SetVariableValue
void SetVariableValue(const MHUnion &value) override
Definition: Variables.cpp:345
BaseActions.h
MHIntegerAction
Definition: Variables.h:179
MHObjectRefVar::SetVariableValue
void SetVariableValue(const MHUnion &value) override
Definition: Variables.cpp:435
MHTestVariable::MHTestVariable
MHTestVariable()
Definition: Variables.h:167
MHOctetStrVar::ClassName
const char * ClassName() override
Definition: Variables.h:90
MHIntegerVar::Preparation
void Preparation(MHEngine *engine) override
Definition: Variables.cpp:169
MHOctetString::Copy
void Copy(const MHOctetString &str)
Definition: BaseClasses.cpp:119
MHContentRefVar::ClassName
const char * ClassName() override
Definition: Variables.h:132
MHIntegerVar
Definition: Variables.h:64
MHBooleanVar::Preparation
void Preparation(MHEngine *engine) override
Definition: Variables.cpp:92