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

« back to all changes in this revision

Viewing changes to mozilla/db/mork/src/morkAtomMap.cpp

  • 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 _MDB_
 
40
#include "mdb.h"
 
41
#endif
 
42
 
 
43
#ifndef _MORK_
 
44
#include "mork.h"
 
45
#endif
 
46
 
 
47
#ifndef _MORKNODE_
 
48
#include "morkNode.h"
 
49
#endif
 
50
 
 
51
#ifndef _MORKENV_
 
52
#include "morkEnv.h"
 
53
#endif
 
54
 
 
55
#ifndef _MORKMAP_
 
56
#include "morkMap.h"
 
57
#endif
 
58
 
 
59
#ifndef _MORKATOMMAP_
 
60
#include "morkAtomMap.h"
 
61
#endif
 
62
 
 
63
#ifndef _MORKATOM_
 
64
#include "morkAtom.h"
 
65
#endif
 
66
 
 
67
#ifndef _MORKINTMAP_
 
68
#include "morkIntMap.h"
 
69
#endif
 
70
 
 
71
#ifndef _MORKROW_
 
72
#include "morkRow.h"
 
73
#endif
 
74
 
 
75
//3456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789
 
76
 
 
77
// ````` ````` ````` ````` ````` 
 
78
// { ===== begin morkNode interface =====
 
79
 
 
80
/*public virtual*/ void
 
81
morkAtomAidMap::CloseMorkNode(morkEnv* ev) // CloseAtomAidMap() only if open
 
82
{
 
83
  if ( this->IsOpenNode() )
 
84
  {
 
85
    this->MarkClosing();
 
86
    this->CloseAtomAidMap(ev);
 
87
    this->MarkShut();
 
88
  }
 
89
}
 
90
 
 
91
/*public virtual*/
 
92
morkAtomAidMap::~morkAtomAidMap() // assert CloseAtomAidMap() executed earlier
 
93
{
 
94
  MORK_ASSERT(this->IsShutNode());
 
95
}
 
96
 
 
97
 
 
98
/*public non-poly*/
 
99
morkAtomAidMap::morkAtomAidMap(morkEnv* ev, const morkUsage& inUsage,
 
100
    nsIMdbHeap* ioHeap, nsIMdbHeap* ioSlotHeap)
 
101
#ifdef MORK_ENABLE_PROBE_MAPS
 
102
: morkProbeMap(ev, inUsage,  ioHeap,
 
103
  /*inKeySize*/ sizeof(morkBookAtom*), /*inValSize*/ 0,
 
104
  ioSlotHeap, morkAtomAidMap_kStartSlotCount, 
 
105
  /*inZeroIsClearKey*/ morkBool_kTrue)
 
106
#else /*MORK_ENABLE_PROBE_MAPS*/
 
107
: morkMap(ev, inUsage,  ioHeap,
 
108
  /*inKeySize*/ sizeof(morkBookAtom*), /*inValSize*/ 0,
 
109
  morkAtomAidMap_kStartSlotCount, ioSlotHeap,
 
110
  /*inHoldChanges*/ morkBool_kFalse)
 
111
#endif /*MORK_ENABLE_PROBE_MAPS*/
 
112
{
 
113
  if ( ev->Good() )
 
114
    mNode_Derived = morkDerived_kAtomAidMap;
 
115
}
 
116
 
 
117
/*public non-poly*/ void
 
118
morkAtomAidMap::CloseAtomAidMap(morkEnv* ev) // called by CloseMorkNode();
 
119
{
 
120
  if ( this )
 
121
  {
 
122
    if ( this->IsNode() )
 
123
    {
 
124
#ifdef MORK_ENABLE_PROBE_MAPS
 
125
      this->CloseProbeMap(ev);
 
126
#else /*MORK_ENABLE_PROBE_MAPS*/
 
127
      this->CloseMap(ev);
 
128
#endif /*MORK_ENABLE_PROBE_MAPS*/
 
129
      this->MarkShut();
 
130
    }
 
131
    else
 
132
      this->NonNodeError(ev);
 
133
  }
 
134
  else
 
135
    ev->NilPointerError();
 
136
}
 
