Reenable test.
[wine-gecko.git] / db / mork / src / orkinRowCellCursor.cpp
blob89da83f9db1f154a1024d2fe1dbfad94a7377c88
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
13 * License.
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.
22 * Contributor(s):
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 ***** */
38 #ifndef _MDB_
39 #include "mdb.h"
40 #endif
42 #ifndef _MORK_
43 #include "mork.h"
44 #endif
46 #ifndef _MORKNODE_
47 #include "morkNode.h"
48 #endif
50 #ifndef _MORKHANDLE_
51 #include "morkHandle.h"
52 #endif
54 #ifndef _MORKROWCELLCURSOR_
55 #include "morkRowCellCursor.h"
56 #endif
58 #ifndef _ORKINROWCELLCURSOR_
59 #include "orkinRowCellCursor.h"
60 #endif
62 #ifndef _MORKROWOBJECT_
63 #include "morkRowObject.h"
64 #endif
66 #ifndef _MORKROW_
67 #include "morkRow.h"
68 #endif
70 #ifndef _ORKINROW_
71 #include "orkinRow.h"
72 #endif
74 #ifndef _MORKCELL_
75 #include "morkCell.h"
76 #endif
78 #ifndef _MORKENV_
79 #include "morkEnv.h"
80 #endif
82 //3456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789
84 /* public virtual*/
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();
103 MORK_ASSERT(isEnv);
104 if ( isEnv )
106 morkHandleFace* face = ev->NewHandle(sizeof(orkinRowCellCursor));
107 if ( face )
108 return new(face) orkinRowCellCursor(ev, face, ioObject);
109 else
110 ev->OutOfMemoryError();
113 return (orkinRowCellCursor*) 0;
116 morkEnv*
117 orkinRowCellCursor::CanUseRowCellCursor(nsIMdbEnv* mev, mork_bool inMutable,
118 mdb_err* outErr, morkRow** outRow) const
120 morkEnv* outEnv = 0;
121 morkRow* row = 0;
122 morkEnv* ev = morkEnv::FromMdbEnv(mev);
123 if ( ev )
125 morkRowCellCursor* self = (morkRowCellCursor*)
126 this->GetGoodHandleObject(ev, inMutable, morkMagic_kRowCellCursor,
127 /*inClosedOkay*/ morkBool_kFalse);
128 if ( self )
130 if ( self->IsRowCellCursor() )
132 if ( self->IsMutable() || !inMutable )
134 morkRowObject* rowObj = self->mRowCellCursor_RowObject;
135 if ( rowObj )
137 morkRow* theRow = rowObj->mRowObject_Row;
138 if ( theRow )
140 if ( theRow->IsRow() )
142 outEnv = ev;
143 row = theRow;
145 else
146 theRow->NonRowTypeError(ev);
148 else
149 rowObj->NilRowError(ev);
151 else
152 self->NilRowObjectError(ev);
154 else
155 self->NonMutableNodeError(ev);
157 else
158 self->NonRowCellCursorTypeError(ev);
160 *outErr = ev->AsErr();
162 *outRow = row;
163 MORK_ASSERT(outEnv);
164 return outEnv;
167 // { ===== begin nsIMdbISupports methods =====
168 NS_IMPL_QUERY_INTERFACE0(orkinRowCellCursor)
170 /*virtual*/ nsrefcnt
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());
176 else
177 return morkEnv_kNonEnvTypeError;
180 /*virtual*/ nsrefcnt
181 orkinRowCellCursor::Release() // cut strong ref
183 morkEnv* ev = mHandle_Env;
184 if ( ev && ev->IsEnv() )
185 return this->Handle_CutStrongRef(ev->AsMdbEnv());
186 else
187 return morkEnv_kNonEnvTypeError;
189 // } ===== end nsIMdbObject methods =====
191 // { ===== begin nsIMdbObject methods =====
193 // { ----- begin attribute methods -----
194 /*virtual*/ mdb_err
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 -----
203 /*virtual*/ mdb_err
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 -----
211 /*virtual*/ mdb_err
212 orkinRowCellCursor::GetWeakRefCount(nsIMdbEnv* mev, // weak refs
213 mdb_count* outCount)
215 return this->Handle_GetWeakRefCount(mev, outCount);
217 /*virtual*/ mdb_err
218 orkinRowCellCursor::GetStrongRefCount(nsIMdbEnv* mev, // strong refs
219 mdb_count* outCount)
221 return this->Handle_GetStrongRefCount(mev, outCount);
224 /*virtual*/ mdb_err
225 orkinRowCellCursor::AddWeakRef(nsIMdbEnv* mev)
227 return this->Handle_AddWeakRef(mev);
229 /*virtual*/ mdb_err
230 orkinRowCellCursor::AddStrongRef(nsIMdbEnv* mev)
232 return this->Handle_AddStrongRef(mev);
235 /*virtual*/ mdb_err
236 orkinRowCellCursor::CutWeakRef(nsIMdbEnv* mev)
238 return this->Handle_CutWeakRef(mev);
240 /*virtual*/ mdb_err
241 orkinRowCellCursor::CutStrongRef(nsIMdbEnv* mev)
243 return this->Handle_CutStrongRef(mev);
246 /*virtual*/ mdb_err
247 orkinRowCellCursor::CloseMdbObject(nsIMdbEnv* mev)
249 return this->Handle_CloseMdbObject(mev);
252 /*virtual*/ mdb_err
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 -----
264 /*virtual*/ mdb_err
265 orkinRowCellCursor::GetCount(nsIMdbEnv* mev, mdb_count* outCount)
267 mdb_err outErr = 0;
268 mdb_count count = 0;
269 morkRow* row = 0;
270 morkEnv* ev =
271 this->CanUseRowCellCursor(mev, /*mut*/ morkBool_kFalse, &outErr, &row);
272 if ( ev )
274 count = row->mRow_Length;
275 outErr = ev->AsErr();
277 if ( outCount )
278 *outCount = count;
279 return outErr;
282 /*virtual*/ mdb_err
283 orkinRowCellCursor::GetSeed(nsIMdbEnv* mev, mdb_seed* outSeed)
285 mdb_err outErr = 0;
286 mdb_seed seed = 0;
287 morkRow* row = 0;
288 morkEnv* ev =
289 this->CanUseRowCellCursor(mev, /*mut*/ morkBool_kFalse, &outErr, &row);
290 if ( ev )
292 seed = row->mRow_Seed;
293 outErr = ev->AsErr();
295 if ( outSeed )
296 *outSeed = seed;
297 return outErr;
300 /*virtual*/ mdb_err
301 orkinRowCellCursor::SetPos(nsIMdbEnv* mev, mdb_pos inPos)
303 mdb_err outErr = 0;
304 morkRow* row = 0;
305 morkEnv* ev =
306 this->CanUseRowCellCursor(mev, /*mut*/ morkBool_kFalse, &outErr, &row);
307 if ( ev )
309 morkRowCellCursor* cursor = (morkRowCellCursor*) mHandle_Object;
310 cursor->mCursor_Pos = inPos;
311 outErr = ev->AsErr();
313 return outErr;
316 /*virtual*/ mdb_err
317 orkinRowCellCursor::GetPos(nsIMdbEnv* mev, mdb_pos* outPos)
319 mdb_err outErr = 0;
320 mdb_pos pos = 0;
321 morkRow* row = 0;
322 morkEnv* ev =
323 this->CanUseRowCellCursor(mev, /*mut*/ morkBool_kFalse, &outErr, &row);
324 if ( ev )
326 morkRowCellCursor* cursor = (morkRowCellCursor*) mHandle_Object;
327 pos = cursor->mCursor_Pos;
328 outErr = ev->AsErr();
330 if ( outPos )
331 *outPos = pos;
332 return outErr;
335 /*virtual*/ mdb_err
336 orkinRowCellCursor::SetDoFailOnSeedOutOfSync(nsIMdbEnv* mev, mdb_bool inFail)
338 mdb_err outErr = 0;
339 morkRow* row = 0;
340 morkEnv* ev =
341 this->CanUseRowCellCursor(mev, /*mut*/ morkBool_kFalse, &outErr, &row);
342 if ( ev )
344 morkRowCellCursor* cursor = (morkRowCellCursor*) mHandle_Object;
345 cursor->mCursor_DoFailOnSeedOutOfSync = inFail;
346 outErr = ev->AsErr();
348 return outErr;
351 /*virtual*/ mdb_err
352 orkinRowCellCursor::GetDoFailOnSeedOutOfSync(nsIMdbEnv* mev, mdb_bool* outFail)
354 mdb_err outErr = 0;
355 mdb_bool doFail = morkBool_kFalse;
356 morkRow* row = 0;
357 morkEnv* ev =
358 this->CanUseRowCellCursor(mev, /*mut*/ morkBool_kFalse, &outErr, &row);
359 if ( ev )
361 morkRowCellCursor* cursor = (morkRowCellCursor*) mHandle_Object;
362 doFail = cursor->mCursor_DoFailOnSeedOutOfSync;
363 outErr = ev->AsErr();
365 if ( outFail )
366 *outFail = doFail;
367 return outErr;
369 // } ----- end attribute methods -----
371 // } ===== end nsIMdbCursor methods =====
373 // { ===== begin nsIMdbRowCellCursor methods =====
375 // { ----- begin attribute methods -----
376 /*virtual*/ mdb_err
377 orkinRowCellCursor::SetRow(nsIMdbEnv* mev, nsIMdbRow* ioRow)
379 mdb_err outErr = 0;
380 morkRow* row = 0;
381 morkEnv* ev =
382 this->CanUseRowCellCursor(mev, /*mut*/ morkBool_kFalse, &outErr, &row);
383 if ( ev )
385 morkRowCellCursor* cursor = (morkRowCellCursor*) mHandle_Object;
386 row = (morkRow *) ioRow;
387 morkStore* store = row->GetRowSpaceStore(ev);
388 if ( store )
390 morkRowObject* rowObj = row->AcquireRowObject(ev, store);
391 if ( rowObj )
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();
404 return outErr;
407 /*virtual*/ mdb_err
408 orkinRowCellCursor::GetRow(nsIMdbEnv* mev, nsIMdbRow** acqRow)
410 mdb_err outErr = 0;
411 nsIMdbRow* outRow = 0;
412 morkRow* row = 0;
413 morkEnv* ev =
414 this->CanUseRowCellCursor(mev, /*mut*/ morkBool_kFalse, &outErr, &row);
415 if ( ev )
417 morkRowCellCursor* cursor = (morkRowCellCursor*) mHandle_Object;
418 morkRowObject* rowObj = cursor->mRowCellCursor_RowObject;
419 if ( rowObj )
420 outRow = rowObj->AcquireRowHandle(ev);
422 outErr = ev->AsErr();
424 if ( acqRow )
425 *acqRow = outRow;
426 return outErr;
428 // } ----- end attribute methods -----
430 // { ----- begin cell creation methods -----
431 /*virtual*/ mdb_err
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)
438 mdb_err outErr = 0;
439 nsIMdbCell* outCell = 0;
440 mdb_pos pos = 0;
441 mdb_column col = 0;
442 morkRow* row = 0;
443 morkEnv* ev =
444 this->CanUseRowCellCursor(mev, /*mut*/ morkBool_kFalse, &outErr, &row);
445 if ( ev )
447 morkRowCellCursor* cursor = (morkRowCellCursor*) mHandle_Object;
448 pos = cursor->mCursor_Pos;
449 morkCell* cell = row->CellAt(ev, pos);
450 if ( cell )
452 col = cell->GetColumn();
453 outCell = row->AcquireCellHandle(ev, cell, col, pos);
455 outErr = ev->AsErr();
457 if ( acqCell )
458 *acqCell = outCell;
459 if ( outPos )
460 *outPos = pos;
461 if ( outColumn )
462 *outColumn = col;
464 return outErr;
466 // } ----- end cell creation methods -----
468 // { ----- begin cell seeking methods -----
469 /*virtual*/ mdb_err
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)
476 MORK_USED_1(inPos);
477 mdb_err outErr = 0;
478 mdb_column column = 0;
479 nsIMdbCell* outCell = 0;
480 morkRow* row = 0;
481 morkEnv* ev =
482 this->CanUseRowCellCursor(mev, /*mut*/ morkBool_kFalse, &outErr, &row);
483 if ( ev )
485 morkRowCellCursor* cursor;
486 cursor = (morkRowCellCursor*) mHandle_Object;
487 ev->StubMethodOnlyError();
488 outErr = ev->AsErr();
490 if ( acqCell )
491 *acqCell = outCell;
492 if ( outColumn )
493 *outColumn = column;
494 return outErr;
496 // } ----- end cell seeking methods -----
498 // { ----- begin cell iteration methods -----
499 /*virtual*/ mdb_err
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
504 mdb_pos* outPos)
506 MORK_USED_1(ioCell);
507 mdb_err outErr = 0;
508 mdb_pos pos = -1;
509 mdb_column column = 0;
510 morkRow* row = 0;
511 morkEnv* ev =
512 this->CanUseRowCellCursor(mev, /*mut*/ morkBool_kFalse, &outErr, &row);
513 if ( ev )
515 morkRowCellCursor* cursor;
516 cursor = (morkRowCellCursor*) mHandle_Object;
517 ev->StubMethodOnlyError();
518 outErr = ev->AsErr();
520 if ( outColumn )
521 *outColumn = column;
522 if ( outPos )
523 *outPos = pos;
524 return outErr;
527 /*virtual*/ mdb_err
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
533 mdb_pos* outPos)
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);
539 mdb_pos pos = -1;
540 mdb_column column = 0;
541 mdb_err outErr = 0;
542 morkRow* row = 0;
543 morkEnv* ev =
544 this->CanUseRowCellCursor(mev, /*mut*/ morkBool_kFalse, &outErr, &row);
545 if ( ev )
547 morkRowCellCursor* cursor;
548 cursor = (morkRowCellCursor*) mHandle_Object;
549 ev->StubMethodOnlyError();
550 outErr = ev->AsErr();
552 if ( outColumn )
553 *outColumn = column;
554 if ( outPos )
555 *outPos = pos;
556 return outErr;
559 // } ----- end cell iteration methods -----
561 // } ===== end nsIMdbRowCellCursor methods =====
564 //3456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789