txSingleNodeContext.h 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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. #ifndef __TX_XPATH_SINGLENODE_CONTEXT
  6. #define __TX_XPATH_SINGLENODE_CONTEXT
  7. #include "mozilla/Attributes.h"
  8. #include "txIXPathContext.h"
  9. class txSingleNodeContext : public txIEvalContext
  10. {
  11. public:
  12. txSingleNodeContext(const txXPathNode& aContextNode,
  13. txIMatchContext* aContext)
  14. : mNode(aContextNode),
  15. mInner(aContext)
  16. {
  17. NS_ASSERTION(aContext, "txIMatchContext must be given");
  18. }
  19. nsresult getVariable(int32_t aNamespace, nsIAtom* aLName,
  20. txAExprResult*& aResult) override
  21. {
  22. NS_ASSERTION(mInner, "mInner is null!!!");
  23. return mInner->getVariable(aNamespace, aLName, aResult);
  24. }
  25. bool isStripSpaceAllowed(const txXPathNode& aNode) override
  26. {
  27. NS_ASSERTION(mInner, "mInner is null!!!");
  28. return mInner->isStripSpaceAllowed(aNode);
  29. }
  30. void* getPrivateContext() override
  31. {
  32. NS_ASSERTION(mInner, "mInner is null!!!");
  33. return mInner->getPrivateContext();
  34. }
  35. txResultRecycler* recycler() override
  36. {
  37. NS_ASSERTION(mInner, "mInner is null!!!");
  38. return mInner->recycler();
  39. }
  40. void receiveError(const nsAString& aMsg, nsresult aRes) override
  41. {
  42. NS_ASSERTION(mInner, "mInner is null!!!");
  43. #ifdef DEBUG
  44. nsAutoString error(NS_LITERAL_STRING("forwarded error: "));
  45. error.Append(aMsg);
  46. mInner->receiveError(error, aRes);
  47. #else
  48. mInner->receiveError(aMsg, aRes);
  49. #endif
  50. }
  51. const txXPathNode& getContextNode() override
  52. {
  53. return mNode;
  54. }
  55. uint32_t size() override
  56. {
  57. return 1;
  58. }
  59. uint32_t position() override
  60. {
  61. return 1;
  62. }
  63. private:
  64. const txXPathNode& mNode;
  65. txIMatchContext* mInner;
  66. };
  67. #endif // __TX_XPATH_SINGLENODE_CONTEXT