Back to index

lightning-sunbird  0.9+nobinonly
morkRowSpace.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 _MORKROWSPACE_
00039 #define _MORKROWSPACE_ 1
00040 
00041 #ifndef _MORK_
00042 #include "mork.h"
00043 #endif
00044 
00045 #ifndef _MORKNODE_
00046 #include "morkNode.h"
00047 #endif
00048 
00049 #ifndef _MORKSPACE_
00050 #include "morkSpace.h"
00051 #endif
00052 
00053 #ifndef _MORKNODEMAP_
00054 #include "morkNodeMap.h"
00055 #endif
00056 
00057 #ifndef _MORKROWMAP_
00058 #include "morkRowMap.h"
00059 #endif
00060 
00061 #ifndef _MORKTABLE_
00062 #include "morkTable.h"
00063 #endif
00064 
00065 #ifndef _MORKARRAY_
00066 #include "morkArray.h"
00067 #endif
00068 
00069 #ifndef _MORKDEQUE_
00070 #include "morkDeque.h"
00071 #endif
00072 
00073 //3456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789
00074 
00075 #define morkDerived_kRowSpace  /*i*/ 0x7253 /* ascii 'rS' */
00076 
00077 #define morkRowSpace_kStartRowMapSlotCount 11
00078 
00079 #define morkRowSpace_kMaxIndexCount 8 /* no more indexes than this */
00080 #define morkRowSpace_kPrimeCacheSize 17 /* should be prime number */
00081 
00082 class morkAtomRowMap;
00083 
00084 /*| morkRowSpace:
00085 |*/
00086 class morkRowSpace : public morkSpace { // 
00087 
00088 // public: // slots inherited from morkSpace (meant to inform only)
00089   // nsIMdbHeap*    mNode_Heap;
00090 
00091   // mork_base      mNode_Base;     // must equal morkBase_kNode
00092   // mork_derived   mNode_Derived;  // depends on specific node subclass
00093   
00094   // mork_access    mNode_Access;   // kOpen, kClosing, kShut, or kDead
00095   // mork_usage     mNode_Usage;    // kHeap, kStack, kMember, kGlobal, kNone
00096   // mork_able      mNode_Mutable;  // can this node be modified?
00097   // mork_load      mNode_Load;     // is this node clean or dirty?
00098   
00099   // mork_uses      mNode_Uses;     // refcount for strong refs
00100   // mork_refs      mNode_Refs;     // refcount for strong refs + weak refs
00101   
00102   // morkStore*  mSpace_Store; // weak ref to containing store
00103   
00104   // mork_bool   mSpace_DoAutoIDs;    // whether db should assign member IDs
00105   // mork_bool   mSpace_HaveDoneAutoIDs; // whether actually auto assigned IDs
00106   // mork_u1     mSpace_Pad[ 2 ];    // pad to u4 alignment
00107 
00108 public: // state is public because the entire Mork system is private
00109 
00110   nsIMdbHeap*  mRowSpace_SlotHeap;
00111 
00112 #ifdef MORK_ENABLE_PROBE_MAPS
00113   morkRowProbeMap   mRowSpace_Rows;   // hash table of morkRow instances
00114 #else /*MORK_ENABLE_PROBE_MAPS*/
00115   morkRowMap   mRowSpace_Rows;   // hash table of morkRow instances
00116 #endif /*MORK_ENABLE_PROBE_MAPS*/
00117   morkTableMap mRowSpace_Tables; // all the tables in this row scope
00118 
00119   mork_tid     mRowSpace_NextTableId;  // for auto-assigning table IDs
00120   mork_rid     mRowSpace_NextRowId;    // for auto-assigning row IDs
00121   
00122   mork_count   mRowSpace_IndexCount; // if nonzero, row indexes exist
00123     
00124   // every nonzero slot in IndexCache is a strong ref to a morkAtomRowMap:
00125   morkAtomRowMap* mRowSpace_IndexCache[ morkRowSpace_kPrimeCacheSize ];
00126 
00127   morkDeque    mRowSpace_TablesByPriority[ morkPriority_kCount ];
00128 
00129 public: // more specific dirty methods for row space:
00130   void SetRowSpaceDirty() { this->SetNodeDirty(); }
00131   void SetRowSpaceClean() { this->SetNodeClean(); }
00132   
00133   mork_bool IsRowSpaceClean() const { return this->IsNodeClean(); }
00134   mork_bool IsRowSpaceDirty() const { return this->IsNodeDirty(); }
00135 
00136 // { ===== begin morkNode interface =====
00137 public: // morkNode virtual methods
00138   virtual void CloseMorkNode(morkEnv* ev); // CloseRowSpace() only if open
00139   virtual ~morkRowSpace(); // assert that CloseRowSpace() executed earlier
00140   
00141 public: // morkMap construction & destruction
00142   morkRowSpace(morkEnv* ev, const morkUsage& inUsage, mork_scope inScope,
00143     morkStore* ioStore, nsIMdbHeap* ioNodeHeap, nsIMdbHeap* ioSlotHeap);
00144   void CloseRowSpace(morkEnv* ev); // called by CloseMorkNode();
00145 
00146 public: // dynamic type identification
00147   mork_bool IsRowSpace() const
00148   { return IsNode() && mNode_Derived == morkDerived_kRowSpace; }
00149 // } ===== end morkNode methods =====
00150 
00151 public: // typing
00152   static void NonRowSpaceTypeError(morkEnv* ev);
00153   static void ZeroScopeError(morkEnv* ev);
00154   static void ZeroKindError(morkEnv* ev);
00155   static void ZeroTidError(morkEnv* ev);
00156   static void MinusOneRidError(morkEnv* ev);
00157 
00158   //static void ExpectAutoIdOnlyError(morkEnv* ev);
00159   //static void ExpectAutoIdNeverError(morkEnv* ev);
00160 
00161 public: // other space methods
00162 
00163   mork_num CutAllRows(morkEnv* ev, morkPool* ioPool);
00164   // CutAllRows() puts all rows and cells back into the pool.
00165   
00166   morkTable* NewTable(morkEnv* ev, mork_kind inTableKind,
00167     mdb_bool inMustBeUnique, const mdbOid* inOptionalMetaRowOid);
00168   
00169   morkTable* NewTableWithTid(morkEnv* ev, mork_tid inTid,
00170     mork_kind inTableKind, const mdbOid* inOptionalMetaRowOid);
00171   
00172   morkTable* FindTableByKind(morkEnv* ev, mork_kind inTableKind);
00173   morkTable* FindTableByTid(morkEnv* ev, mork_tid inTid)
00174   { return mRowSpace_Tables.GetTable(ev, inTid); }
00175 
00176   mork_tid MakeNewTableId(morkEnv* ev);
00177   mork_rid MakeNewRowId(morkEnv* ev);
00178 
00179   // morkRow* FindRowByRid(morkEnv* ev, mork_rid inRid)
00180   // { return (morkRow*) mRowSpace_Rows.GetRow(ev, inRid); }
00181 
00182   morkRow* NewRowWithOid(morkEnv* ev, const mdbOid* inOid);
00183   morkRow* NewRow(morkEnv* ev);
00184 
00185   morkRow* FindRow(morkEnv* ev, mork_column inColumn, const mdbYarn* inYarn);
00186 
00187   morkAtomRowMap* ForceMap(morkEnv* ev, mork_column inColumn);
00188   morkAtomRowMap* FindMap(morkEnv* ev, mork_column inColumn);
00189 
00190 protected: // internal utilities
00191   morkAtomRowMap* make_index(morkEnv* ev, mork_column inColumn);
00192 
00193 public: // typesafe refcounting inlines calling inherited morkNode methods
00194   static void SlotWeakRowSpace(morkRowSpace* me,
00195     morkEnv* ev, morkRowSpace** ioSlot)
00196   { morkNode::SlotWeakNode((morkNode*) me, ev, (morkNode**) ioSlot); }
00197   
00198   static void SlotStrongRowSpace(morkRowSpace* me,
00199     morkEnv* ev, morkRowSpace** ioSlot)
00200   { morkNode::SlotStrongNode((morkNode*) me, ev, (morkNode**) ioSlot); }
00201 };
00202 
00203 //3456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789
00204 
00205 #define morkDerived_kRowSpaceMap  /*i*/ 0x725A /* ascii 'rZ' */
00206 
00207 /*| morkRowSpaceMap: maps mork_scope -> morkRowSpace
00208 |*/
00209 class morkRowSpaceMap : public morkNodeMap { // for mapping tokens to tables
00210 
00211 public:
00212 
00213   virtual ~morkRowSpaceMap();
00214   morkRowSpaceMap(morkEnv* ev, const morkUsage& inUsage,
00215     nsIMdbHeap* ioHeap, nsIMdbHeap* ioSlotHeap);
00216 
00217 public: // other map methods
00218 
00219   mork_bool  AddRowSpace(morkEnv* ev, morkRowSpace* ioRowSpace)
00220   { return this->AddNode(ev, ioRowSpace->SpaceScope(), ioRowSpace); }
00221   // the AddRowSpace() boolean return equals ev->Good().
00222 
00223   mork_bool  CutRowSpace(morkEnv* ev, mork_scope inScope)
00224   { return this->CutNode(ev, inScope); }
00225   // The CutRowSpace() boolean return indicates whether removal happened. 
00226   
00227   morkRowSpace*  GetRowSpace(morkEnv* ev, mork_scope inScope)
00228   { return (morkRowSpace*) this->GetNode(ev, inScope); }
00229   // Note the returned space does NOT have an increase in refcount for this.
00230 
00231   mork_num CutAllRowSpaces(morkEnv* ev)
00232   { return this->CutAllNodes(ev); }
00233   // CutAllRowSpaces() releases all the referenced table values.
00234 };
00235 
00236 class morkRowSpaceMapIter: public morkMapIter{ // typesafe wrapper class
00237 
00238 public:
00239   morkRowSpaceMapIter(morkEnv* ev, morkRowSpaceMap* ioMap)
00240   : morkMapIter(ev, ioMap) { }
00241  
00242   morkRowSpaceMapIter( ) : morkMapIter()  { }
00243   void InitRowSpaceMapIter(morkEnv* ev, morkRowSpaceMap* ioMap)
00244   { this->InitMapIter(ev, ioMap); }
00245    
00246   mork_change*
00247   FirstRowSpace(morkEnv* ev, mork_scope* outScope, morkRowSpace** outRowSpace)
00248   { return this->First(ev, outScope, outRowSpace); }
00249   
00250   mork_change*
00251   NextRowSpace(morkEnv* ev, mork_scope* outScope, morkRowSpace** outRowSpace)
00252   { return this->Next(ev, outScope, outRowSpace); }
00253   
00254   mork_change*
00255   HereRowSpace(morkEnv* ev, mork_scope* outScope, morkRowSpace** outRowSpace)
00256   { return this->Here(ev, outScope, outRowSpace); }
00257   
00258   mork_change*
00259   CutHereRowSpace(morkEnv* ev, mork_scope* outScope, morkRowSpace** outRowSpace)
00260   { return this->CutHere(ev, outScope, outRowSpace); }
00261 };
00262 
00263 //3456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789
00264 
00265 #endif /* _MORKROWSPACE_ */