137
 
 
138
// } ===== end morkNode methods =====
 
139
// ````` ````` ````` ````` ````` 
 
140
 
 
141
#ifdef MORK_ENABLE_PROBE_MAPS
 
142
 
 
143
  /*virtual*/ mork_test // hit(a,b) implies hash(a) == hash(b)
 
144
  morkAtomAidMap::MapTest(morkEnv* ev, const void* inMapKey,
 
145
    const void* inAppKey) const
 
146
  {
 
147
    MORK_USED_1(ev);
 
148
    const morkBookAtom* key = *(const morkBookAtom**) inMapKey;
 
149
    if ( key )
 
150
    {
 
151
      mork_bool hit = key->EqualAid(*(const morkBookAtom**) inAppKey);
 
152
      return ( hit ) ? morkTest_kHit : morkTest_kMiss;
 
153
    }
 
154
    else
 
155
      return morkTest_kVoid;
 
156
  }
 
157
 
 
158
  /*virtual*/ mork_u4 // hit(a,b) implies hash(a) == hash(b)
 
159
  morkAtomAidMap::MapHash(morkEnv* ev, const void* inAppKey) const
 
160
  {
 
161
    const morkBookAtom* key = *(const morkBookAtom**) inAppKey;
 
162
    if ( key )
 
163
      return key->HashAid();
 
164
    else
 
165
    {
 
166
      ev->NilPointerWarning();
 
167
      return 0;
 
168
    }
 
169
  }
 
170
 
 
171
  /*virtual*/ mork_u4 
 
172
  morkAtomAidMap::ProbeMapHashMapKey(morkEnv* ev,
 
173
    const void* inMapKey) const
 
174
  {
 
175
    const morkBookAtom* key = *(const morkBookAtom**) inMapKey;
 
176
    if ( key )
 
177
      return key->HashAid();
 
178
    else
 
179
    {
 
180
      ev->NilPointerWarning();
 
181
      return 0;
 
182
    }
 
183
  }
 
184
#else /*MORK_ENABLE_PROBE_MAPS*/
 
185
  // { ===== begin morkMap poly interface =====
 
186
  /*virtual*/ mork_bool // 
 
187
  morkAtomAidMap::Equal(morkEnv* ev, const void* inKeyA,
 
188
    const void* inKeyB) const
 
189
  {
 
190
    MORK_USED_1(ev);
 
191
    return (*(const morkBookAtom**) inKeyA)->EqualAid(
 
192
      *(const morkBookAtom**) inKeyB);
 
193
  }
 
194
 
 
195
  /*virtual*/ mork_u4 // 
 
196
  morkAtomAidMap::Hash(morkEnv* ev, const void* inKey) const
 
197
  {
 
198
    MORK_USED_1(ev);
 
199
    return (*(const morkBookAtom**) inKey)->HashAid();
 
200
  }
 
201
  // } ===== end morkMap poly interface =====
 
202
#endif /*MORK_ENABLE_PROBE_MAPS*/
 
203
 
 
204
 
 
205
mork_bool
 
206
morkAtomAidMap::AddAtom(morkEnv* ev, morkBookAtom* ioAtom)
 
207
{
 
208
  if ( ev->Good() )
 
209
  {
 
210
#ifdef MORK_ENABLE_PROBE_MAPS
 
211
    this->MapAtPut(ev, &ioAtom, /*val*/ (void*) 0, 
 
212
      /*key*/ (void*) 0, /*val*/ (void*) 0);
 
213
#else /*MORK_ENABLE_PROBE_MAPS*/
 
214
    this->Put(ev, &ioAtom, /*val*/ (void*) 0, 
 
215
      /*key*/ (void*) 0, /*val*/ (void*) 0, (mork_change**) 0);
 
216
#endif /*MORK_ENABLE_PROBE_MAPS*/
 
217
  }
 
218
  return ev->Good();
 
219
}
 
220
 
 
221
morkBookAtom*
 
222
morkAtomAidMap::CutAtom(morkEnv* ev, const morkBookAtom* inAtom)
 
