1
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
/* ***** BEGIN LICENSE BLOCK *****
3
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
5
* The contents of this file are subject to the Netscape Public License
6
* Version 1.1 (the "License"); you may not use this file except in
7
* compliance with the License. You may obtain a copy of the License at
8
* http://www.mozilla.org/NPL/
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
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.
25
* Alternatively, the contents of this file may be used under the terms of
26
* either the GNU General Public License Version 2 or later (the "GPL"), or
27
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28
* in which case the provisions of the GPL or the LGPL are applicable instead
29
* of those above. If you wish to allow use of your version of this file only
30
* under the terms of either the GPL or the LGPL, and not to allow others to
31
* use your version of this file under the terms of the NPL, indicate your
32
* decision by deleting the provisions above and replace them with the notice
33
* and other provisions required by the GPL or the LGPL. If you do not delete
34
* the provisions above, a recipient may use your version of this file under
35
* the terms of any one of the NPL, the GPL or the LGPL.
37
* ***** END LICENSE BLOCK ***** */
39
#ifndef _MORKATOMSPACE_
40
#define _MORKATOMSPACE_ 1
51
#include "morkSpace.h"
55
#include "morkAtomMap.h"
59
#include "morkNodeMap.h"
62
//3456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789
64
/*| kMinUnderId: the smallest ID we auto-assign to the 'under' namespace
65
**| reserved for tokens expected to occur very frequently, such as the names
66
**| of columns. We reserve single byte ids in the ASCII range to correspond
67
**| one-to-one to those tokens consisting single ASCII characters (so that
68
**| this assignment is always known and constant). So we start at 0x80, and
69
**| then reserve the upper half of two hex digit ids and all the three hex
70
**| digit IDs for the 'under' namespace for common tokens.
72
#define morkAtomSpace_kMinUnderId 0x80 /* low 7 bits mean byte tokens */
74
#define morkAtomSpace_kMaxSevenBitAid 0x7F /* low seven bit integer ID */
76
/*| kMinOverId: the smallest ID we auto-assign to the 'over' namespace that
77
**| might include very large numbers of tokens that are used infrequently,
78
**| so that we care less whether the shortest hex representation is used.
79
**| So we start all IDs for 'over' category tokens at a value range that
80
**| needs at least four hex digits, so we can reserve three hex digits and
81
**| shorter for more commonly occuring tokens in the 'under' category.
83
#define morkAtomSpace_kMinOverId 0x1000 /* using at least four hex bytes */
85
#define morkDerived_kAtomSpace /*i*/ 0x6153 /* ascii 'aS' */
87
#define morkAtomSpace_kColumnScope ((mork_scope) 'c') /* column scope is forever */
91
class morkAtomSpace : public morkSpace { //
93
// public: // slots inherited from morkSpace (meant to inform only)
94
// nsIMdbHeap* mNode_Heap;
96
// mork_base mNode_Base; // must equal morkBase_kNode
97
// mork_derived mNode_Derived; // depends on specific node subclass
99
// mork_access mNode_Access; // kOpen, kClosing, kShut, or kDead
100
// mork_usage mNode_Usage; // kHeap, kStack, kMember, kGlobal, kNone
101
// mork_able mNode_Mutable; // can this node be modified?
102
// mork_load mNode_Load; // is this node clean or dirty?
104
// mork_uses mNode_Uses; // refcount for strong refs
105
// mork_refs mNode_Refs; // refcount for strong refs + weak refs
107
// morkStore* mSpace_Store; // weak ref to containing store
109
// mork_bool mSpace_DoAutoIDs; // whether db should assign member IDs
110
// mork_bool mSpace_HaveDoneAutoIDs; // whether actually auto assigned IDs
111
// mork_u1 mSpace_Pad[ 2 ]; // pad to u4 alignment
113
public: // state is public because the entire Mork system is private
115
mork_aid mAtomSpace_HighUnderId; // high ID in 'under' range
116
mork_aid mAtomSpace_HighOverId; // high ID in 'over' range
118
morkAtomAidMap mAtomSpace_AtomAids; // all atoms in space by ID
119
morkAtomBodyMap mAtomSpace_AtomBodies; // all atoms in space by body
121
public: // more specific dirty methods for atom space:
122
void SetAtomSpaceDirty() { this->SetNodeDirty(); }
123
void SetAtomSpaceClean() { this->SetNodeClean(); }
125
mork_bool IsAtomSpaceClean() const { return this->IsNodeClean(); }
126
mork_bool IsAtomSpaceDirty() const { return this->IsNodeDirty(); }
128
// { ===== begin morkNode interface =====
129
public: // morkNode virtual methods
130
virtual void CloseMorkNode(morkEnv* ev); // CloseAtomSpace() only if open
131
virtual ~morkAtomSpace(); // assert that CloseAtomSpace() executed earlier
133
public: // morkMap construction & destruction
134
morkAtomSpace(morkEnv* ev, const morkUsage& inUsage, mork_scope inScope,
135
morkStore* ioStore, nsIMdbHeap* ioNodeHeap, nsIMdbHeap* ioSlotHeap);
136
void CloseAtomSpace(morkEnv* ev); // called by CloseMorkNode();
138
public: // dynamic type identification
139
mork_bool IsAtomSpace() const
140
{ return IsNode() && mNode_Derived == morkDerived_kAtomSpace; }
141
// } ===== end morkNode methods =====
144
void NonAtomSpaceTypeError(morkEnv* ev);
148
mork_bool MarkAllAtomSpaceContentDirty(morkEnv* ev);
149
// MarkAllAtomSpaceContentDirty() visits every space object and marks
150
// them dirty, including every table, row, cell, and atom. The return
151
// equals ev->Good(), to show whether any error happened. This method is
152
// intended for use in the beginning of a "compress commit" which writes
153
// all store content, whether dirty or not. We dirty everything first so
154
// that later iterations over content can mark things clean as they are
155
// written, and organize the process of serialization so that objects are
156
// written only at need (because of being dirty).
158
public: // other space methods
160
// void ReserveColumnAidCount(mork_count inCount)
162
// mAtomSpace_HighUnderId = morkAtomSpace_kMinUnderId + inCount;
163
// mAtomSpace_HighOverId = morkAtomSpace_kMinOverId + inCount;
166
mork_num CutAllAtoms(morkEnv* ev, morkPool* ioPool);
167
// CutAllAtoms() puts all the atoms back in the pool.
169
morkBookAtom* MakeBookAtomCopyWithAid(morkEnv* ev,
170
const morkFarBookAtom& inAtom, mork_aid inAid);
171
// Make copy of inAtom and put it in both maps, using specified ID.
173
morkBookAtom* MakeBookAtomCopy(morkEnv* ev, const morkFarBookAtom& inAtom);
174
// Make copy of inAtom and put it in both maps, using a new ID as needed.
176
mork_aid MakeNewAtomId(morkEnv* ev, morkBookAtom* ioAtom);
177
// generate an unused atom id.
179
public: // typesafe refcounting inlines calling inherited morkNode methods
180
static void SlotWeakAtomSpace(morkAtomSpace* me,
181
morkEnv* ev, morkAtomSpace** ioSlot)
182
{ morkNode::SlotWeakNode((morkNode*) me, ev, (morkNode**) ioSlot); }
184
static void SlotStrongAtomSpace(morkAtomSpace* me,
185
morkEnv* ev, morkAtomSpace** ioSlot)
186
{ morkNode::SlotStrongNode((morkNode*) me, ev, (morkNode**) ioSlot); }
189
//3456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789
191
#define morkDerived_kAtomSpaceMap /*i*/ 0x615A /* ascii 'aZ' */
193
/*| morkAtomSpaceMap: maps mork_scope -> morkAtomSpace
195
class morkAtomSpaceMap : public morkNodeMap { // for mapping tokens to tables
199
virtual ~morkAtomSpaceMap();
200
morkAtomSpaceMap(morkEnv* ev, const morkUsage& inUsage,
201
nsIMdbHeap* ioHeap, nsIMdbHeap* ioSlotHeap);
203
public: // other map methods
205
mork_bool AddAtomSpace(morkEnv* ev, morkAtomSpace* ioAtomSpace)
206
{ return this->AddNode(ev, ioAtomSpace->SpaceScope(), ioAtomSpace); }
207
// the AddAtomSpace() boolean return equals ev->Good().
209
mork_bool CutAtomSpace(morkEnv* ev, mork_scope inScope)
210
{ return this->CutNode(ev, inScope); }
211
// The CutAtomSpace() boolean return indicates whether removal happened.
213
morkAtomSpace* GetAtomSpace(morkEnv* ev, mork_scope inScope)
214
{ return (morkAtomSpace*) this->GetNode(ev, inScope); }
215
// Note the returned space does NOT have an increase in refcount for this.
217
mork_num CutAllAtomSpaces(morkEnv* ev)
218
{ return this->CutAllNodes(ev); }
219
// CutAllAtomSpaces() releases all the referenced table values.
222
class morkAtomSpaceMapIter: public morkMapIter{ // typesafe wrapper class
225
morkAtomSpaceMapIter(morkEnv* ev, morkAtomSpaceMap* ioMap)
226
: morkMapIter(ev, ioMap) { }
228
morkAtomSpaceMapIter( ) : morkMapIter() { }
229
void InitAtomSpaceMapIter(morkEnv* ev, morkAtomSpaceMap* ioMap)
230
{ this->InitMapIter(ev, ioMap); }
233
FirstAtomSpace(morkEnv* ev, mork_scope* outScope, morkAtomSpace** outAtomSpace)
234
{ return this->First(ev, outScope, outAtomSpace); }
237
NextAtomSpace(morkEnv* ev, mork_scope* outScope, morkAtomSpace** outAtomSpace)
238
{ return this->Next(ev, outScope, outAtomSpace); }
241
HereAtomSpace(morkEnv* ev, mork_scope* outScope, morkAtomSpace** outAtomSpace)
242
{ return this->Here(ev, outScope, outAtomSpace); }
245
CutHereAtomSpace(morkEnv* ev, mork_scope* outScope, morkAtomSpace** outAtomSpace)
246
{ return this->CutHere(ev, outScope, outAtomSpace); }
249
//3456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789
251
#endif /* _MORKATOMSPACE_ */