txNodeSetContext.h 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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_SET_CONTEXT
  6. #define __TX_XPATH_SET_CONTEXT
  7. #include "txIXPathContext.h"
  8. #include "txNodeSet.h"
  9. #include "nsAutoPtr.h"
  10. class txNodeSetContext : public txIEvalContext
  11. {
  12. public:
  13. txNodeSetContext(txNodeSet* aContextNodeSet, txIMatchContext* aContext)
  14. : mContextSet(aContextNodeSet), mPosition(0), mInner(aContext)
  15. {
  16. }
  17. // Iteration over the given NodeSet
  18. bool hasNext()
  19. {
  20. return mPosition < size();
  21. }
  22. void next()
  23. {
  24. NS_ASSERTION(mPosition < size(), "Out of bounds.");
  25. mPosition++;
  26. }
  27. void setPosition(uint32_t aPosition)
  28. {
  29. NS_ASSERTION(aPosition > 0 &&
  30. aPosition <= size(), "Out of bounds.");
  31. mPosition = aPosition;
  32. }
  33. TX_DECL_EVAL_CONTEXT;
  34. protected:
  35. RefPtr<txNodeSet> mContextSet;
  36. uint32_t mPosition;
  37. txIMatchContext* mInner;
  38. };
  39. #endif // __TX_XPATH_SET_CONTEXT