Back to index

lightning-sunbird  0.9+nobinonly
morkSortingRowCursor.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 _MORKSORTINGROWCURSOR_
00059 #include "morkSortingRowCursor.h"
00060 #endif
00061 
00062 #ifndef _ORKINTABLEROWCURSOR_
00063 #include "orkinTableRowCursor.h"
00064 #endif
00065 
00066 #ifndef _MORKSTORE_
00067 #include "morkStore.h"
00068 #endif
00069 
00070 #ifndef _MORKTABLE_
00071 #include "morkTable.h"
00072 #endif
00073 
00074 #ifndef _MORKSORTING_
00075 #include "morkSorting.h"
00076 #endif
00077 
00078 #ifndef _MORKROW_
00079 #include "morkRow.h"
00080 #endif
00081 
00082 //3456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789
00083 
00084 // ````` ````` ````` ````` ````` 
00085 // { ===== begin morkNode interface =====
00086 
00087 /*public virtual*/ void
00088 morkSortingRowCursor::CloseMorkNode(morkEnv* ev) // CloseSortingRowCursor() only if open
00089 {
00090   if ( this->IsOpenNode() )
00091   {
00092     this->MarkClosing();
00093     this->CloseSortingRowCursor(ev);
00094     this->MarkShut();
00095   }
00096 }
00097 
00098 /*public virtual*/
00099 morkSortingRowCursor::~morkSortingRowCursor() // CloseSortingRowCursor() executed earlier
00100 {
00101   MORK_ASSERT(this->IsShutNode());
00102 }
00103 
00104 /*public non-poly*/
00105 morkSortingRowCursor::morkSortingRowCursor(morkEnv* ev,
00106   const morkUsage& inUsage,
00107   nsIMdbHeap* ioHeap, morkTable* ioTable, mork_pos inRowPos,
00108   morkSorting* ioSorting)
00109 : morkTableRowCursor(ev, inUsage, ioHeap, ioTable, inRowPos)
00110 , mSortingRowCursor_Sorting( 0 )
00111 {
00112   if ( ev->Good() )
00113   {
00114     if ( ioSorting )
00115     {
00116       morkSorting::SlotWeakSorting(ioSorting, ev, &mSortingRowCursor_Sorting);
00117       if ( ev->Good() )
00118       {
00119         // mNode_Derived = morkDerived_kTableRowCursor;
00120         // mNode_Derived must stay equal to  kTableRowCursor
00121       }
00122     }
00123     else
00124       ev->NilPointerError();
00125   }
00126 }
00127 
00128 /*public non-poly*/ void
00129 morkSortingRowCursor::CloseSortingRowCursor(morkEnv* ev) 
00130 {
00131   if ( this )
00132   {
00133     if ( this->IsNode() )
00134     {
00135       mCursor_Pos = -1;
00136       mCursor_Seed = 0;
00137       morkSorting::SlotWeakSorting((morkSorting*) 0, ev, &mSortingRowCursor_Sorting);
00138       this->CloseTableRowCursor(ev);
00139       this->MarkShut();
00140     }
00141     else
00142       this->NonNodeError(ev);
00143   }
00144   else
00145     ev->NilPointerError();
00146 }
00147 
00148 // } ===== end morkNode methods =====
00149 // ````` ````` ````` ````` ````` 
00150 
00151 /*static*/ void
00152 morkSortingRowCursor::NonSortingRowCursorTypeError(morkEnv* ev)
00153 {
00154   ev->NewError("non morkSortingRowCursor");
00155 }
00156 
00157 orkinTableRowCursor*
00158 morkSortingRowCursor::AcquireUniqueRowCursorHandle(morkEnv* ev)
00159 {
00160   return this->AcquireTableRowCursorHandle(ev);
00161 }
00162 
00163 mork_bool
00164 morkSortingRowCursor::CanHaveDupRowMembers(morkEnv* ev)
00165 {
00166   return morkBool_kFalse; // false is correct
00167 }
00168 
00169 mork_count
00170 morkSortingRowCursor::GetMemberCount(morkEnv* ev)
00171 {
00172   morkTable* table = mTableRowCursor_Table;
00173   if ( table )
00174     return table->mTable_RowArray.mArray_Fill;
00175   else
00176     return 0;
00177 
00178   // morkSorting* sorting = mSortingRowCursor_Sorting;
00179   // if ( sorting )
00180   //   return sorting->mSorting_RowArray.mArray_Fill;
00181   // else
00182   //   return 0;
00183 }
00184 
00185 morkRow*
00186 morkSortingRowCursor::NextRow(morkEnv* ev, mdbOid* outOid, mdb_pos* outPos)
00187 {
00188   morkRow* outRow = 0;
00189   mork_pos pos = -1;
00190   
00191   morkSorting* sorting = mSortingRowCursor_Sorting;
00192   if ( sorting )
00193   {
00194     if ( sorting->IsOpenNode() )
00195     {
00196       morkArray* array = &sorting->mSorting_RowArray;
00197       pos = mCursor_Pos;
00198       if ( pos < 0 )
00199         pos = 0;
00200       else
00201         ++pos;
00202         
00203       if ( pos < (mork_pos)(array->mArray_Fill))
00204       {
00205         mCursor_Pos = pos; // update for next time
00206         morkRow* row = (morkRow*) array->At(pos);
00207         if ( row )
00208         {
00209           if ( row->IsRow() )
00210           {
00211             outRow = row;
00212             *outOid = row->mRow_Oid;
00213           }
00214           else
00215             row->NonRowTypeError(ev);
00216         }
00217         else
00218           ev->NilPointerError();
00219       }
00220       else
00221       {
00222         outOid->mOid_Scope = 0;
00223         outOid->mOid_Id = morkId_kMinusOne;
00224       }
00225     }
00226     else
00227       sorting->NonOpenNodeError(ev);
00228   }
00229   else
00230     ev->NilPointerError();
00231 
00232   *outPos = pos;
00233   return outRow;
00234 }
00235 
00236 //3456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789