Back to index

lightning-sunbird  0.9+nobinonly
morkArray.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 _MORKARRAY_
00039 #define _MORKARRAY_ 1
00040 
00041 #ifndef _MORK_
00042 #include "mork.h"
00043 #endif
00044 
00045 #ifndef _MORKNODE_
00046 #include "morkNode.h"
00047 #endif
00048 
00049 //3456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789
00050 
00051 #define morkDerived_kArray  /*i*/ 0x4179 /* ascii 'Ay' */
00052 
00053 class morkArray : public morkNode { // row iterator
00054 
00055 // public: // slots inherited from morkObject (meant to inform only)
00056   // nsIMdbHeap*     mNode_Heap;
00057   // mork_able    mNode_Mutable; // can this node be modified?
00058   // mork_load    mNode_Load;    // is this node clean or dirty?
00059   // mork_base    mNode_Base;    // must equal morkBase_kNode
00060   // mork_derived mNode_Derived; // depends on specific node subclass
00061   // mork_access  mNode_Access;  // kOpen, kClosing, kShut, or kDead
00062   // mork_usage   mNode_Usage;   // kHeap, kStack, kMember, kGlobal, kNone
00063   // mork_uses    mNode_Uses;    // refcount for strong refs
00064   // mork_refs    mNode_Refs;    // refcount for strong refs + weak refs
00065 
00066 public: // state is public because the entire Mork system is private
00067   void**       mArray_Slots; // array of pointers
00068   nsIMdbHeap*  mArray_Heap;  // required heap for allocating mArray_Slots
00069   mork_fill    mArray_Fill;  // logical count of used slots in mArray_Slots
00070   mork_size    mArray_Size;  // physical count of mArray_Slots ( >= Fill)
00071   mork_seed    mArray_Seed;  // change counter for syncing with iterators
00072   
00073 // { ===== begin morkNode interface =====
00074 public: // morkNode virtual methods
00075   virtual void CloseMorkNode(morkEnv* ev); // CloseArray()
00076   virtual ~morkArray(); // assert that close executed earlier
00077   
00078 public: // morkArray construction & destruction
00079   morkArray(morkEnv* ev, const morkUsage& inUsage,
00080     nsIMdbHeap* ioHeap, mork_size inSize, nsIMdbHeap* ioSlotHeap);
00081   void CloseArray(morkEnv* ev); // called by CloseMorkNode();
00082 
00083 private: // copying is not allowed
00084   morkArray(const morkArray& other);
00085   morkArray& operator=(const morkArray& other);
00086 
00087 public: // dynamic type identification
00088   mork_bool IsArray() const
00089   { return IsNode() && mNode_Derived == morkDerived_kArray; }
00090 // } ===== end morkNode methods =====
00091 
00092 public: // typing & errors
00093   static void NonArrayTypeError(morkEnv* ev);
00094   static void IndexBeyondEndError(morkEnv* ev);
00095   static void NilSlotsAddressError(morkEnv* ev);
00096   static void FillBeyondSizeError(morkEnv* ev);
00097 
00098 public: // other table row cursor methods
00099 
00100   mork_fill  Length() const { return mArray_Fill; }
00101   mork_size  Capacity() const { return mArray_Size; }
00102   
00103   mork_bool  Grow(morkEnv* ev, mork_size inNewSize);
00104   // Grow() returns true if capacity becomes >= inNewSize and ev->Good()
00105   
00106   void*      At(mork_pos inPos) const { return mArray_Slots[ inPos ]; }
00107   void       AtPut(mork_pos inPos, void* ioSlot)
00108   { mArray_Slots[ inPos ] = ioSlot; }
00109   
00110   void*      SafeAt(morkEnv* ev, mork_pos inPos);
00111   void       SafeAtPut(morkEnv* ev, mork_pos inPos, void* ioSlot);
00112   
00113   mork_pos   AppendSlot(morkEnv* ev, void* ioSlot);
00114   void       AddSlot(morkEnv* ev, mork_pos inPos, void* ioSlot);
00115   void       CutSlot(morkEnv* ev, mork_pos inPos);
00116   void       CutAllSlots(morkEnv* ev);
00117 
00118 public: // typesafe refcounting inlines calling inherited morkNode methods
00119   static void SlotWeakArray(morkArray* me,
00120     morkEnv* ev, morkArray** ioSlot)
00121   { morkNode::SlotWeakNode((morkNode*) me, ev, (morkNode**) ioSlot); }
00122   
00123   static void SlotStrongArray(morkArray* me,
00124     morkEnv* ev, morkArray** ioSlot)
00125   { morkNode::SlotStrongNode((morkNode*) me, ev, (morkNode**) ioSlot); }
00126 };
00127 
00128 //3456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789
00129 
00130 #endif /* _MORKTABLEROWCURSOR_ */