Back to index

lightning-sunbird  0.9+nobinonly
orkinTableRowCursor.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 _ORKINTABLEROWCURSOR_
00039 #define _ORKINTABLEROWCURSOR_ 1
00040 
00041 #ifndef _MDB_
00042 #include "mdb.h"
00043 #endif
00044 
00045 #ifndef _MORK_
00046 #include "mork.h"
00047 #endif
00048 
00049 #ifndef _MORKNODE_
00050 #include "morkNode.h"
00051 #endif
00052 
00053 #ifndef _MORKHANDLE_
00054 #include "morkHandle.h"
00055 #endif
00056 
00057 #ifndef _MORKTABLEROWCURSOR_
00058 #include "morkTableRowCursor.h"
00059 #endif
00060 
00061 //3456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789
00062 
00063 class morkTableRowCursor;
00064 #define morkMagic_kTableRowCursor 0x54724375 /* ascii 'TrCu' */
00065 
00066 /*| orkinTableRowCursor:
00067 |*/
00068 class orkinTableRowCursor :
00069   public morkHandle, public nsIMdbTableRowCursor { // nsIMdbCursor
00070 
00071 // { ===== begin morkNode interface =====
00072 public: // morkNode virtual methods
00073   // virtual void CloseMorkNode(morkEnv* ev); // morkHandle is fine
00074   virtual ~orkinTableRowCursor(); // morkHandle destructor does everything
00075   
00076 protected: // construction is protected (use the static Make() method)
00077   orkinTableRowCursor(morkEnv* ev, // note morkUsage is always morkUsage_kPool
00078     morkHandleFace* ioFace,    // must not be nil, cookie for this handle
00079     morkTableRowCursor* ioObject); // must not be nil, object for this handle
00080     
00081   // void CloseHandle(morkEnv* ev); // don't need to specialize closing
00082 
00083 private: // copying is not allowed
00084   orkinTableRowCursor(const morkHandle& other);
00085   orkinTableRowCursor& operator=(const morkHandle& other);
00086 
00087 // public: // dynamic type identification
00088   // mork_bool IsHandle() const //
00089   // { return IsNode() && mNode_Derived == morkDerived_kHandle; }
00090 // } ===== end morkNode methods =====
00091 
00092 protected: // morkHandle memory management operators
00093   void* operator new(size_t inSize, morkPool& ioPool, morkZone& ioZone, morkEnv* ev) CPP_THROW_NEW
00094   { return ioPool.NewHandle(ev, inSize, &ioZone); }
00095   
00096   void* operator new(size_t inSize, morkPool& ioPool, morkEnv* ev) CPP_THROW_NEW
00097   { return ioPool.NewHandle(ev, inSize, (morkZone*) 0); }
00098   
00099   void* operator new(size_t inSize, morkHandleFace* ioFace) CPP_THROW_NEW
00100   { MORK_USED_1(inSize); return ioFace; }
00101   
00102   
00103 public: // construction:
00104 
00105   static orkinTableRowCursor* MakeTableRowCursor(morkEnv* ev, 
00106     morkTableRowCursor* ioObject);
00107 
00108 public: // utilities:
00109 
00110   morkEnv* CanUseTableRowCursor(nsIMdbEnv* mev, mork_bool inMutable,
00111     mdb_err* outErr) const;
00112 
00113 public: // type identification
00114   mork_bool IsOrkinTableRowCursor() const
00115   { return mHandle_Magic == morkMagic_kTableRowCursor; }
00116 
00117   mork_bool IsOrkinTableRowCursorHandle() const
00118   { return this->IsHandle() && this->IsOrkinTableRowCursor(); }
00119 
00120   NS_DECL_ISUPPORTS
00121 // { ===== begin nsIMdbObject methods =====
00122 
00123   // { ----- begin attribute methods -----
00124   NS_IMETHOD IsFrozenMdbObject(nsIMdbEnv* ev, mdb_bool* outIsReadonly);
00125   // same as nsIMdbPort::GetIsPortReadonly() when this object is inside a port.
00126   // } ----- end attribute methods -----
00127 
00128   // { ----- begin factory methods -----
00129   NS_IMETHOD GetMdbFactory(nsIMdbEnv* ev, nsIMdbFactory** acqFactory); 
00130   // } ----- end factory methods -----
00131 
00132   // { ----- begin ref counting for well-behaved cyclic graphs -----
00133   NS_IMETHOD GetWeakRefCount(nsIMdbEnv* ev, // weak refs
00134     mdb_count* outCount);  
00135   NS_IMETHOD GetStrongRefCount(nsIMdbEnv* ev, // strong refs
00136     mdb_count* outCount);
00137 
00138   NS_IMETHOD AddWeakRef(nsIMdbEnv* ev);
00139   NS_IMETHOD AddStrongRef(nsIMdbEnv* ev);
00140 
00141   NS_IMETHOD CutWeakRef(nsIMdbEnv* ev);
00142   NS_IMETHOD CutStrongRef(nsIMdbEnv* ev);
00143   
00144   NS_IMETHOD CloseMdbObject(nsIMdbEnv* ev); // called at strong refs zero
00145   NS_IMETHOD IsOpenMdbObject(nsIMdbEnv* ev, mdb_bool* outOpen);
00146   // } ----- end ref counting -----
00147   
00148 // } ===== end nsIMdbObject methods =====
00149 
00150 // { ===== begin nsIMdbCursor methods =====
00151 
00152   // { ----- begin attribute methods -----
00153   NS_IMETHOD GetCount(nsIMdbEnv* ev, mdb_count* outCount); // readonly
00154   NS_IMETHOD GetSeed(nsIMdbEnv* ev, mdb_seed* outSeed);    // readonly
00155   
00156   NS_IMETHOD SetPos(nsIMdbEnv* ev, mdb_pos inPos);   // mutable
00157   NS_IMETHOD GetPos(nsIMdbEnv* ev, mdb_pos* outPos);
00158   
00159   NS_IMETHOD SetDoFailOnSeedOutOfSync(nsIMdbEnv* ev, mdb_bool inFail);
00160   NS_IMETHOD GetDoFailOnSeedOutOfSync(nsIMdbEnv* ev, mdb_bool* outFail);
00161   // } ----- end attribute methods -----
00162 
00163 // } ===== end nsIMdbCursor methods =====
00164 
00165 // { ===== begin nsIMdbTableRowCursor methods =====
00166 
00167   // { ----- begin attribute methods -----
00168   NS_IMETHOD GetTable(nsIMdbEnv* ev, nsIMdbTable** acqTable);
00169   // } ----- end attribute methods -----
00170 
00171   // { ----- begin oid iteration methods -----
00172   NS_IMETHOD NextRowOid( // get row id of next row in the table
00173     nsIMdbEnv* ev, // context
00174     mdbOid* outOid, // out row oid
00175     mdb_pos* outRowPos);    // zero-based position of the row in table
00176   // } ----- end oid iteration methods -----
00177 
00178   // { ----- begin row iteration methods -----
00179   NS_IMETHOD NextRow( // get row cells from table for cells already in row
00180     nsIMdbEnv* ev, // context
00181     nsIMdbRow** acqRow, // acquire next row in table
00182     mdb_pos* outRowPos);    // zero-based position of the row in table
00183   // } ----- end row iteration methods -----
00184 
00185   // { ----- begin duplicate row removal methods -----
00186   NS_IMETHOD CanHaveDupRowMembers(nsIMdbEnv* ev, // cursor might hold dups?
00187     mdb_bool* outCanHaveDups);
00188     
00189   NS_IMETHOD MakeUniqueCursor( // clone cursor, removing duplicate rows
00190     nsIMdbEnv* ev, // context
00191     nsIMdbTableRowCursor** acqCursor);    // acquire clone with no dups
00192     // Note that MakeUniqueCursor() is never necessary for a cursor which was
00193     // created by table method nsIMdbTable::GetTableRowCursor(), because a table
00194     // never contains the same row as a member more than once.  However, a cursor
00195     // created by table method nsIMdbTable::FindRowMatches() might contain the
00196     // same row more than once, because the same row can generate a hit by more
00197     // than one column with a matching string prefix.  Note this method can
00198     // return the very same cursor instance with just an incremented refcount,
00199     // when the original cursor could not contain any duplicate rows (calling
00200     // CanHaveDupRowMembers() shows this case on a false return).  Otherwise
00201     // this method returns a different cursor instance.  Callers should not use
00202     // this MakeUniqueCursor() method lightly, because it tends to defeat the
00203     // purpose of lazy programming techniques, since it can force creation of
00204     // an explicit row collection in a new cursor's representation, in order to
00205     // inspect the row membership and remove any duplicates; this can have big
00206     // impact if a collection holds tens of thousands of rows or more, when
00207     // the original cursor with dups simply referenced rows indirectly by row
00208     // position ranges, without using an explicit row set representation.
00209     // Callers are encouraged to use nsIMdbCursor::GetCount() to determine
00210     // whether the row collection is very large (tens of thousands), and to
00211     // delay calling MakeUniqueCursor() when possible, until a user interface
00212     // element actually demands the creation of an explicit set representation.
00213   // } ----- end duplicate row removal methods -----
00214 
00215 // } ===== end nsIMdbTableRowCursor methods =====
00216 };
00217 
00218 //3456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789
00219 
00220 #endif /* _ORKINTABLEROWCURSOR_ */