1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
15 * The Original Code is mozilla.org code.
17 * The Initial Developer of the Original Code is
18 * Netscape Communications Corporation.
19 * Portions created by the Initial Developer are Copyright (C) 1999
20 * the Initial Developer. All Rights Reserved.
24 * Alternatively, the contents of this file may be used under the terms of
25 * either of the GNU General Public License Version 2 or later (the "GPL"),
26 * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 * in which case the provisions of the GPL or the LGPL are applicable instead
28 * of those above. If you wish to allow use of your version of this file only
29 * under the terms of either the GPL or the LGPL, and not to allow others to
30 * use your version of this file under the terms of the MPL, indicate your
31 * decision by deleting the provisions above and replace them with the notice
32 * and other provisions required by the GPL or the LGPL. If you do not delete
33 * the provisions above, a recipient may use your version of this file under
34 * the terms of any one of the MPL, the GPL or the LGPL.
36 * ***** END LICENSE BLOCK ***** */
59 #include "morkIntMap.h"
62 //3456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789
64 // ````` ````` ````` ````` `````
65 // { ===== begin morkNode interface =====
67 /*public virtual*/ void
68 morkIntMap::CloseMorkNode(morkEnv
* ev
) // CloseIntMap() only if open
70 if ( this->IsOpenNode() )
73 this->CloseIntMap(ev
);
79 morkIntMap::~morkIntMap() // assert CloseIntMap() executed earlier
81 MORK_ASSERT(this->IsShutNode());
85 morkIntMap::morkIntMap(morkEnv
* ev
,
86 const morkUsage
& inUsage
, mork_size inValSize
,
87 nsIMdbHeap
* ioHeap
, nsIMdbHeap
* ioSlotHeap
, mork_bool inHoldChanges
)
88 : morkMap(ev
, inUsage
, ioHeap
, sizeof(mork_u4
), inValSize
,
89 morkIntMap_kStartSlotCount
, ioSlotHeap
, inHoldChanges
)
92 mNode_Derived
= morkDerived_kIntMap
;
95 /*public non-poly*/ void
96 morkIntMap::CloseIntMap(morkEnv
* ev
) // called by CloseMorkNode();
100 if ( this->IsNode() )
106 this->NonNodeError(ev
);
109 ev
->NilPointerError();
112 // } ===== end morkNode methods =====
113 // ````` ````` ````` ````` `````
115 // { ===== begin morkMap poly interface =====
116 /*virtual*/ mork_bool
// *((mork_u4*) inKeyA) == *((mork_u4*) inKeyB)
117 morkIntMap::Equal(morkEnv
* ev
, const void* inKeyA
, const void* inKeyB
) const
120 return *((const mork_u4
*) inKeyA
) == *((const mork_u4
*) inKeyB
);
123 /*virtual*/ mork_u4
// some integer function of *((mork_u4*) inKey)
124 morkIntMap::Hash(morkEnv
* ev
, const void* inKey
) const
127 return *((const mork_u4
*) inKey
);
129 // } ===== end morkMap poly interface =====
132 morkIntMap::AddInt(morkEnv
* ev
, mork_u4 inKey
, void* ioAddress
)
133 // the AddInt() method return value equals ev->Good().
137 this->Put(ev
, &inKey
, &ioAddress
,
138 /*key*/ (void*) 0, /*val*/ (void*) 0, (mork_change
**) 0);
145 morkIntMap::CutInt(morkEnv
* ev
, mork_u4 inKey
)
147 return this->Cut(ev
, &inKey
, /*key*/ (void*) 0, /*val*/ (void*) 0,
152 morkIntMap::GetInt(morkEnv
* ev
, mork_u4 inKey
)
153 // Note the returned val does NOT have an increase in refcount for this.
155 void* val
= 0; // old val in the map
156 this->Get(ev
, &inKey
, /*key*/ (void*) 0, &val
, (mork_change
**) 0);
162 morkIntMap::HasInt(morkEnv
* ev
, mork_u4 inKey
)
163 // Note the returned val does NOT have an increase in refcount for this.
165 return this->Get(ev
, &inKey
, /*key*/ (void*) 0, /*val*/ (void*) 0,
169 //3456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789
171 #ifdef MORK_POINTER_MAP_IMPL
173 // ````` ````` ````` ````` `````
174 // { ===== begin morkNode interface =====
176 /*public virtual*/ void
177 morkPointerMap::CloseMorkNode(morkEnv
* ev
) // ClosePointerMap() only if open
179 if ( this->IsOpenNode() )
182 this->ClosePointerMap(ev
);
188 morkPointerMap::~morkPointerMap() // assert ClosePointerMap() executed earlier
190 MORK_ASSERT(this->IsShutNode());
194 morkPointerMap::morkPointerMap(morkEnv
* ev
,
195 const morkUsage
& inUsage
, nsIMdbHeap
* ioHeap
, nsIMdbHeap
* ioSlotHeap
)
196 : morkMap(ev
, inUsage
, ioHeap
, sizeof(void*), sizeof(void*),
197 morkPointerMap_kStartSlotCount
, ioSlotHeap
,
198 /*inHoldChanges*/ morkBool_kFalse
)
201 mNode_Derived
= morkDerived_kPointerMap
;
204 /*public non-poly*/ void
205 morkPointerMap::ClosePointerMap(morkEnv
* ev
) // called by CloseMorkNode();
209 if ( this->IsNode() )
215 this->NonNodeError(ev
);
218 ev
->NilPointerError();
221 // } ===== end morkNode methods =====
222 // ````` ````` ````` ````` `````
224 // { ===== begin morkMap poly interface =====
225 /*virtual*/ mork_bool
// *((void**) inKeyA) == *((void**) inKeyB)
226 morkPointerMap::Equal(morkEnv
* ev
, const void* inKeyA
, const void* inKeyB
) const
229 return *((const void**) inKeyA
) == *((const void**) inKeyB
);
232 /*virtual*/ mork_u4
// some integer function of *((mork_u4*) inKey)
233 morkPointerMap::Hash(morkEnv
* ev
, const void* inKey
) const
236 return *((const mork_u4
*) inKey
);
238 // } ===== end morkMap poly interface =====
241 morkPointerMap::AddPointer(morkEnv
* ev
, void* inKey
, void* ioAddress
)
242 // the AddPointer() method return value equals ev->Good().
246 this->Put(ev
, &inKey
, &ioAddress
,
247 /*key*/ (void*) 0, /*val*/ (void*) 0, (mork_change
**) 0);
254 morkPointerMap::CutPointer(morkEnv
* ev
, void* inKey
)
256 return this->Cut(ev
, &inKey
, /*key*/ (void*) 0, /*val*/ (void*) 0,
261 morkPointerMap::GetPointer(morkEnv
* ev
, void* inKey
)
262 // Note the returned val does NOT have an increase in refcount for this.
264 void* val
= 0; // old val in the map
265 this->Get(ev
, &inKey
, /*key*/ (void*) 0, &val
, (mork_change
**) 0);
271 morkPointerMap::HasPointer(morkEnv
* ev
, void* inKey
)
272 // Note the returned val does NOT have an increase in refcount for this.
274 return this->Get(ev
, &inKey
, /*key*/ (void*) 0, /*val*/ (void*) 0,
277 #endif /*MORK_POINTER_MAP_IMPL*/
280 //3456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789