Back to index

lightning-sunbird  0.9+nobinonly
morkRowMap.h
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 _MORKROWMAP_
00039 #define _MORKROWMAP_ 1
00040 
00041 #ifndef _MORK_
00042 #include "mork.h"
00043 #endif
00044 
00045 #ifndef _MORKNODE_
00046 #include "morkNode.h"
00047 #endif
00048 
00049 #ifndef _MORKMAP_
00050 #include "morkMap.h"
00051 #endif
00052 
00053 #ifndef _MORKPROBEMAP_
00054 #include "morkProbeMap.h"
00055 #endif
00056 
00057 //3456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789
00058 
00059 #define morkDerived_kRowMap  /*i*/ 0x724D /* ascii 'rM' */
00060 
00061 /*| morkRowMap: maps a set of morkRow by contained Oid
00062 |*/
00063 class morkRowMap : public morkMap { // for mapping row IDs to rows
00064 
00065 // { ===== begin morkNode interface =====
00066 public: // morkNode virtual methods
00067   virtual void CloseMorkNode(morkEnv* ev); // CloseRowMap() only if open
00068   virtual ~morkRowMap(); // assert that CloseRowMap() executed earlier
00069   
00070 public: // morkMap construction & destruction
00071   morkRowMap(morkEnv* ev, const morkUsage& inUsage,
00072     nsIMdbHeap* ioHeap, nsIMdbHeap* ioSlotHeap, mork_size inSlots);
00073   void CloseRowMap(morkEnv* ev); // called by CloseMorkNode();
00074 
00075 public: // dynamic type identification
00076   mork_bool IsRowMap() const
00077   { return IsNode() && mNode_Derived == morkDerived_kRowMap; }
00078 // } ===== end morkNode methods =====
00079 
00080 // { ===== begin morkMap poly interface =====
00081   virtual mork_bool // note: equal(a,b) implies hash(a) == hash(b)
00082   Equal(morkEnv* ev, const void* inKeyA, const void* inKeyB) const;
00083   // implemented using morkRow::EqualRow()
00084 
00085   virtual mork_u4 // note: equal(a,b) implies hash(a) == hash(b)
00086   Hash(morkEnv* ev, const void* inKey) const;
00087   // implemented using morkRow::HashRow()
00088 // } ===== end morkMap poly interface =====
00089 
00090 public: // other map methods
00091 
00092   mork_bool AddRow(morkEnv* ev, morkRow* ioRow);
00093   // AddRow() returns ev->Good()
00094 
00095   morkRow*  CutOid(morkEnv* ev, const mdbOid* inOid);
00096   // CutRid() returns the row removed equal to inRid, if there was one
00097 
00098   morkRow*  CutRow(morkEnv* ev, const morkRow* ioRow);
00099   // CutRow() returns the row removed equal to ioRow, if there was one
00100   
00101   morkRow*  GetOid(morkEnv* ev, const mdbOid* inOid);
00102   // GetOid() returns the row equal to inRid, or else nil
00103   
00104   morkRow*  GetRow(morkEnv* ev, const morkRow* ioRow);
00105   // GetRow() returns the row equal to ioRow, or else nil
00106   
00107   // note the rows are owned elsewhere, usuall by morkRowSpace
00108 
00109 public: // typesafe refcounting inlines calling inherited morkNode methods
00110   static void SlotWeakRowMap(morkRowMap* me,
00111     morkEnv* ev, morkRowMap** ioSlot)
00112   { morkNode::SlotWeakNode((morkNode*) me, ev, (morkNode**) ioSlot); }
00113   
00114   static void SlotStrongRowMap(morkRowMap* me,
00115     morkEnv* ev, morkRowMap** ioSlot)
00116   { morkNode::SlotStrongNode((morkNode*) me, ev, (morkNode**) ioSlot); }
00117 };
00118 
00119 class morkRowMapIter: public morkMapIter{ // typesafe wrapper class
00120 
00121 public:
00122   morkRowMapIter(morkEnv* ev, morkRowMap* ioMap)
00123   : morkMapIter(ev, ioMap) { }
00124  
00125   morkRowMapIter( ) : morkMapIter()  { }
00126   void InitRowMapIter(morkEnv* ev, morkRowMap* ioMap)
00127   { this->InitMapIter(ev, ioMap); }
00128    
00129   mork_change* FirstRow(morkEnv* ev, morkRow** outRowPtr)
00130   { return this->First(ev, outRowPtr, /*val*/ (void*) 0); }
00131   
00132   mork_change* NextRow(morkEnv* ev, morkRow** outRowPtr)
00133   { return this->Next(ev, outRowPtr, /*val*/ (void*) 0); }
00134   
00135   mork_change* HereRow(morkEnv* ev, morkRow** outRowPtr)
00136   { return this->Here(ev, outRowPtr, /*val*/ (void*) 0); }
00137   
00138   mork_change* CutHereRow(morkEnv* ev, morkRow** outRowPtr)
00139   { return this->CutHere(ev, outRowPtr, /*val*/ (void*) 0); }
00140 };
00141 
00142 
00143 //3456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789
00144 
00145 #define morkDerived_kRowProbeMap  /*i*/ 0x726D /* ascii 'rm' */
00146 
00147 /*| morkRowProbeMap: maps a set of morkRow by contained Oid
00148 |*/
00149 class morkRowProbeMap : public morkProbeMap { // for mapping row IDs to rows
00150 
00151 // { ===== begin morkNode interface =====
00152 public: // morkNode virtual methods
00153   virtual void CloseMorkNode(morkEnv* ev); // CloseRowProbeMap() only if open
00154   virtual ~morkRowProbeMap(); // assert CloseRowProbeMap() executed earlier
00155   
00156 public: // morkMap construction & destruction
00157   morkRowProbeMap(morkEnv* ev, const morkUsage& inUsage,
00158     nsIMdbHeap* ioHeap, nsIMdbHeap* ioSlotHeap, mork_size inSlots);
00159   void CloseRowProbeMap(morkEnv* ev); // called by CloseMorkNode();
00160 
00161 public: // dynamic type identification
00162   mork_bool IsRowMap() const
00163   { return IsNode() && mNode_Derived == morkDerived_kRowMap; }
00164 // } ===== end morkNode methods =====
00165 
00166   // { ===== begin morkProbeMap methods =====
00167   virtual mork_test // hit(a,b) implies hash(a) == hash(b)
00168   MapTest(morkEnv* ev, const void* inMapKey, const void* inAppKey) const;
00169 
00170   virtual mork_u4 // hit(a,b) implies hash(a) == hash(b)
00171   MapHash(morkEnv* ev, const void* inAppKey) const;
00172 
00173   virtual mork_u4 ProbeMapHashMapKey(morkEnv* ev, const void* inMapKey) const;
00174 
00175   // virtual mork_bool ProbeMapIsKeyNil(morkEnv* ev, void* ioMapKey);
00176 
00177   // virtual void ProbeMapClearKey(morkEnv* ev, // put 'nil' alls keys inside map
00178   //   void* ioMapKey, mork_count inKeyCount); // array of keys inside map
00179 
00180   // virtual void ProbeMapPushIn(morkEnv* ev, // move (key,val) into the map
00181   //   const void* inAppKey, const void* inAppVal, // (key,val) outside map
00182   //   void* outMapKey, void* outMapVal);      // (key,val) inside map
00183 
00184   // virtual void ProbeMapPullOut(morkEnv* ev, // move (key,val) out from the map
00185   //   const void* inMapKey, const void* inMapVal, // (key,val) inside map
00186   //   void* outAppKey, void* outAppVal) const;    // (key,val) outside map
00187   // } ===== end morkProbeMap methods =====
00188 
00189 public: // other map methods
00190 
00191   mork_bool AddRow(morkEnv* ev, morkRow* ioRow);
00192   // AddRow() returns ev->Good()
00193 
00194   morkRow*  CutOid(morkEnv* ev, const mdbOid* inOid);
00195   // CutRid() returns the row removed equal to inRid, if there was one
00196 
00197   morkRow*  CutRow(morkEnv* ev, const morkRow* ioRow);
00198   // CutRow() returns the row removed equal to ioRow, if there was one
00199   
00200   morkRow*  GetOid(morkEnv* ev, const mdbOid* inOid);
00201   // GetOid() returns the row equal to inRid, or else nil
00202   
00203   morkRow*  GetRow(morkEnv* ev, const morkRow* ioRow);
00204   // GetRow() returns the row equal to ioRow, or else nil
00205   
00206   // note the rows are owned elsewhere, usuall by morkRowSpace
00207 
00208 public: // typesafe refcounting inlines calling inherited morkNode methods
00209   static void SlotWeakRowProbeMap(morkRowProbeMap* me,
00210     morkEnv* ev, morkRowProbeMap** ioSlot)
00211   { morkNode::SlotWeakNode((morkNode*) me, ev, (morkNode**) ioSlot); }
00212   
00213   static void SlotStrongRowProbeMap(morkRowProbeMap* me,
00214     morkEnv* ev, morkRowProbeMap** ioSlot)
00215   { morkNode::SlotStrongNode((morkNode*) me, ev, (morkNode**) ioSlot); }
00216 };
00217 
00218 class morkRowProbeMapIter: public morkProbeMapIter{ // typesafe wrapper class
00219 
00220 public:
00221   morkRowProbeMapIter(morkEnv* ev, morkRowProbeMap* ioMap)
00222   : morkProbeMapIter(ev, ioMap) { }
00223  
00224   morkRowProbeMapIter( ) : morkProbeMapIter()  { }
00225   void InitRowMapIter(morkEnv* ev, morkRowProbeMap* ioMap)
00226   { this->InitMapIter(ev, ioMap); }
00227    
00228   mork_change* FirstRow(morkEnv* ev, morkRow** outRowPtr)
00229   { return this->First(ev, outRowPtr, /*val*/ (void*) 0); }
00230   
00231   mork_change* NextRow(morkEnv* ev, morkRow** outRowPtr)
00232   { return this->Next(ev, outRowPtr, /*val*/ (void*) 0); }
00233   
00234   mork_change* HereRow(morkEnv* ev, morkRow** outRowPtr)
00235   { return this->Here(ev, outRowPtr, /*val*/ (void*) 0); }
00236   
00237   mork_change* CutHereRow(morkEnv* ev, morkRow** outRowPtr)
00238   { return this->CutHere(ev, outRowPtr, /*val*/ (void*) 0); }
00239 };
00240 
00241 //3456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789
00242 
00243 #endif /* _MORKROWMAP_ */