nsRDFConInstanceTestNode.h 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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 nsRDFConInstanceTestNode_h__
  6. #define nsRDFConInstanceTestNode_h__
  7. #include "mozilla/Attributes.h"
  8. #include "nscore.h"
  9. #include "nsRDFTestNode.h"
  10. #include "nsIRDFResource.h"
  11. #include "nsIRDFDataSource.h"
  12. #include "nsXULTemplateQueryProcessorRDF.h"
  13. /**
  14. * Rule network node that tests if a resource is an RDF container, or
  15. * uses multi-attributes to ``contain'' other elements.
  16. */
  17. class nsRDFConInstanceTestNode : public nsRDFTestNode
  18. {
  19. public:
  20. enum Test { eFalse, eTrue, eDontCare };
  21. nsRDFConInstanceTestNode(TestNode* aParent,
  22. nsXULTemplateQueryProcessorRDF* aProcessor,
  23. nsIAtom* aContainerVariable,
  24. Test aContainer,
  25. Test aEmpty);
  26. virtual nsresult FilterInstantiations(InstantiationSet& aInstantiations,
  27. bool* aCantHandleYet) const override;
  28. virtual bool
  29. CanPropagate(nsIRDFResource* aSource,
  30. nsIRDFResource* aProperty,
  31. nsIRDFNode* aTarget,
  32. Instantiation& aInitialBindings) const override;
  33. virtual void
  34. Retract(nsIRDFResource* aSource,
  35. nsIRDFResource* aProperty,
  36. nsIRDFNode* aTarget) const override;
  37. class Element : public MemoryElement {
  38. public:
  39. Element(nsIRDFResource* aContainer,
  40. Test aContainerTest,
  41. Test aEmptyTest)
  42. : mContainer(aContainer),
  43. mContainerTest(aContainerTest),
  44. mEmptyTest(aEmptyTest) {
  45. MOZ_COUNT_CTOR(nsRDFConInstanceTestNode::Element); }
  46. virtual ~Element() { MOZ_COUNT_DTOR(nsRDFConInstanceTestNode::Element); }
  47. virtual const char* Type() const override {
  48. return "nsRDFConInstanceTestNode::Element"; }
  49. virtual PLHashNumber Hash() const override {
  50. return mozilla::HashGeneric(mContainerTest, mEmptyTest, mContainer.get());
  51. }
  52. virtual bool Equals(const MemoryElement& aElement) const override {
  53. if (aElement.Type() == Type()) {
  54. const Element& element = static_cast<const Element&>(aElement);
  55. return mContainer == element.mContainer
  56. && mContainerTest == element.mContainerTest
  57. && mEmptyTest == element.mEmptyTest;
  58. }
  59. return false; }
  60. protected:
  61. nsCOMPtr<nsIRDFResource> mContainer;
  62. Test mContainerTest;
  63. Test mEmptyTest;
  64. };
  65. protected:
  66. nsXULTemplateQueryProcessorRDF* mProcessor;
  67. nsCOMPtr<nsIAtom> mContainerVariable;
  68. Test mContainer;
  69. Test mEmpty;
  70. };
  71. #endif // nsRDFConInstanceTestNode_h__