Back to index

lightning-sunbird  0.9+nobinonly
morkPortTableCursor.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 _MORKPORTTABLECURSOR_
00039 #define _MORKPORTTABLECURSOR_ 1
00040 
00041 #ifndef _MORK_
00042 #include "mork.h"
00043 #endif
00044 
00045 #ifndef _MORKCURSOR_
00046 #include "morkCursor.h"
00047 #endif
00048 
00049 #ifndef _MORKROWSPACE_
00050 #include "morkRowSpace.h"
00051 #endif
00052 
00053 //3456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789
00054 
00055 class orkinPortTableCursor;
00056 #define morkDerived_kPortTableCursor  /*i*/ 0x7443 /* ascii 'tC' */
00057 
00058 class morkPortTableCursor : public morkCursor, public nsIMdbPortTableCursor { // row iterator
00059 public:
00060   NS_DECL_ISUPPORTS_INHERITED
00061 // public: // slots inherited from morkObject (meant to inform only)
00062   // nsIMdbHeap*     mNode_Heap;
00063   // mork_able    mNode_Mutable; // can this node be modified?
00064   // mork_load    mNode_Load;    // is this node clean or dirty?
00065   // mork_base    mNode_Base;    // must equal morkBase_kNode
00066   // mork_derived mNode_Derived; // depends on specific node subclass
00067   // mork_access  mNode_Access;  // kOpen, kClosing, kShut, or kDead
00068   // mork_usage   mNode_Usage;   // kHeap, kStack, kMember, kGlobal, kNone
00069   // mork_uses    mNode_Uses;    // refcount for strong refs
00070   // mork_refs    mNode_Refs;    // refcount for strong refs + weak refs
00071 
00072   // morkFactory* mObject_Factory;  // weak ref to suite factory
00073 
00074   // mork_seed  mCursor_Seed;
00075   // mork_pos   mCursor_Pos;
00076   // mork_bool  mCursor_DoFailOnSeedOutOfSync;
00077   // mork_u1    mCursor_Pad[ 3 ]; // explicitly pad to u4 alignment
00078 
00079 public: // state is public because the entire Mork system is private
00080   // { ----- begin attribute methods -----
00081   NS_IMETHOD SetPort(nsIMdbEnv* ev, nsIMdbPort* ioPort); // sets pos to -1
00082   NS_IMETHOD GetPort(nsIMdbEnv* ev, nsIMdbPort** acqPort);
00083   
00084   NS_IMETHOD SetRowScope(nsIMdbEnv* ev, // sets pos to -1
00085     mdb_scope inRowScope);
00086   NS_IMETHOD GetRowScope(nsIMdbEnv* ev, mdb_scope* outRowScope); 
00087   // setting row scope to zero iterates over all row scopes in port
00088     
00089   NS_IMETHOD SetTableKind(nsIMdbEnv* ev, // sets pos to -1
00090     mdb_kind inTableKind);
00091   NS_IMETHOD GetTableKind(nsIMdbEnv* ev, mdb_kind* outTableKind);
00092   // setting table kind to zero iterates over all table kinds in row scope
00093   // } ----- end attribute methods -----
00094 
00095   // { ----- begin table iteration methods -----
00096   NS_IMETHOD NextTable( // get table at next position in the db
00097     nsIMdbEnv* ev, // context
00098     nsIMdbTable** acqTable); // the next table in the iteration
00099   // } ----- end table iteration methods -----
00100   morkStore*    mPortTableCursor_Store;  // weak ref to store
00101   
00102   mdb_scope     mPortTableCursor_RowScope;
00103   mdb_kind      mPortTableCursor_TableKind;
00104   
00105   // We only care if LastTable is non-nil, so it is not refcounted;
00106   // so you must never access table state or methods using LastTable:
00107   
00108   morkTable* mPortTableCursor_LastTable; // nil or last table (no refcount)
00109   morkRowSpace* mPortTableCursor_RowSpace; // current space (strong ref)
00110 
00111   morkRowSpaceMapIter mPortTableCursor_SpaceIter; // iter over spaces
00112   morkTableMapIter    mPortTableCursor_TableIter; // iter over tables 
00113   
00114   // these booleans indicate when the table or space iterator is exhausted:
00115   
00116   mork_bool           mPortTableCursor_TablesDidEnd; // no more tables?
00117   mork_bool           mPortTableCursor_SpacesDidEnd; // no more spaces?
00118   mork_u1             mPortTableCursor_Pad[ 2 ]; // for u4 alignment
00119    
00120 // { ===== begin morkNode interface =====
00121 public: // morkNode virtual methods
00122   virtual void CloseMorkNode(morkEnv* ev); // ClosePortTableCursor()
00123   virtual ~morkPortTableCursor(); // assert that close executed earlier
00124   
00125 public: // morkPortTableCursor construction & destruction
00126   morkPortTableCursor(morkEnv* ev, const morkUsage& inUsage,
00127     nsIMdbHeap* ioHeap, morkStore* ioStore, mdb_scope inRowScope,
00128       mdb_kind inTableKind, nsIMdbHeap* ioSlotHeap);
00129   void ClosePortTableCursor(morkEnv* ev); // called by CloseMorkNode();
00130 
00131 private: // copying is not allowed
00132   morkPortTableCursor(const morkPortTableCursor& other);
00133   morkPortTableCursor& operator=(const morkPortTableCursor& other);
00134 
00135 public: // dynamic type identification
00136   mork_bool IsPortTableCursor() const
00137   { return IsNode() && mNode_Derived == morkDerived_kPortTableCursor; }
00138 // } ===== end morkNode methods =====
00139 
00140 protected: // utilities
00141 
00142   void init_space_tables_map(morkEnv* ev);
00143 
00144 public: // other cursor methods
00145 
00146   static void NilCursorStoreError(morkEnv* ev);
00147   static void NonPortTableCursorTypeError(morkEnv* ev);
00148 
00149  morkEnv* CanUsePortTableCursor(nsIMdbEnv* mev,
00150   mork_bool inMutable, mdb_err* outErr) const;
00151 
00152   
00153   morkRowSpace* NextSpace(morkEnv* ev);
00154   morkTable* NextTable(morkEnv* ev);
00155 
00156   mork_bool SetRowScope(morkEnv* ev, mork_scope inRowScope);
00157   mork_bool SetTableKind(morkEnv* ev, mork_kind inTableKind);
00158 
00159 public: // typesafe refcounting inlines calling inherited morkNode methods
00160   static void SlotWeakPortTableCursor(morkPortTableCursor* me,
00161     morkEnv* ev, morkPortTableCursor** ioSlot)
00162   { morkNode::SlotWeakNode((morkNode*) me, ev, (morkNode**) ioSlot); }
00163   
00164   static void SlotStrongPortTableCursor(morkPortTableCursor* me,
00165     morkEnv* ev, morkPortTableCursor** ioSlot)
00166   { morkNode::SlotStrongNode((morkNode*) me, ev, (morkNode**) ioSlot); }
00167 };
00168 
00169 
00170 
00171 //3456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789
00172 
00173 #endif /* _MORKPORTTABLECURSOR_ */