223
{
 
224
  morkBookAtom* oldKey = 0;
 
225
  
 
226
#ifdef MORK_ENABLE_PROBE_MAPS
 
227
  MORK_USED_1(inAtom);
 
228
  morkProbeMap::ProbeMapCutError(ev);
 
229
#else /*MORK_ENABLE_PROBE_MAPS*/
 
230
  this->Cut(ev, &inAtom, &oldKey, /*val*/ (void*) 0,
 
231
    (mork_change**) 0);
 
232
#endif /*MORK_ENABLE_PROBE_MAPS*/
 
233
    
 
234
  return oldKey;
 
235
}
 
236
 
 
237
morkBookAtom*
 
238
morkAtomAidMap::GetAtom(morkEnv* ev, const morkBookAtom* inAtom)
 
239
{
 
240
  morkBookAtom* key = 0; // old val in the map
 
241
 
 
242
#ifdef MORK_ENABLE_PROBE_MAPS
 
243
  this->MapAt(ev, &inAtom, &key, /*val*/ (void*) 0);
 
244
#else /*MORK_ENABLE_PROBE_MAPS*/
 
245
  this->Get(ev, &inAtom, &key, /*val*/ (void*) 0, (mork_change**) 0);
 
246
#endif /*MORK_ENABLE_PROBE_MAPS*/
 
247
  
 
248
  return key;
 
249
}
 
250
 
 
251
morkBookAtom*
 
252
morkAtomAidMap::GetAid(morkEnv* ev, mork_aid inAid)
 
253
{
 
254
  morkWeeBookAtom weeAtom(inAid);
 
255
  morkBookAtom* key = &weeAtom; // we need a pointer
 
256
  morkBookAtom* oldKey = 0; // old key in the map
 
257
 
 
258
#ifdef MORK_ENABLE_PROBE_MAPS
 
259
  this->MapAt(ev, &key, &oldKey, /*val*/ (void*) 0);
 
260
#else /*MORK_ENABLE_PROBE_MAPS*/
 
261
  this->Get(ev, &key, &oldKey, /*val*/ (void*) 0, (mork_change**) 0);
 
262
#endif /*MORK_ENABLE_PROBE_MAPS*/
 
263
  
 
264
  return oldKey;
 
265
}
 
266
 
 
267
//3456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789
 
268
 
 
269
 
 
270
//3456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789
 
271
 
 
272
// ````` ````` ````` ````` ````` 
 
273
// { ===== begin morkNode interface =====
 
274
 
 
275
/*public virtual*/ void
 
276
morkAtomBodyMap::CloseMorkNode(morkEnv* ev) // CloseAtomBodyMap() only if open
 
277
{
 
278
  if ( this->IsOpenNode() )
 
279
  {
 
280
    this->MarkClosing();
 
281
    this->CloseAtomBodyMap(ev);
 
282
    this->MarkShut();
 
283
  }
 
284
}
 
285
 
 
286
/*public virtual*/
 
287
morkAtomBodyMap::~morkAtomBodyMap() // assert CloseAtomBodyMap() executed earlier
 
288
{
 
289
  MORK_ASSERT(this->IsShutNode());
 
290
}
 
291
 
 
292
 
 
293
/*public non-poly*/
 
294
morkAtomBodyMap::morkAtomBodyMap(morkEnv* ev, const morkUsage& inUsage,
 
295
    nsIMdbHeap* ioHeap, nsIMdbHeap* ioSlotHeap)
 
296
#ifdef MORK_ENABLE_PROBE_MAPS
 
297
: morkProbeMap(ev, inUsage,  ioHeap,
 
298
  /*inKeySize*/ sizeof(morkBookAtom*), /*inValSize*/ 0,
 
299
  ioSlotHeap, morkAtomBodyMap_kStartSlotCount, 
 
300
  /*inZeroIsClearKey*/ morkBool_kTrue)
 
301
#else /*MORK_ENABLE_PROBE_MAPS*/
 
302
: morkMap(ev, inUsage,  ioHeap,
 
303
  /*inKeySize*/ sizeof(morkBookAtom*), /*inValSize*/ 0,
 
304
  morkAtomBodyMap_kStartSlotCount, ioSlotHeap,
 
305
  /*inHoldChanges*/ morkBool_kFalse)
 
