Back to index

lightning-sunbird  0.9+nobinonly
morkRowCellCursor.cpp
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 _MDB_
00039 #include "mdb.h"
00040 #endif
00041 
00042 #ifndef _MORK_
00043 #include "mork.h"
00044 #endif
00045 
00046 #ifndef _MORKNODE_
00047 #include "morkNode.h"
00048 #endif
00049 
00050 #ifndef _MORKENV_
00051 #include "morkEnv.h"
00052 #endif
00053 
00054 #ifndef _MORKCURSOR_
00055 #include "morkCursor.h"
00056 #endif
00057 
00058 #ifndef _MORKROWCELLCURSOR_
00059 #include "morkRowCellCursor.h"
00060 #endif
00061 
00062 #ifndef _ORKINROWCELLCURSOR_
00063 #include "orkinRowCellCursor.h"
00064 #endif
00065 
00066 #ifndef _MORKSTORE_
00067 #include "morkStore.h"
00068 #endif
00069 
00070 #ifndef _MORKROWOBJECT_
00071 #include "morkRowObject.h"
00072 #endif
00073 
00074 #ifndef _MORKROW_
00075 #include "morkRow.h"
00076 #endif
00077 
00078 //3456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789
00079 
00080 // ````` ````` ````` ````` ````` 
00081 // { ===== begin morkNode interface =====
00082 
00083 /*public virtual*/ void
00084 morkRowCellCursor::CloseMorkNode(morkEnv* ev) // CloseRowCellCursor() only if open
00085 {
00086   if ( this->IsOpenNode() )
00087   {
00088     this->MarkClosing();
00089     this->CloseRowCellCursor(ev);
00090     this->MarkShut();
00091   }
00092 }
00093 
00094 /*public virtual*/
00095 morkRowCellCursor::~morkRowCellCursor() // CloseRowCellCursor() executed earlier
00096 {
00097   CloseMorkNode(mMorkEnv);
00098   MORK_ASSERT(this->IsShutNode());
00099 }
00100 
00101 /*public non-poly*/
00102 morkRowCellCursor::morkRowCellCursor(morkEnv* ev,
00103   const morkUsage& inUsage,
00104   nsIMdbHeap* ioHeap, morkRowObject* ioRowObject)
00105 : morkCursor(ev, inUsage, ioHeap)
00106 , mRowCellCursor_RowObject( 0 )
00107 , mRowCellCursor_Col( 0 )
00108 {
00109   if ( ev->Good() )
00110   {
00111     if ( ioRowObject )
00112     {
00113       morkRow* row = ioRowObject->mRowObject_Row;
00114       if ( row )
00115       {
00116         if ( row->IsRow() )
00117         {
00118           mCursor_Pos = -1;
00119           mCursor_Seed = row->mRow_Seed;
00120           
00121           morkRowObject::SlotStrongRowObject(ioRowObject, ev,
00122             &mRowCellCursor_RowObject);
00123           if ( ev->Good() )
00124             mNode_Derived = morkDerived_kRowCellCursor;
00125         }
00126         else
00127           row->NonRowTypeError(ev);
00128       }
00129       else
00130         ioRowObject->NilRowError(ev);
00131     }
00132     else
00133       ev->NilPointerError();
00134   }
00135 }
00136 
00137 NS_IMPL_ISUPPORTS_INHERITED1(morkRowCellCursor, morkCursor, nsIMdbRowCellCursor)
00138 
00139 /*public non-poly*/ void
00140 morkRowCellCursor::CloseRowCellCursor(morkEnv* ev) 
00141 {
00142   if ( this )
00143   {
00144     if ( this->IsNode() )
00145     {
00146       mCursor_Pos = -1;
00147       mCursor_Seed = 0;
00148       morkRowObject::SlotStrongRowObject((morkRowObject*) 0, ev,
00149         &mRowCellCursor_RowObject);
00150       this->CloseCursor(ev);
00151       this->MarkShut();
00152     }
00153     else
00154       this->NonNodeError(ev);
00155   }
00156   else
00157     ev->NilPointerError();
00158 }
00159 
00160 // } ===== end morkNode methods =====
00161 // ````` ````` ````` ````` ````` 
00162 
00163 /*static*/ void
00164 morkRowCellCursor::NilRowObjectError(morkEnv* ev)
00165 {
00166   ev->NewError("nil mRowCellCursor_RowObject");
00167 }
00168 
00169 /*static*/ void
00170 morkRowCellCursor::NonRowCellCursorTypeError(morkEnv* ev)
00171 {
00172   ev->NewError("non morkRowCellCursor");
00173 }
00174 
00175 
00176 //3456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789
00177 // { ----- begin attribute methods -----
00178 NS_IMETHODIMP
00179 morkRowCellCursor::SetRow(nsIMdbEnv* mev, nsIMdbRow* ioRow)
00180 {
00181   mdb_err outErr = 0;
00182   morkRow* row = 0;
00183   morkEnv* ev = morkEnv::FromMdbEnv(mev);
00184   if ( ev )
00185   {
00186     row = (morkRow *) ioRow;
00187     morkStore* store = row->GetRowSpaceStore(ev);
00188     if ( store )
00189     {
00190       morkRowObject* rowObj = row->AcquireRowObject(ev, store);
00191       if ( rowObj )
00192       {
00193         morkRowObject::SlotStrongRowObject((morkRowObject*) 0, ev,
00194           &mRowCellCursor_RowObject);
00195           
00196         mRowCellCursor_RowObject = rowObj; // take this strong ref
00197         mCursor_Seed = row->mRow_Seed;
00198         
00199         row->GetCell(ev, mRowCellCursor_Col, &mCursor_Pos);
00200       }
00201     }
00202     outErr = ev->AsErr();
00203   }
00204   return outErr;
00205 }
00206 
00207 NS_IMETHODIMP
00208 morkRowCellCursor::GetRow(nsIMdbEnv* mev, nsIMdbRow** acqRow)
00209 {
00210   mdb_err outErr = 0;
00211   nsIMdbRow* outRow = 0;
00212   morkEnv* ev = morkEnv::FromMdbEnv(mev);
00213   if ( ev )
00214   {
00215     morkRowObject* rowObj = mRowCellCursor_RowObject;
00216     if ( rowObj )
00217       outRow = rowObj->AcquireRowHandle(ev);
00218 
00219     outErr = ev->AsErr();
00220   }
00221   if ( acqRow )
00222     *acqRow = outRow;
00223   return outErr;
00224 }
00225 // } ----- end attribute methods -----
00226 
00227 // { ----- begin cell creation methods -----
00228 NS_IMETHODIMP
00229 morkRowCellCursor::MakeCell( // get cell at current pos in the row
00230   nsIMdbEnv* mev, // context
00231   mdb_column* outColumn, // column for this particular cell
00232   mdb_pos* outPos, // position of cell in row sequence
00233   nsIMdbCell** acqCell)
00234 {
00235   mdb_err outErr = 0;
00236   nsIMdbCell* outCell = 0;
00237   mdb_pos pos = 0;
00238   mdb_column col = 0;
00239   morkRow* row = 0;
00240   morkEnv* ev = morkEnv::FromMdbEnv(mev);
00241   if ( ev )
00242   {
00243     pos = mCursor_Pos;
00244     morkCell* cell = row->CellAt(ev, pos);
00245     if ( cell )
00246     {
00247       col = cell->GetColumn();
00248       outCell = row->AcquireCellHandle(ev, cell, col, pos);
00249     }
00250     outErr = ev->AsErr();
00251   }
00252   if ( acqCell )
00253     *acqCell = outCell;
00254    if ( outPos )
00255      *outPos = pos;
00256    if ( outColumn )
00257      *outColumn = col;
00258      
00259   return outErr;
00260 }
00261 // } ----- end cell creation methods -----
00262 
00263 // { ----- begin cell seeking methods -----
00264 NS_IMETHODIMP
00265 morkRowCellCursor::SeekCell( // same as SetRow() followed by MakeCell()
00266   nsIMdbEnv* mev, // context
00267   mdb_pos inPos, // position of cell in row sequence
00268   mdb_column* outColumn, // column for this particular cell
00269   nsIMdbCell** acqCell)
00270 {
00271   NS_ASSERTION(PR_FALSE, "not implemented");
00272   return NS_ERROR_NOT_IMPLEMENTED;
00273 }
00274 // } ----- end cell seeking methods -----
00275 
00276 // { ----- begin cell iteration methods -----
00277 NS_IMETHODIMP
00278 morkRowCellCursor::NextCell( // get next cell in the row
00279   nsIMdbEnv* mev, // context
00280   nsIMdbCell** acqCell, // changes to the next cell in the iteration
00281   mdb_column* outColumn, // column for this particular cell
00282   mdb_pos* outPos)
00283 {
00284   morkEnv* ev = morkEnv::FromMdbEnv(mev);
00285   mdb_column col = 0;
00286   mdb_pos pos = mRowCellCursor_Col;
00287   if ( pos < 0 )
00288     pos = 0;
00289   else
00290     ++pos;
00291 
00292   morkCell* cell = mRowCellCursor_RowObject->mRowObject_Row->CellAt(ev, pos);
00293   if ( cell )
00294   {
00295     col = cell->GetColumn();
00296     *acqCell = mRowCellCursor_RowObject->mRowObject_Row->AcquireCellHandle(ev, cell, col, pos);
00297   }
00298   else
00299   {
00300     *acqCell = nsnull;
00301     pos = -1;
00302   }
00303  if ( outPos )
00304    *outPos = pos;
00305  if ( outColumn )
00306    *outColumn = col;
00307      
00308   mRowCellCursor_Col = pos;
00309   *outPos = pos;
00310   return NS_OK;
00311 }
00312   
00313 NS_IMETHODIMP
00314 morkRowCellCursor::PickNextCell( // get next cell in row within filter set
00315   nsIMdbEnv* mev, // context
00316   nsIMdbCell* ioCell, // changes to the next cell in the iteration
00317   const mdbColumnSet* inFilterSet, // col set of actual caller interest
00318   mdb_column* outColumn, // column for this particular cell
00319   mdb_pos* outPos)
00320 // Note that inFilterSet should not have too many (many more than 10?)
00321 // cols, since this might imply a potential excessive consumption of time
00322 // over many cursor calls when looking for column and filter intersection.
00323 {
00324   NS_ASSERTION(PR_FALSE, "not implemented");
00325   return NS_ERROR_NOT_IMPLEMENTED;
00326 }
00327 
00328 // } ----- end cell iteration methods -----
00329 
00330 // } ===== end nsIMdbRowCellCursor methods =====
00331