Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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/. */
5 :
6 : #ifndef TRANSFRMX_VARIABLEMAP_H
7 : #define TRANSFRMX_VARIABLEMAP_H
8 :
9 : #include "nsError.h"
10 : #include "txXMLUtils.h"
11 : #include "txExprResult.h"
12 : #include "txExpandedNameMap.h"
13 :
14 : class txVariableMap {
15 : public:
16 : txVariableMap();
17 : ~txVariableMap();
18 :
19 : nsresult bindVariable(const txExpandedName& aName, txAExprResult* aValue);
20 :
21 : void getVariable(const txExpandedName& aName, txAExprResult** aResult);
22 :
23 : void removeVariable(const txExpandedName& aName);
24 :
25 : private:
26 : txExpandedNameMap<txAExprResult> mMap;
27 : };
28 :
29 :
30 : inline
31 0 : txVariableMap::txVariableMap()
32 : {
33 0 : MOZ_COUNT_CTOR(txVariableMap);
34 0 : }
35 :
36 : inline
37 0 : txVariableMap::~txVariableMap()
38 : {
39 0 : MOZ_COUNT_DTOR(txVariableMap);
40 :
41 0 : txExpandedNameMap<txAExprResult>::iterator iter(mMap);
42 0 : while (iter.next()) {
43 0 : txAExprResult* res = iter.value();
44 0 : NS_RELEASE(res);
45 : }
46 0 : }
47 :
48 : inline nsresult
49 0 : txVariableMap::bindVariable(const txExpandedName& aName, txAExprResult* aValue)
50 : {
51 0 : NS_ASSERTION(aValue, "can't add null-variables to a txVariableMap");
52 0 : nsresult rv = mMap.add(aName, aValue);
53 0 : if (NS_SUCCEEDED(rv)) {
54 0 : NS_ADDREF(aValue);
55 : }
56 0 : else if (rv == NS_ERROR_XSLT_ALREADY_SET) {
57 0 : rv = NS_ERROR_XSLT_VAR_ALREADY_SET;
58 : }
59 0 : return rv;
60 : }
61 :
62 : inline void
63 0 : txVariableMap::getVariable(const txExpandedName& aName, txAExprResult** aResult)
64 : {
65 0 : *aResult = mMap.get(aName);
66 0 : if (*aResult) {
67 0 : NS_ADDREF(*aResult);
68 : }
69 0 : }
70 :
71 : inline void
72 0 : txVariableMap::removeVariable(const txExpandedName& aName)
73 : {
74 0 : txAExprResult* var = mMap.remove(aName);
75 0 : NS_IF_RELEASE(var);
76 0 : }
77 :
78 : #endif //TRANSFRMX_VARIABLEMAP_H
|