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
28class MHGroup;
29
30// Abstract base class for the text and binary parsers.
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:
41 enum NodeType : std::uint8_t { PNTagged, PNBool, PNInt, PNEnum, PNString, PNNull, PNSeq };
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
70
71 void PrintMe(FILE *f);
72};
73
74// Sequence of parse nodes.
75class 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.
85{
86 public:
87 explicit MHPTagged(int nTag)
88 : MHParseNode(PNTagged), m_TagNo(nTag) {}
89 void AddArg(MHParseNode *pArg);
90
93};
94
95// Primitive integer value.
96class MHPInt: public MHParseNode
97{
98 public:
99 explicit MHPInt(int v): MHParseNode(PNInt), m_Value(v) {}
100
101 public:
103};
104
105// Enumerated type - treat much as integer
106class MHPEnum: public MHParseNode
107{
108 public:
109 explicit MHPEnum(int v): MHParseNode(PNEnum), m_Value(v) {}
110 public:
112};
113
114// Primitive boolean value
115class MHPBool: public MHParseNode
116{
117 public:
118 explicit MHPBool(bool v): MHParseNode(PNBool), m_Value(v) {}
119
120 public:
122};
123
124// Primitive string value
126{
127 public:
128 explicit MHPString(const MHOctetString &pSrc): MHParseNode(PNString) { m_Value.Copy(pSrc); }
129
130 public:
132};
133
134// ASN1 NULL value.
135class MHPNull: public MHParseNode
136{
137 public:
139};
140
141void PrintTabs(FILE *fd, int nTabs); // Support function for printing.
142
143#endif
void PrintTabs(FILE *fd, int nTabs)
Definition: ParseNode.cpp:34
Definition: Groups.h:47
void Copy(const MHOctetString &str)
MHPBool(bool v)
Definition: ParseNode.h:118
bool m_Value
Definition: ParseNode.h:121
MHPEnum(int v)
Definition: ParseNode.h:109
int m_Value
Definition: ParseNode.h:111
MHPInt(int v)
Definition: ParseNode.h:99
int m_Value
Definition: ParseNode.h:102
MHPNull()
Definition: ParseNode.h:138
MHOctetString m_Value
Definition: ParseNode.h:131
MHPString(const MHOctetString &pSrc)
Definition: ParseNode.h:128
MHParseSequence m_Args
Definition: ParseNode.h:92
int m_TagNo
Definition: ParseNode.h:91
void AddArg(MHParseNode *pArg)
Definition: ParseNode.cpp:28
MHPTagged(int nTag)
Definition: ParseNode.h:87
virtual ~MHParseBase()=default
virtual MHParseNode * Parse()=0
MHParseNode * GetSeqN(int n)
Definition: ParseNode.cpp:152
MHParseNode * GetArgN(int n)
Definition: ParseNode.cpp:78
static void Failure(const char *p)
Definition: ParseNode.cpp:43
int GetEnumValue()
Definition: ParseNode.cpp:181
void GetStringValue(MHOctetString &str)
Definition: ParseNode.cpp:203
int GetArgCount()
Definition: ParseNode.cpp:60
int GetTagNo()
Definition: ParseNode.cpp:49
MHParseNode(enum NodeType nt)
Definition: ParseNode.h:43
virtual ~MHParseNode()=default
void PrintMe(FILE *f)
Definition: ParseNode.cpp:213
bool GetBoolValue()
Definition: ParseNode.cpp:192
int GetSeqCount()
Definition: ParseNode.cpp:141
MHParseNode * GetNamedArg(int nTag)
Definition: ParseNode.cpp:110
enum NodeType m_nNodeType
Definition: ParseNode.h:46
int GetIntValue()
Definition: ParseNode.cpp:170
void PrintUnbracketed(int nTabs)
int FILE
Definition: mythburn.py:138