1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-  */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3  * License, v. 2.0. If a copy of the MPL was not distributed with this
4  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 
6 #ifndef _MORKROWOBJECT_
7 #define _MORKROWOBJECT_ 1
8 
9 #ifndef _MORK_
10 #  include "mork.h"
11 #endif
12 
13 #ifndef _MORKOBJECT_
14 #  include "morkObject.h"
15 #endif
16 
17 // 456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789
18 
19 class nsIMdbRow;
20 #define morkDerived_kRowObject /*i*/ 0x724F /* ascii 'rO' */
21 
22 class morkRowObject : public morkObject, public nsIMdbRow {  //
23 
24  public:  // state is public because the entire Mork system is private
25   NS_DECL_ISUPPORTS_INHERITED
26 
27   morkRow* mRowObject_Row;      // non-refcounted alias to morkRow
28   morkStore* mRowObject_Store;  // non-refcounted ptr to store containing row
29 
30   // { ===== begin morkNode interface =====
31  public:  // morkNode virtual methods
32   virtual void CloseMorkNode(
33       morkEnv* ev) override;  // CloseRowObject() only if open
34 
35  public:  // morkRowObject construction & destruction
36   morkRowObject(morkEnv* ev, const morkUsage& inUsage, nsIMdbHeap* ioHeap,
37                 morkRow* ioRow, morkStore* ioStore);
38   void CloseRowObject(morkEnv* ev);  // called by CloseMorkNode();
39 
40   // { ===== begin nsIMdbCollection methods =====
41 
42   // { ----- begin attribute methods -----
43   NS_IMETHOD GetSeed(nsIMdbEnv* ev,
44                      mdb_seed* outSeed) override;  // member change count
45   NS_IMETHOD GetCount(nsIMdbEnv* ev,
46                       mdb_count* outCount) override;  // member count
47 
48   NS_IMETHOD GetPort(nsIMdbEnv* ev,
49                      nsIMdbPort** acqPort) override;  // collection container
50   // } ----- end attribute methods -----
51 
52   // { ----- begin cursor methods -----
53   NS_IMETHOD GetCursor(     // make a cursor starting iter at inMemberPos
54       nsIMdbEnv* ev,        // context
55       mdb_pos inMemberPos,  // zero-based ordinal pos of member in collection
56       nsIMdbCursor** acqCursor) override;  // acquire new cursor instance
57   // } ----- end cursor methods -----
58 
59   // { ----- begin ID methods -----
60   NS_IMETHOD GetOid(nsIMdbEnv* ev,
61                     mdbOid* outOid) override;  // read object identity
62   NS_IMETHOD BecomeContent(nsIMdbEnv* ev,
63                            const mdbOid* inOid) override;  // exchange content
64   // } ----- end ID methods -----
65 
66   // { ----- begin activity dropping methods -----
67   NS_IMETHOD DropActivity(  // tell collection usage no longer expected
68       nsIMdbEnv* ev) override;
69   // } ----- end activity dropping methods -----
70 
71   // } ===== end nsIMdbCollection methods =====
72   // { ===== begin nsIMdbRow methods =====
73 
74   // { ----- begin cursor methods -----
75   NS_IMETHOD GetRowCellCursor(  // make a cursor starting iteration at inRowPos
76       nsIMdbEnv* ev,            // context
77       mdb_pos inRowPos,         // zero-based ordinal position of row in table
78       nsIMdbRowCellCursor** acqCursor) override;  // acquire new cursor instance
79   // } ----- end cursor methods -----
80 
81   // { ----- begin column methods -----
82   NS_IMETHOD AddColumn(     // make sure a particular column is inside row
83       nsIMdbEnv* ev,        // context
84       mdb_column inColumn,  // column to add
85       const mdbYarn* inYarn) override;  // cell value to install
86 
87   NS_IMETHOD CutColumn(  // make sure a column is absent from the row
88       nsIMdbEnv* ev,     // context
89       mdb_column inColumn) override;  // column to ensure absent from row
90 
91   NS_IMETHOD CutAllColumns(     // remove all columns from the row
92       nsIMdbEnv* ev) override;  // context
93   // } ----- end column methods -----
94 
95   // { ----- begin cell methods -----
96   NS_IMETHOD NewCell(       // get cell for specified column, or add new one
97       nsIMdbEnv* ev,        // context
98       mdb_column inColumn,  // column to add
99       nsIMdbCell** acqCell) override;  // cell column and value
100 
101   NS_IMETHOD AddCell(  // copy a cell from another row to this row
102       nsIMdbEnv* ev,   // context
103       const nsIMdbCell* inCell) override;  // cell column and value
104 
105   NS_IMETHOD GetCell(                  // find a cell in this row
106       nsIMdbEnv* ev,                   // context
107       mdb_column inColumn,             // column to find
108       nsIMdbCell** acqCell) override;  // cell for specified column, or null
109 
110   NS_IMETHOD EmptyAllCells(     // make all cells in row empty of content
111       nsIMdbEnv* ev) override;  // context
112   // } ----- end cell methods -----
113 
114   // { ----- begin row methods -----
115   NS_IMETHOD AddRow(  // add all cells in another row to this one
116       nsIMdbEnv* ev,  // context
117       nsIMdbRow* ioSourceRow) override;  // row to union with
118 
119   NS_IMETHOD SetRow(                     // make exact duplicate of another row
120       nsIMdbEnv* ev,                     // context
121       nsIMdbRow* ioSourceRow) override;  // row to duplicate
122   // } ----- end row methods -----
123 
124   // { ----- begin blob methods -----
125   NS_IMETHOD SetCellYarn(
126       nsIMdbEnv* ev,                    // synonym for AddColumn()
127       mdb_column inColumn,              // column to write
128       const mdbYarn* inYarn) override;  // reads from yarn slots
129   // make this text object contain content from the yarn's buffer
130 
131   NS_IMETHOD GetCellYarn(nsIMdbEnv* ev,
132                          mdb_column inColumn,         // column to read
133                          mdbYarn* outYarn) override;  // writes some yarn slots
134   // copy content into the yarn buffer, and update mYarn_Fill and mYarn_Form
135 
136   NS_IMETHOD AliasCellYarn(nsIMdbEnv* ev,
137                            mdb_column inColumn,         // column to alias
138                            mdbYarn* outYarn) override;  // writes ALL yarn slots
139 
140   NS_IMETHOD NextCellYarn(nsIMdbEnv* ev,  // iterative version of GetCellYarn()
141                           mdb_column* ioColumn,        // next column to read
142                           mdbYarn* outYarn) override;  // writes some yarn slots
143   // copy content into the yarn buffer, and update mYarn_Fill and mYarn_Form
144   //
145   // The ioColumn argument is an inout parameter which initially contains the
146   // last column accessed and returns the next column corresponding to the
147   // content read into the yarn.  Callers should start with a zero column
148   // value to say 'no previous column', which causes the first column to be
149   // read.  Then the value returned in ioColumn is perfect for the next call
150   // to NextCellYarn(), since it will then be the previous column accessed.
151   // Callers need only examine the column token returned to see which cell
152   // in the row is being read into the yarn.  When no more columns remain,
153   // and the iteration has ended, ioColumn will return a zero token again.
154   // So iterating over cells starts and ends with a zero column token.
155 
156   NS_IMETHOD SeekCellYarn(         // resembles nsIMdbRowCellCursor::SeekCell()
157       nsIMdbEnv* ev,               // context
158       mdb_pos inPos,               // position of cell in row sequence
159       mdb_column* outColumn,       // column for this particular cell
160       mdbYarn* outYarn) override;  // writes some yarn slots
161   // copy content into the yarn buffer, and update mYarn_Fill and mYarn_Form
162   // Callers can pass nil for outYarn to indicate no interest in content, so
163   // only the outColumn value is returned.  NOTE to subclasses: you must be
164   // able to ignore outYarn when the pointer is nil; please do not crash.
165 
166   // } ----- end blob methods -----
167 
168   // } ===== end nsIMdbRow methods =====
169 
170  private:  // copying is not allowed
171   morkRowObject(const morkRowObject& other);
172   morkRowObject& operator=(const morkRowObject& other);
173   virtual ~morkRowObject();  // assert that CloseRowObject() executed earlier
174 
175  public:  // dynamic type identification
IsRowObject()176   mork_bool IsRowObject() const {
177     return IsNode() && mNode_Derived == morkDerived_kRowObject;
178   }
179   // } ===== end morkNode methods =====
180 
181  public:  // typing
182   static void NonRowObjectTypeError(morkEnv* ev);
183   static void NilRowError(morkEnv* ev);
184   static void NilStoreError(morkEnv* ev);
185   static void RowObjectRowNotSelfError(morkEnv* ev);
186 
187  public:                                     // other row node methods
188   nsIMdbRow* AcquireRowHandle(morkEnv* ev);  // mObject_Handle
189 
190  public:  // typesafe refcounting inlines calling inherited morkNode methods
SlotWeakRowObject(morkRowObject * me,morkEnv * ev,morkRowObject ** ioSlot)191   static void SlotWeakRowObject(morkRowObject* me, morkEnv* ev,
192                                 morkRowObject** ioSlot) {
193     morkNode::SlotWeakNode((morkNode*)me, ev, (morkNode**)ioSlot);
194   }
195 
SlotStrongRowObject(morkRowObject * me,morkEnv * ev,morkRowObject ** ioSlot)196   static void SlotStrongRowObject(morkRowObject* me, morkEnv* ev,
197                                   morkRowObject** ioSlot) {
198     morkNode::SlotStrongNode((morkNode*)me, ev, (morkNode**)ioSlot);
199   }
200 };
201 
202 // 456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789
203 
204 #endif /* _MORKROWOBJECT_ */
205