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
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/
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
15 * The Original Code is Mozilla Communicator client code.
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.
23 * Chris Waterson <waterson@netscape.com>
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.
37 * ***** END LICENSE BLOCK ***** */
39 #ifndef nsRDFPropertyTestNode_h__
40 #define nsRDFPropertyTestNode_h__
43 #include "nsRDFTestNode.h"
44 #include "nsIRDFDataSource.h"
45 #include "nsIRDFResource.h"
46 #include "nsXULTemplateQueryProcessorRDF.h"
48 class nsRDFPropertyTestNode
: public nsRDFTestNode
52 * Both source and target unbound (?source ^property ?target)
54 nsRDFPropertyTestNode(TestNode
* aParent
,
55 nsXULTemplateQueryProcessorRDF
* aProcessor
,
56 nsIAtom
* aSourceVariable
,
57 nsIRDFResource
* aProperty
,
58 nsIAtom
* aTargetVariable
);
61 * Source bound, target unbound (source ^property ?target)
63 nsRDFPropertyTestNode(TestNode
* aParent
,
64 nsXULTemplateQueryProcessorRDF
* aProcessor
,
65 nsIRDFResource
* aSource
,
66 nsIRDFResource
* aProperty
,
67 nsIAtom
* aTargetVariable
);
70 * Source unbound, target bound (?source ^property target)
72 nsRDFPropertyTestNode(TestNode
* aParent
,
73 nsXULTemplateQueryProcessorRDF
* aProcessor
,
74 nsIAtom
* aSourceVariable
,
75 nsIRDFResource
* aProperty
,
78 virtual nsresult
FilterInstantiations(InstantiationSet
& aInstantiations
,
79 PRBool
* aCantHandleYet
) const;
82 CanPropagate(nsIRDFResource
* aSource
,
83 nsIRDFResource
* aProperty
,
85 Instantiation
& aInitialBindings
) const;
88 Retract(nsIRDFResource
* aSource
,
89 nsIRDFResource
* aProperty
,
90 nsIRDFNode
* aTarget
) const;
93 class Element
: public MemoryElement
{
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 static void operator delete(void*, size_t) {}
101 Element(nsIRDFResource
* aSource
,
102 nsIRDFResource
* aProperty
,
105 mProperty(aProperty
),
107 MOZ_COUNT_CTOR(nsRDFPropertyTestNode::Element
); }
109 virtual ~Element() { MOZ_COUNT_DTOR(nsRDFPropertyTestNode::Element
); }
112 Create(nsIRDFResource
* aSource
,
113 nsIRDFResource
* aProperty
,
114 nsIRDFNode
* aTarget
) {
115 void* place
= MemoryElement::gPool
.Alloc(sizeof(Element
));
116 return place
? ::new (place
) Element(aSource
, aProperty
, aTarget
) : nsnull
; }
120 MemoryElement::gPool
.Free(this, sizeof(Element
));
123 virtual const char* Type() const {
124 return "nsRDFPropertyTestNode::Element"; }
126 virtual PLHashNumber
Hash() const {
127 return PLHashNumber(NS_PTR_TO_INT32(mSource
.get())) ^
128 (PLHashNumber(NS_PTR_TO_INT32(mProperty
.get())) >> 4) ^
129 (PLHashNumber(NS_PTR_TO_INT32(mTarget
.get())) >> 12); }
131 virtual PRBool
Equals(const MemoryElement
& aElement
) const {
132 if (aElement
.Type() == Type()) {
133 const Element
& element
= static_cast<const Element
&>(aElement
);
134 return mSource
== element
.mSource
135 && mProperty
== element
.mProperty
136 && mTarget
== element
.mTarget
;
141 nsCOMPtr
<nsIRDFResource
> mSource
;
142 nsCOMPtr
<nsIRDFResource
> mProperty
;
143 nsCOMPtr
<nsIRDFNode
> mTarget
;
147 nsXULTemplateQueryProcessorRDF
* mProcessor
;
148 nsCOMPtr
<nsIAtom
> mSourceVariable
;
149 nsCOMPtr
<nsIRDFResource
> mSource
;
150 nsCOMPtr
<nsIRDFResource
> mProperty
;
151 nsCOMPtr
<nsIAtom
> mTargetVariable
;
152 nsCOMPtr
<nsIRDFNode
> mTarget
;
155 #endif // nsRDFPropertyTestNode_h__