Back to index

lightning-sunbird  0.9+nobinonly
morkIntMap.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 _MORKINTMAP_
00039 #define _MORKINTMAP_ 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 //3456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789
00054 
00055 #define morkDerived_kIntMap  /*i*/ 0x694D /* ascii 'iM' */
00056 
00057 #define morkIntMap_kStartSlotCount 256
00058 
00059 /*| morkIntMap: maps mork_token -> morkNode
00060 |*/
00061 class morkIntMap : public morkMap { // for mapping tokens to maps
00062 
00063 // { ===== begin morkNode interface =====
00064 public: // morkNode virtual methods
00065   virtual void CloseMorkNode(morkEnv* ev); // CloseIntMap() only if open
00066   virtual ~morkIntMap(); // assert that CloseIntMap() executed earlier
00067   
00068 public: // morkMap construction & destruction
00069 
00070   // keySize for morkIntMap equals sizeof(mork_u4)
00071   morkIntMap(morkEnv* ev, const morkUsage& inUsage, mork_size inValSize,
00072     nsIMdbHeap* ioHeap, nsIMdbHeap* ioSlotHeap, mork_bool inHoldChanges);
00073   void CloseIntMap(morkEnv* ev); // called by CloseMorkNode();
00074 
00075 public: // dynamic type identification
00076   mork_bool IsIntMap() const
00077   { return IsNode() && mNode_Derived == morkDerived_kIntMap; }
00078 // } ===== end morkNode methods =====
00079 
00080 // { ===== begin morkMap poly interface =====
00081   virtual mork_bool // *((mork_u4*) inKeyA) == *((mork_u4*) inKeyB)
00082   Equal(morkEnv* ev, const void* inKeyA, const void* inKeyB) const;
00083 
00084   virtual mork_u4 // some integer function of *((mork_u4*) inKey)
00085   Hash(morkEnv* ev, const void* inKey) const;
00086 // } ===== end morkMap poly interface =====
00087 
00088 public: // other map methods
00089 
00090   mork_bool  AddInt(morkEnv* ev, mork_u4 inKey, void* ioAddress);
00091   // the AddInt() boolean return equals ev->Good().
00092 
00093   mork_bool  CutInt(morkEnv* ev, mork_u4 inKey);
00094   // The CutInt() boolean return indicates whether removal happened. 
00095   
00096   void*      GetInt(morkEnv* ev, mork_u4 inKey);
00097   // Note the returned node does NOT have an increase in refcount for this.
00098   
00099   mork_bool  HasInt(morkEnv* ev, mork_u4 inKey);
00100   // Note the returned node does NOT have an increase in refcount for this.
00101 
00102 };
00103 
00104 //3456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789
00105 
00106 #ifdef MORK_POINTER_MAP_IMPL
00107 
00108 #define morkDerived_kPointerMap  /*i*/ 0x704D /* ascii 'pM' */
00109 
00110 #define morkPointerMap_kStartSlotCount 256
00111 
00112 /*| morkPointerMap: maps void* -> void*
00113 **|
00114 **| This pointer map class is equivalent to morkIntMap when sizeof(mork_u4)
00115 **| equals sizeof(void*).  However, when these two sizes are different,
00116 **| then we cannot use the same hash table structure very easily without
00117 **| being very careful about the size and usage assumptions of those
00118 **| clients using the smaller data type.  So we just go ahead and use
00119 **| morkPointerMap for hash tables using pointer key types.
00120 |*/
00121 class morkPointerMap : public morkMap { // for mapping tokens to maps
00122 
00123 // { ===== begin morkNode interface =====
00124 public: // morkNode virtual methods
00125   virtual void CloseMorkNode(morkEnv* ev); // ClosePointerMap() only if open
00126   virtual ~morkPointerMap(); // assert that ClosePointerMap() executed earlier
00127   
00128 public: // morkMap construction & destruction
00129 
00130   // keySize for morkPointerMap equals sizeof(mork_u4)
00131   morkPointerMap(morkEnv* ev, const morkUsage& inUsage,
00132     nsIMdbHeap* ioHeap, nsIMdbHeap* ioSlotHeap);
00133   void ClosePointerMap(morkEnv* ev); // called by CloseMorkNode();
00134 
00135 public: // dynamic type identification
00136   mork_bool IsPointerMap() const
00137   { return IsNode() && mNode_Derived == morkDerived_kPointerMap; }
00138 // } ===== end morkNode methods =====
00139 
00140 // { ===== begin morkMap poly interface =====
00141   virtual mork_bool // *((void**) inKeyA) == *((void**) inKeyB)
00142   Equal(morkEnv* ev, const void* inKeyA, const void* inKeyB) const;
00143 
00144   virtual mork_u4 // some integer function of *((mork_u4*) inKey)
00145   Hash(morkEnv* ev, const void* inKey) const;
00146 // } ===== end morkMap poly interface =====
00147 
00148 public: // other map methods
00149 
00150   mork_bool  AddPointer(morkEnv* ev, void* inKey, void* ioAddress);
00151   // the AddPointer() boolean return equals ev->Good().
00152 
00153   mork_bool  CutPointer(morkEnv* ev, void* inKey);
00154   // The CutPointer() boolean return indicates whether removal happened. 
00155   
00156   void*      GetPointer(morkEnv* ev, void* inKey);
00157   // Note the returned node does NOT have an increase in refcount for this.
00158   
00159   mork_bool  HasPointer(morkEnv* ev, void* inKey);
00160   // Note the returned node does NOT have an increase in refcount for this.
00161 
00162 public: // typesafe refcounting inlines calling inherited morkNode methods
00163   static void SlotWeakIntMap(morkIntMap* me,
00164     morkEnv* ev, morkIntMap** ioSlot)
00165   { morkNode::SlotWeakNode((morkNode*) me, ev, (morkNode**) ioSlot); }
00166   
00167   static void SlotStrongIntMap(morkIntMap* me,
00168     morkEnv* ev, morkIntMap** ioSlot)
00169   { morkNode::SlotStrongNode((morkNode*) me, ev, (morkNode**) ioSlot); }
00170 
00171 };
00172 #endif /*MORK_POINTER_MAP_IMPL*/
00173 
00174 
00175 //3456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789
00176 
00177 #endif /* _MORKINTMAP_ */