1
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2
/* ***** BEGIN LICENSE BLOCK *****
3
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
5
* The contents of this file are subject to the Netscape Public License
6
* Version 1.1 (the "License"); you may not use this file except in
7
* compliance with the License. You may obtain a copy of the License at
8
* http://www.mozilla.org/NPL/
10
* Software distributed under the License is distributed on an "AS IS" basis,
11
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12
* for the specific language governing rights and limitations under the
15
* The Original Code is mozilla.org code.
17
* The Initial Developer of the Original Code is
18
* Netscape Communications Corporation.
19
* Portions created by the Initial Developer are Copyright (C) 1998
20
* the Initial Developer. All Rights Reserved.
25
* Alternatively, the contents of this file may be used under the terms of
26
* either the GNU General Public License Version 2 or later (the "GPL"), or
27
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28
* in which case the provisions of the GPL or the LGPL are applicable instead
29
* of those above. If you wish to allow use of your version of this file only
30
* under the terms of either the GPL or the LGPL, and not to allow others to
31
* use your version of this file under the terms of the NPL, indicate your
32
* decision by deleting the provisions above and replace them with the notice
33
* and other provisions required by the GPL or the LGPL. If you do not delete
34
* the provisions above, a recipient may use your version of this file under
35
* the terms of any one of the NPL, the GPL or the LGPL.
37
* ***** END LICENSE BLOCK ***** */
44
* This class is defines the basic interface between the
45
* parser and the content sink. The parser will iterate
46
* over the collection of tokens that it sees from the
47
* tokenizer, coverting each related "group" into one of
48
* these. This object gets passed to the sink, and is
49
* then immediately reused.
51
* If you want to hang onto one of these, you should
56
#ifndef NS_PARSERNODE__
57
#define NS_PARSERNODE__
59
#include "nsIParserNode.h"
62
#include "nsParserCIID.h"
64
#include "nsDTDUtils.h"
66
class nsTokenAllocator;
68
class nsCParserNode : public nsIParserNode {
81
void Release(nsFixedSizeAllocator& aPool)
87
#ifndef HEAP_ALLOCATED_NODES
91
* Hide operator new; clients should use Create() instead.
93
static void* operator new(size_t) CPP_THROW_NEW { return 0; }
96
* Hide operator delete; clients should use Destroy() instead.
98
static void operator delete(void*,size_t) {}
103
static nsCParserNode* Create(CToken* aToken,
104
nsTokenAllocator* aTokenAllocator,
105
nsNodeAllocator* aNodeAllocator)
107
#ifdef HEAP_ALLOCATED_NODES
110
nsFixedSizeAllocator& pool = aNodeAllocator->GetArenaPool();
111
void* place = pool.Alloc(sizeof(nsCParserNode));
114
nsCParserNode(aToken, aTokenAllocator, aNodeAllocator);
117
static void Destroy(nsCParserNode* aNode, nsFixedSizeAllocator& aPool)
119
#ifdef HEAP_ALLOCATED_NODES
122
aNode->~nsCParserNode();
123
aPool.Free(aNode, sizeof(*aNode));
128
* Default constructor
134
* @update gess5/11/98
135
* @param aToken is the token this node "refers" to
137
nsCParserNode(CToken* aToken,
138
nsTokenAllocator* aTokenAllocator,
139
nsNodeAllocator* aNodeAllocator=0);
143
* @update gess5/11/98
145
virtual ~nsCParserNode();
149
* @update gess5/11/98
151
virtual nsresult Init(CToken* aToken,
152
nsTokenAllocator* aTokenAllocator,
153
nsNodeAllocator* aNodeAllocator=0);
156
* Retrieve the name of the node
157
* @update gess5/11/98
158
* @return string containing node name
160
virtual const nsAString& GetTagName() const;
163
* Retrieve the text from the given node
164
* @update gess5/11/98
165
* @return string containing node text
167
virtual const nsAString& GetText() const;
170
* Retrieve the type of the parser node.
171
* @update gess5/11/98
174
virtual PRInt32 GetNodeType() const;
177
* Retrieve token type of parser node
178
* @update gess5/11/98
181
virtual PRInt32 GetTokenType() const;
184
//***************************************
185
//methods for accessing key/value pairs
186
//***************************************
189
* Retrieve the number of attributes in this node.
190
* @update gess5/11/98
191
* @return count of attributes (may be 0)
193
virtual PRInt32 GetAttributeCount(PRBool askToken=PR_FALSE) const;
196
* Retrieve the key (of key/value pair) at given index
197
* @update gess5/11/98
198
* @param anIndex is the index of the key you want
199
* @return string containing key.
201
virtual const nsAString& GetKeyAt(PRUint32 anIndex) const;
204
* Retrieve the value (of key/value pair) at given index
205
* @update gess5/11/98
206
* @param anIndex is the index of the value you want
207
* @return string containing value.
209
virtual const nsAString& GetValueAt(PRUint32 anIndex) const;
212
* NOTE: When the node is an entity, this will translate the entity
213
* to it's unicode value, and store it in aString.
214
* @update gess5/11/98
215
* @param aString will contain the resulting unicode string value
216
* @return int (unicode char or unicode index from table)
218
virtual PRInt32 TranslateToUnicodeStr(nsString& aString) const;
222
* @update gess5/11/98
226
virtual void AddAttribute(CToken* aToken);
229
* This getter retrieves the line number from the input source where
230
* the token occured. Lines are interpreted as occuring between \n characters.
231
* @update gess7/24/98
232
* @return int containing the line number the token was found on
234
virtual PRInt32 GetSourceLineNumber(void) const;
236
/** This method pop the attribute token from the given index
237
* @update harishd 03/25/99
238
* @return token at anIndex
240
virtual CToken* PopAttributeToken();
242
/** Retrieve a string containing the tag and its attributes in "source" form
243
* @update rickg 06June2000
246
virtual void GetSource(nsString& aString);
249
* This pair of methods allows us to set a generic bit (for arbitrary use)
250
* on each node stored in the context.
251
* @update gess 11May2000
253
virtual PRBool GetGenericState(void) const {return mGenericState;}
254
virtual void SetGenericState(PRBool aState) {mGenericState=aState;}
256
/** Release all the objects you're holding
257
* @update harishd 08/02/00
260
virtual nsresult ReleaseAll();
264
PRPackedBool mGenericState;
266
nsTokenAllocator* mTokenAllocator;
267
#ifdef HEAP_ALLOCATED_NODES
268
nsNodeAllocator* mNodeAllocator; // weak
273
class nsCParserStartNode : public nsCParserNode
276
static nsCParserNode* Create(CToken* aToken,
277
nsTokenAllocator* aTokenAllocator,
278
nsNodeAllocator* aNodeAllocator)
280
#ifdef HEAP_ALLOCATED_NODES
283
nsFixedSizeAllocator& pool = aNodeAllocator->GetArenaPool();
284
void* place = pool.Alloc(sizeof(nsCParserStartNode));
287
nsCParserStartNode(aToken, aTokenAllocator, aNodeAllocator);
291
: nsCParserNode(), mAttributes(0) { }
293
nsCParserStartNode(CToken* aToken,
294
nsTokenAllocator* aTokenAllocator,
295
nsNodeAllocator* aNodeAllocator = 0)
296
: nsCParserNode(aToken, aTokenAllocator, aNodeAllocator), mAttributes(0) { }
298
virtual ~nsCParserStartNode()
300
NS_ASSERTION(0 != mTokenAllocator, "Error: no token allocator");
301
CToken* theAttrToken = 0;
302
while ((theAttrToken = NS_STATIC_CAST(CToken*, mAttributes.Pop()))) {
303
IF_FREE(theAttrToken, mTokenAllocator);
307
virtual nsresult Init(CToken* aToken,
308
nsTokenAllocator* aTokenAllocator,
309
nsNodeAllocator* aNodeAllocator = 0);
310
virtual void AddAttribute(CToken* aToken);
311
virtual PRInt32 GetAttributeCount(PRBool askToken = PR_FALSE) const;
312
virtual const nsAString& GetKeyAt(PRUint32 anIndex) const;
313
virtual const nsAString& GetValueAt(PRUint32 anIndex) const;
314
virtual CToken* PopAttributeToken();
315
virtual void GetSource(nsString& aString);
316
virtual nsresult ReleaseAll();