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

« back to all changes in this revision

Viewing changes to mozilla/db/mork/src/morkHandle.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 _MORKHANDLE_
 
40
#define _MORKHANDLE_ 1
 
41
 
 
42
#ifndef _MORK_
 
43
#include "mork.h"
 
44
#endif
 
45
 
 
46
#ifndef _MORKNODE_
 
47
#include "morkNode.h"
 
48
#endif
 
49
 
 
50
#ifndef _MORKDEQUE_
 
51
#include "morkDeque.h"
 
52
#endif
 
53
 
 
54
#ifndef _MORKPOOL_
 
55
#include "morkPool.h"
 
56
#endif
 
57
 
 
58
//3456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789
 
59
 
 
60
class morkPool;
 
61
class morkObject;
 
62
class morkFactory;
 
63
 
 
64
#define morkDerived_kHandle     /*i*/ 0x486E /* ascii 'Hn' */
 
65
#define morkHandle_kTag   0x68416E44 /* ascii 'hAnD' */
 
66
 
 
67
/*| morkHandle: 
 
68
|*/
 
69
class morkHandle : public morkNode {
 
70
  
 
71
// public: // slots inherited from morkNode (meant to inform only)
 
72
  // nsIMdbHeap*    mNode_Heap;
 
73
 
 
74
  // mork_base      mNode_Base;     // must equal morkBase_kNode
 
75
  // mork_derived   mNode_Derived;  // depends on specific node subclass
 
76
  
 
77
  // mork_access    mNode_Access;   // kOpen, kClosing, kShut, or kDead
 
78
  // mork_usage     mNode_Usage;    // kHeap, kStack, kMember, kGlobal, kNone
 
79
  // mork_able      mNode_Mutable;  // can this node be modified?
 
80
  // mork_load      mNode_Load;     // is this node clean or dirty?
 
81
  
 
82
  // mork_uses      mNode_Uses;     // refcount for strong refs
 
83
  // mork_refs      mNode_Refs;     // refcount for strong refs + weak refs
 
84
 
 
85
public: // state is public because the entire Mork system is private
 
86
 
 
87
  mork_u4         mHandle_Tag;     // must equal morkHandle_kTag
 
88
  morkEnv*        mHandle_Env;     // pool that allocated this handle
 
89
  morkHandleFace* mHandle_Face;    // cookie from pool containing this
 
90
  morkObject*     mHandle_Object;  // object this handle wraps for MDB API
 
91
  mork_magic      mHandle_Magic;   // magic sig different in each subclass
 
92
  
 
93
// { ===== begin morkNode interface =====
 
94
public: // morkNode virtual methods
 
95
  virtual void CloseMorkNode(morkEnv* ev); // CloseHandle() only if open
 
96
  virtual ~morkHandle(); // assert that CloseHandle() executed earlier
 
97
  
 
98
public: // morkHandle construction & destruction
 
99
  morkHandle(morkEnv* ev, // note morkUsage is always morkUsage_kPool
 
100
    morkHandleFace* ioFace,  // must not be nil, cookie for this handle
 
101
    morkObject* ioObject,    // must not be nil, the object for this handle
 
102
    mork_magic inMagic);     // magic sig to denote specific subclass
 
103
  void CloseHandle(morkEnv* ev); // called by CloseMorkNode();
 
104
 
 
105
private: // copying is not allowed
 
106
  morkHandle(const morkHandle& other);
 
107
  morkHandle& operator=(const morkHandle& other);
 
108
  
 
109
protected: // special case empty construction for morkHandleFrame
 
110
  friend class morkHandleFrame;
 
111
  morkHandle() { }
 
112
 
 
113
public: // dynamic type identification
 
114
  mork_bool IsHandle() const
 
115
  { return IsNode() && mNode_Derived == morkDerived_kHandle; }
 
116
// } ===== end morkNode methods =====
 
117
 
 
118
public: // morkHandle memory management operators
 
119
  void* operator new(size_t inSize, morkPool& ioPool, morkZone& ioZone, morkEnv* ev) CPP_THROW_NEW
 
120
  { return ioPool.NewHandle(ev, inSize, &ioZone); }
 
121
  
 
122
  void* operator new(size_t inSize, morkPool& ioPool, morkEnv* ev) CPP_THROW_NEW
 
123
  { return ioPool.NewHandle(ev, inSize, (morkZone*) 0); }
 
124
  
 
125
  void* operator new(size_t inSize, morkHandleFace* ioFace) CPP_THROW_NEW
 
126
  { MORK_USED_1(inSize); return ioFace; }
 
127
  
 
128
 
 
129
public: // other handle methods
 
130
  mork_bool GoodHandleTag() const
 
131
  { return mHandle_Tag == morkHandle_kTag; }
 
132
  
 
133
  void NewBadMagicHandleError(morkEnv* ev, mork_magic inMagic) const;
 
134
  void NewDownHandleError(morkEnv* ev) const;
 
135
  void NilFactoryError(morkEnv* ev) const;
 
136
  void NilHandleObjectError(morkEnv* ev) const;
 
137
  void NonNodeObjectError(morkEnv* ev) const;
 
138
  void NonOpenObjectError(morkEnv* ev) const;
 
139
  
 
140
  morkObject* GetGoodHandleObject(morkEnv* ev,
 
141
    mork_bool inMutable, mork_magic inMagicType, mork_bool inClosedOkay) const;
 
142
 
 
143
public: // interface supporting mdbObject methods
 
144
 
 
145
  morkEnv* CanUseHandle(nsIMdbEnv* mev, mork_bool inMutable,
 
146
    mork_bool inClosedOkay, mdb_err* outErr) const;
 
147
    
 
148
  // { ----- begin mdbObject style methods -----
 
149
  mdb_err Handle_IsFrozenMdbObject(nsIMdbEnv* ev, mdb_bool* outIsReadonly);
 
150
 
 
151
  mdb_err Handle_GetMdbFactory(nsIMdbEnv* ev, nsIMdbFactory** acqFactory); 
 
152
  mdb_err Handle_GetWeakRefCount(nsIMdbEnv* ev,  mdb_count* outCount);  
 
153
  mdb_err Handle_GetStrongRefCount(nsIMdbEnv* ev, mdb_count* outCount);
 
154
 
 
155
  mdb_err Handle_AddWeakRef(nsIMdbEnv* ev);
 
156
  mdb_err Handle_AddStrongRef(nsIMdbEnv* ev);
 
157
 
 
158
  mdb_err Handle_CutWeakRef(nsIMdbEnv* ev);
 
159
  mdb_err Handle_CutStrongRef(nsIMdbEnv* ev);
 
160
  
 
161
  mdb_err Handle_CloseMdbObject(nsIMdbEnv* ev);
 
162
  mdb_err Handle_IsOpenMdbObject(nsIMdbEnv* ev, mdb_bool* outOpen);
 
163
  // } ----- end mdbObject style methods -----
 
164
 
 
165
public: // typesafe refcounting inlines calling inherited morkNode methods
 
166
  static void SlotWeakHandle(morkHandle* me,
 
167
    morkEnv* ev, morkHandle** ioSlot)
 
168
  { morkNode::SlotWeakNode((morkNode*) me, ev, (morkNode**) ioSlot); }
 
169
  
 
170
  static void SlotStrongHandle(morkHandle* me,
 
171
    morkEnv* ev, morkHandle** ioSlot)
 
172
  { morkNode::SlotStrongNode((morkNode*) me, ev, (morkNode**) ioSlot); }
 
173
};
 
