1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /* ***** BEGIN LICENSE BLOCK *****
3 : * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4 : *
5 : * The contents of this file are subject to the Mozilla Public License Version
6 : * 1.1 (the "License"); you may not use this file except in compliance with
7 : * the License. You may obtain a copy of the License at
8 : * http://www.mozilla.org/MPL/
9 : *
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
13 : * License.
14 : *
15 : * The Original Code is TransforMiiX XSLT processor code.
16 : *
17 : * The Initial Developer of the Original Code is
18 : * Netscape Communications Corporation.
19 : * Portions created by the Initial Developer are Copyright (C) 2003
20 : * the Initial Developer. All Rights Reserved.
21 : *
22 : * Contributor(s):
23 : * Peter Van der Beken <peterv@propagandism.org>
24 : *
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 MPL, 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 MPL, the GPL or the LGPL.
36 : *
37 : * ***** END LICENSE BLOCK ***** */
38 :
39 : #ifndef txXPathNode_h__
40 : #define txXPathNode_h__
41 :
42 : #include "nsAutoPtr.h"
43 : #include "nsIContent.h"
44 : #include "nsIDocument.h"
45 : #include "nsIDOMNode.h"
46 : #include "nsINameSpaceManager.h"
47 : #include "nsContentUtils.h"
48 :
49 : typedef nsIDOMNode txXPathNodeType;
50 :
51 : class txXPathNode
52 : {
53 : public:
54 : bool operator==(const txXPathNode& aNode) const;
55 0 : bool operator!=(const txXPathNode& aNode) const
56 : {
57 0 : return !(*this == aNode);
58 : }
59 : ~txXPathNode();
60 :
61 : private:
62 : friend class txNodeSet;
63 : friend class txXPathNativeNode;
64 : friend class txXPathNodeUtils;
65 : friend class txXPathTreeWalker;
66 :
67 : txXPathNode(const txXPathNode& aNode);
68 :
69 0 : txXPathNode(nsIDocument* aDocument) : mNode(aDocument),
70 : mRefCountRoot(0),
71 0 : mIndex(eDocument)
72 : {
73 0 : MOZ_COUNT_CTOR(txXPathNode);
74 0 : }
75 42 : txXPathNode(nsINode *aNode, PRUint32 aIndex, nsINode *aRoot)
76 : : mNode(aNode),
77 : mRefCountRoot(aRoot ? 1 : 0),
78 42 : mIndex(aIndex)
79 : {
80 42 : MOZ_COUNT_CTOR(txXPathNode);
81 42 : if (aRoot) {
82 0 : NS_ADDREF(aRoot);
83 : }
84 42 : }
85 :
86 0 : static nsINode *RootOf(nsINode *aNode)
87 : {
88 0 : nsINode *ancestor, *root = aNode;
89 0 : while ((ancestor = root->GetNodeParent())) {
90 0 : root = ancestor;
91 : }
92 0 : return root;
93 : }
94 0 : nsINode *Root() const
95 : {
96 0 : return RootOf(mNode);
97 : }
98 : nsINode *GetRootToAddRef() const
99 : {
100 : return mRefCountRoot ? Root() : nsnull;
101 : }
102 :
103 84 : bool isDocument() const
104 : {
105 84 : return mIndex == eDocument;
106 : }
107 168 : bool isContent() const
108 : {
109 168 : return mIndex == eContent;
110 : }
111 126 : bool isAttribute() const
112 : {
113 126 : return mIndex != eDocument && mIndex != eContent;
114 : }
115 :
116 126 : nsIContent* Content() const
117 : {
118 126 : NS_ASSERTION(isContent() || isAttribute(), "wrong type");
119 126 : return static_cast<nsIContent*>(mNode);
120 : }
121 0 : nsIDocument* Document() const
122 : {
123 0 : NS_ASSERTION(isDocument(), "wrong type");
124 0 : return static_cast<nsIDocument*>(mNode);
125 : }
126 :
127 : enum PositionType
128 : {
129 : eDocument = (1 << 30),
130 : eContent = eDocument - 1
131 : };
132 :
133 : nsINode* mNode;
134 : PRUint32 mRefCountRoot : 1;
135 : PRUint32 mIndex : 31;
136 : };
137 :
138 : class txNamespaceManager
139 : {
140 : public:
141 : static PRInt32 getNamespaceID(const nsAString& aNamespaceURI);
142 : static nsresult getNamespaceURI(const PRInt32 aID, nsAString& aResult);
143 : };
144 :
145 : /* static */
146 : inline PRInt32
147 22464 : txNamespaceManager::getNamespaceID(const nsAString& aNamespaceURI)
148 : {
149 22464 : PRInt32 namespaceID = kNameSpaceID_Unknown;
150 22464 : nsContentUtils::NameSpaceManager()->
151 22464 : RegisterNameSpace(aNamespaceURI, namespaceID);
152 22464 : return namespaceID;
153 : }
154 :
155 : /* static */
156 : inline nsresult
157 0 : txNamespaceManager::getNamespaceURI(const PRInt32 aID, nsAString& aResult)
158 : {
159 0 : return nsContentUtils::NameSpaceManager()->
160 0 : GetNameSpaceURI(aID, aResult);
161 : }
162 :
163 : inline bool
164 0 : txXPathNode::operator==(const txXPathNode& aNode) const
165 : {
166 0 : return mIndex == aNode.mIndex && mNode == aNode.mNode;
167 : }
168 :
169 : #endif /* txXPathNode_h__ */
|