1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef _MDB_
# include "mdb.h"
#endif
#ifndef _MORK_
# include "mork.h"
#endif
#ifndef _MORKNODE_
# include "morkNode.h"
#endif
#ifndef _MORKENV_
# include "morkEnv.h"
#endif
#ifndef _MORKMAP_
# include "morkMap.h"
#endif
#ifndef _MORKINTMAP_
# include "morkIntMap.h"
#endif
#ifndef _MORKNODEMAP_
# include "morkNodeMap.h"
#endif
// 456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789
// ````` ````` ````` ````` `````
// { ===== begin morkNode interface =====
/*public virtual*/ void morkNodeMap::CloseMorkNode(
morkEnv* ev) // CloseNodeMap() only if open
{
if (this->IsOpenNode()) {
this->MarkClosing();
this->CloseNodeMap(ev);
this->MarkShut();
}
}
/*public virtual*/
morkNodeMap::~morkNodeMap() // assert CloseNodeMap() executed earlier
{
MORK_ASSERT(this->IsShutNode());
}
/*public non-poly*/
morkNodeMap::morkNodeMap(morkEnv* ev, const morkUsage& inUsage,
nsIMdbHeap* ioHeap, nsIMdbHeap* ioSlotHeap)
: morkIntMap(ev, inUsage, /*valsize*/ sizeof(morkNode*), ioHeap, ioSlotHeap,
/*inHoldChanges*/ morkBool_kTrue) {
if (ev->Good()) mNode_Derived = morkDerived_kNodeMap;
}
/*public non-poly*/ void morkNodeMap::CloseNodeMap(
morkEnv* ev) // called by CloseMorkNode();
{
if (this->IsNode()) {
this->CutAllNodes(ev);
this->CloseMap(ev);
this->MarkShut();
} else
this->NonNodeError(ev);
}
// } ===== end morkNode methods =====
// ````` ````` ````` ````` `````
mork_bool morkNodeMap::AddNode(morkEnv* ev, mork_token inToken,
morkNode* ioNode)
// the AddNode() method return value equals ev->Good().
{
if (ioNode && ev->Good()) {
morkNode* node = 0; // old val in the map
mork_bool put = this->Put(ev, &inToken, &ioNode,
/*key*/ (void*)0, &node, (mork_change**)0);
if (put) // replaced an existing value for key inToken?
{
if (node && node != ioNode) // need to release old node?
node->CutStrongRef(ev);
}
if (ev->Bad() || !ioNode->AddStrongRef(ev)) {
// problems adding node or increasing refcount?
this->Cut(ev, &inToken, // make sure not in map
/*key*/ (void*)0, /*val*/ (void*)0, (mork_change**)0);
}
} else if (!ioNode)
ev->NilPointerError();
return ev->Good();
}
mork_bool morkNodeMap::CutNode(morkEnv* ev, mork_token inToken) {
morkNode* node = 0; // old val in the map
mork_bool outCutNode = this->Cut(ev, &inToken,
/*key*/ (void*)0, &node, (mork_change**)0);
if (node) node->CutStrongRef(ev);
return outCutNode;
}
morkNode* morkNodeMap::GetNode(morkEnv* ev, mork_token inToken)
// Note the returned node does NOT have an increase in refcount for this.
{
morkNode* node = 0; // old val in the map
this->Get(ev, &inToken, /*key*/ (void*)0, &node, (mork_change**)0);
return node;
}
mork_num morkNodeMap::CutAllNodes(morkEnv* ev)
// CutAllNodes() releases all the reference node values.
{
mork_num outSlots = mMap_Slots;
mork_token key = 0; // old key token in the map
morkNode* val = 0; // old val node in the map
mork_change* c = 0;
morkNodeMapIter i(ev, this);
for (c = i.FirstNode(ev, &key, &val); c; c = i.NextNode(ev, &key, &val)) {
if (val) val->CutStrongRef(ev);
i.CutHereNode(ev, /*key*/ (mork_token*)0, /*val*/ (morkNode**)0);
}
return outSlots;
}
// 456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789
|