306
#endif /*MORK_ENABLE_PROBE_MAPS*/
 
307
{
 
308
  if ( ev->Good() )
 
309
    mNode_Derived = morkDerived_kAtomBodyMap;
 
310
}
 
311
 
 
312
/*public non-poly*/ void
 
313
morkAtomBodyMap::CloseAtomBodyMap(morkEnv* ev) // called by CloseMorkNode();
 
314
{
 
315
  if ( this )
 
316
  {
 
317
    if ( this->IsNode() )
 
318
    {
 
319
#ifdef MORK_ENABLE_PROBE_MAPS
 
320
      this->CloseProbeMap(ev);
 
321
#else /*MORK_ENABLE_PROBE_MAPS*/
 
322
      this->CloseMap(ev);
 
323
#endif /*MORK_ENABLE_PROBE_MAPS*/
 
324
      this->MarkShut();
 
325
    }
 
326
    else
 
327
      this->NonNodeError(ev);
 
328
  }
 
329
  else
 
330
    ev->NilPointerError();
 
331
}
 
332
 
 
333
// } ===== end morkNode methods =====
 
334
// ````` ````` ````` ````` ````` 
 
335
#ifdef MORK_ENABLE_PROBE_MAPS
 
336
 
 
337
  /*virtual*/ mork_test // hit(a,b) implies hash(a) == hash(b)
 
338
  morkAtomBodyMap::MapTest(morkEnv* ev, const void* inMapKey,
 
339
    const void* inAppKey) const
 
340
  {
 
341
    const morkBookAtom* key = *(const morkBookAtom**) inMapKey;
 
342
    if ( key )
 
343
    {
 
344
      return ( key->EqualFormAndBody(ev, *(const morkBookAtom**) inAppKey) ) ?
 
345
        morkTest_kHit : morkTest_kMiss;
 
346
    }
 
347
    else
 
348
      return morkTest_kVoid;
 
349
  }
 
350
 
 
351
  /*virtual*/ mork_u4 // hit(a,b) implies hash(a) == hash(b)
 
352
  morkAtomBodyMap::MapHash(morkEnv* ev, const void* inAppKey) const
 
353
  {
 
354
    const morkBookAtom* key = *(const morkBookAtom**) inAppKey;
 
355
    if ( key )
 
356
      return key->HashFormAndBody(ev);
 
357
    else
 
358
      return 0;
 
359
  }
 
360
 
 
361
  /*virtual*/ mork_u4 
 
362
  morkAtomBodyMap::ProbeMapHashMapKey(morkEnv* ev, const void* inMapKey) const
 
363
  {
 
364
    const morkBookAtom* key = *(const morkBookAtom**) inMapKey;
 
365
    if ( key )
 
366
      return key->HashFormAndBody(ev);
 
367
    else
 
368
      return 0;
 
369
  }
 
370
#else /*MORK_ENABLE_PROBE_MAPS*/
 
371
  // { ===== begin morkMap poly interface =====
 
372
  /*virtual*/ mork_bool // 
 
373
  morkAtomBodyMap::Equal(morkEnv* ev, const void* inKeyA,
 
374
    const void* inKeyB) const
 
375
  {
 
376
    return (*(const morkBookAtom**) inKeyA)->EqualFormAndBody(ev,
 
377
      *(const morkBookAtom**) inKeyB);
 
378
  }
 
379
 
 
380
  /*virtual*/ mork_u4 // 
 
381
  morkAtomBodyMap::Hash(morkEnv* ev, const void* inKey) const
 
382
  {
 
383
    return (*(const morkBookAtom**) inKey)->HashFormAndBody(ev);
 
384
  }
 
385
  // } ===== end morkMap poly interface =====
 
386
#endif /*MORK_ENABLE_PROBE_MAPS*/
 
387
 
 
388
 
 
389
mork_bool
 
390
morkAtomBodyMap::AddAtom(morkEnv* ev, morkBookAtom* ioAtom)
 
