Back to index

lightning-sunbird  0.9+nobinonly
morkIntMap.cpp
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-  */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is mozilla.org code.
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Netscape Communications Corporation.
00019  * Portions created by the Initial Developer are Copyright (C) 1999
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *
00024  * Alternatively, the contents of this file may be used under the terms of
00025  * either of the GNU General Public License Version 2 or later (the "GPL"),
00026  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00027  * in which case the provisions of the GPL or the LGPL are applicable instead
00028  * of those above. If you wish to allow use of your version of this file only
00029  * under the terms of either the GPL or the LGPL, and not to allow others to
00030  * use your version of this file under the terms of the MPL, indicate your
00031  * decision by deleting the provisions above and replace them with the notice
00032  * and other provisions required by the GPL or the LGPL. If you do not delete
00033  * the provisions above, a recipient may use your version of this file under
00034  * the terms of any one of the MPL, the GPL or the LGPL.
00035  *
00036  * ***** END LICENSE BLOCK ***** */
00037 
00038 #ifndef _MDB_
00039 #include "mdb.h"
00040 #endif
00041 
00042 #ifndef _MORK_
00043 #include "mork.h"
00044 #endif
00045 
00046 #ifndef _MORKNODE_
00047 #include "morkNode.h"
00048 #endif
00049 
00050 #ifndef _MORKENV_
00051 #include "morkEnv.h"
00052 #endif
00053 
00054 #ifndef _MORKMAP_
00055 #include "morkMap.h"
00056 #endif
00057 
00058 #ifndef _MORKINTMAP_
00059 #include "morkIntMap.h"
00060 #endif
00061 
00062 //3456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789
00063 
00064 // ````` ````` ````` ````` ````` 
00065 // { ===== begin morkNode interface =====
00066 
00067 /*public virtual*/ void
00068 morkIntMap::CloseMorkNode(morkEnv* ev) // CloseIntMap() only if open
00069 {
00070   if ( this->IsOpenNode() )
00071   {
00072     this->MarkClosing();
00073     this->CloseIntMap(ev);
00074     this->MarkShut();
00075   }
00076 }
00077 
00078 /*public virtual*/
00079 morkIntMap::~morkIntMap() // assert CloseIntMap() executed earlier
00080 {
00081   MORK_ASSERT(this->IsShutNode());
00082 }
00083 
00084 /*public non-poly*/
00085 morkIntMap::morkIntMap(morkEnv* ev,
00086   const morkUsage& inUsage, mork_size inValSize,
00087   nsIMdbHeap* ioHeap, nsIMdbHeap* ioSlotHeap, mork_bool inHoldChanges)
00088 : morkMap(ev, inUsage, ioHeap, sizeof(mork_u4), inValSize,
00089   morkIntMap_kStartSlotCount, ioSlotHeap, inHoldChanges)
00090 {
00091   if ( ev->Good() )
00092     mNode_Derived = morkDerived_kIntMap;
00093 }
00094 
00095 /*public non-poly*/ void
00096 morkIntMap::CloseIntMap(morkEnv* ev) // called by CloseMorkNode();
00097 {
00098   if ( this )
00099   {
00100     if ( this->IsNode() )
00101     {
00102       this->CloseMap(ev);
00103       this->MarkShut();
00104     }
00105     else
00106       this->NonNodeError(ev);
00107   }
00108   else
00109     ev->NilPointerError();
00110 }
00111 
00112 // } ===== end morkNode methods =====
00113 // ````` ````` ````` ````` ````` 
00114 
00115 // { ===== begin morkMap poly interface =====
00116 /*virtual*/ mork_bool // *((mork_u4*) inKeyA) == *((mork_u4*) inKeyB)
00117 morkIntMap::Equal(morkEnv* ev, const void* inKeyA, const void* inKeyB) const
00118 {
00119   MORK_USED_1(ev);
00120   return *((const mork_u4*) inKeyA) == *((const mork_u4*) inKeyB);
00121 }
00122 
00123 /*virtual*/ mork_u4 // some integer function of *((mork_u4*) inKey)
00124 morkIntMap::Hash(morkEnv* ev, const void* inKey) const
00125 {
00126   MORK_USED_1(ev);
00127   return *((const mork_u4*) inKey);
00128 }
00129 // } ===== end morkMap poly interface =====
00130 
00131 mork_bool
00132 morkIntMap::AddInt(morkEnv* ev, mork_u4 inKey, void* ioAddress)
00133   // the AddInt() method return value equals ev->Good().
00134 {
00135   if ( ev->Good() )
00136   {
00137     this->Put(ev, &inKey, &ioAddress, 
00138       /*key*/ (void*) 0, /*val*/ (void*) 0, (mork_change**) 0);
00139   }
00140     
00141   return ev->Good();
00142 }
00143 
00144 mork_bool
00145 morkIntMap::CutInt(morkEnv* ev, mork_u4 inKey)
00146 {
00147   return this->Cut(ev, &inKey, /*key*/ (void*) 0, /*val*/ (void*) 0,
00148     (mork_change**) 0);
00149 }
00150 
00151 void*
00152 morkIntMap::GetInt(morkEnv* ev, mork_u4 inKey)
00153   // Note the returned val does NOT have an increase in refcount for this.
00154 {
00155   void* val = 0; // old val in the map
00156   this->Get(ev, &inKey, /*key*/ (void*) 0, &val, (mork_change**) 0);
00157   
00158   return val;
00159 }
00160 
00161 mork_bool
00162 morkIntMap::HasInt(morkEnv* ev, mork_u4 inKey)
00163   // Note the returned val does NOT have an increase in refcount for this.
00164 {
00165   return this->Get(ev, &inKey, /*key*/ (void*) 0, /*val*/ (void*) 0, 
00166     (mork_change**) 0);
00167 }
00168 
00169 //3456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789
00170 
00171 #ifdef MORK_POINTER_MAP_IMPL
00172 
00173 // ````` ````` ````` ````` ````` 
00174 // { ===== begin morkNode interface =====
00175 
00176 /*public virtual*/ void
00177 morkPointerMap::CloseMorkNode(morkEnv* ev) // ClosePointerMap() only if open
00178 {
00179   if ( this->IsOpenNode() )
00180   {
00181     this->MarkClosing();
00182     this->ClosePointerMap(ev);
00183     this->MarkShut();
00184   }
00185 }
00186 
00187 /*public virtual*/
00188 morkPointerMap::~morkPointerMap() // assert ClosePointerMap() executed earlier
00189 {
00190   MORK_ASSERT(this->IsShutNode());
00191 }
00192 
00193 /*public non-poly*/
00194 morkPointerMap::morkPointerMap(morkEnv* ev,
00195   const morkUsage& inUsage, nsIMdbHeap* ioHeap, nsIMdbHeap* ioSlotHeap)
00196 : morkMap(ev, inUsage, ioHeap, sizeof(void*), sizeof(void*),
00197   morkPointerMap_kStartSlotCount, ioSlotHeap,
00198   /*inHoldChanges*/ morkBool_kFalse)
00199 {
00200   if ( ev->Good() )
00201     mNode_Derived = morkDerived_kPointerMap;
00202 }
00203 
00204 /*public non-poly*/ void
00205 morkPointerMap::ClosePointerMap(morkEnv* ev) // called by CloseMorkNode();
00206 {
00207   if ( this )
00208   {
00209     if ( this->IsNode() )
00210     {
00211       this->CloseMap(ev);
00212       this->MarkShut();
00213     }
00214     else
00215       this->NonNodeError(ev);
00216   }
00217   else
00218     ev->NilPointerError();
00219 }
00220 
00221 // } ===== end morkNode methods =====
00222 // ````` ````` ````` ````` ````` 
00223 
00224 // { ===== begin morkMap poly interface =====
00225 /*virtual*/ mork_bool // *((void**) inKeyA) == *((void**) inKeyB)
00226 morkPointerMap::Equal(morkEnv* ev, const void* inKeyA, const void* inKeyB) const
00227 {
00228   MORK_USED_1(ev);
00229   return *((const void**) inKeyA) == *((const void**) inKeyB);
00230 }
00231 
00232 /*virtual*/ mork_u4 // some integer function of *((mork_u4*) inKey)
00233 morkPointerMap::Hash(morkEnv* ev, const void* inKey) const
00234 {
00235   MORK_USED_1(ev);
00236   return *((const mork_u4*) inKey);
00237 }
00238 // } ===== end morkMap poly interface =====
00239 
00240 mork_bool
00241 morkPointerMap::AddPointer(morkEnv* ev, void* inKey, void* ioAddress)
00242   // the AddPointer() method return value equals ev->Good().
00243 {
00244   if ( ev->Good() )
00245   {
00246     this->Put(ev, &inKey, &ioAddress, 
00247       /*key*/ (void*) 0, /*val*/ (void*) 0, (mork_change**) 0);
00248   }
00249     
00250   return ev->Good();
00251 }
00252 
00253 mork_bool
00254 morkPointerMap::CutPointer(morkEnv* ev, void* inKey)
00255 {
00256   return this->Cut(ev, &inKey, /*key*/ (void*) 0, /*val*/ (void*) 0,
00257     (mork_change**) 0);
00258 }
00259 
00260 void*
00261 morkPointerMap::GetPointer(morkEnv* ev, void* inKey)
00262   // Note the returned val does NOT have an increase in refcount for this.
00263 {
00264   void* val = 0; // old val in the map
00265   this->Get(ev, &inKey, /*key*/ (void*) 0, &val, (mork_change**) 0);
00266   
00267   return val;
00268 }
00269 
00270 mork_bool
00271 morkPointerMap::HasPointer(morkEnv* ev, void* inKey)
00272   // Note the returned val does NOT have an increase in refcount for this.
00273 {
00274   return this->Get(ev, &inKey, /*key*/ (void*) 0, /*val*/ (void*) 0, 
00275     (mork_change**) 0);
00276 }
00277 #endif /*MORK_POINTER_MAP_IMPL*/
00278 
00279 
00280 //3456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789