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
4  *
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/
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  * 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.
35  *
36  * ***** END LICENSE BLOCK ***** */
37 
38 #ifndef _MORK_
39 #define _MORK_ 1
40 
41 #ifndef _MDB_
42 #  include "mdb.h"
43 #endif
44 
45 #include "nscore.h"
46 // 456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789
47 
48 // { %%%%% begin disable unused param warnings %%%%%
49 #define MORK_USED_1(x) (void)(&x)
50 #define MORK_USED_2(x, y) \
51   (void)(&x);             \
52   (void)(&y);
53 #define MORK_USED_3(x, y, z) \
54   (void)(&x);                \
55   (void)(&y);                \
56   (void)(&z);
57 #define MORK_USED_4(w, x, y, z) \
58   (void)(&w);                   \
59   (void)(&x);                   \
60   (void)(&y);                   \
61   (void)(&z);
62 
63 // } %%%%% end disable unused param warnings %%%%%
64 
65 // { %%%%% begin macro for finding class member offset %%%%%
66 
67 /*| OffsetOf: the unsigned integer offset of a class or struct
68 **| field from the beginning of that class or struct.  This is
69 **| the same as the similarly named public domain IronDoc macro,
70 **| and is also the same as another macro appearing in stdlib.h.
71 **| We want these offsets so we can correctly convert pointers
72 **| to member slots back into pointers to enclosing objects, and
73 **| have this exactly match what the compiler thinks is true.
74 **|
75 **|| Basically we are asking the compiler to determine the offset at
76 **| compile time, and we use the definition of address artithmetic
77 **| to do this.  By casting integer zero to a pointer of type obj*,
78 **| we can reference the address of a slot in such an object that
79 **| is hypothetically physically placed at address zero, but without
80 **| actually dereferencing a memory location.  The absolute address
81 **| of slot is the same as offset of that slot, when the object is
82 **| placed at address zero.
83 |*/
84 #define mork_OffsetOf(obj, slot) ((unsigned int)&((obj*)0)->slot)
85 
86 // } %%%%% end macro for finding class member offset %%%%%
87 
88 // { %%%%% begin specific-size integer scalar typedefs %%%%%
89 typedef unsigned char mork_u1;   // make sure this is one byte
90 typedef unsigned short mork_u2;  // make sure this is two bytes
91 typedef short mork_i2;           // make sure this is two bytes
92 typedef uint32_t mork_u4;        // make sure this is four bytes
93 typedef int32_t mork_i4;         // make sure this is four bytes
94 typedef PRWord mork_ip;          // make sure sizeof(mork_ip) == sizeof(void*)
95 
96 typedef mork_u1 mork_ch;     // small byte-sized character (never wide)
97 typedef mork_u1 mork_flags;  // one byte's worth of predicate bit flags
98 
99 typedef mork_u2 mork_base;     // 2-byte magic class signature slot in object
100 typedef mork_u2 mork_derived;  // 2-byte magic class signature slot in object
101 
102 typedef mork_u4 mork_token;      // unsigned token for atomized string
103 typedef mork_token mork_scope;   // token used to id scope for rows
104 typedef mork_token mork_kind;    // token used to id kind for tables
105 typedef mork_token mork_cscode;  // token used to id charset names
106 typedef mork_token mork_aid;     // token used to id atomize cell values
107 
108 typedef mork_token mork_column;  // token used to id columns for rows
109 typedef mork_column mork_delta;  // mork_column plus mork_change
110 
111 typedef mork_token mork_color;  // bead ID
112 #define morkColor_kNone ((mork_color)0)
113 
114 typedef mork_u4 mork_magic;  // unsigned magic signature
115 
116 typedef mork_u4 mork_seed;    // unsigned collection change counter
117 typedef mork_u4 mork_count;   // unsigned collection member count
118 typedef mork_count mork_num;  // synonym for count
119 typedef mork_u4 mork_size;    // unsigned physical media size
120 typedef mork_u4 mork_fill;    // unsigned logical content size
121 typedef mork_u4 mork_more;    // more available bytes for larger buffer
122 
123 typedef mdb_u4 mork_percent;  // 0..100, with values >100 same as 100
124 
125 typedef mork_i4 mork_pos;   // negative means "before first" (at zero pos)
126 typedef mork_i4 mork_line;  // negative means "before first line in file"
127 
128 typedef mork_u1 mork_usage;   // 1-byte magic usage signature slot in object
129 typedef mork_u1 mork_access;  // 1-byte magic access signature slot in object
130 
131 typedef mork_u1 mork_change;    // add, cut, put, set, nil
132 typedef mork_u1 mork_priority;  // 0..9, for a total of ten different values
133 
134 typedef mork_u1 mork_able;  // on, off, asleep (clone IronDoc's fe_able)
135 typedef mork_u1 mork_load;  // dirty or clean (clone IronDoc's fe_load)
136 // } %%%%% end specific-size integer scalar typedefs %%%%%
137 
138 // 'test' is a public domain Mithril for key equality tests in probe maps
139 typedef mork_i2 mork_test; /* neg=>kVoid, zero=>kHit, pos=>kMiss */
140 
141 #define morkTest_kVoid ((mork_test)-1) /* -1: nil key slot, no key order */
142 #define morkTest_kHit ((mork_test)0)   /*  0: keys are equal, a map hit */
143 #define morkTest_kMiss ((mork_test)1)  /*  1: keys not equal, a map miss */
144 
145 // { %%%%% begin constants for Mork scalar types %%%%%
146 #define morkPriority_kHi ((mork_priority)0)  /* best priority */
147 #define morkPriority_kMin ((mork_priority)0) /* best priority is smallest */
148 
149 #define morkPriority_kLo ((mork_priority)9)  /* worst priority */
150 #define morkPriority_kMax ((mork_priority)9) /* worst priority is biggest */
151 
152 #define morkPriority_kCount 10 /* number of distinct priority values */
153 
154 #define morkAble_kEnabled ((mork_able)0x55)  /* same as IronDoc constant */
155 #define morkAble_kDisabled ((mork_able)0xAA) /* same as IronDoc constant */
156 #define morkAble_kAsleep ((mork_able)0x5A)   /* same as IronDoc constant */
157 
158 #define morkChange_kAdd 'a' /* add member */
159 #define morkChange_kCut 'c' /* cut member */
160 #define morkChange_kPut 'p' /* put member */
161 #define morkChange_kSet 's' /* set all members */
162 #define morkChange_kNil 0   /* no change in this member */
163 #define morkChange_kDup 'd' /* duplicate changes have no effect */
164 // kDup is intended to replace another change constant in an object as a
165 // conclusion about change feasibility while staging intended alterations.
166 
167 #define morkLoad_kDirty ((mork_load)0xDD) /* same as IronDoc constant */
168 #define morkLoad_kClean ((mork_load)0x22) /* same as IronDoc constant */
169 
170 #define morkAccess_kOpen 'o'
171 #define morkAccess_kClosing 'c'
172 #define morkAccess_kShut 's'
173 #define morkAccess_kDead 'd'
174 // } %%%%% end constants for Mork scalar types %%%%%
175 
176 // { %%%%% begin non-specific-size integer scalar typedefs %%%%%
177 typedef int mork_char;  // nominal type for ints used to hold input byte
178 #define morkChar_IsWhite(c) \
179   ((c) == 0xA || (c) == 0x9 || (c) == 0xD || (c) == ' ')
180 // } %%%%% end non-specific-size integer scalar typedefs %%%%%
181 
182 // { %%%%% begin mdb-driven scalar typedefs %%%%%
183 // easier to define bool exactly the same as mdb:
184 typedef mdb_bool mork_bool;  // unsigned byte with zero=false, nonzero=true
185 
186 /* canonical boolean constants provided only for code clarity: */
187 #define morkBool_kTrue ((mork_bool)1)  /* actually any nonzero means true */
188 #define morkBool_kFalse ((mork_bool)0) /* only zero means false */
189 
190 // mdb clients can assign these, so we cannot pick maximum size:
191 typedef mdb_id mork_id;    // unsigned object identity in a scope
192 typedef mork_id mork_rid;  // unsigned row identity inside scope
193 typedef mork_id mork_tid;  // unsigned table identity inside scope
194 typedef mork_id mork_gid;  // unsigned group identity without any scope
195 
196 // we only care about neg, zero, pos -- so we don't care about size:
197 typedef mdb_order mork_order;  // neg:lessthan, zero:equalto, pos:greaterthan
198 // } %%%%% end mdb-driven scalar typedefs %%%%%
199 
200 #define morkId_kMinusOne ((mdb_id)-1)
201 
202 // { %%%%% begin class forward defines %%%%%
203 // try to put these in alphabetical order for easier examination:
204 class morkMid;
205 class morkAtom;
206 class morkAtomSpace;
207 class morkBookAtom;
208 class morkBuf;
209 class morkBuilder;
210 class morkCell;
211 class morkCellObject;
212 class morkCursor;
213 class morkEnv;
214 class morkFactory;
215 class morkFile;
216 class morkHandle;
217 class morkHandleFace;  // just an opaque cookie type
218 class morkHandleFrame;
219 class morkHashArrays;
220 class morkMap;
221 class morkNode;
222 class morkObject;
223 class morkOidAtom;
224 class morkParser;
225 class morkPool;
226 class morkPlace;
227 class morkPort;
228 class morkPortTableCursor;
229 class morkProbeMap;
230 class morkRow;
231 class morkRowCellCursor;
232 class morkRowObject;
233 class morkRowSpace;
234 class morkSorting;
235 class morkSortingRowCursor;
236 class morkSpace;
237 class morkSpan;
238 class morkStore;
239 class morkStream;
240 class morkTable;
241 class morkTableChange;
242 class morkTableRowCursor;
243 class morkThumb;
244 class morkWriter;
245 class morkZone;
246 // } %%%%% end class forward defines %%%%%
247 
248 // include this config file last for platform & environment specific stuff:
249 #ifndef _MORKCONFIG_
250 #  include "morkConfig.h"
251 #endif
252 
253 // 456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789
254 
255 #endif /* _MORK_ */
256