1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /* ***** BEGIN LICENSE BLOCK *****
3 : * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4 : *
5 : * The contents of this file are subject to the Mozilla Public License Version
6 : * 1.1 (the "License"); you may not use this file except in compliance with
7 : * the License. You may obtain a copy of the License at
8 : * http://www.mozilla.org/MPL/
9 : *
10 : * Software distributed under the License is distributed on an "AS IS" basis,
11 : * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 : * for the specific language governing rights and limitations under the
13 : * License.
14 : *
15 : * The Original Code is Mozilla Communicator client code.
16 : *
17 : * The Initial Developer of the Original Code is
18 : * Netscape Communications Corporation.
19 : * Portions created by the Initial Developer are Copyright (C) 1998
20 : * the Initial Developer. All Rights Reserved.
21 : *
22 : * Contributor(s):
23 : * Chris Waterson <waterson@netscape.com>
24 : *
25 : * Alternatively, the contents of this file may be used under the terms of
26 : * either of the GNU General Public License Version 2 or later (the "GPL"),
27 : * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28 : * in which case the provisions of the GPL or the LGPL are applicable instead
29 : * of those above. If you wish to allow use of your version of this file only
30 : * under the terms of either the GPL or the LGPL, and not to allow others to
31 : * use your version of this file under the terms of the MPL, indicate your
32 : * decision by deleting the provisions above and replace them with the notice
33 : * and other provisions required by the GPL or the LGPL. If you do not delete
34 : * the provisions above, a recipient may use your version of this file under
35 : * the terms of any one of the MPL, the GPL or the LGPL.
36 : *
37 : * ***** END LICENSE BLOCK ***** */
38 :
39 : #ifndef nsRDFConMemberTestNode_h__
40 : #define nsRDFConMemberTestNode_h__
41 :
42 : #include "nscore.h"
43 : #include "nsRDFTestNode.h"
44 : #include "nsIRDFDataSource.h"
45 : #include "nsXULTemplateQueryProcessorRDF.h"
46 :
47 : /**
48 : * Rule network node that test if a resource is a member of an RDF
49 : * container, or is ``contained'' by another resource that refers to
50 : * it using a ``containment'' attribute.
51 : */
52 : class nsRDFConMemberTestNode : public nsRDFTestNode
53 0 : {
54 : public:
55 : nsRDFConMemberTestNode(TestNode* aParent,
56 : nsXULTemplateQueryProcessorRDF* aProcessor,
57 : nsIAtom* aContainerVariable,
58 : nsIAtom* aMemberVariable);
59 :
60 : virtual nsresult FilterInstantiations(InstantiationSet& aInstantiations,
61 : bool* aCantHandleYet) const;
62 :
63 : virtual bool
64 : CanPropagate(nsIRDFResource* aSource,
65 : nsIRDFResource* aProperty,
66 : nsIRDFNode* aTarget,
67 : Instantiation& aInitialBindings) const;
68 :
69 : virtual void
70 : Retract(nsIRDFResource* aSource,
71 : nsIRDFResource* aProperty,
72 : nsIRDFNode* aTarget) const;
73 :
74 : class Element : public MemoryElement {
75 : protected:
76 : // Hide so that only Create() and Destroy() can be used to
77 : // allocate and deallocate from the heap
78 : static void* operator new(size_t) CPP_THROW_NEW { return 0; }
79 0 : static void operator delete(void*, size_t) {}
80 :
81 : public:
82 0 : Element(nsIRDFResource* aContainer,
83 : nsIRDFNode* aMember)
84 : : mContainer(aContainer),
85 0 : mMember(aMember) {
86 0 : MOZ_COUNT_CTOR(nsRDFConMemberTestNode::Element); }
87 :
88 0 : virtual ~Element() { MOZ_COUNT_DTOR(nsRDFConMemberTestNode::Element); }
89 :
90 : static Element*
91 0 : Create(nsIRDFResource* aContainer, nsIRDFNode* aMember) {
92 0 : void* place = MemoryElement::gPool.Alloc(sizeof(Element));
93 0 : return place ? ::new (place) Element(aContainer, aMember) : nsnull; }
94 :
95 0 : void Destroy() {
96 0 : this->~Element();
97 0 : MemoryElement::gPool.Free(this, sizeof(Element));
98 0 : }
99 :
100 0 : virtual const char* Type() const {
101 0 : return "nsRDFConMemberTestNode::Element"; }
102 :
103 0 : virtual PLHashNumber Hash() const {
104 0 : return PLHashNumber(NS_PTR_TO_INT32(mContainer.get())) ^
105 0 : (PLHashNumber(NS_PTR_TO_INT32(mMember.get())) >> 12); }
106 :
107 0 : virtual bool Equals(const MemoryElement& aElement) const {
108 0 : if (aElement.Type() == Type()) {
109 0 : const Element& element = static_cast<const Element&>(aElement);
110 0 : return mContainer == element.mContainer && mMember == element.mMember;
111 : }
112 0 : return false; }
113 :
114 : protected:
115 : nsCOMPtr<nsIRDFResource> mContainer;
116 : nsCOMPtr<nsIRDFNode> mMember;
117 : };
118 :
119 : protected:
120 : nsXULTemplateQueryProcessorRDF* mProcessor;
121 : nsCOMPtr<nsIAtom> mContainerVariable;
122 : nsCOMPtr<nsIAtom> mMemberVariable;
123 : };
124 :
125 : #endif // nsRDFConMemberTestNode_h__
|