nsRDFConMemberTestNode.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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 nsRDFConMemberTestNode_h__
  6. #define nsRDFConMemberTestNode_h__
  7. #include "mozilla/Attributes.h"
  8. #include "nscore.h"
  9. #include "nsRDFTestNode.h"
  10. #include "nsIRDFDataSource.h"
  11. #include "nsXULTemplateQueryProcessorRDF.h"
  12. /**
  13. * Rule network node that test if a resource is a member of an RDF
  14. * container, or is ``contained'' by another resource that refers to
  15. * it using a ``containment'' attribute.
  16. */
  17. class nsRDFConMemberTestNode : public nsRDFTestNode
  18. {
  19. public:
  20. nsRDFConMemberTestNode(TestNode* aParent,
  21. nsXULTemplateQueryProcessorRDF* aProcessor,
  22. nsIAtom* aContainerVariable,
  23. nsIAtom* aMemberVariable);
  24. virtual nsresult FilterInstantiations(InstantiationSet& aInstantiations,
  25. bool* aCantHandleYet) const override;
  26. virtual bool
  27. CanPropagate(nsIRDFResource* aSource,
  28. nsIRDFResource* aProperty,
  29. nsIRDFNode* aTarget,
  30. Instantiation& aInitialBindings) const override;
  31. virtual void
  32. Retract(nsIRDFResource* aSource,
  33. nsIRDFResource* aProperty,
  34. nsIRDFNode* aTarget) const override;
  35. class Element : public MemoryElement {
  36. public:
  37. Element(nsIRDFResource* aContainer,
  38. nsIRDFNode* aMember)
  39. : mContainer(aContainer),
  40. mMember(aMember) {
  41. MOZ_COUNT_CTOR(nsRDFConMemberTestNode::Element); }
  42. virtual ~Element() { MOZ_COUNT_DTOR(nsRDFConMemberTestNode::Element); }
  43. virtual const char* Type() const override {
  44. return "nsRDFConMemberTestNode::Element"; }
  45. virtual PLHashNumber Hash() const override {
  46. return PLHashNumber(NS_PTR_TO_INT32(mContainer.get())) ^
  47. (PLHashNumber(NS_PTR_TO_INT32(mMember.get())) >> 12); }
  48. virtual bool Equals(const MemoryElement& aElement) const override {
  49. if (aElement.Type() == Type()) {
  50. const Element& element = static_cast<const Element&>(aElement);
  51. return mContainer == element.mContainer && mMember == element.mMember;
  52. }
  53. return false; }
  54. protected:
  55. nsCOMPtr<nsIRDFResource> mContainer;
  56. nsCOMPtr<nsIRDFNode> mMember;
  57. };
  58. protected:
  59. nsXULTemplateQueryProcessorRDF* mProcessor;
  60. nsCOMPtr<nsIAtom> mContainerVariable;
  61. nsCOMPtr<nsIAtom> mMemberVariable;
  62. };
  63. #endif // nsRDFConMemberTestNode_h__