Back to index

lightning-sunbird  0.9+nobinonly
morkRowMap.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 _MORKROWMAP_
00059 #include "morkRowMap.h"
00060 #endif
00061 
00062 #ifndef _MORKROW_
00063 #include "morkRow.h"
00064 #endif
00065 
00066 //3456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789
00067 
00068 // ````` ````` ````` ````` ````` 
00069 // { ===== begin morkNode interface =====
00070 
00071 /*public virtual*/ void
00072 morkRowMap::CloseMorkNode(morkEnv* ev) // CloseRowMap() only if open
00073 {
00074   if ( this->IsOpenNode() )
00075   {
00076     this->MarkClosing();
00077     this->CloseRowMap(ev);
00078     this->MarkShut();
00079   }
00080 }
00081 
00082 /*public virtual*/
00083 morkRowMap::~morkRowMap() // assert CloseRowMap() executed earlier
00084 {
00085   MORK_ASSERT(this->IsShutNode());
00086 }
00087 
00088 /*public non-poly*/
00089 morkRowMap::morkRowMap(morkEnv* ev, const morkUsage& inUsage,
00090   nsIMdbHeap* ioHeap, nsIMdbHeap* ioSlotHeap, mork_size inSlots)
00091 : morkMap(ev, inUsage,  ioHeap,
00092   /*inKeySize*/ sizeof(morkRow*), /*inValSize*/ 0,
00093   inSlots, ioSlotHeap, /*inHoldChanges*/ morkBool_kFalse)
00094 {
00095   if ( ev->Good() )
00096     mNode_Derived = morkDerived_kRowMap;
00097 }
00098 
00099 /*public non-poly*/ void
00100 morkRowMap::CloseRowMap(morkEnv* ev) // called by CloseMorkNode();
00101 {
00102   if ( this )
00103   {
00104     if ( this->IsNode() )
00105     {
00106       this->CloseMap(ev);
00107       this->MarkShut();
00108     }
00109     else
00110       this->NonNodeError(ev);
00111   }
00112   else
00113     ev->NilPointerError();
00114 }
00115 
00116 // } ===== end morkNode methods =====
00117 // ````` ````` ````` ````` ````` 
00118 
00119 
00120 // { ===== begin morkMap poly interface =====
00121 /*virtual*/ mork_bool // 
00122 morkRowMap::Equal(morkEnv* ev, const void* inKeyA,
00123   const void* inKeyB) const
00124 {
00125   MORK_USED_1(ev);
00126   return (*(const morkRow**) inKeyA)->EqualRow(*(const morkRow**) inKeyB);
00127 }
00128 
00129 /*virtual*/ mork_u4 // 
00130 morkRowMap::Hash(morkEnv* ev, const void* inKey) const
00131 {
00132   MORK_USED_1(ev);
00133   return (*(const morkRow**) inKey)->HashRow();
00134 }
00135 // } ===== end morkMap poly interface =====
00136 
00137 
00138 mork_bool
00139 morkRowMap::AddRow(morkEnv* ev, morkRow* ioRow)
00140 {
00141   if ( ev->Good() )
00142   {
00143     this->Put(ev, &ioRow, /*val*/ (void*) 0, 
00144       /*key*/ (void*) 0, /*val*/ (void*) 0, (mork_change**) 0);
00145   }
00146   return ev->Good();
00147 }
00148 
00149 morkRow*
00150 morkRowMap::CutOid(morkEnv* ev, const mdbOid* inOid)
00151 {
00152   morkRow row(inOid);
00153   morkRow* key = &row;
00154   morkRow* oldKey = 0;
00155   this->Cut(ev, &key, &oldKey, /*val*/ (void*) 0,
00156     (mork_change**) 0);
00157     
00158   return oldKey;
00159 }
00160 
00161 morkRow*
00162 morkRowMap::CutRow(morkEnv* ev, const morkRow* ioRow)
00163 {
00164   morkRow* oldKey = 0;
00165   this->Cut(ev, &ioRow, &oldKey, /*val*/ (void*) 0,
00166     (mork_change**) 0);
00167     
00168   return oldKey;
00169 }
00170 
00171 morkRow*
00172 morkRowMap::GetOid(morkEnv* ev, const mdbOid* inOid)
00173 {
00174   morkRow row(inOid);
00175   morkRow* key = &row;
00176   morkRow* oldKey = 0;
00177   this->Get(ev, &key, &oldKey, /*val*/ (void*) 0, (mork_change**) 0);
00178   
00179   return oldKey;
00180 }
00181 
00182 morkRow*
00183 morkRowMap::GetRow(morkEnv* ev, const morkRow* ioRow)
00184 {
00185   morkRow* oldKey = 0;
00186   this->Get(ev, &ioRow, &oldKey, /*val*/ (void*) 0, (mork_change**) 0);
00187   
00188   return oldKey;
00189 }
00190 
00191 
00192 
00193 //3456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789
00194 
00195 // ````` ````` ````` ````` ````` 
00196 // { ===== begin morkNode interface =====
00197 
00198 /*public virtual*/ void
00199 morkRowProbeMap::CloseMorkNode(morkEnv* ev) // CloseRowProbeMap() only if open
00200 {
00201   if ( this->IsOpenNode() )
00202   {
00203     this->MarkClosing();
00204     this->CloseRowProbeMap(ev);
00205     this->MarkShut();
00206   }
00207 }
00208 
00209 /*public virtual*/
00210 morkRowProbeMap::~morkRowProbeMap() // assert CloseRowProbeMap() executed earlier
00211 {
00212   MORK_ASSERT(this->IsShutNode());
00213 }
00214 
00215 /*public non-poly*/
00216 morkRowProbeMap::morkRowProbeMap(morkEnv* ev, const morkUsage& inUsage,
00217   nsIMdbHeap* ioHeap, nsIMdbHeap* ioSlotHeap, mork_size inSlots)
00218 : morkProbeMap(ev, inUsage,  ioHeap,
00219   /*inKeySize*/ sizeof(morkRow*), /*inValSize*/ 0,
00220   ioSlotHeap, inSlots, 
00221   /*inHoldChanges*/ morkBool_kTrue)
00222 {
00223   if ( ev->Good() )
00224     mNode_Derived = morkDerived_kRowProbeMap;
00225 }
00226 
00227 /*public non-poly*/ void
00228 morkRowProbeMap::CloseRowProbeMap(morkEnv* ev) // called by CloseMorkNode();
00229 {
00230   if ( this )
00231   {
00232     if ( this->IsNode() )
00233     {
00234       this->CloseProbeMap(ev);
00235       this->MarkShut();
00236     }
00237     else
00238       this->NonNodeError(ev);
00239   }
00240   else
00241     ev->NilPointerError();
00242 }
00243 
00244 // } ===== end morkNode methods =====
00245 // ````` ````` ````` ````` ````` 
00246 
00247 /*virtual*/ mork_test // hit(a,b) implies hash(a) == hash(b)
00248 morkRowProbeMap::MapTest(morkEnv* ev, const void* inMapKey,
00249   const void* inAppKey) const
00250 {
00251   MORK_USED_1(ev);
00252   const morkRow* key = *(const morkRow**) inMapKey;
00253   if ( key )
00254   {
00255     mork_bool hit = key->EqualRow(*(const morkRow**) inAppKey);
00256     return ( hit ) ? morkTest_kHit : morkTest_kMiss;
00257   }
00258   else
00259     return morkTest_kVoid;
00260 }
00261 
00262 /*virtual*/ mork_u4 // hit(a,b) implies hash(a) == hash(b)
00263 morkRowProbeMap::MapHash(morkEnv* ev, const void* inAppKey) const
00264 {
00265   const morkRow* key = *(const morkRow**) inAppKey;
00266   if ( key )
00267     return key->HashRow();
00268   else
00269   {
00270     ev->NilPointerWarning();
00271     return 0;
00272   }
00273 }
00274 
00275 /*virtual*/ mork_u4 
00276 morkRowProbeMap::ProbeMapHashMapKey(morkEnv* ev,
00277   const void* inMapKey) const
00278 {
00279   const morkRow* key = *(const morkRow**) inMapKey;
00280   if ( key )
00281     return key->HashRow();
00282   else
00283   {
00284     ev->NilPointerWarning();
00285     return 0;
00286   }
00287 }
00288 
00289 mork_bool
00290 morkRowProbeMap::AddRow(morkEnv* ev, morkRow* ioRow)
00291 {
00292   if ( ev->Good() )
00293   {
00294     this->MapAtPut(ev, &ioRow, /*val*/ (void*) 0, 
00295       /*key*/ (void*) 0, /*val*/ (void*) 0);
00296   }
00297   return ev->Good();
00298 }
00299 
00300 morkRow*
00301 morkRowProbeMap::CutOid(morkEnv* ev, const mdbOid* inOid)
00302 {
00303   MORK_USED_1(inOid);
00304   morkProbeMap::ProbeMapCutError(ev);
00305     
00306   return 0;
00307 }
00308 
00309 morkRow*
00310 morkRowProbeMap::CutRow(morkEnv* ev, const morkRow* ioRow)
00311 {
00312   MORK_USED_1(ioRow);
00313   morkProbeMap::ProbeMapCutError(ev);
00314     
00315   return 0;
00316 }
00317 
00318 morkRow*
00319 morkRowProbeMap::GetOid(morkEnv* ev, const mdbOid* inOid)
00320 {
00321   morkRow row(inOid);
00322   morkRow* key = &row;
00323   morkRow* oldKey = 0;
00324   this->MapAt(ev, &key, &oldKey, /*val*/ (void*) 0);
00325   
00326   return oldKey;
00327 }
00328 
00329 morkRow*
00330 morkRowProbeMap::GetRow(morkEnv* ev, const morkRow* ioRow)
00331 {
00332   morkRow* oldKey = 0;
00333   this->MapAt(ev, &ioRow, &oldKey, /*val*/ (void*) 0);
00334   
00335   return oldKey;
00336 }
00337 
00338 
00339 //3456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789