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 nsRDFConInstanceTestNode_h__
40 : #define nsRDFConInstanceTestNode_h__
41 :
42 : #include "nscore.h"
43 : #include "nsFixedSizeAllocator.h"
44 : #include "nsRDFTestNode.h"
45 : #include "nsIRDFResource.h"
46 : #include "nsIRDFDataSource.h"
47 : #include "nsXULTemplateQueryProcessorRDF.h"
48 :
49 : /**
50 : * Rule network node that tests if a resource is an RDF container, or
51 : * uses multi-attributes to ``contain'' other elements.
52 : */
53 : class nsRDFConInstanceTestNode : public nsRDFTestNode
54 0 : {
55 : public:
56 : enum Test { eFalse, eTrue, eDontCare };
57 :
58 : nsRDFConInstanceTestNode(TestNode* aParent,
59 : nsXULTemplateQueryProcessorRDF* aProcessor,
60 : nsIAtom* aContainerVariable,
61 : Test aContainer,
62 : Test aEmpty);
63 :
64 : virtual nsresult FilterInstantiations(InstantiationSet& aInstantiations,
65 : bool* aCantHandleYet) const;
66 :
67 : virtual bool
68 : CanPropagate(nsIRDFResource* aSource,
69 : nsIRDFResource* aProperty,
70 : nsIRDFNode* aTarget,
71 : Instantiation& aInitialBindings) const;
72 :
73 : virtual void
74 : Retract(nsIRDFResource* aSource,
75 : nsIRDFResource* aProperty,
76 : nsIRDFNode* aTarget) const;
77 :
78 :
79 : class Element : public MemoryElement {
80 : protected:
81 : // Hide so that only Create() and Destroy() can be used to
82 : // allocate and deallocate from the heap
83 : static void* operator new(size_t) CPP_THROW_NEW { return 0; }
84 0 : static void operator delete(void*, size_t) {}
85 :
86 : public:
87 0 : Element(nsIRDFResource* aContainer,
88 : Test aContainerTest,
89 : Test aEmptyTest)
90 : : mContainer(aContainer),
91 : mContainerTest(aContainerTest),
92 0 : mEmptyTest(aEmptyTest) {
93 0 : MOZ_COUNT_CTOR(nsRDFConInstanceTestNode::Element); }
94 :
95 0 : virtual ~Element() { MOZ_COUNT_DTOR(nsRDFConInstanceTestNode::Element); }
96 :
97 : static Element*
98 0 : Create(nsIRDFResource* aContainer,
99 : Test aContainerTest, Test aEmptyTest) {
100 0 : void* place = MemoryElement::gPool.Alloc(sizeof(Element));
101 0 : return place ? ::new (place) Element(aContainer, aContainerTest, aEmptyTest) : nsnull; }
102 :
103 0 : void Destroy() {
104 0 : this->~Element();
105 0 : MemoryElement::gPool.Free(this, sizeof(Element));
106 0 : }
107 :
108 0 : virtual const char* Type() const {
109 0 : return "nsRDFConInstanceTestNode::Element"; }
110 :
111 0 : virtual PLHashNumber Hash() const {
112 0 : return mozilla::HashGeneric(mContainerTest, mEmptyTest, mContainer.get());
113 : }
114 :
115 0 : virtual bool Equals(const MemoryElement& aElement) const {
116 0 : if (aElement.Type() == Type()) {
117 0 : const Element& element = static_cast<const Element&>(aElement);
118 0 : return mContainer == element.mContainer
119 : && mContainerTest == element.mContainerTest
120 0 : && mEmptyTest == element.mEmptyTest;
121 : }
122 0 : return false; }
123 :
124 : protected:
125 : nsCOMPtr<nsIRDFResource> mContainer;
126 : Test mContainerTest;
127 : Test mEmptyTest;
128 : };
129 :
130 : protected:
131 : nsXULTemplateQueryProcessorRDF* mProcessor;
132 : nsCOMPtr<nsIAtom> mContainerVariable;
133 : Test mContainer;
134 : Test mEmpty;
135 : };
136 :
137 : #endif // nsRDFConInstanceTestNode_h__
138 :
|