Back to index

lightning-sunbird  0.9+nobinonly
morkBead.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 _MORKBEAD_
00039 #define _MORKBEAD_ 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_kBead   /*i*/ 0x426F /* ascii 'Bo' */
00060 
00061 /*| morkBead: subclass of morkNode that adds knowledge of db suite factory
00062 **| and containing port to those objects that are exposed as instances of
00063 **| nsIMdbBead in the public interface.
00064 |*/
00065 class morkBead : public morkNode { 
00066 
00067 // public: // slots inherited from morkNode (meant to inform only)
00068   // nsIMdbHeap*    mNode_Heap;
00069 
00070   // mork_base      mNode_Base;     // must equal morkBase_kNode
00071   // mork_derived   mNode_Derived;  // depends on specific node subclass
00072   
00073   // mork_access    mNode_Access;   // kOpen, kClosing, kShut, or kDead
00074   // mork_usage     mNode_Usage;    // kHeap, kStack, kMember, kGlobal, kNone
00075   // mork_able      mNode_Mutable;  // can this node be modified?
00076   // mork_load      mNode_Load;     // is this node clean or dirty?
00077   
00078   // mork_uses      mNode_Uses;     // refcount for strong refs
00079   // mork_refs      mNode_Refs;     // refcount for strong refs + weak refs
00080   
00081 public: // state is public because the entire Mork system is private
00082 
00083   mork_color      mBead_Color;   // ID for this bead
00084 
00085 public: // Hash() and Equal() for bead maps are same for all subclasses:
00086 
00087   mork_u4 BeadHash() const { return (mork_u4) mBead_Color; }
00088   mork_bool BeadEqual(const morkBead* inBead) const
00089   { return ( mBead_Color == inBead->mBead_Color); }
00090   
00091 // { ===== begin morkNode interface =====
00092 public: // morkNode virtual methods
00093   virtual void CloseMorkNode(morkEnv* ev); // CloseBead() only if open
00094   virtual ~morkBead(); // assert that CloseBead() executed earlier
00095   
00096 public: // special case for stack construction for map usage:
00097   morkBead(mork_color inBeadColor); // stack-based bead instance
00098   
00099 protected: // special case for morkObject:
00100   morkBead(const morkUsage& inUsage, nsIMdbHeap* ioHeap,
00101     mork_color inBeadColor);
00102   
00103 public: // morkEnv construction & destruction
00104   morkBead(morkEnv* ev, const morkUsage& inUsage, nsIMdbHeap* ioHeap, 
00105      mork_color inBeadColor);
00106   void CloseBead(morkEnv* ev); // called by CloseMorkNode();
00107 
00108 private: // copying is not allowed
00109   morkBead(const morkBead& other);
00110   morkBead& operator=(const morkBead& other);
00111 
00112 public: // dynamic type identification
00113   mork_bool IsBead() const
00114   { return IsNode() && mNode_Derived == morkDerived_kBead; }
00115 // } ===== end morkNode methods =====
00116 
00117   // void NewNilHandleError(morkEnv* ev); // mBead_Handle is nil
00118   
00119 public: // typesafe refcounting inlines calling inherited morkNode methods
00120   static void SlotWeakBead(morkBead* me,
00121     morkEnv* ev, morkBead** ioSlot)
00122   { morkNode::SlotWeakNode((morkNode*) me, ev, (morkNode**) ioSlot); }
00123   
00124   static void SlotStrongBead(morkBead* me,
00125     morkEnv* ev, morkBead** ioSlot)
00126   { morkNode::SlotStrongNode((morkNode*) me, ev, (morkNode**) ioSlot); }
00127 };
00128 
00129 //3456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789
00130 
00131 #define morkDerived_kBeadMap  /*i*/ 0x744D /* ascii 'bM' */
00132 
00133 /*| morkBeadMap: maps bead -> bead (key only using mBead_Color)
00134 |*/
00135 class morkBeadMap : public morkMap {
00136 
00137 
00138 // { ===== begin morkNode interface =====
00139 public: // morkNode virtual methods
00140   virtual void CloseMorkNode(morkEnv* ev); // CloseBeadMap() only if open
00141   virtual ~morkBeadMap(); // assert that CloseBeadMap() executed earlier
00142   
00143 public: // morkMap construction & destruction
00144   morkBeadMap(morkEnv* ev, const morkUsage& inUsage,
00145     nsIMdbHeap* ioHeap, nsIMdbHeap* ioSlotHeap);
00146   void CloseBeadMap(morkEnv* ev); // called by CloseMorkNode();
00147 
00148 public: // dynamic type identification
00149   mork_bool IsBeadMap() const
00150   { return IsNode() && mNode_Derived == morkDerived_kBeadMap; }
00151 // } ===== end morkNode methods =====
00152 
00153 // { ===== begin morkMap poly interface =====
00154 public:
00155   virtual mork_bool // *((mork_u4*) inKeyA) == *((mork_u4*) inKeyB)
00156   Equal(morkEnv* ev, const void* inKeyA, const void* inKeyB) const;
00157 
00158   virtual mork_u4 // some integer function of *((mork_u4*) inKey)
00159   Hash(morkEnv* ev, const void* inKey) const;
00160 // } ===== end morkMap poly interface =====
00161 
00162 public: // other map methods
00163 
00164   mork_bool  AddBead(morkEnv* ev, morkBead* ioBead);
00165   // the AddBead() boolean return equals ev->Good().
00166 
00167   mork_bool  CutBead(morkEnv* ev, mork_color inColor);
00168   // The CutBead() boolean return indicates whether removal happened. 
00169   
00170   morkBead*  GetBead(morkEnv* ev, mork_color inColor);
00171   // Note the returned bead does NOT have an increase in refcount for this.
00172 
00173   mork_num CutAllBeads(morkEnv* ev);
00174   // CutAllBeads() releases all the referenced beads.
00175 };
00176 
00177 class morkBeadMapIter: public morkMapIter{ // typesafe wrapper class
00178 
00179 public:
00180   morkBeadMapIter(morkEnv* ev, morkBeadMap* ioMap)
00181   : morkMapIter(ev, ioMap) { }
00182  
00183   morkBeadMapIter( ) : morkMapIter()  { }
00184   void InitBeadMapIter(morkEnv* ev, morkBeadMap* ioMap)
00185   { this->InitMapIter(ev, ioMap); }
00186    
00187   morkBead* FirstBead(morkEnv* ev);
00188   morkBead* NextBead(morkEnv* ev);
00189   morkBead* HereBead(morkEnv* ev);
00190   void      CutHereBead(morkEnv* ev);
00191   
00192 };
00193 
00194 //3456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789
00195 
00196 #define morkDerived_kBeadProbeMap  /*i*/ 0x6D74 /* ascii 'mb' */
00197 
00198 /*| morkBeadProbeMap: maps bead -> bead (key only using mBead_Color)
00199 |*/
00200 class morkBeadProbeMap : public morkProbeMap {
00201 
00202 
00203 // { ===== begin morkNode interface =====
00204 public: // morkNode virtual methods
00205   virtual void CloseMorkNode(morkEnv* ev); // CloseBeadProbeMap() only if open
00206   virtual ~morkBeadProbeMap(); // assert that CloseBeadProbeMap() executed earlier
00207   
00208 public: // morkMap construction & destruction
00209   morkBeadProbeMap(morkEnv* ev, const morkUsage& inUsage,
00210     nsIMdbHeap* ioHeap, nsIMdbHeap* ioSlotHeap);
00211   void CloseBeadProbeMap(morkEnv* ev); // called by CloseMorkNode();
00212 
00213 public: // dynamic type identification
00214   mork_bool IsBeadProbeMap() const
00215   { return IsNode() && mNode_Derived == morkDerived_kBeadProbeMap; }
00216 // } ===== end morkNode methods =====
00217 
00218   // { ===== begin morkProbeMap methods =====
00219 public:
00220   virtual mork_test // hit(a,b) implies hash(a) == hash(b)
00221   MapTest(morkEnv* ev, const void* inMapKey, const void* inAppKey) const;
00222 
00223   virtual mork_u4 // hit(a,b) implies hash(a) == hash(b)
00224   MapHash(morkEnv* ev, const void* inAppKey) const;
00225 
00226   virtual mork_u4 ProbeMapHashMapKey(morkEnv* ev, const void* inMapKey) const;
00227 
00228   // virtual mork_bool ProbeMapIsKeyNil(morkEnv* ev, void* ioMapKey);
00229 
00230   // virtual void ProbeMapClearKey(morkEnv* ev, // put 'nil' alls keys inside map
00231   //   void* ioMapKey, mork_count inKeyCount); // array of keys inside map
00232 
00233   // virtual void ProbeMapPushIn(morkEnv* ev, // move (key,val) into the map
00234   //   const void* inAppKey, const void* inAppVal, // (key,val) outside map
00235   //   void* outMapKey, void* outMapVal);      // (key,val) inside map
00236 
00237   // virtual void ProbeMapPullOut(morkEnv* ev, // move (key,val) out from the map
00238   //   const void* inMapKey, const void* inMapVal, // (key,val) inside map
00239   //   void* outAppKey, void* outAppVal) const;    // (key,val) outside map
00240   // } ===== end morkProbeMap methods =====
00241 
00242 public: // other map methods
00243 
00244   mork_bool  AddBead(morkEnv* ev, morkBead* ioBead);
00245   // the AddBead() boolean return equals ev->Good().
00246   
00247   morkBead*  GetBead(morkEnv* ev, mork_color inColor);
00248   // Note the returned bead does NOT have an increase in refcount for this.
00249 
00250   mork_num   CutAllBeads(morkEnv* ev);
00251   // CutAllBeads() releases all the referenced bead values.
00252 };
00253 
00254 class morkBeadProbeMapIter: public morkProbeMapIter { // typesafe wrapper class
00255 
00256 public:
00257   morkBeadProbeMapIter(morkEnv* ev, morkBeadProbeMap* ioMap)
00258   : morkProbeMapIter(ev, ioMap) { }
00259  
00260   morkBeadProbeMapIter( ) : morkProbeMapIter()  { }
00261   void InitBeadProbeMapIter(morkEnv* ev, morkBeadProbeMap* ioMap)
00262   { this->InitProbeMapIter(ev, ioMap); }
00263    
00264   morkBead* FirstBead(morkEnv* ev)
00265   { return (morkBead*) this->IterFirstKey(ev); }
00266   
00267   morkBead* NextBead(morkEnv* ev)
00268   { return (morkBead*) this->IterNextKey(ev); }
00269   
00270   morkBead* HereBead(morkEnv* ev)
00271   { return (morkBead*) this->IterHereKey(ev); }
00272   
00273 };
00274 
00275 //3456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789
00276 
00277 #endif /* _MORKBEAD_ */