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 nsRDFPropertyTestNode_h__
40 : #define nsRDFPropertyTestNode_h__
41 :
42 : #include "nscore.h"
43 : #include "nsRDFTestNode.h"
44 : #include "nsIRDFDataSource.h"
45 : #include "nsIRDFResource.h"
46 : #include "nsXULTemplateQueryProcessorRDF.h"
47 :
48 : class nsRDFPropertyTestNode : public nsRDFTestNode
49 0 : {
50 : public:
51 : /**
52 : * Both source and target unbound (?source ^property ?target)
53 : */
54 : nsRDFPropertyTestNode(TestNode* aParent,
55 : nsXULTemplateQueryProcessorRDF* aProcessor,
56 : nsIAtom* aSourceVariable,
57 : nsIRDFResource* aProperty,
58 : nsIAtom* aTargetVariable);
59 :
60 : /**
61 : * Source bound, target unbound (source ^property ?target)
62 : */
63 : nsRDFPropertyTestNode(TestNode* aParent,
64 : nsXULTemplateQueryProcessorRDF* aProcessor,
65 : nsIRDFResource* aSource,
66 : nsIRDFResource* aProperty,
67 : nsIAtom* aTargetVariable);
68 :
69 : /**
70 : * Source unbound, target bound (?source ^property target)
71 : */
72 : nsRDFPropertyTestNode(TestNode* aParent,
73 : nsXULTemplateQueryProcessorRDF* aProcessor,
74 : nsIAtom* aSourceVariable,
75 : nsIRDFResource* aProperty,
76 : nsIRDFNode* aTarget);
77 :
78 : virtual nsresult FilterInstantiations(InstantiationSet& aInstantiations,
79 : bool* aCantHandleYet) const;
80 :
81 : virtual bool
82 : CanPropagate(nsIRDFResource* aSource,
83 : nsIRDFResource* aProperty,
84 : nsIRDFNode* aTarget,
85 : Instantiation& aInitialBindings) const;
86 :
87 : virtual void
88 : Retract(nsIRDFResource* aSource,
89 : nsIRDFResource* aProperty,
90 : nsIRDFNode* aTarget) const;
91 :
92 :
93 : class Element : public MemoryElement {
94 : protected:
95 : // Hide so that only Create() and Destroy() can be used to
96 : // allocate and deallocate from the heap
97 : static void* operator new(size_t) CPP_THROW_NEW { return 0; }
98 0 : static void operator delete(void*, size_t) {}
99 :
100 : public:
101 0 : Element(nsIRDFResource* aSource,
102 : nsIRDFResource* aProperty,
103 : nsIRDFNode* aTarget)
104 : : mSource(aSource),
105 : mProperty(aProperty),
106 0 : mTarget(aTarget) {
107 0 : MOZ_COUNT_CTOR(nsRDFPropertyTestNode::Element); }
108 :
109 0 : virtual ~Element() { MOZ_COUNT_DTOR(nsRDFPropertyTestNode::Element); }
110 :
111 : static Element*
112 0 : Create(nsIRDFResource* aSource,
113 : nsIRDFResource* aProperty,
114 : nsIRDFNode* aTarget) {
115 0 : void* place = MemoryElement::gPool.Alloc(sizeof(Element));
116 0 : return place ? ::new (place) Element(aSource, aProperty, aTarget) : nsnull; }
117 :
118 0 : void Destroy() {
119 0 : this->~Element();
120 0 : MemoryElement::gPool.Free(this, sizeof(Element));
121 0 : }
122 :
123 0 : virtual const char* Type() const {
124 0 : return "nsRDFPropertyTestNode::Element"; }
125 :
126 0 : virtual PLHashNumber Hash() const {
127 0 : return mozilla::HashGeneric(mSource.get(), mProperty.get(), mTarget.get());
128 : }
129 :
130 0 : virtual bool Equals(const MemoryElement& aElement) const {
131 0 : if (aElement.Type() == Type()) {
132 0 : const Element& element = static_cast<const Element&>(aElement);
133 0 : return mSource == element.mSource
134 0 : && mProperty == element.mProperty
135 0 : && mTarget == element.mTarget;
136 : }
137 0 : return false; }
138 :
139 : protected:
140 : nsCOMPtr<nsIRDFResource> mSource;
141 : nsCOMPtr<nsIRDFResource> mProperty;
142 : nsCOMPtr<nsIRDFNode> mTarget;
143 : };
144 :
145 : protected:
146 : nsXULTemplateQueryProcessorRDF* mProcessor;
147 : nsCOMPtr<nsIAtom> mSourceVariable;
148 : nsCOMPtr<nsIRDFResource> mSource;
149 : nsCOMPtr<nsIRDFResource> mProperty;
150 : nsCOMPtr<nsIAtom> mTargetVariable;
151 : nsCOMPtr<nsIRDFNode> mTarget;
152 : };
153 :
154 : #endif // nsRDFPropertyTestNode_h__
|