1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #ifndef TRANSFRMX_VARIABLEMAP_H
7 #define TRANSFRMX_VARIABLEMAP_H
10 #include "txXMLUtils.h"
11 #include "txExprResult.h"
12 #include "txExpandedNameMap.h"
15 * Map that maps from expanded name to an expression result value. This is just
16 * a base class, use txVariableMap or txParameterMap instead.
18 class txVariableMapBase
{
20 nsresult
bindVariable(const txExpandedName
& aName
, txAExprResult
* aValue
);
22 void getVariable(const txExpandedName
& aName
, txAExprResult
** aResult
);
24 void removeVariable(const txExpandedName
& aName
);
27 txVariableMapBase() = default;
30 txExpandedNameMap
<txAExprResult
> mMap
;
34 * Map for mapping from expanded name to variable values. This is not
35 * refcounted, so owners need to be careful to clean this up.
37 class txVariableMap
: public txVariableMapBase
{
39 txVariableMap() { MOZ_COUNT_CTOR(txVariableMap
); }
40 MOZ_COUNTED_DTOR(txVariableMap
)
44 * Map for mapping from expanded name to parameter values. This is refcounted,
45 * so multiple owners can hold a reference.
47 class txParameterMap
: public txVariableMapBase
{
49 NS_INLINE_DECL_REFCOUNTING(txParameterMap
)
52 ~txParameterMap() = default;
55 inline txVariableMapBase::~txVariableMapBase() {
56 txExpandedNameMap
<txAExprResult
>::iterator
iter(mMap
);
58 txAExprResult
* res
= iter
.value();
63 inline nsresult
txVariableMapBase::bindVariable(const txExpandedName
& aName
,
64 txAExprResult
* aValue
) {
65 NS_ASSERTION(aValue
, "can't add null-variables to a txVariableMap");
66 nsresult rv
= mMap
.add(aName
, aValue
);
67 if (NS_SUCCEEDED(rv
)) {
69 } else if (rv
== NS_ERROR_XSLT_ALREADY_SET
) {
70 rv
= NS_ERROR_XSLT_VAR_ALREADY_SET
;
75 inline void txVariableMapBase::getVariable(const txExpandedName
& aName
,
76 txAExprResult
** aResult
) {
77 *aResult
= mMap
.get(aName
);
83 inline void txVariableMapBase::removeVariable(const txExpandedName
& aName
) {
84 txAExprResult
* var
= mMap
.remove(aName
);
88 #endif // TRANSFRMX_VARIABLEMAP_H