Bug 470455 - test_database_sync_embed_visits.js leaks, r=sdwilsh
[wine-gecko.git] / db / mork / src / morkAtomSpace.h
blobfc0757d9e5492ca0856f4904508229b4f8281443
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
13 * License.
15 * The Original Code is mozilla.org code.
17 * The Initial Developer of the Original Code is
18 * Netscape Communications Corporation.
19 * Portions created by the Initial Developer are Copyright (C) 1999
20 * the Initial Developer. All Rights Reserved.
22 * Contributor(s):
24 * Alternatively, the contents of this file may be used under the terms of
25 * either of the GNU General Public License Version 2 or later (the "GPL"),
26 * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 * in which case the provisions of the GPL or the LGPL are applicable instead
28 * of those above. If you wish to allow use of your version of this file only
29 * under the terms of either the GPL or the LGPL, and not to allow others to
30 * use your version of this file under the terms of the MPL, indicate your
31 * decision by deleting the provisions above and replace them with the notice
32 * and other provisions required by the GPL or the LGPL. If you do not delete
33 * the provisions above, a recipient may use your version of this file under
34 * the terms of any one of the MPL, the GPL or the LGPL.
36 * ***** END LICENSE BLOCK ***** */
38 #ifndef _MORKATOMSPACE_
39 #define _MORKATOMSPACE_ 1
41 #ifndef _MORK_
42 #include "mork.h"
43 #endif
45 #ifndef _MORKNODE_
46 #include "morkNode.h"
47 #endif
49 #ifndef _MORKSPACE_
50 #include "morkSpace.h"
51 #endif
53 #ifndef _MORKATOMMAP_
54 #include "morkAtomMap.h"
55 #endif
57 #ifndef _MORKNODEMAP_
58 #include "morkNodeMap.h"
59 #endif
61 //3456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789
63 /*| kMinUnderId: the smallest ID we auto-assign to the 'under' namespace
64 **| reserved for tokens expected to occur very frequently, such as the names
65 **| of columns. We reserve single byte ids in the ASCII range to correspond
66 **| one-to-one to those tokens consisting single ASCII characters (so that
67 **| this assignment is always known and constant). So we start at 0x80, and
68 **| then reserve the upper half of two hex digit ids and all the three hex
69 **| digit IDs for the 'under' namespace for common tokens.
70 |*/
71 #define morkAtomSpace_kMinUnderId 0x80 /* low 7 bits mean byte tokens */
73 #define morkAtomSpace_kMaxSevenBitAid 0x7F /* low seven bit integer ID */
75 /*| kMinOverId: the smallest ID we auto-assign to the 'over' namespace that
76 **| might include very large numbers of tokens that are used infrequently,
77 **| so that we care less whether the shortest hex representation is used.
78 **| So we start all IDs for 'over' category tokens at a value range that
79 **| needs at least four hex digits, so we can reserve three hex digits and
80 **| shorter for more commonly occuring tokens in the 'under' category.
81 |*/
82 #define morkAtomSpace_kMinOverId 0x1000 /* using at least four hex bytes */
84 #define morkDerived_kAtomSpace /*i*/ 0x6153 /* ascii 'aS' */
86 #define morkAtomSpace_kColumnScope ((mork_scope) 'c') /* column scope is forever */
88 /*| morkAtomSpace:
89 |*/
90 class morkAtomSpace : public morkSpace { //
92 // public: // slots inherited from morkSpace (meant to inform only)
93 // nsIMdbHeap* mNode_Heap;
95 // mork_base mNode_Base; // must equal morkBase_kNode
96 // mork_derived mNode_Derived; // depends on specific node subclass
98 // mork_access mNode_Access; // kOpen, kClosing, kShut, or kDead
99 // mork_usage mNode_Usage; // kHeap, kStack, kMember, kGlobal, kNone
100 // mork_able mNode_Mutable; // can this node be modified?
101 // mork_load mNode_Load; // is this node clean or dirty?
103 // mork_uses mNode_Uses; // refcount for strong refs
104 // mork_refs mNode_Refs; // refcount for strong refs + weak refs
106 // morkStore* mSpace_Store; // weak ref to containing store
108 // mork_bool mSpace_DoAutoIDs; // whether db should assign member IDs
109 // mork_bool mSpace_HaveDoneAutoIDs; // whether actually auto assigned IDs
110 // mork_u1 mSpace_Pad[ 2 ]; // pad to u4 alignment
112 public: // state is public because the entire Mork system is private
114 mork_aid mAtomSpace_HighUnderId; // high ID in 'under' range
115 mork_aid mAtomSpace_HighOverId; // high ID in 'over' range
117 morkAtomAidMap mAtomSpace_AtomAids; // all atoms in space by ID
118 morkAtomBodyMap mAtomSpace_AtomBodies; // all atoms in space by body
120 public: // more specific dirty methods for atom space:
121 void SetAtomSpaceDirty() { this->SetNodeDirty(); }
122 void SetAtomSpaceClean() { this->SetNodeClean(); }
124 mork_bool IsAtomSpaceClean() const { return this->IsNodeClean(); }
125 mork_bool IsAtomSpaceDirty() const { return this->IsNodeDirty(); }
127 // { ===== begin morkNode interface =====
128 public: // morkNode virtual methods
129 virtual void CloseMorkNode(morkEnv* ev); // CloseAtomSpace() only if open
130 virtual ~morkAtomSpace(); // assert that CloseAtomSpace() executed earlier
132 public: // morkMap construction & destruction
133 morkAtomSpace(morkEnv* ev, const morkUsage& inUsage, mork_scope inScope,
134 morkStore* ioStore, nsIMdbHeap* ioNodeHeap, nsIMdbHeap* ioSlotHeap);
135 void CloseAtomSpace(morkEnv* ev); // called by CloseMorkNode();
137 public: // dynamic type identification
138 mork_bool IsAtomSpace() const
139 { return IsNode() && mNode_Derived == morkDerived_kAtomSpace; }
140 // } ===== end morkNode methods =====
142 public: // typing
143 void NonAtomSpaceTypeError(morkEnv* ev);
145 public: // setup
147 mork_bool MarkAllAtomSpaceContentDirty(morkEnv* ev);
148 // MarkAllAtomSpaceContentDirty() visits every space object and marks
149 // them dirty, including every table, row, cell, and atom. The return
150 // equals ev->Good(), to show whether any error happened. This method is
151 // intended for use in the beginning of a "compress commit" which writes
152 // all store content, whether dirty or not. We dirty everything first so
153 // that later iterations over content can mark things clean as they are
154 // written, and organize the process of serialization so that objects are
155 // written only at need (because of being dirty).
157 public: // other space methods
159 // void ReserveColumnAidCount(mork_count inCount)
160 // {
161 // mAtomSpace_HighUnderId = morkAtomSpace_kMinUnderId + inCount;
162 // mAtomSpace_HighOverId = morkAtomSpace_kMinOverId + inCount;
163 // }
165 mork_num CutAllAtoms(morkEnv* ev, morkPool* ioPool);
166 // CutAllAtoms() puts all the atoms back in the pool.
168 morkBookAtom* MakeBookAtomCopyWithAid(morkEnv* ev,
169 const morkFarBookAtom& inAtom, mork_aid inAid);
170 // Make copy of inAtom and put it in both maps, using specified ID.
172 morkBookAtom* MakeBookAtomCopy(morkEnv* ev, const morkFarBookAtom& inAtom);
173 // Make copy of inAtom and put it in both maps, using a new ID as needed.
175 mork_aid MakeNewAtomId(morkEnv* ev, morkBookAtom* ioAtom);
176 // generate an unused atom id.
178 public: // typesafe refcounting inlines calling inherited morkNode methods
179 static void SlotWeakAtomSpace(morkAtomSpace* me,
180 morkEnv* ev, morkAtomSpace** ioSlot)
181 { morkNode::SlotWeakNode((morkNode*) me, ev, (morkNode**) ioSlot); }
183 static void SlotStrongAtomSpace(morkAtomSpace* me,
184 morkEnv* ev, morkAtomSpace** ioSlot)
185 { morkNode::SlotStrongNode((morkNode*) me, ev, (morkNode**) ioSlot); }
188 //3456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789
190 #define morkDerived_kAtomSpaceMap /*i*/ 0x615A /* ascii 'aZ' */
192 /*| morkAtomSpaceMap: maps mork_scope -> morkAtomSpace
194 class morkAtomSpaceMap : public morkNodeMap { // for mapping tokens to tables
196 public:
198 virtual ~morkAtomSpaceMap();
199 morkAtomSpaceMap(morkEnv* ev, const morkUsage& inUsage,
200 nsIMdbHeap* ioHeap, nsIMdbHeap* ioSlotHeap);
202 public: // other map methods
204 mork_bool AddAtomSpace(morkEnv* ev, morkAtomSpace* ioAtomSpace)
205 { return this->AddNode(ev, ioAtomSpace->SpaceScope(), ioAtomSpace); }
206 // the AddAtomSpace() boolean return equals ev->Good().
208 mork_bool CutAtomSpace(morkEnv* ev, mork_scope inScope)
209 { return this->CutNode(ev, inScope); }
210 // The CutAtomSpace() boolean return indicates whether removal happened.
212 morkAtomSpace* GetAtomSpace(morkEnv* ev, mork_scope inScope)
213 { return (morkAtomSpace*) this->GetNode(ev, inScope); }
214 // Note the returned space does NOT have an increase in refcount for this.
216 mork_num CutAllAtomSpaces(morkEnv* ev)
217 { return this->CutAllNodes(ev); }
218 // CutAllAtomSpaces() releases all the referenced table values.
221 class morkAtomSpaceMapIter: public morkMapIter{ // typesafe wrapper class
223 public:
224 morkAtomSpaceMapIter(morkEnv* ev, morkAtomSpaceMap* ioMap)
225 : morkMapIter(ev, ioMap) { }
227 morkAtomSpaceMapIter( ) : morkMapIter() { }
228 void InitAtomSpaceMapIter(morkEnv* ev, morkAtomSpaceMap* ioMap)
229 { this->InitMapIter(ev, ioMap); }
231 mork_change*
232 FirstAtomSpace(morkEnv* ev, mork_scope* outScope, morkAtomSpace** outAtomSpace)
233 { return this->First(ev, outScope, outAtomSpace); }
235 mork_change*
236 NextAtomSpace(morkEnv* ev, mork_scope* outScope, morkAtomSpace** outAtomSpace)
237 { return this->Next(ev, outScope, outAtomSpace); }
239 mork_change*
240 HereAtomSpace(morkEnv* ev, mork_scope* outScope, morkAtomSpace** outAtomSpace)
241 { return this->Here(ev, outScope, outAtomSpace); }
243 mork_change*
244 CutHereAtomSpace(morkEnv* ev, mork_scope* outScope, morkAtomSpace** outAtomSpace)
245 { return this->CutHere(ev, outScope, outAtomSpace); }
248 //3456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789
250 #endif /* _MORKATOMSPACE_ */