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 _MDB_
7 #  include "mdb.h"
8 #endif
9 
10 #ifndef _MORK_
11 #  include "mork.h"
12 #endif
13 
14 #ifndef _MORKNODE_
15 #  include "morkNode.h"
16 #endif
17 
18 #ifndef _MORKENV_
19 #  include "morkEnv.h"
20 #endif
21 
22 #ifndef _MORKMAP_
23 #  include "morkMap.h"
24 #endif
25 
26 #ifndef _MORKINTMAP_
27 #  include "morkIntMap.h"
28 #endif
29 
30 // 456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789
31 
32 // ````` ````` ````` ````` `````
33 // { ===== begin morkNode interface =====
34 
CloseMorkNode(morkEnv * ev)35 /*public virtual*/ void morkIntMap::CloseMorkNode(
36     morkEnv* ev)  // CloseIntMap() only if open
37 {
38   if (this->IsOpenNode()) {
39     this->MarkClosing();
40     this->CloseIntMap(ev);
41     this->MarkShut();
42   }
43 }
44 
45 /*public virtual*/
~morkIntMap()46 morkIntMap::~morkIntMap()  // assert CloseIntMap() executed earlier
47 {
48   MORK_ASSERT(this->IsShutNode());
49 }
50 
51 /*public non-poly*/
morkIntMap(morkEnv * ev,const morkUsage & inUsage,mork_size inValSize,nsIMdbHeap * ioHeap,nsIMdbHeap * ioSlotHeap,mork_bool inHoldChanges)52 morkIntMap::morkIntMap(morkEnv* ev, const morkUsage& inUsage,
53                        mork_size inValSize, nsIMdbHeap* ioHeap,
54                        nsIMdbHeap* ioSlotHeap, mork_bool inHoldChanges)
55     : morkMap(ev, inUsage, ioHeap, sizeof(mork_u4), inValSize,
56               morkIntMap_kStartSlotCount, ioSlotHeap, inHoldChanges) {
57   if (ev->Good()) mNode_Derived = morkDerived_kIntMap;
58 }
59 
CloseIntMap(morkEnv * ev)60 /*public non-poly*/ void morkIntMap::CloseIntMap(
61     morkEnv* ev)  // called by CloseMorkNode();
62 {
63   if (this->IsNode()) {
64     this->CloseMap(ev);
65     this->MarkShut();
66   } else
67     this->NonNodeError(ev);
68 }
69 
70 // } ===== end morkNode methods =====
71 // ````` ````` ````` ````` `````
72 
73 // { ===== begin morkMap poly interface =====
74 /*virtual*/ mork_bool  // *((mork_u4*) inKeyA) == *((mork_u4*) inKeyB)
Equal(morkEnv * ev,const void * inKeyA,const void * inKeyB) const75 morkIntMap::Equal(morkEnv* ev, const void* inKeyA, const void* inKeyB) const {
76   MORK_USED_1(ev);
77   return *((const mork_u4*)inKeyA) == *((const mork_u4*)inKeyB);
78 }
79 
80 /*virtual*/ mork_u4  // some integer function of *((mork_u4*) inKey)
Hash(morkEnv * ev,const void * inKey) const81 morkIntMap::Hash(morkEnv* ev, const void* inKey) const {
82   MORK_USED_1(ev);
83   return *((const mork_u4*)inKey);
84 }
85 // } ===== end morkMap poly interface =====
86 
AddInt(morkEnv * ev,mork_u4 inKey,void * ioAddress)87 mork_bool morkIntMap::AddInt(morkEnv* ev, mork_u4 inKey, void* ioAddress)
88 // the AddInt() method return value equals ev->Good().
89 {
90   if (ev->Good()) {
91     this->Put(ev, &inKey, &ioAddress,
92               /*key*/ (void*)0, /*val*/ (void*)0, (mork_change**)0);
93   }
94 
95   return ev->Good();
96 }
97 
CutInt(morkEnv * ev,mork_u4 inKey)98 mork_bool morkIntMap::CutInt(morkEnv* ev, mork_u4 inKey) {
99   return this->Cut(ev, &inKey, /*key*/ (void*)0, /*val*/ (void*)0,
100                    (mork_change**)0);
101 }
102 
GetInt(morkEnv * ev,mork_u4 inKey)103 void* morkIntMap::GetInt(morkEnv* ev, mork_u4 inKey)
104 // Note the returned val does NOT have an increase in refcount for this.
105 {
106   void* val = 0;  // old val in the map
107   this->Get(ev, &inKey, /*key*/ (void*)0, &val, (mork_change**)0);
108 
109   return val;
110 }
111 
HasInt(morkEnv * ev,mork_u4 inKey)112 mork_bool morkIntMap::HasInt(morkEnv* ev, mork_u4 inKey)
113 // Note the returned val does NOT have an increase in refcount for this.
114 {
115   return this->Get(ev, &inKey, /*key*/ (void*)0, /*val*/ (void*)0,
116                    (mork_change**)0);
117 }
118 
119 // 456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789
120 
121 #ifdef MORK_POINTER_MAP_IMPL
122 
123 // ````` ````` ````` ````` `````
124 // { ===== begin morkNode interface =====
125 
CloseMorkNode(morkEnv * ev)126 /*public virtual*/ void morkPointerMap::CloseMorkNode(
127     morkEnv* ev)  // ClosePointerMap() only if open
128 {
129   if (this->IsOpenNode()) {
130     this->MarkClosing();
131     this->ClosePointerMap(ev);
132     this->MarkShut();
133   }
134 }
135 
136 /*public virtual*/
~morkPointerMap()137 morkPointerMap::~morkPointerMap()  // assert ClosePointerMap() executed earlier
138 {
139   MORK_ASSERT(this->IsShutNode());
140 }
141 
142 /*public non-poly*/
morkPointerMap(morkEnv * ev,const morkUsage & inUsage,nsIMdbHeap * ioHeap,nsIMdbHeap * ioSlotHeap)143 morkPointerMap::morkPointerMap(morkEnv* ev, const morkUsage& inUsage,
144                                nsIMdbHeap* ioHeap, nsIMdbHeap* ioSlotHeap)
145     : morkMap(ev, inUsage, ioHeap, sizeof(void*), sizeof(void*),
146               morkPointerMap_kStartSlotCount, ioSlotHeap,
147               /*inHoldChanges*/ morkBool_kFalse) {
148   if (ev->Good()) mNode_Derived = morkDerived_kPointerMap;
149 }
150 
ClosePointerMap(morkEnv * ev)151 /*public non-poly*/ void morkPointerMap::ClosePointerMap(
152     morkEnv* ev)  // called by CloseMorkNode();
153 {
154   if (this->IsNode()) {
155     this->CloseMap(ev);
156     this->MarkShut();
157   } else
158     this->NonNodeError(ev);
159 }
160 
161 // } ===== end morkNode methods =====
162 // ````` ````` ````` ````` `````
163 
164 // { ===== begin morkMap poly interface =====
165 /*virtual*/ mork_bool  // *((void**) inKeyA) == *((void**) inKeyB)
Equal(morkEnv * ev,const void * inKeyA,const void * inKeyB) const166 morkPointerMap::Equal(morkEnv* ev, const void* inKeyA,
167                       const void* inKeyB) const {
168   MORK_USED_1(ev);
169   return *((const void**)inKeyA) == *((const void**)inKeyB);
170 }
171 
172 /*virtual*/ mork_u4  // some integer function of *((mork_u4*) inKey)
Hash(morkEnv * ev,const void * inKey) const173 morkPointerMap::Hash(morkEnv* ev, const void* inKey) const {
174   MORK_USED_1(ev);
175   return *((const mork_u4*)inKey);
176 }
177 // } ===== end morkMap poly interface =====
178 
AddPointer(morkEnv * ev,void * inKey,void * ioAddress)179 mork_bool morkPointerMap::AddPointer(morkEnv* ev, void* inKey, void* ioAddress)
180 // the AddPointer() method return value equals ev->Good().
181 {
182   if (ev->Good()) {
183     this->Put(ev, &inKey, &ioAddress,
184               /*key*/ (void*)0, /*val*/ (void*)0, (mork_change**)0);
185   }
186 
187   return ev->Good();
188 }
189 
CutPointer(morkEnv * ev,void * inKey)190 mork_bool morkPointerMap::CutPointer(morkEnv* ev, void* inKey) {
191   return this->Cut(ev, &inKey, /*key*/ (void*)0, /*val*/ (void*)0,
192                    (mork_change**)0);
193 }
194 
GetPointer(morkEnv * ev,void * inKey)195 void* morkPointerMap::GetPointer(morkEnv* ev, void* inKey)
196 // Note the returned val does NOT have an increase in refcount for this.
197 {
198   void* val = 0;  // old val in the map
199   this->Get(ev, &inKey, /*key*/ (void*)0, &val, (mork_change**)0);
200 
201   return val;
202 }
203 
HasPointer(morkEnv * ev,void * inKey)204 mork_bool morkPointerMap::HasPointer(morkEnv* ev, void* inKey)
205 // Note the returned val does NOT have an increase in refcount for this.
206 {
207   return this->Get(ev, &inKey, /*key*/ (void*)0, /*val*/ (void*)0,
208                    (mork_change**)0);
209 }
210 #endif /*MORK_POINTER_MAP_IMPL*/
211 
212 // 456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789
213