MythTV  master
ParseNode.h
Go to the documentation of this file.
1 /* ParseNode.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 
23 #if !defined(PARSE_NODE_H)
24 #define PARSE_NODE_H
25 
26 #include "BaseClasses.h"
27 
28 class MHGroup;
29 
30 // Abstract base class for the text and binary parsers.
31 class MHParseBase {
32  public:
33  virtual ~MHParseBase() = default;
34  virtual MHParseNode *Parse() = 0;
35 };
36 
37 // Element of the parse tree, basically a piece of the program.
39 {
40  public:
42  protected:
43  explicit MHParseNode(enum NodeType nt): m_nNodeType(nt) {}
44  public:
45  virtual ~MHParseNode() = default;
47 
48  [[noreturn]] static void Failure(const char *p); // Report a parse failure.
49 
50  // Destructors - extract data and raise an exception if the Node Type is wrong.
51 
52  // Tagged
53  int GetTagNo();
54  int GetArgCount();
55  MHParseNode *GetArgN(int n);
56  MHParseNode *GetNamedArg(int nTag); // Also for sequence.
57 
58  // Sequence.
59  int GetSeqCount();
60  MHParseNode *GetSeqN(int n);
61 
62  // Int
63  int GetIntValue();
64  // Enum
65  int GetEnumValue();
66  // Bool
67  bool GetBoolValue();
68  // String
69  void GetStringValue(MHOctetString &str);
70 
71  void PrintMe(FILE *f);
72 };
73 
74 // Sequence of parse nodes.
75 class MHParseSequence: public MHParseNode, public MHOwnPtrSequence<MHParseNode>
76 {
77  public:
79  void PrintUnbracketed(int nTabs);
80 };
81 
82 // At the moment all tagged items, i.e. everything except a primitive constant, belong
83 // to this class. We will make derived classes in due course.
84 class MHPTagged: public MHParseNode
85 {
86  public:
87  explicit MHPTagged(int nTag)
88  : MHParseNode(PNTagged), m_TagNo(nTag) {}
89  void AddArg(MHParseNode *pArg);
90 
91  int m_TagNo;
93 };
94 
95 // Primitive integer value.
96 class MHPInt: public MHParseNode
97 {
98  public:
99  explicit MHPInt(int v): MHParseNode(PNInt), m_Value(v) {}
100 
101  public:
102  int m_Value;
103 };
104 
105 // Enumerated type - treat much as integer
106 class MHPEnum: public MHParseNode
107 {
108  public:
109  explicit MHPEnum(int v): MHParseNode(PNEnum), m_Value(v) {}
110  public:
111  int m_Value;
112 };
113 
114 // Primitive boolean value
115 class MHPBool: public MHParseNode
116 {
117  public:
118  explicit MHPBool(bool v): MHParseNode(PNBool), m_Value(v) {}
119 
120  public:
121  bool m_Value;
122 };
123 
124 // Primitive string value
125 class MHPString: public MHParseNode
126 {
127  public:
128  explicit MHPString(const MHOctetString &pSrc): MHParseNode(PNString) { m_Value.Copy(pSrc); }
129 
130  public:
132 };
133 
134 // ASN1 NULL value.
135 class MHPNull: public MHParseNode
136 {
137  public:
139 };
140 
141 void PrintTabs(FILE *fd, int nTabs); // Support function for printing.
142 
143 #endif
MHGroup
Definition: Groups.h:46
MHParseNode::m_nNodeType
enum NodeType m_nNodeType
Definition: ParseNode.h:46
MHParseNode::~MHParseNode
virtual ~MHParseNode()=default
MHParseBase::~MHParseBase
virtual ~MHParseBase()=default
MHParseNode::PrintMe
void PrintMe(FILE *f)
Definition: ParseNode.cpp:213
MHParseSequence::PrintUnbracketed
void PrintUnbracketed(int nTabs)
MHPTagged::MHPTagged
MHPTagged(int nTag)
Definition: ParseNode.h:87
MHParseNode::GetIntValue
int GetIntValue()
Definition: ParseNode.cpp:170
MHParseNode::GetSeqN
MHParseNode * GetSeqN(int n)
Definition: ParseNode.cpp:152
MHParseNode::PNEnum
@ PNEnum
Definition: ParseNode.h:41
MHParseNode::PNTagged
@ PNTagged
Definition: ParseNode.h:41
MHPTagged
Definition: ParseNode.h:84
MHParseNode::MHParseNode
MHParseNode(enum NodeType nt)
Definition: ParseNode.h:43
MHOctetString
Definition: BaseClasses.h:107
MHPEnum::MHPEnum
MHPEnum(int v)
Definition: ParseNode.h:109
MHParseNode::PNNull
@ PNNull
Definition: ParseNode.h:41
mythburn.FILE
int FILE
Definition: mythburn.py:139
MHPNull
Definition: ParseNode.h:135
MHParseSequence::MHParseSequence
MHParseSequence()
Definition: ParseNode.h:78
hardwareprofile.config.p
p
Definition: config.py:33
MHParseNode::GetSeqCount
int GetSeqCount()
Definition: ParseNode.cpp:141
MHParseNode::GetArgN
MHParseNode * GetArgN(int n)
Definition: ParseNode.cpp:78
MHParseNode::GetTagNo
int GetTagNo()
Definition: ParseNode.cpp:49
MHParseSequence
Definition: ParseNode.h:75
MHPBool::MHPBool
MHPBool(bool v)
Definition: ParseNode.h:118
MHPInt::MHPInt
MHPInt(int v)
Definition: ParseNode.h:99
MHParseNode::NodeType
NodeType
Definition: ParseNode.h:41
MHPEnum
Definition: ParseNode.h:106
PrintTabs
void PrintTabs(FILE *fd, int nTabs)
Definition: ParseNode.cpp:34
MHParseBase
Definition: ParseNode.h:31
MHParseNode::GetArgCount
int GetArgCount()
Definition: ParseNode.cpp:60
MHParseNode::GetNamedArg
MHParseNode * GetNamedArg(int nTag)
Definition: ParseNode.cpp:110
MHParseNode::PNSeq
@ PNSeq
Definition: ParseNode.h:41
MHPString
Definition: ParseNode.h:125
MHParseNode::GetBoolValue
bool GetBoolValue()
Definition: ParseNode.cpp:192
MHPBool
Definition: ParseNode.h:115
MHPString::m_Value
MHOctetString m_Value
Definition: ParseNode.h:131
MHParseBase::Parse
virtual MHParseNode * Parse()=0
MHParseNode::Failure
static void Failure(const char *p)
Definition: ParseNode.cpp:43
MHParseNode::PNBool
@ PNBool
Definition: ParseNode.h:41
BaseClasses.h
MHPTagged::AddArg
void AddArg(MHParseNode *pArg)
Definition: ParseNode.cpp:28
MHParseNode
Definition: ParseNode.h:38
MHPNull::MHPNull
MHPNull()
Definition: ParseNode.h:138
MHParseNode::GetEnumValue
int GetEnumValue()
Definition: ParseNode.cpp:181
MHParseNode::GetStringValue
void GetStringValue(MHOctetString &str)
Definition: ParseNode.cpp:203
MHParseNode::PNString
@ PNString
Definition: ParseNode.h:41
MHPBool::m_Value
bool m_Value
Definition: ParseNode.h:121
MHPString::MHPString
MHPString(const MHOctetString &pSrc)
Definition: ParseNode.h:128
MHPInt
Definition: ParseNode.h:96
MHPEnum::m_Value
int m_Value
Definition: ParseNode.h:111
MHParseNode::PNInt
@ PNInt
Definition: ParseNode.h:41
MHPInt::m_Value
int m_Value
Definition: ParseNode.h:102
MHOwnPtrSequence
Definition: BaseClasses.h:77
MHPTagged::m_Args
MHParseSequence m_Args
Definition: ParseNode.h:92
MHOctetString::Copy
void Copy(const MHOctetString &str)
Definition: BaseClasses.cpp:131
MHPTagged::m_TagNo
int m_TagNo
Definition: ParseNode.h:91