391
{
 
392
  if ( ev->Good() )
 
393
  {
 
394
#ifdef MORK_ENABLE_PROBE_MAPS
 
395
    this->MapAtPut(ev, &ioAtom, /*val*/ (void*) 0, 
 
396
      /*key*/ (void*) 0, /*val*/ (void*) 0);
 
397
#else /*MORK_ENABLE_PROBE_MAPS*/
 
398
    this->Put(ev, &ioAtom, /*val*/ (void*) 0, 
 
399
      /*key*/ (void*) 0, /*val*/ (void*) 0, (mork_change**) 0);
 
400
#endif /*MORK_ENABLE_PROBE_MAPS*/
 
401
  }
 
402
  return ev->Good();
 
403
}
 
404
 
 
405
morkBookAtom*
 
406
morkAtomBodyMap::CutAtom(morkEnv* ev, const morkBookAtom* inAtom)
 
407
{
 
408
  morkBookAtom* oldKey = 0;
 
409
 
 
410
#ifdef MORK_ENABLE_PROBE_MAPS
 
411
  MORK_USED_1(inAtom);
 
412
  morkProbeMap::ProbeMapCutError(ev);
 
413
#else /*MORK_ENABLE_PROBE_MAPS*/
 
414
  this->Cut(ev, &inAtom, &oldKey, /*val*/ (void*) 0,
 
415
    (mork_change**) 0);
 
416
#endif /*MORK_ENABLE_PROBE_MAPS*/
 
417
    
 
418
  return oldKey;
 
419
}
 
420
 
 
421
morkBookAtom*
 
422
morkAtomBodyMap::GetAtom(morkEnv* ev, const morkBookAtom* inAtom)
 
423
{
 
424
  morkBookAtom* key = 0; // old val in the map
 
425
#ifdef MORK_ENABLE_PROBE_MAPS
 
426
  this->MapAt(ev, &inAtom, &key, /*val*/ (void*) 0);
 
427
#else /*MORK_ENABLE_PROBE_MAPS*/
 
428
  this->Get(ev, &inAtom, &key, /*val*/ (void*) 0, (mork_change**) 0);
 
429
#endif /*MORK_ENABLE_PROBE_MAPS*/
 
430
  
 
431
  return key;
 
432
}
 
433
 
 
434
//3456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789
 
435
 
 
436
morkAtomRowMap::~morkAtomRowMap()
 
437
{
 
438
}
 
439
 
 
440
// I changed to sizeof(mork_ip) from sizeof(mork_aid) to fix a crash on
 
441
// 64 bit machines.  I am not sure it was the right way to fix the problem,
 
442
// but it does stop the crash.  Perhaps we should be using the
 
443
// morkPointerMap instead?
 
444
morkAtomRowMap::morkAtomRowMap(morkEnv* ev, const morkUsage& inUsage,
 
445
  nsIMdbHeap* ioHeap, nsIMdbHeap* ioSlotHeap, mork_column inIndexColumn)
 
446
  : morkIntMap(ev, inUsage, sizeof(mork_ip), ioHeap, ioSlotHeap,
 
447
    /*inHoldChanges*/ morkBool_kFalse)
 
448
, mAtomRowMap_IndexColumn( inIndexColumn )
 
449
{
 
450
  if ( ev->Good() )
 
451
    mNode_Derived = morkDerived_kAtomRowMap;
 
452
}
 
453
 
 
454
void morkAtomRowMap::AddRow(morkEnv* ev, morkRow* ioRow)
 
455
// add ioRow only if it contains a cell in mAtomRowMap_IndexColumn. 
 
456
{
 
457
  mork_aid aid = ioRow->GetCellAtomAid(ev, mAtomRowMap_IndexColumn);
 
458
  if ( aid )
 
459
    this->AddAid(ev, aid, ioRow);
 
460
}
 
461
 
 
462
void morkAtomRowMap::CutRow(morkEnv* ev, morkRow* ioRow)
 
463
// cut ioRow only if it contains a cell in mAtomRowMap_IndexColumn. 
 
464
{
 
465
  mork_aid aid = ioRow->GetCellAtomAid(ev, mAtomRowMap_IndexColumn);
 
466
  if ( aid )
 
467
    this->CutAid(ev, aid);
 
468
}
 
469
 
 
470
//3456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789