michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef nsXMLBinding_h__ michael@0: #define nsXMLBinding_h__ michael@0: michael@0: #include "nsAutoPtr.h" michael@0: #include "nsIAtom.h" michael@0: #include "nsCycleCollectionParticipant.h" michael@0: #include "mozilla/Attributes.h" michael@0: michael@0: class nsXULTemplateResultXML; michael@0: class nsXMLBindingValues; michael@0: michael@0: /** michael@0: * Classes related to storing bindings for XML handling. michael@0: */ michael@0: michael@0: /** michael@0: * a description michael@0: */ michael@0: struct nsXMLBinding { michael@0: nsCOMPtr mVar; michael@0: nsCOMPtr mExpr; michael@0: michael@0: nsAutoPtr mNext; michael@0: michael@0: nsXMLBinding(nsIAtom* aVar, nsIDOMXPathExpression* aExpr) michael@0: : mVar(aVar), mExpr(aExpr), mNext(nullptr) michael@0: { michael@0: MOZ_COUNT_CTOR(nsXMLBinding); michael@0: } michael@0: michael@0: ~nsXMLBinding() michael@0: { michael@0: MOZ_COUNT_DTOR(nsXMLBinding); michael@0: } michael@0: }; michael@0: michael@0: /** michael@0: * a collection of descriptors. This object is refcounted by michael@0: * nsXMLBindingValues objects and the query processor. michael@0: */ michael@0: class nsXMLBindingSet MOZ_FINAL michael@0: { michael@0: public: michael@0: michael@0: // results hold a reference to a binding set in their michael@0: // nsXMLBindingValues fields michael@0: nsCycleCollectingAutoRefCnt mRefCnt; michael@0: michael@0: // pointer to the first binding in a linked list michael@0: nsAutoPtr mFirst; michael@0: michael@0: public: michael@0: michael@0: NS_METHOD_(MozExternalRefCountType) AddRef(); michael@0: NS_METHOD_(MozExternalRefCountType) Release(); michael@0: NS_DECL_OWNINGTHREAD michael@0: NS_DECL_CYCLE_COLLECTION_NATIVE_CLASS(nsXMLBindingSet) michael@0: michael@0: /** michael@0: * Add a binding to the set michael@0: */ michael@0: nsresult michael@0: AddBinding(nsIAtom* aVar, nsIDOMXPathExpression* aExpr); michael@0: michael@0: /** michael@0: * The nsXMLBindingValues class stores an array of values, one for each michael@0: * target symbol that could be set by the bindings in the set. michael@0: * LookupTargetIndex determines the index into the array for a given michael@0: * target symbol. michael@0: */ michael@0: int32_t michael@0: LookupTargetIndex(nsIAtom* aTargetVariable, nsXMLBinding** aBinding); michael@0: }; michael@0: michael@0: /** michael@0: * a set of values of bindings. This object is used once per result. michael@0: */ michael@0: class nsXMLBindingValues michael@0: { michael@0: protected: michael@0: michael@0: // the binding set michael@0: nsRefPtr mBindings; michael@0: michael@0: /** michael@0: * A set of values for variable bindings. To look up a binding value, michael@0: * scan through the binding set in mBindings for the right target atom. michael@0: * Its index will correspond to the index in this array. michael@0: */ michael@0: nsCOMArray mValues; michael@0: michael@0: public: michael@0: michael@0: nsXMLBindingValues() { MOZ_COUNT_CTOR(nsXMLBindingValues); } michael@0: ~nsXMLBindingValues() { MOZ_COUNT_DTOR(nsXMLBindingValues); } michael@0: michael@0: nsXMLBindingSet* GetBindingSet() { return mBindings; } michael@0: michael@0: void SetBindingSet(nsXMLBindingSet* aBindings) { mBindings = aBindings; } michael@0: michael@0: int32_t michael@0: LookupTargetIndex(nsIAtom* aTargetVariable, nsXMLBinding** aBinding) michael@0: { michael@0: return mBindings ? michael@0: mBindings->LookupTargetIndex(aTargetVariable, aBinding) : -1; michael@0: } michael@0: michael@0: /** michael@0: * Retrieve the assignment for a particular variable michael@0: * michael@0: * aResult the result generated from the template michael@0: * aBinding the binding looked up using LookupTargetIndex michael@0: * aIndex the index of the assignment to retrieve michael@0: * aType the type of result expected michael@0: * aValue the value of the assignment michael@0: */ michael@0: void michael@0: GetAssignmentFor(nsXULTemplateResultXML* aResult, michael@0: nsXMLBinding* aBinding, michael@0: int32_t idx, michael@0: uint16_t type, michael@0: nsIDOMXPathResult** aValue); michael@0: michael@0: void michael@0: GetNodeAssignmentFor(nsXULTemplateResultXML* aResult, michael@0: nsXMLBinding* aBinding, michael@0: int32_t idx, michael@0: nsIDOMNode** aValue); michael@0: michael@0: void michael@0: GetStringAssignmentFor(nsXULTemplateResultXML* aResult, michael@0: nsXMLBinding* aBinding, michael@0: int32_t idx, michael@0: nsAString& aValue); michael@0: }; michael@0: michael@0: #endif // nsXMLBinding_h__