1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
15 * The Original Code is mozilla.org code.
17 * The Initial Developer of the Original Code is
18 * Netscape Communications Corporation.
19 * Portions created by the Initial Developer are Copyright (C) 1999
20 * the Initial Developer. All Rights Reserved.
24 * Alternatively, the contents of this file may be used under the terms of
25 * either of the GNU General Public License Version 2 or later (the "GPL"),
26 * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 * in which case the provisions of the GPL or the LGPL are applicable instead
28 * of those above. If you wish to allow use of your version of this file only
29 * under the terms of either the GPL or the LGPL, and not to allow others to
30 * use your version of this file under the terms of the MPL, indicate your
31 * decision by deleting the provisions above and replace them with the notice
32 * and other provisions required by the GPL or the LGPL. If you do not delete
33 * the provisions above, a recipient may use your version of this file under
34 * the terms of any one of the MPL, the GPL or the LGPL.
36 * ***** END LICENSE BLOCK ***** */
51 #include "morkHandle.h"
54 #ifndef _MORKROWCELLCURSOR_
55 #include "morkRowCellCursor.h"
58 #ifndef _ORKINROWCELLCURSOR_
59 #include "orkinRowCellCursor.h"
62 #ifndef _MORKROWOBJECT_
63 #include "morkRowObject.h"
82 //3456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789
85 orkinRowCellCursor:: ~orkinRowCellCursor() // morkHandle destructor does everything
89 /*protected non-poly construction*/
90 orkinRowCellCursor::orkinRowCellCursor(morkEnv
* ev
, // morkUsage is morkUsage_kPool
91 morkHandleFace
* ioFace
, // must not be nil, cookie for this handle
92 morkRowCellCursor
* ioObject
) // must not be nil, the object for this handle
93 : morkHandle(ev
, ioFace
, ioObject
, morkMagic_kRowCellCursor
)
95 // do not modify mNode_Derived; leave it equal to morkDerived_kHandle
99 /*static */ orkinRowCellCursor
*
100 orkinRowCellCursor::MakeRowCellCursor(morkEnv
* ev
, morkRowCellCursor
* ioObject
)
102 mork_bool isEnv
= ev
->IsEnv();
106 morkHandleFace
* face
= ev
->NewHandle(sizeof(orkinRowCellCursor
));
108 return new(face
) orkinRowCellCursor(ev
, face
, ioObject
);
110 ev
->OutOfMemoryError();
113 return (orkinRowCellCursor
*) 0;
117 orkinRowCellCursor::CanUseRowCellCursor(nsIMdbEnv
* mev
, mork_bool inMutable
,
118 mdb_err
* outErr
, morkRow
** outRow
) const
122 morkEnv
* ev
= morkEnv::FromMdbEnv(mev
);
125 morkRowCellCursor
* self
= (morkRowCellCursor
*)
126 this->GetGoodHandleObject(ev
, inMutable
, morkMagic_kRowCellCursor
,
127 /*inClosedOkay*/ morkBool_kFalse
);
130 if ( self
->IsRowCellCursor() )
132 if ( self
->IsMutable() || !inMutable
)
134 morkRowObject
* rowObj
= self
->mRowCellCursor_RowObject
;
137 morkRow
* theRow
= rowObj
->mRowObject_Row
;
140 if ( theRow
->IsRow() )
146 theRow
->NonRowTypeError(ev
);
149 rowObj
->NilRowError(ev
);
152 self
->NilRowObjectError(ev
);
155 self
->NonMutableNodeError(ev
);
158 self
->NonRowCellCursorTypeError(ev
);
160 *outErr
= ev
->AsErr();
167 // { ===== begin nsIMdbISupports methods =====
168 NS_IMPL_QUERY_INTERFACE0(orkinRowCellCursor
)
171 orkinRowCellCursor::AddRef() // add strong ref with no
173 morkEnv
* ev
= mHandle_Env
;
174 if ( ev
&& ev
->IsEnv() )
175 return this->Handle_AddStrongRef(ev
->AsMdbEnv());
177 return morkEnv_kNonEnvTypeError
;
181 orkinRowCellCursor::Release() // cut strong ref
183 morkEnv
* ev
= mHandle_Env
;
184 if ( ev
&& ev
->IsEnv() )
185 return this->Handle_CutStrongRef(ev
->AsMdbEnv());
187 return morkEnv_kNonEnvTypeError
;
189 // } ===== end nsIMdbObject methods =====
191 // { ===== begin nsIMdbObject methods =====
193 // { ----- begin attribute methods -----
195 orkinRowCellCursor::IsFrozenMdbObject(nsIMdbEnv
* mev
, mdb_bool
* outIsReadonly
)
197 return this->Handle_IsFrozenMdbObject(mev
, outIsReadonly
);
199 // same as nsIMdbPort::GetIsPortReadonly() when this object is inside a port.
200 // } ----- end attribute methods -----
202 // { ----- begin factory methods -----
204 orkinRowCellCursor::GetMdbFactory(nsIMdbEnv
* mev
, nsIMdbFactory
** acqFactory
)
206 return this->Handle_GetMdbFactory(mev
, acqFactory
);
208 // } ----- end factory methods -----
210 // { ----- begin ref counting for well-behaved cyclic graphs -----
212 orkinRowCellCursor::GetWeakRefCount(nsIMdbEnv
* mev
, // weak refs
215 return this->Handle_GetWeakRefCount(mev
, outCount
);
218 orkinRowCellCursor::GetStrongRefCount(nsIMdbEnv
* mev
, // strong refs
221 return this->Handle_GetStrongRefCount(mev
, outCount
);
225 orkinRowCellCursor::AddWeakRef(nsIMdbEnv
* mev
)
227 return this->Handle_AddWeakRef(mev
);
230 orkinRowCellCursor::AddStrongRef(nsIMdbEnv
* mev
)
232 return this->Handle_AddStrongRef(mev
);
236 orkinRowCellCursor::CutWeakRef(nsIMdbEnv
* mev
)
238 return this->Handle_CutWeakRef(mev
);
241 orkinRowCellCursor::CutStrongRef(nsIMdbEnv
* mev
)
243 return this->Handle_CutStrongRef(mev
);
247 orkinRowCellCursor::CloseMdbObject(nsIMdbEnv
* mev
)
249 return this->Handle_CloseMdbObject(mev
);
253 orkinRowCellCursor::IsOpenMdbObject(nsIMdbEnv
* mev
, mdb_bool
* outOpen
)
255 return this->Handle_IsOpenMdbObject(mev
, outOpen
);
257 // } ----- end ref counting -----
259 // } ===== end nsIMdbObject methods =====
261 // { ===== begin nsIMdbCursor methods =====
263 // { ----- begin attribute methods -----
265 orkinRowCellCursor::GetCount(nsIMdbEnv
* mev
, mdb_count
* outCount
)
271 this->CanUseRowCellCursor(mev
, /*mut*/ morkBool_kFalse
, &outErr
, &row
);
274 count
= row
->mRow_Length
;
275 outErr
= ev
->AsErr();
283 orkinRowCellCursor::GetSeed(nsIMdbEnv
* mev
, mdb_seed
* outSeed
)
289 this->CanUseRowCellCursor(mev
, /*mut*/ morkBool_kFalse
, &outErr
, &row
);
292 seed
= row
->mRow_Seed
;
293 outErr
= ev
->AsErr();
301 orkinRowCellCursor::SetPos(nsIMdbEnv
* mev
, mdb_pos inPos
)
306 this->CanUseRowCellCursor(mev
, /*mut*/ morkBool_kFalse
, &outErr
, &row
);
309 morkRowCellCursor
* cursor
= (morkRowCellCursor
*) mHandle_Object
;
310 cursor
->mCursor_Pos
= inPos
;
311 outErr
= ev
->AsErr();
317 orkinRowCellCursor::GetPos(nsIMdbEnv
* mev
, mdb_pos
* outPos
)
323 this->CanUseRowCellCursor(mev
, /*mut*/ morkBool_kFalse
, &outErr
, &row
);
326 morkRowCellCursor
* cursor
= (morkRowCellCursor
*) mHandle_Object
;
327 pos
= cursor
->mCursor_Pos
;
328 outErr
= ev
->AsErr();
336 orkinRowCellCursor::SetDoFailOnSeedOutOfSync(nsIMdbEnv
* mev
, mdb_bool inFail
)
341 this->CanUseRowCellCursor(mev
, /*mut*/ morkBool_kFalse
, &outErr
, &row
);
344 morkRowCellCursor
* cursor
= (morkRowCellCursor
*) mHandle_Object
;
345 cursor
->mCursor_DoFailOnSeedOutOfSync
= inFail
;
346 outErr
= ev
->AsErr();
352 orkinRowCellCursor::GetDoFailOnSeedOutOfSync(nsIMdbEnv
* mev
, mdb_bool
* outFail
)
355 mdb_bool doFail
= morkBool_kFalse
;
358 this->CanUseRowCellCursor(mev
, /*mut*/ morkBool_kFalse
, &outErr
, &row
);
361 morkRowCellCursor
* cursor
= (morkRowCellCursor
*) mHandle_Object
;
362 doFail
= cursor
->mCursor_DoFailOnSeedOutOfSync
;
363 outErr
= ev
->AsErr();
369 // } ----- end attribute methods -----
371 // } ===== end nsIMdbCursor methods =====
373 // { ===== begin nsIMdbRowCellCursor methods =====
375 // { ----- begin attribute methods -----
377 orkinRowCellCursor::SetRow(nsIMdbEnv
* mev
, nsIMdbRow
* ioRow
)
382 this->CanUseRowCellCursor(mev
, /*mut*/ morkBool_kFalse
, &outErr
, &row
);
385 morkRowCellCursor
* cursor
= (morkRowCellCursor
*) mHandle_Object
;
386 row
= (morkRow
*) ioRow
;
387 morkStore
* store
= row
->GetRowSpaceStore(ev
);
390 morkRowObject
* rowObj
= row
->AcquireRowObject(ev
, store
);
393 morkRowObject::SlotStrongRowObject((morkRowObject
*) 0, ev
,
394 &cursor
->mRowCellCursor_RowObject
);
396 cursor
->mRowCellCursor_RowObject
= rowObj
; // take this strong ref
397 cursor
->mCursor_Seed
= row
->mRow_Seed
;
399 row
->GetCell(ev
, cursor
->mRowCellCursor_Col
, &cursor
->mCursor_Pos
);
402 outErr
= ev
->AsErr();
408 orkinRowCellCursor::GetRow(nsIMdbEnv
* mev
, nsIMdbRow
** acqRow
)
411 nsIMdbRow
* outRow
= 0;
414 this->CanUseRowCellCursor(mev
, /*mut*/ morkBool_kFalse
, &outErr
, &row
);
417 morkRowCellCursor
* cursor
= (morkRowCellCursor
*) mHandle_Object
;
418 morkRowObject
* rowObj
= cursor
->mRowCellCursor_RowObject
;
420 outRow
= rowObj
->AcquireRowHandle(ev
);
422 outErr
= ev
->AsErr();
428 // } ----- end attribute methods -----
430 // { ----- begin cell creation methods -----
432 orkinRowCellCursor::MakeCell( // get cell at current pos in the row
433 nsIMdbEnv
* mev
, // context
434 mdb_column
* outColumn
, // column for this particular cell
435 mdb_pos
* outPos
, // position of cell in row sequence
436 nsIMdbCell
** acqCell
)
439 nsIMdbCell
* outCell
= 0;
444 this->CanUseRowCellCursor(mev
, /*mut*/ morkBool_kFalse
, &outErr
, &row
);
447 morkRowCellCursor
* cursor
= (morkRowCellCursor
*) mHandle_Object
;
448 pos
= cursor
->mCursor_Pos
;
449 morkCell
* cell
= row
->CellAt(ev
, pos
);
452 col
= cell
->GetColumn();
453 outCell
= row
->AcquireCellHandle(ev
, cell
, col
, pos
);
455 outErr
= ev
->AsErr();
466 // } ----- end cell creation methods -----
468 // { ----- begin cell seeking methods -----
470 orkinRowCellCursor::SeekCell( // same as SetRow() followed by MakeCell()
471 nsIMdbEnv
* mev
, // context
472 mdb_pos inPos
, // position of cell in row sequence
473 mdb_column
* outColumn
, // column for this particular cell
474 nsIMdbCell
** acqCell
)
478 mdb_column column
= 0;
479 nsIMdbCell
* outCell
= 0;
482 this->CanUseRowCellCursor(mev
, /*mut*/ morkBool_kFalse
, &outErr
, &row
);
485 morkRowCellCursor
* cursor
;
486 cursor
= (morkRowCellCursor
*) mHandle_Object
;
487 ev
->StubMethodOnlyError();
488 outErr
= ev
->AsErr();
496 // } ----- end cell seeking methods -----
498 // { ----- begin cell iteration methods -----
500 orkinRowCellCursor::NextCell( // get next cell in the row
501 nsIMdbEnv
* mev
, // context
502 nsIMdbCell
* ioCell
, // changes to the next cell in the iteration
503 mdb_column
* outColumn
, // column for this particular cell
509 mdb_column column
= 0;
512 this->CanUseRowCellCursor(mev
, /*mut*/ morkBool_kFalse
, &outErr
, &row
);
515 morkRowCellCursor
* cursor
;
516 cursor
= (morkRowCellCursor
*) mHandle_Object
;
517 ev
->StubMethodOnlyError();
518 outErr
= ev
->AsErr();
528 orkinRowCellCursor::PickNextCell( // get next cell in row within filter set
529 nsIMdbEnv
* mev
, // context
530 nsIMdbCell
* ioCell
, // changes to the next cell in the iteration
531 const mdbColumnSet
* inFilterSet
, // col set of actual caller interest
532 mdb_column
* outColumn
, // column for this particular cell
534 // Note that inFilterSet should not have too many (many more than 10?)
535 // cols, since this might imply a potential excessive consumption of time
536 // over many cursor calls when looking for column and filter intersection.
538 MORK_USED_2(ioCell
,inFilterSet
);
540 mdb_column column
= 0;
544 this->CanUseRowCellCursor(mev
, /*mut*/ morkBool_kFalse
, &outErr
, &row
);
547 morkRowCellCursor
* cursor
;
548 cursor
= (morkRowCellCursor
*) mHandle_Object
;
549 ev
->StubMethodOnlyError();
550 outErr
= ev
->AsErr();
559 // } ----- end cell iteration methods -----
561 // } ===== end nsIMdbRowCellCursor methods =====
564 //3456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789