|
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
|
2 /* This Source Code Form is subject to the terms of the Mozilla Public |
|
3 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
5 |
|
6 #ifndef nsXPathExpression_h__ |
|
7 #define nsXPathExpression_h__ |
|
8 |
|
9 #include "nsIDOMXPathExpression.h" |
|
10 #include "nsIDOMNSXPathExpression.h" |
|
11 #include "txIXPathContext.h" |
|
12 #include "txResultRecycler.h" |
|
13 #include "nsAutoPtr.h" |
|
14 #include "nsCycleCollectionParticipant.h" |
|
15 #include "mozilla/Attributes.h" |
|
16 |
|
17 class Expr; |
|
18 class txXPathNode; |
|
19 |
|
20 /** |
|
21 * A class for evaluating an XPath expression string |
|
22 */ |
|
23 class nsXPathExpression MOZ_FINAL : public nsIDOMXPathExpression, |
|
24 public nsIDOMNSXPathExpression |
|
25 { |
|
26 public: |
|
27 nsXPathExpression(nsAutoPtr<Expr>& aExpression, txResultRecycler* aRecycler, |
|
28 nsIDOMDocument *aDocument); |
|
29 |
|
30 // nsISupports interface |
|
31 NS_DECL_CYCLE_COLLECTING_ISUPPORTS |
|
32 NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(nsXPathExpression, |
|
33 nsIDOMXPathExpression) |
|
34 |
|
35 // nsIDOMXPathExpression interface |
|
36 NS_DECL_NSIDOMXPATHEXPRESSION |
|
37 |
|
38 // nsIDOMNSXPathExpression interface |
|
39 NS_DECL_NSIDOMNSXPATHEXPRESSION |
|
40 |
|
41 private: |
|
42 nsAutoPtr<Expr> mExpression; |
|
43 nsRefPtr<txResultRecycler> mRecycler; |
|
44 nsCOMPtr<nsIDOMDocument> mDocument; |
|
45 |
|
46 class EvalContextImpl : public txIEvalContext |
|
47 { |
|
48 public: |
|
49 EvalContextImpl(const txXPathNode& aContextNode, |
|
50 uint32_t aContextPosition, uint32_t aContextSize, |
|
51 txResultRecycler* aRecycler) |
|
52 : mContextNode(aContextNode), |
|
53 mContextPosition(aContextPosition), |
|
54 mContextSize(aContextSize), |
|
55 mLastError(NS_OK), |
|
56 mRecycler(aRecycler) |
|
57 { |
|
58 } |
|
59 |
|
60 nsresult getError() |
|
61 { |
|
62 return mLastError; |
|
63 } |
|
64 |
|
65 TX_DECL_EVAL_CONTEXT; |
|
66 |
|
67 private: |
|
68 const txXPathNode& mContextNode; |
|
69 uint32_t mContextPosition; |
|
70 uint32_t mContextSize; |
|
71 nsresult mLastError; |
|
72 nsRefPtr<txResultRecycler> mRecycler; |
|
73 }; |
|
74 }; |
|
75 |
|
76 #endif |