174
 
 
175
#define morkHandleFrame_kPadSlotCount 4
 
176
 
 
177
/*| morkHandleFrame: an object format used for allocating and maintaining
 
178
**| instances of morkHandle, with leading slots used to maintain this in a
 
179
**| linked list, and following slots to provide extra footprint that might
 
180
**| be needed by any morkHandle subclasses that include very little extra
 
181
**| space (by virtue of the fact that each morkHandle subclass is expected
 
182
**| to multiply inherit from another base class that has only abstact methods
 
183
**| for space overhead related only to some vtable representation).
 
184
|*/
 
185
class morkHandleFrame {
 
186
public:
 
187
  morkLink    mHandleFrame_Link;    // list storage without trampling Handle
 
188
  morkHandle  mHandleFrame_Handle;
 
189
  mork_ip     mHandleFrame_Padding[ morkHandleFrame_kPadSlotCount ];
 
190
  
 
191
public:
 
192
  morkHandle*  AsHandle() { return &mHandleFrame_Handle; }
 
193
  
 
194
  morkHandleFrame() {}  // actually, morkHandleFrame never gets constructed
 
195
 
 
196
private: // copying is not allowed
 
197
  morkHandleFrame(const morkHandleFrame& other);
 
198
  morkHandleFrame& operator=(const morkHandleFrame& other);
 
199
};
 
200
 
 
201
#define morkHandleFrame_kHandleOffset \
 
202
  mork_OffsetOf(morkHandleFrame,mHandleFrame_Handle)
 
203
  
 
204
#define morkHandle_AsHandleFrame(h) ((h)->mHandle_Block , \
 
205
 ((morkHandleFrame*) (((mork_u1*)(h)) - morkHandleFrame_kHandleOffset)))
 
206
 
 
207
//3456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789
 
208
 
 
209
#endif /* _MORKHANDLE_ */