Back to index

lightning-sunbird  0.9+nobinonly
morkCellObject.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 _MORKCELLOBJECT_
00039 #define _MORKCELLOBJECT_ 1
00040 
00041 #ifndef _MORK_
00042 #include "mork.h"
00043 #endif
00044 
00045 #ifndef _MORKNODE_
00046 #include "morkNode.h"
00047 #endif
00048 
00049 #ifndef _MORKOBJECT_
00050 #include "morkObject.h"
00051 #endif
00052 
00053 //3456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789
00054 
00055 #define morkDerived_kCellObject  /*i*/ 0x634F /* ascii 'cO' */
00056 
00057 class morkCellObject : public morkObject, public nsIMdbCell { // blob attribute in column scope
00058 
00059 // public: // slots inherited from morkObject (meant to inform only)
00060   // nsIMdbHeap*     mNode_Heap;
00061   // mork_able    mNode_Mutable; // can this node be modified?
00062   // mork_load    mNode_Load;    // is this node clean or dirty?
00063   // mork_base    mNode_Base;    // must equal morkBase_kNode
00064   // mork_derived mNode_Derived; // depends on specific node subclass
00065   // mork_access  mNode_Access;  // kOpen, kClosing, kShut, or kDead
00066   // mork_usage   mNode_Usage;   // kHeap, kStack, kMember, kGlobal, kNone
00067   // mork_uses    mNode_Uses;    // refcount for strong refs
00068   // mork_refs    mNode_Refs;    // refcount for strong refs + weak refs
00069 
00070   // mork_color   mBead_Color;   // ID for this bead
00071   // morkHandle*  mObject_Handle;  // weak ref to handle for this object
00072 
00073 public: // state is public because the entire Mork system is private
00074   NS_DECL_ISUPPORTS_INHERITED
00075 
00076   morkRowObject*  mCellObject_RowObject;  // strong ref to row's object
00077   morkRow*        mCellObject_Row;        // cell's row if still in row object
00078   morkCell*       mCellObject_Cell;       // cell in row if rowseed matches
00079   mork_column     mCellObject_Col;        // col of cell last living in pos
00080   mork_u2         mCellObject_RowSeed;    // copy of row's seed
00081   mork_u2         mCellObject_Pos;        // position of cell in row
00082   
00083 // { ===== begin morkNode interface =====
00084 public: // morkNode virtual methods
00085   virtual void CloseMorkNode(morkEnv* ev); // CloseCellObject() only if open
00086   virtual ~morkCellObject(); // assert that CloseCellObject() executed earlier
00087   
00088 public: // morkCellObject construction & destruction
00089   morkCellObject(morkEnv* ev, const morkUsage& inUsage,
00090     nsIMdbHeap* ioHeap, morkRow* ioRow, morkCell* ioCell,
00091     mork_column inCol, mork_pos inPos);
00092   void CloseCellObject(morkEnv* ev); // called by CloseMorkNode();
00093 
00094   NS_IMETHOD SetBlob(nsIMdbEnv* ev,
00095     nsIMdbBlob* ioBlob); // reads inBlob slots
00096   // when inBlob is in the same suite, this might be fastest cell-to-cell
00097   
00098   NS_IMETHOD ClearBlob( // make empty (so content has zero length)
00099     nsIMdbEnv* ev);
00100   // clearing a yarn is like SetYarn() with empty yarn instance content
00101   
00102   NS_IMETHOD GetBlobFill(nsIMdbEnv* ev,
00103     mdb_fill* outFill);  // size of blob 
00104   // Same value that would be put into mYarn_Fill, if one called GetYarn()
00105   // with a yarn instance that had mYarn_Buf==nil and mYarn_Size==0.
00106   
00107   NS_IMETHOD SetYarn(nsIMdbEnv* ev, 
00108     const mdbYarn* inYarn);   // reads from yarn slots
00109   // make this text object contain content from the yarn's buffer
00110   
00111   NS_IMETHOD GetYarn(nsIMdbEnv* ev, 
00112     mdbYarn* outYarn);  // writes some yarn slots 
00113   // copy content into the yarn buffer, and update mYarn_Fill and mYarn_Form
00114   
00115   NS_IMETHOD AliasYarn(nsIMdbEnv* ev, 
00116     mdbYarn* outYarn); // writes ALL yarn slots
00117   NS_IMETHOD SetColumn(nsIMdbEnv* ev, mdb_column inColumn); 
00118   NS_IMETHOD GetColumn(nsIMdbEnv* ev, mdb_column* outColumn);
00119   
00120   NS_IMETHOD GetCellInfo(  // all cell metainfo except actual content
00121     nsIMdbEnv* ev, 
00122     mdb_column* outColumn,           // the column in the containing row
00123     mdb_fill*   outBlobFill,         // the size of text content in bytes
00124     mdbOid*     outChildOid,         // oid of possible row or table child
00125     mdb_bool*   outIsRowChild);  // nonzero if child, and a row child
00126 
00127   // Checking all cell metainfo is a good way to avoid forcing a large cell
00128   // in to memory when you don't actually want to use the content.
00129   
00130   NS_IMETHOD GetRow(nsIMdbEnv* ev, // parent row for this cell
00131     nsIMdbRow** acqRow);
00132   NS_IMETHOD GetPort(nsIMdbEnv* ev, // port containing cell
00133     nsIMdbPort** acqPort);
00134   // } ----- end attribute methods -----
00135 
00136   // { ----- begin children methods -----
00137   NS_IMETHOD HasAnyChild( // does cell have a child instead of text?
00138     nsIMdbEnv* ev,
00139     mdbOid* outOid,  // out id of row or table (or unbound if no child)
00140     mdb_bool* outIsRow); // nonzero if child is a row (rather than a table)
00141 
00142   NS_IMETHOD GetAnyChild( // access table of specific attribute
00143     nsIMdbEnv* ev, // context
00144     nsIMdbRow** acqRow, // child row (or null)
00145     nsIMdbTable** acqTable); // child table (or null)
00146 
00147 
00148   NS_IMETHOD SetChildRow( // access table of specific attribute
00149     nsIMdbEnv* ev, // context
00150     nsIMdbRow* ioRow); // inRow must be bound inside this same db port
00151 
00152   NS_IMETHOD GetChildRow( // access row of specific attribute
00153     nsIMdbEnv* ev, // context
00154     nsIMdbRow** acqRow); // acquire child row (or nil if no child)
00155 
00156 
00157   NS_IMETHOD SetChildTable( // access table of specific attribute
00158     nsIMdbEnv* ev, // context
00159     nsIMdbTable* inTable); // table must be bound inside this same db port
00160 
00161   NS_IMETHOD GetChildTable( // access table of specific attribute
00162     nsIMdbEnv* ev, // context
00163     nsIMdbTable** acqTable); // acquire child table (or nil if no child)
00164   // } ----- end children methods -----
00165 
00166 // } ===== end nsIMdbCell methods =====
00167 private: // copying is not allowed
00168   morkCellObject(const morkCellObject& other);
00169   morkCellObject& operator=(const morkCellObject& other);
00170 
00171 public: // dynamic type identification
00172   mork_bool IsCellObject() const
00173   { return IsNode() && mNode_Derived == morkDerived_kCellObject; }
00174 // } ===== end morkNode methods =====
00175 
00176 public: // other cell node methods
00177 
00178   morkEnv*  CanUseCell(nsIMdbEnv* mev, mork_bool inMutable,
00179     mdb_err* outErr, morkCell** outCell) ;
00180 
00181   mork_bool ResyncWithRow(morkEnv* ev); // return ev->Good()
00182   morkAtom* GetCellAtom(morkEnv* ev) const;
00183 
00184   static void MissingRowColumnError(morkEnv* ev);
00185   static void NilRowError(morkEnv* ev);
00186   static void NilCellError(morkEnv* ev);
00187   static void NilRowObjectError(morkEnv* ev);
00188   static void WrongRowObjectRowError(morkEnv* ev);
00189   static void NonCellObjectTypeError(morkEnv* ev);
00190 
00191   nsIMdbCell* AcquireCellHandle(morkEnv* ev);
00192 
00193 public: // typesafe refcounting inlines calling inherited morkNode methods
00194   static void SlotWeakCellObject(morkCellObject* me,
00195     morkEnv* ev, morkCellObject** ioSlot)
00196   { morkNode::SlotWeakNode((morkNode*) me, ev, (morkNode**) ioSlot); }
00197   
00198   static void SlotStrongCellObject(morkCellObject* me,
00199     morkEnv* ev, morkCellObject** ioSlot)
00200   { morkNode::SlotStrongNode((morkNode*) me, ev, (morkNode**) ioSlot); }
00201 };
00202 
00203 //3456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789
00204 
00205 #endif /* _MORKCELLOBJECT_ */