~ubuntu-branches/ubuntu/precise/kompozer/precise

« back to all changes in this revision

Viewing changes to mozilla/db/mork/src/morkAtomSpace.h

  • Committer: Bazaar Package Importer
  • Author(s): Anthony Yarusso
  • Date: 2007-08-27 01:11:03 UTC
  • Revision ID: james.westby@ubuntu.com-20070827011103-2jgf4s6532gqu2ka
Tags: upstream-0.7.10
ImportĀ upstreamĀ versionĀ 0.7.10

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 
4
 *
 
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/
 
9
 *
 
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.
 
14
 *
 
15
 * The Original Code is mozilla.org code.
 
16
 *
 
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.
 
21
 *
 
22
 * Contributor(s):
 
23
 *
 
24
 *
 
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.
 
36
 *
 
37
 * ***** END LICENSE BLOCK ***** */
 
38
 
 
39
#ifndef _MORKATOMSPACE_
 
40
#define _MORKATOMSPACE_ 1
 
41
 
 
42
#ifndef _MORK_
 
43
#include "mork.h"
 
44
#endif
 
45
 
 
46
#ifndef _MORKNODE_
 
47
#include "morkNode.h"
 
48
#endif
 
49
 
 
50
#ifndef _MORKSPACE_
 
51
#include "morkSpace.h"
 
52
#endif
 
53
 
 
54
#ifndef _MORKATOMMAP_
 
55
#include "morkAtomMap.h"
 
56
#endif
 
57
 
 
58
#ifndef _MORKNODEMAP_
 
59
#include "morkNodeMap.h"
 
60
#endif
 
61
 
 
62
//3456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789
 
63
 
 
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.
 
71
|*/
 
72
#define morkAtomSpace_kMinUnderId 0x80   /* low 7 bits mean byte tokens */
 
73
 
 
74
#define morkAtomSpace_kMaxSevenBitAid 0x7F  /* low seven bit integer ID */
 
75
 
 
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.
 
82
|*/
 
83
#define morkAtomSpace_kMinOverId 0x1000  /* using at least four hex bytes */
 
84
 
 
85
#define morkDerived_kAtomSpace  /*i*/ 0x6153 /* ascii 'aS' */
 
86
 
 
87
#define morkAtomSpace_kColumnScope ((mork_scope) 'c') /* column scope is forever */
 
88
 
 
89
/*| morkAtomSpace:
 
90
|*/
 
91
class morkAtomSpace : public morkSpace { // 
 
92
 
 
93
// public: // slots inherited from morkSpace (meant to inform only)
 
94
  // nsIMdbHeap*    mNode_Heap;
 
95
 
 
96
  // mork_base      mNode_Base;     // must equal morkBase_kNode
 
97
  // mork_derived   mNode_Derived;  // depends on specific node subclass
 
98
  
 
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?
 
103
  
 
104
  // mork_uses      mNode_Uses;     // refcount for strong refs
 
105
  // mork_refs      mNode_Refs;     // refcount for strong refs + weak refs
 
106
  
 
107
  // morkStore*  mSpace_Store; // weak ref to containing store
 
108
  
 
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
 
112
 
 
113
public: // state is public because the entire Mork system is private
 
114
 
 
115
  mork_aid         mAtomSpace_HighUnderId; // high ID in 'under' range
 
116
  mork_aid         mAtomSpace_HighOverId;  // high ID in 'over' range
 
117
  
 
118
  morkAtomAidMap   mAtomSpace_AtomAids; // all atoms in space by ID
 
119
  morkAtomBodyMap  mAtomSpace_AtomBodies; // all atoms in space by body
 
120
 
 
121
public: // more specific dirty methods for atom space:
 
122
  void SetAtomSpaceDirty() { this->SetNodeDirty(); }
 
123
  void SetAtomSpaceClean() { this->SetNodeClean(); }
 
124
  
 
125
  mork_bool IsAtomSpaceClean() const { return this->IsNodeClean(); }
 
126
  mork_bool IsAtomSpaceDirty() const { return this->IsNodeDirty(); }
 
127
 
 
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
 
132
  
 
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();
 
137
 
 
138
public: // dynamic type identification
 
139
  mork_bool IsAtomSpace() const
 
140
  { return IsNode() && mNode_Derived == morkDerived_kAtomSpace; }
 
141
// } ===== end morkNode methods =====
 
142
 
 
143
public: // typing
 
144
  void NonAtomSpaceTypeError(morkEnv* ev);
 
145
 
 
146
public: // setup
 
147
 
 
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).
 
