| 1 |
<HTML> |
| 2 |
|
| 3 |
<HEAD> |
| 4 |
<TITLE> ACEDB source code documentation: the BS package </TITLE> |
| 5 |
|
| 6 |
<LINK rel=stylesheet type="text/css" |
| 7 |
href="./wdoc.css" |
| 8 |
title="Style sheet for wdoc developer documents"> |
| 9 |
|
| 10 |
</HEAD> |
| 11 |
|
| 12 |
<BODY> |
| 13 |
|
| 14 |
<H1>Application programmers' guide to the BS package</H1> |
| 15 |
|
| 16 |
<PRE> |
| 17 |
|
| 18 |
|
| 19 |
Programmers guide to the BS package |
| 20 |
|
| 21 |
This is the basic interface to all the tree objects in the database. |
| 22 |
It is fundamental to extracting data from ACEDB. |
| 23 |
|
| 24 |
General Principles |
| 25 |
================== |
| 26 |
|
| 27 |
The programmer interacts with acedb objects via handles of type OBJ. |
| 28 |
These have associated with them an implicit cursor. |
| 29 |
|
| 30 |
The Find, Get and Add functions in general reposition the cursor as |
| 31 |
well as getting/adding data. They all return a BOOL value which |
| 32 |
indicates if their operation was successful. If this is FALSE then |
| 33 |
the cursor position is not changed. |
| 34 |
|
| 35 |
Get and Add functions require a tag for location. This can either be |
| 36 |
a tag in the current model, or one of the pseudotags _bsHere, |
| 37 |
_bsRight and _bsDown. |
| 38 |
|
| 39 |
bsMark/Goto can be used to store cursor positions to return to later. |
| 40 |
|
| 41 |
Overview of functions |
| 42 |
===================== |
| 43 |
|
| 44 |
operations on to get and free object handles: |
| 45 |
bsCreate(), bsCreateCopy(), bsUpdate(), bsClone() - get object handles |
| 46 |
bsDestroy(), bsSave(), bsKill() - release handles |
| 47 |
|
| 48 |
access primitives on an object: |
| 49 |
bsFindTag() - locate on a tag |
| 50 |
bsGetKey(), bsGetKeyTags(), bsGetData() - get data |
| 51 |
bsPushObj() - enter subobject |
| 52 |
bsFlatten() - get subtree as Array |
| 53 |
bsAddTag(), bsAddKey(), bsAddData(), bsAddComment() - add data |
| 54 |
bsPrune(), bsRemove() - delete data |
| 55 |
bsType(), bsIsTagInObj() - check consistency |
| 56 |
bsMark(), bsGoto(), bsMarkFree() - save cursor info |
| 57 |
|
| 58 |
dump functions: |
| 59 |
bsAceDump() - .ace file dump |
| 60 |
bsDump() - for debugging |
| 61 |
|
| 62 |
special functions, mostly for upper kernel use: |
| 63 |
bsKeySet() - all keys in object |
| 64 |
bsLocalClass() - current model |
| 65 |
bsTagsInClass() - tags in a model |
| 66 |
bsParentKey() - for query package |
| 67 |
|
| 68 |
|
| 69 |
Alphabetic list of functions |
| 70 |
============================ |
| 71 |
|
| 72 |
Starred functions are ones not normally used in general code, |
| 73 |
i.e. things written primarily for specific purposes. |
| 74 |
|
| 75 |
---------------------------------------------------------------- bsAceDump |
| 76 |
* void bsAceDump (OBJ obj, ACEOUT dump_out, BOOL isInternal) |
| 77 |
|
| 78 |
Dumps the object in .ace format. Writes to an ACEOUT stream openend |
| 79 |
by aceOutCreateTo<Xxxx> functions. |
| 80 |
|
| 81 |
|
| 82 |
------------------------------------------------------------- bsAddComment |
| 83 |
* BOOL bsAddComment (OBJ obj, char *text, char type) |
| 84 |
|
| 85 |
Adds a comment at the current cursor position in obj. See the |
| 86 |
introduction for general comments on the bsAdd* functions. Note |
| 87 |
however that this function does not change the cursor position, since |
| 88 |
the cursor can not rest on a comment, and there is no type checking |
| 89 |
with the model, because comments can be added anywhere. |
| 90 |
|
| 91 |
Comments can be added anywhere in a tree, and are ignored by the |
| 92 |
bsGet* functions. The only way to see them is in a tree display, or a |
| 93 |
.ace dump. The only legal type just now is 'C'. |
| 94 |
|
| 95 |
---------------------------------------------------------------- bsAddData |
| 96 |
BOOL bsAddData (OBJ obj, KEY tag, KEY type, void *data) |
| 97 |
|
| 98 |
Adds the given data at the current cursor position in obj. See the |
| 99 |
introduction for general comments on the bsAdd* functions. |
| 100 |
|
| 101 |
Type must be one of the legal data types, i.e. the systags with values |
| 102 |
less than _LastC. For now these are {_Int, _Float, _DateType, _Text, |
| 103 |
_Greek}. The final argument is a pointer to the data in the case of |
| 104 |
Int, Float or DateType, or the char* pointer itself for text types |
| 105 |
(Text, Greek). |
| 106 |
|
| 107 |
----------------------------------------------------------------- bsAddKey |
| 108 |
BOOL bsAddKey (OBJ obj, KEY tag, KEY key) |
| 109 |
|
| 110 |
Adds the given key at the current cursor position in obj. See the |
| 111 |
introduction for general comments on the bsAdd* functions. |
| 112 |
|
| 113 |
----------------------------------------------------------------- bsAddTag |
| 114 |
BOOL bsAddTag (OBJ obj, KEY tag) |
| 115 |
|
| 116 |
Adds the given tag, which must be a true tag in the model, not |
| 117 |
_bsRight or _bsDown. Resets the cursor to this tag. Returns FALSE if |
| 118 |
the tag was already present, else TRUE. |
| 119 |
|
| 120 |
------------------------------------------------------------------ bsClone |
| 121 |
* OBJ bsClone (KEY key, OBJ source) |
| 122 |
|
| 123 |
Specialised routine. Creates or updates object refered to by key; |
| 124 |
throw away existing contents (if any) and replace with source. |
| 125 |
|
| 126 |
----------------------------------------------------------------- bsCreate |
| 127 |
OBJ bsCreate (KEY key) |
| 128 |
|
| 129 |
Returns a read only handle for accessing an object. Will return 0 if |
| 130 |
the object has no data attached yet. |
| 131 |
|
| 132 |
bsCreate() gives a handle to the last saved version of an object in |
| 133 |
secondary cache, building a tree structure there if necessary. |
| 134 |
Multiple calls to bsCreate() on the same key will give pointers into |
| 135 |
the same object. Repeated bsCreate()/bsDestroy() calls to the same |
| 136 |
object are cheap. |
| 137 |
|
| 138 |
------------------------------------------------------------- bsCreateCopy |
| 139 |
* OBJ bsCreateCopy (KEY key) |
| 140 |
|
| 141 |
Returns a handle of an object that you can edit, but will not be |
| 142 |
allowed to save using bsSave(). i.e. you must bsDestroy() it. |
| 143 |
|
| 144 |
---------------------------------------------------------------- bsDestroy |
| 145 |
void bsDestroy (obj) |
| 146 |
|
| 147 |
Releases an object handle. This call should match bsCreate(), |
| 148 |
bsCreateCopy() or bsUpdate(). Once all handles onto an object are |
| 149 |
released it can be bumped out of secondary cache. If used on an |
| 150 |
object handle obtained with bsUpdate(), all changes made to the object |
| 151 |
are abandoned. To save the changes use bsSave(). |
| 152 |
|
| 153 |
------------------------------------------------------------------- bsDump |
| 154 |
* void bsDump (OBJ obj) |
| 155 |
|
| 156 |
For debugging (for which it can be very useful). Writes to stdout the |
| 157 |
complete tree structure of the object, giving all the pointer values |
| 158 |
as well as node key values. Uses bsTreeDump (BS bs) which allows |
| 159 |
dumping of subtrees, but needs a BS argument, which is only available |
| 160 |
inside privileged packages. |
| 161 |
|
| 162 |
---------------------------------------------------------------- bsFindTag |
| 163 |
BOOL bsFindTag (OBJ obj, KEY tag) |
| 164 |
|
| 165 |
If the tag exists in object then moves the cursor there and returns |
| 166 |
TRUE, else returns FALSE. |
| 167 |
|
| 168 |
---------------------------------------------------------------- bsFlatten |
| 169 |
BOOL bsFlatten (OBJ obj, int n, Array a) |
| 170 |
|
| 171 |
This is a (very useful) convenience routine. This recovers the entire |
| 172 |
subtree to the right of the current cursor position into a set of |
| 173 |
n-tuples in the given array. i.e. it looks n positions to the right. |
| 174 |
The array a must be an array of BSunit, which are defined in bs.h as |
| 175 |
|
| 176 |
typedef union { int i; float f; KEY k; char *s ; mytime_t time } BSunit ; |
| 177 |
|
| 178 |
It is presumed that the user knows the model, and so knows which |
| 179 |
version of the union to look at. Missing values are entered as 0, |
| 180 |
which is unfortunately not distinguishable from a true 0 for numerical |
| 181 |
data. bsFlatten() returns TRUE if any data were found, in which case |
| 182 |
arrayMax(a) will be n times the number of rows (tuples). |
| 183 |
|
| 184 |
Does not move the cursor. |
| 185 |
|
| 186 |
An example: |
| 187 |
{ |
| 188 |
Array flatA, segs ; |
| 189 |
SEG *seg ; |
| 190 |
OBJ Seq ; |
| 191 |
int i ; |
| 192 |
|
| 193 |
flatA = arrayCreate (8, BSunit) ; |
| 194 |
|
| 195 |
if (bsFindTag (Seq, _Source_Exons) && bsFlatten (Seq, 3, flatA)) |
| 196 |
for (i = 0 ; i < arrayMax (flatA) ; i += 3) |
| 197 |
{ seg = arrayp (segs, arrayMax(segs)++, SEG) ; |
| 198 |
seg->key = arr(flatA, i, BSunit).k ; |
| 199 |
seg->x1 = arr(flatA, i+1, BSunit).i ; |
| 200 |
seg->x2 = arr(flatA, i+2, BSunit).i ; |
| 201 |
} |
| 202 |
} |
| 203 |
|
| 204 |
---------------------------------------------------------------- bsGetData |
| 205 |
BOOL bsGetData (OBJ obj, KEY tag, KEY type, void *x) |
| 206 |
|
| 207 |
Gets data from the position specified by tag. Same arguments as |
| 208 |
bsAddData(), although in this case for Text types x should be a |
| 209 |
pointer to a string, i.e. type char**. Returns TRUE if there was |
| 210 |
something there and fills x, otherwise does not change x. If x is 0 |
| 211 |
then still locates and returns TRUE or FALSE, but does not give you |
| 212 |
the value. |
| 213 |
|
| 214 |
----------------------------------------------------------------- bsGetKey |
| 215 |
BOOL bsGetKey (OBJ obj, KEY tag, KEY *found) |
| 216 |
|
| 217 |
Gets a key if present at the position given by tag, in which case |
| 218 |
returns TRUE and fills found (if non-zero). Will not get a tag. |
| 219 |
|
| 220 |
------------------------------------------------------------- bsGetKeyTags |
| 221 |
BOOL bsGetKeyTags (OBJ obj, KEY tag, KEY *found) |
| 222 |
|
| 223 |
Will get either a key or a tag. This function must be used when you |
| 224 |
want to get a tag. To just find out if a tag is present and locate on |
| 225 |
it, call bsFindTag(). |
| 226 |
|
| 227 |
------------------------------------------------------------------- bsGoto |
| 228 |
void bsGoto (OBJ obj, BSMARK mark) |
| 229 |
|
| 230 |
Returns the cursor position for obj to that stored by bsMark() in |
| 231 |
mark. You must use the correct obj! bsGoto(obj,0) will return to the |
| 232 |
root of the object, which can be useful when you have been inside |
| 233 |
subobjects. |
| 234 |
|
| 235 |
------------------------------------------------------------- bsIsTagInObj |
| 236 |
BOOL bsIsTagInObj (OBJ obj, KEY key, KEY tag) |
| 237 |
|
| 238 |
To test if a tag is present in an object or the model. You might do |
| 239 |
this prior to calling bsAddTag(obj, tag), to check that the call |
| 240 |
would work. If called with an obj it will look in the object from |
| 241 |
the current cursor position (possibly a submodel) for the tag. |
| 242 |
If obj is NULL and key non-zero it will look in the model for the |
| 243 |
class of key for the tag. Hence you can test either an individual |
| 244 |
object or the database model for the presence of a particular tag. |
| 245 |
|
| 246 |
----------------------------------------------------------------- bsKeySet |
| 247 |
KEYSET bsKeySet (KEY key) |
| 248 |
|
| 249 |
Returns a keySet containing all the keys that can be found in |
| 250 |
bsCreate(key). |
| 251 |
|
| 252 |
------------------------------------------------------------------- bsKill |
| 253 |
void bsKill (obj) |
| 254 |
|
| 255 |
Removes all data from obj and marks it as empty/deleted. |
| 256 |
|
| 257 |
------------------------------------------------------------------- bsMark |
| 258 |
BSMARK bsMark (OBJ obj, BSMARK mark) |
| 259 |
|
| 260 |
Stores the current cursor information inside mark. If given a |
| 261 |
non-zero mark as an argument, it will refill that structure. If the |
| 262 |
mark argument is 0 it will make a new one and pass on a handle. This |
| 263 |
saves on very frequent alloc/free operations. |
| 264 |
|
| 265 |
--------------------------------------------------------------- bsMarkFree |
| 266 |
void bsMarkFree (BSMARK mark) |
| 267 |
|
| 268 |
Frees a mark created with bsMark(). Normally they are not freed, but |
| 269 |
used static as in the example under bsMark(). Implemented as a macro |
| 270 |
that only frees mark if non-zero, and if so sets it to 0. |
| 271 |
|
| 272 |
------------------------------------------------------------------ bsPrune |
| 273 |
BOOL bsPrune (OBJ obj) |
| 274 |
|
| 275 |
Removes everything at the current cursor position and to the right of |
| 276 |
it, and also everything left of it that is unique. i.e. If you add a |
| 277 |
fields which requires that several intermediate tags are made, then |
| 278 |
locate on the field, then call bsPrune() you will remove all the |
| 279 |
intermediate tags as well. If you do not want to remove intermediate |
| 280 |
tags then use bsRemove(). |
| 281 |
|
| 282 |
This call returns the cursor to the root of the object. |
| 283 |
|
| 284 |
---------------------------------------------------------------- bsPushObj |
| 285 |
BOOL bsPushObj (OBJ obj) |
| 286 |
|
| 287 |
If the cursor is currently located at a position just left of a |
| 288 |
#submodel in the model, then returns TRUE and changes the current |
| 289 |
model to that of the submodel, locating the cursor conceptually at the |
| 290 |
root of that. Otherwise, returns FALSE. A quick way to step back |
| 291 |
into the current model is: bsGoto(obj,0) there is no bsPopObj(). |
| 292 |
|
| 293 |
----------------------------------------------------------------- bsRemove |
| 294 |
BOOL bsRemove (OBJ obj) |
| 295 |
|
| 296 |
Like bsPrune(), except that it only removes the current cursor postion |
| 297 |
and everything to the right, not unique stuff to the left. It also |
| 298 |
returns the cursor to the root. |
| 299 |
|
| 300 |
------------------------------------------------------------------- bsSave |
| 301 |
void bsSave (OBJ obj) |
| 302 |
|
| 303 |
Save an updated object back to the database. obj must have been |
| 304 |
created by a call to bsUpdate(). |
| 305 |
|
| 306 |
------------------------------------------------------------ bsTagsInClass |
| 307 |
* KEYSET bsTagsInClass (int table) |
| 308 |
|
| 309 |
Returns a keyset of all the tags in a model, which must be specified |
| 310 |
as a table or class number (a low integer) not as a key in the ?Model |
| 311 |
class. |
| 312 |
|
| 313 |
------------------------------------------------------------------- bsType |
| 314 |
KEY bsType (OBJ obj, KEY direction) |
| 315 |
|
| 316 |
Finds out what the model expects. direction must be _bsRight or |
| 317 |
_bsHere or _bsDown (almost always _bsRight). Will return 0 if there |
| 318 |
is nothing to the right, else a basic type tag (_Text, _Int etc.) else |
| 319 |
the 0'th element of a class for a pointer to that class, or the 1'st |
| 320 |
element of a class for a #construction. |
| 321 |
|
| 322 |
----------------------------------------------------------------- bsUpdate |
| 323 |
OBJ bsUpdate (KEY key) |
| 324 |
|
| 325 |
Open an object for update, i.e. with write access. Returns a handle |
| 326 |
to the object defined by key. Will return 0 if the key does not |
| 327 |
exist, or the object is already being updated elsewhere. It is |
| 328 |
possible to open an object with bsUpdate even if the user does not |
| 329 |
have write access. In this case the object will be changed and locked |
| 330 |
in secondary cache, but not written back to disk. |
| 331 |
|
| 332 |
-------------------------------------------------------------------------- |
| 333 |
|
| 334 |
<PRE> |
| 335 |
|
| 336 |
|
| 337 |
|
| 338 |
</BODY> |
| 339 |
</HTML> |