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  MHParseNode(enum NodeType nt): m_nNodeType(nt) {}
44  public:
45  virtual ~MHParseNode() = default;
47 
48  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 *);
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  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  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:
110  public:
111  int m_Value;
112 };
113 
114 // Primitive boolean value
115 class MHPBool: public MHParseNode
116 {
117  public:
119 
120  public:
121  bool m_Value;
122 };
123 
124 // Primitive string value
125 class MHPString: public MHParseNode
126 {
127  public:
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
void Failure(const char *p)
Definition: ParseNode.cpp:43
void PrintTabs(FILE *fd, int nTabs)
Definition: ParseNode.cpp:34
MHParseNode(enum NodeType nt)
Definition: ParseNode.h:43
MHPTagged(int nTag)
Definition: ParseNode.h:87
MHPNull()
Definition: ParseNode.h:138
enum NodeType m_nNodeType
Definition: ParseNode.h:46
MHOctetString m_Value
Definition: ParseNode.h:131
int m_Value
Definition: ParseNode.h:111
virtual ~MHParseNode()=default
MHPEnum(int v)
Definition: ParseNode.h:109
MHPInt(int v)
Definition: ParseNode.h:99
MHParseNode * GetSeqN(int n)
Definition: ParseNode.cpp:152
void Copy(const MHOctetString &str)
MHPBool(bool v)
Definition: ParseNode.h:118
int m_TagNo
Definition: ParseNode.h:91
int GetIntValue()
Definition: ParseNode.cpp:170
void PrintUnbracketed(int nTabs)
void GetStringValue(MHOctetString &str)
Definition: ParseNode.cpp:203
MHParseNode * GetNamedArg(int nTag)
Definition: ParseNode.cpp:110
virtual MHParseNode * Parse()=0
MHParseSequence m_Args
Definition: ParseNode.h:92
int FILE
Definition: mythburn.py:110
MHPString(MHOctetString &pSrc)
Definition: ParseNode.h:128
bool m_Value
Definition: ParseNode.h:121
int GetEnumValue()
Definition: ParseNode.cpp:181
Definition: Groups.h:45
int GetSeqCount()
Definition: ParseNode.cpp:141
int GetArgCount()
Definition: ParseNode.cpp:60
bool GetBoolValue()
Definition: ParseNode.cpp:192
void PrintMe(FILE *)
Definition: ParseNode.cpp:213
MHParseNode * GetArgN(int n)
Definition: ParseNode.cpp:78
int GetTagNo()
Definition: ParseNode.cpp:49
int m_Value
Definition: ParseNode.h:102
virtual ~MHParseBase()=default
void AddArg(MHParseNode *pArg)
Definition: ParseNode.cpp:28