Back to index

lightning-sunbird  0.9+nobinonly
morkSorting.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 _MORKSORTING_
00039 #define _MORKSORTING_ 1
00040 
00041 #ifndef _MORK_
00042 #include "mork.h"
00043 #endif
00044 
00045 #ifndef _MORKNODE_
00046 #include "morkNode.h"
00047 #endif
00048 
00049 #ifndef _MORKDEQUE_
00050 #include "morkDeque.h"
00051 #endif
00052 
00053 #ifndef _MORKOBJECT_
00054 #include "morkObject.h"
00055 #endif
00056 
00057 #ifndef _MORKARRAY_
00058 #include "morkArray.h"
00059 #endif
00060 
00061 #ifndef _MORKROWMAP_
00062 #include "morkRowMap.h"
00063 #endif
00064 
00065 #ifndef _MORKNODEMAP_
00066 #include "morkNodeMap.h"
00067 #endif
00068 
00069 #ifndef _MORKTABLE_
00070 #include "morkTable.h"
00071 #endif
00072 
00073 //3456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789
00074 
00075 class nsIMdbSorting;
00076 #define morkDerived_kSorting  /*i*/ 0x536F /* ascii 'So' */
00077 
00078 class morkSorting : public morkObject { 
00079 
00080   // NOTE the morkLink base is for morkRowSpace::mRowSpace_SortingsByPriority
00081 
00082 // public: // slots inherited from morkObject (meant to inform only)
00083   // nsIMdbHeap*    mNode_Heap;
00084 
00085   // mork_base      mNode_Base;     // must equal morkBase_kNode
00086   // mork_derived   mNode_Derived;  // depends on specific node subclass
00087   
00088   // mork_access    mNode_Access;   // kOpen, kClosing, kShut, or kDead
00089   // mork_usage     mNode_Usage;    // kHeap, kStack, kMember, kGlobal, kNone
00090   // mork_able      mNode_Mutable;  // can this node be modified?
00091   // mork_load      mNode_Load;     // is this node clean or dirty?
00092   
00093   // mork_uses      mNode_Uses;     // refcount for strong refs
00094   // mork_refs      mNode_Refs;     // refcount for strong refs + weak refs
00095 
00096   // mork_color   mBead_Color;   // ID for this bead
00097   // morkHandle*  mObject_Handle;  // weak ref to handle for this object
00098 
00099 public: // state is public because the entire Mork system is private
00100 
00101   morkTable*        mSorting_Table;    // weak ref to table
00102   
00103   nsIMdbCompare*    mSorting_Compare;
00104 
00105   morkArray         mSorting_RowArray;  // array of morkRow pointers
00106   
00107   mork_column       mSorting_Col;       // column that gets sorted
00108 
00109 public: // sorting dirty handling more than morkNode::SetNodeDirty() etc.
00110 
00111   void SetSortingDirty() { this->SetNodeDirty(); }
00112    
00113   mork_bool IsSortingClean() const { return this->IsNodeClean(); }
00114   mork_bool IsSortingDirty() const { return this->IsNodeDirty(); }
00115 
00116 public: // morkNode memory management operators
00117   void* operator new(size_t inSize, nsIMdbHeap& ioHeap, morkEnv* ev) CPP_THROW_NEW
00118   { return morkNode::MakeNew(inSize, ioHeap, ev); }
00119   
00120  
00121 // { ===== begin morkNode interface =====
00122 public: // morkNode virtual methods
00123   virtual void CloseMorkNode(morkEnv* ev); // CloseSorting() if open
00124   virtual ~morkSorting(); // assert that close executed earlier
00125   
00126 public: // morkSorting construction & destruction
00127   morkSorting(morkEnv* ev, const morkUsage& inUsage,
00128     nsIMdbHeap* ioNodeHeap, morkTable* ioTable,
00129     nsIMdbCompare* ioCompare,
00130     nsIMdbHeap* ioSlotHeap, mork_column inCol);
00131   void CloseSorting(morkEnv* ev); // called by CloseMorkNode();
00132 
00133 private: // copying is not allowed
00134   morkSorting(const morkSorting& other);
00135   morkSorting& operator=(const morkSorting& other);
00136 
00137 public: // dynamic type identification
00138   mork_bool IsSorting() const
00139   { return IsNode() && mNode_Derived == morkDerived_kSorting; }
00140 // } ===== end morkNode methods =====
00141 
00142 public: // errors
00143   static void NonSortingTypeError(morkEnv* ev);
00144   static void NonSortingTypeWarning(morkEnv* ev);
00145   static void ZeroColError(morkEnv* ev);
00146   static void NilTableError(morkEnv* ev);
00147   static void NilCompareError(morkEnv* ev);
00148 
00149 public: // utilities
00150 
00151   void sort_rows(morkEnv* ev);
00152   mork_count copy_table_row_array(morkEnv* ev);
00153 
00154 public: // other sorting methods
00155    
00156   mork_seed SortingSeed() const { return mSorting_RowArray.mArray_Seed; }
00157   
00158   morkRow* SafeRowAt(morkEnv* ev, mork_pos inPos)
00159   { return (morkRow*) mSorting_RowArray.SafeAt(ev, inPos); }
00160 
00161   nsIMdbSorting* AcquireSortingHandle(morkEnv* ev); // mObject_Handle
00162   
00163   mork_count GetRowCount() const { return mSorting_RowArray.mArray_Fill; }
00164   mork_pos  ArrayHasOid(morkEnv* ev, const mdbOid* inOid);
00165 
00166   morkSortingRowCursor* NewSortingRowCursor(morkEnv* ev, mork_pos inRowPos);
00167 
00168   mork_bool AddRow(morkEnv* ev, morkRow* ioRow);
00169 
00170   mork_bool CutRow(morkEnv* ev, morkRow* ioRow);
00171 
00172   mork_bool CutAllRows(morkEnv* ev);
00173 
00174 protected: // table seed sync management
00175    
00176   mork_bool is_seed_stale() const
00177   { return mSorting_RowArray.mArray_Seed != mSorting_Table->TableSeed(); }
00178    
00179   void sync_with_table_seed()
00180   { mSorting_RowArray.mArray_Seed = mSorting_Table->TableSeed(); }
00181 
00182 public: // typesafe refcounting inlines calling inherited morkNode methods
00183   static void SlotWeakSorting(morkSorting* me,
00184     morkEnv* ev, morkSorting** ioSlot)
00185   { morkNode::SlotWeakNode((morkNode*) me, ev, (morkNode**) ioSlot); }
00186   
00187   static void SlotStrongSorting(morkSorting* me,
00188     morkEnv* ev, morkSorting** ioSlot)
00189   { morkNode::SlotStrongNode((morkNode*) me, ev, (morkNode**) ioSlot); }
00190 };
00191 
00192 //3456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789
00193 
00194 #define morkDerived_kSortingMap  /*i*/ 0x734D /* ascii 'sM' */
00195 
00196 /*| morkSortingMap: maps mork_column -> morkSorting
00197 |*/
00198 class morkSortingMap : public morkNodeMap { // for mapping cols to sortings
00199 
00200 public:
00201 
00202   virtual ~morkSortingMap();
00203   morkSortingMap(morkEnv* ev, const morkUsage& inUsage,
00204     nsIMdbHeap* ioHeap, nsIMdbHeap* ioSlotHeap);
00205 
00206 public: // other map methods
00207 
00208   mork_bool  AddSorting(morkEnv* ev, morkSorting* ioSorting)
00209   { return this->AddNode(ev, ioSorting->mSorting_Col, ioSorting); }
00210   // the AddSorting() boolean return equals ev->Good().
00211 
00212   mork_bool  CutSorting(morkEnv* ev, mork_column inCol)
00213   { return this->CutNode(ev, inCol); }
00214   // The CutSorting() boolean return indicates whether removal happened. 
00215   
00216   morkSorting*  GetSorting(morkEnv* ev, mork_column inCol)
00217   { return (morkSorting*) this->GetNode(ev, inCol); }
00218   // Note the returned table does NOT have an increase in refcount for this.
00219 
00220   mork_num CutAllSortings(morkEnv* ev)
00221   { return this->CutAllNodes(ev); }
00222   // CutAllSortings() releases all the referenced table values.
00223 };
00224 
00225 class morkSortingMapIter: public morkMapIter{ // typesafe wrapper class
00226 
00227 public:
00228   morkSortingMapIter(morkEnv* ev, morkSortingMap* ioMap)
00229   : morkMapIter(ev, ioMap) { }
00230  
00231   morkSortingMapIter( ) : morkMapIter()  { }
00232   void InitSortingMapIter(morkEnv* ev, morkSortingMap* ioMap)
00233   { this->InitMapIter(ev, ioMap); }
00234    
00235   mork_change*
00236   FirstSorting(morkEnv* ev, mork_column* outCol, morkSorting** outSorting)
00237   { return this->First(ev, outCol, outSorting); }
00238   
00239   mork_change*
00240   NextSorting(morkEnv* ev, mork_column* outCol, morkSorting** outSorting)
00241   { return this->Next(ev, outCol, outSorting); }
00242   
00243   mork_change*
00244   HereSorting(morkEnv* ev, mork_column* outCol, morkSorting** outSorting)
00245   { return this->Here(ev, outCol, outSorting); }
00246   
00247   // cutting while iterating hash map might dirty the parent table:
00248   mork_change*
00249   CutHereSorting(morkEnv* ev, mork_column* outCol, morkSorting** outSorting)
00250   { return this->CutHere(ev, outCol, outSorting); }
00251 };
00252 
00253 
00254 //3456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789
00255 
00256 #endif /* _MORKSORTING_ */