157
 
 
158
public: // other space methods
 
159
 
 
160
  // void ReserveColumnAidCount(mork_count inCount)
 
161
  // {
 
162
  //   mAtomSpace_HighUnderId = morkAtomSpace_kMinUnderId + inCount;
 
163
  //   mAtomSpace_HighOverId = morkAtomSpace_kMinOverId + inCount;
 
164
  // }
 
165
 
 
166
  mork_num CutAllAtoms(morkEnv* ev, morkPool* ioPool);
 
167
  // CutAllAtoms() puts all the atoms back in the pool.
 
168
  
 
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.
 
172
  
 
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.
 
175
 
 
176
  mork_aid MakeNewAtomId(morkEnv* ev, morkBookAtom* ioAtom);
 
177
  // generate an unused atom id.
 
178
 
 
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); }
 
183
  
 
184
  static void SlotStrongAtomSpace(morkAtomSpace* me,
 
185
    morkEnv* ev, morkAtomSpace** ioSlot)
 
186
  { morkNode::SlotStrongNode((morkNode*) me, ev, (morkNode**) ioSlot); }
 
187
};
 
188
 
 
189
//3456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789
 
190
 
 
191
#define morkDerived_kAtomSpaceMap  /*i*/ 0x615A /* ascii 'aZ' */
 
192
 
 
193
/*| morkAtomSpaceMap: maps mork_scope -> morkAtomSpace
 
194
|*/
 
195
class morkAtomSpaceMap : public morkNodeMap { // for mapping tokens to tables
 
196
 
 
197
public:
 
198
 
 
199
  virtual ~morkAtomSpaceMap();
 
200
  morkAtomSpaceMap(morkEnv* ev, const morkUsage& inUsage,
 
201
    nsIMdbHeap* ioHeap, nsIMdbHeap* ioSlotHeap);
 
202
 
 
203
public: // other map methods
 
204
 
 
205
  mork_bool  AddAtomSpace(morkEnv* ev, morkAtomSpace* ioAtomSpace)
 
206
  { return this->AddNode(ev, ioAtomSpace->SpaceScope(), ioAtomSpace); }
 
207
  // the AddAtomSpace() boolean return equals ev->Good().
 
208
 
 
209
  mork_bool  CutAtomSpace(morkEnv* ev, mork_scope inScope)
 
210
  { return this->CutNode(ev, inScope); }
 
211
  // The CutAtomSpace() boolean return indicates whether removal happened. 
 
212
  
 
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.
 
216
 
 
217
  mork_num CutAllAtomSpaces(morkEnv* ev)
 
218
  { return this->CutAllNodes(ev); }
 
219
  // CutAllAtomSpaces() releases all the referenced table values.
 
220
};
 
221
 
 
222
class morkAtomSpaceMapIter: public morkMapIter{ // typesafe wrapper class
 
223
 
 
224
public:
 
225
  morkAtomSpaceMapIter(morkEnv* ev, morkAtomSpaceMap* ioMap)
 
226
  : morkMapIter(ev, ioMap) { }
 
227
 
 
228
  morkAtomSpaceMapIter( ) : morkMapIter()  { }
 
229
  void InitAtomSpaceMapIter(morkEnv* ev, morkAtomSpaceMap* ioMap)
 
230
  { this->InitMapIter(ev, ioMap); }
 
231
   
 
232
  mork_change*
 
233
  FirstAtomSpace(morkEnv* ev, mork_scope* outScope, morkAtomSpace** outAtomSpace)
 
234
  { return this->First(ev, outScope, outAtomSpace); }
 
235
  
 
236
  mork_change*
 
237
  NextAtomSpace(morkEnv* ev, mork_scope* outScope, morkAtomSpace** outAtomSpace)
 
238
  { return this->Next(ev, outScope, outAtomSpace); }
 
239
  
 
240
  mork_change*
 
241
  HereAtomSpace(morkEnv* ev, mork_scope* outScope, morkAtomSpace** outAtomSpace)
 
242
  { return this->Here(ev, outScope, outAtomSpace); }
 
243
  
 
244
  mork_change*
 
245
  CutHereAtomSpace(morkEnv* ev, mork_scope* outScope, morkAtomSpace** outAtomSpace)
 
246
  { return this->CutHere(ev, outScope, outAtomSpace); }
 
247
};
 
248
 
 
249
//3456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789
 
250
 
 
251
#endif /* _MORKATOMSPACE_ */
 
252