BRL-CAD
db_io.h
Go to the documentation of this file.
1/* D B _ I O . H
2 * BRL-CAD
3 *
4 * Copyright (c) 1993-2023 United States Government as represented by
5 * the U.S. Army Research Laboratory.
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public License
9 * version 2.1 as published by the Free Software Foundation.
10 *
11 * This library is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this file; see the file named COPYING for more
18 * information.
19 */
20/** @file rt/db_io.h
21 *
22 */
23
24#ifndef RT_DB_IO_H
25#define RT_DB_IO_H
26
27#include "common.h"
28
29/* system headers */
30#include <stdio.h> /* for FILE */
31
32/* interface headers */
33#include "vmath.h"
34#include "bu/avs.h"
35#include "rt/db5.h"
36#include "rt/defines.h"
37
38__BEGIN_DECLS
39
40
41struct rt_db_internal; /* forward declaration */
42
43
44/* db_open.c */
45/**
46 * Ensure that the on-disk database has been completely written out of
47 * the operating system's cache.
48 */
49RT_EXPORT extern void db_sync(struct db_i *dbip);
50
51
52/**
53 * for db_open(), open the specified file as read-only
54 */
55#define DB_OPEN_READONLY "r"
56
57/**
58 * for db_open(), open the specified file as read-write
59 */
60#define DB_OPEN_READWRITE "rw"
61
62/**
63 * Open the named database.
64 *
65 * The 'name' parameter specifies the file or filepath to a .g
66 * geometry database file for reading and/or writing.
67 *
68 * The 'mode' parameter specifies whether to open read-only or in
69 * read-write mode, specified via the DB_OPEN_READONLY and
70 * DB_OPEN_READWRITE symbols respectively.
71 *
72 * As a convenience, the returned db_t structure's dbi_filepath field
73 * is a C-style argv array of dirs to search when attempting to open
74 * related files (such as data files for EBM solids or texture-maps).
75 * The default values are "." and the directory containing the ".g"
76 * file. They may be overridden by setting the environment variable
77 * BRLCAD_FILE_PATH.
78 *
79 * Returns:
80 * DBI_NULL error
81 * db_i * success
82 */
83RT_EXPORT extern struct db_i *
84db_open(const char *name, const char *mode);
85
86
87/* create a new model database */
88/**
89 * Create a new database containing just a header record, regardless
90 * of whether the database previously existed or not, and open it for
91 * reading and writing.
92 *
93 * This routine also calls db_dirbuild(), so the caller doesn't need
94 * to.
95 *
96 * Returns:
97 * DBI_NULL on error
98 * db_i * on success
99 */
100RT_EXPORT extern struct db_i *
101db_create(const char *name, int version);
102
103
104/* close a model database */
105/**
106 * De-register a client of this database instance, if provided, and
107 * close out the instance.
108 */
109RT_EXPORT extern void db_close_client(struct db_i *dbip,
110 long *client);
111
112/**
113 * Close a database, releasing dynamic memory Wait until last user is
114 * done, though.
115 */
116RT_EXPORT extern void db_close(struct db_i *dbip);
117
118
119/* dump a full copy of a database */
120/**
121 * Dump a full copy of one database into another. This is a good way
122 * of committing a ".inmem" database to a ".g" file. The input is a
123 * database instance, the output is a LIBWDB object, which could be a
124 * disk file or another database instance.
125 *
126 * Returns -
127 * -1 error
128 * 0 success
129 */
130RT_EXPORT extern int db_dump(struct rt_wdb *wdbp,
131 struct db_i *dbip);
132
133/**
134 * Obtain an additional instance of this same database. A new client
135 * is registered at the same time if one is specified.
136 */
137RT_EXPORT extern struct db_i *db_clone_dbi(struct db_i *dbip,
138 long *client);
139
140
141/**
142 * Create a v5 database "free" object of the specified size, and place
143 * it at the indicated location in the database.
144 *
145 * There are two interesting cases:
146 * - The free object is "small". Just write it all at once.
147 * - The free object is "large". Write header and trailer
148 * separately
149 *
150 * @return 0 OK
151 * @return -1 Fail. This is a horrible error.
152 */
153RT_EXPORT extern int db5_write_free(struct db_i *dbip,
154 struct directory *dp,
155 size_t length);
156
157
158/**
159 * Change the size of a v5 database object.
160 *
161 * If the object is getting smaller, break it into two pieces, and
162 * write out free objects for both. The caller is expected to
163 * re-write new data on the first one.
164 *
165 * If the object is getting larger, seek a suitable "hole" large
166 * enough to hold it, throwing back any surplus, properly marked.
167 *
168 * If the object is getting larger and there is no suitable "hole" in
169 * the database, extend the file, write a free object in the new
170 * space, and write a free object in the old space.
171 *
172 * There is no point to trying to extend in place, that would require
173 * two searches through the memory map, and doesn't save any disk I/O.
174 *
175 * Returns -
176 * 0 OK
177 * -1 Failure
178 */
179RT_EXPORT extern int db5_realloc(struct db_i *dbip,
180 struct directory *dp,
181 struct bu_external *ep);
182
183
184/**
185 * A routine for merging together the three optional parts of an
186 * object into the final on-disk format. Results in extra data
187 * copies, but serves as a starting point for testing. Any of name,
188 * attrib, and body may be null.
189 */
190RT_EXPORT extern void db5_export_object3(struct bu_external *out,
191 int dli,
192 const char *name,
193 const unsigned char hidden,
194 const struct bu_external *attrib,
195 const struct bu_external *body,
196 int major,
197 int minor,
198 int a_zzz,
199 int b_zzz);
200
201
202/**
203 * The attributes are taken from ip->idb_avs
204 *
205 * If present, convert attributes to on-disk format. This must happen
206 * after exporting the body, in case the ft_export5() method happened
207 * to extend the attribute set. Combinations are one "solid" which
208 * does this.
209 *
210 * The internal representation is NOT freed, that's the caller's job.
211 *
212 * The 'ext' pointer is accepted in uninitialized form, and an
213 * initialized structure is always returned, so that the caller may
214 * free it even when an error return is given.
215 *
216 * Returns -
217 * 0 OK
218 * -1 FAIL
219 */
220RT_EXPORT extern int rt_db_cvt_to_external5(struct bu_external *ext,
221 const char *name,
222 const struct rt_db_internal *ip,
223 double conv2mm,
224 struct db_i *dbip,
225 struct resource *resp,
226 const int major);
227
228
229/*
230 * Modify name of external object, if necessary.
231 */
232RT_EXPORT extern int db_wrap_v5_external(struct bu_external *ep,
233 const char *name);
234
235
236/**
237 * Given an external representation of a database object, convert
238 * it into its internal representation.
239 *
240 * Returns -
241 * <0 On error
242 * id On success.
243 */
244RT_EXPORT extern int
246 struct rt_db_internal *ip,
247 const struct bu_external *ep,
248 const char *name,
249 const struct db_i *dbip,
250 const mat_t mat,
251 struct resource *resp);
252
253/**
254 * Get an object from the database, and convert it into its internal
255 * representation.
256 *
257 * Applications and middleware shouldn't call this directly, they
258 * should use the generic interface "rt_db_get_internal()".
259 *
260 * Returns -
261 * <0 On error
262 * id On success.
263 */
264RT_EXPORT extern int rt_db_get_internal5(struct rt_db_internal *ip,
265 const struct directory *dp,
266 const struct db_i *dbip,
267 const mat_t mat,
268 struct resource *resp);
269
270
271/**
272 * Convert the internal representation of a solid to the external one,
273 * and write it into the database.
274 *
275 * Applications and middleware shouldn't call this directly, they
276 * should use the version-generic interface "rt_db_put_internal()".
277 *
278 * The internal representation is always freed. (Not the pointer,
279 * just the contents).
280 *
281 * Returns -
282 * <0 error
283 * 0 success
284 */
285RT_EXPORT extern int rt_db_put_internal5(struct directory *dp,
286 struct db_i *dbip,
287 struct rt_db_internal *ip,
288 struct resource *resp,
289 const int major);
290
291
292/**
293 * Make only the front (header) portion of a free object. This is
294 * used when operating on very large contiguous free objects in the
295 * database (e.g. 50 MBytes).
296 */
297RT_EXPORT extern void db5_make_free_object_hdr(struct bu_external *ep,
298 size_t length);
299
300
301/**
302 * Make a complete, zero-filled, free object. Note that free objects
303 * can sometimes get quite large.
304 */
305RT_EXPORT extern void db5_make_free_object(struct bu_external *ep,
306 size_t length);
307
308
309/**
310 * Given a variable-width length field character pointer (cp) in
311 * network order (XDR), store it in *lenp.
312 *
313 * Format is typically expected to be one of:
314 * DB5HDR_WIDTHCODE_8BIT
315 * DB5HDR_WIDTHCODE_16BIT
316 * DB5HDR_WIDTHCODE_32BIT
317 * DB5HDR_WIDTHCODE_64BIT
318 *
319 * Returns -
320 * The number of bytes of input that were decoded.
321 */
322RT_EXPORT extern size_t db5_decode_signed(size_t *lenp,
323 const unsigned char *cp,
324 int format);
325
326/**
327 * Given a variable-width length field in network order (XDR), store
328 * it in *lenp.
329 *
330 * This routine processes unsigned values.
331 *
332 * Returns -
333 * The number of bytes of input that were decoded.
334 */
335RT_EXPORT extern size_t db5_decode_length(size_t *lenp,
336 const unsigned char *cp,
337 int format);
338#if defined(USE_BINARY_ATTRIBUTES)
339/**
340 * Given a pointer to a binary attribute, determine its length.
341 */
342RT_EXPORT extern void decode_binary_attribute(const size_t len,
343 const unsigned char *cp);
344#endif
345
346/**
347 * Given a number to encode, decide which is the smallest encoding
348 * format which will contain it.
349 */
350RT_EXPORT extern int db5_select_length_encoding(size_t len);
351
352
353RT_EXPORT extern void db5_import_color_table(char *cp);
354
355/**
356 * Given a value and a variable-width format spec, store it in network
357 * order.
358 *
359 * Returns -
360 * pointer to next available byte.
361 */
362RT_EXPORT extern unsigned char *db5_encode_length(unsigned char *cp,
363 size_t val,
364 int format);
365
366/**
367 * Given a pointer to the memory for a serialized database object, get
368 * a raw internal representation.
369 *
370 * Returns -
371 * on success, pointer to next unused byte in 'ip' after object got;
372 * NULL, on error.
373 */
374RT_EXPORT extern const unsigned char *db5_get_raw_internal_ptr(struct db5_raw_internal *rip,
375 const unsigned char *ip);
376
377
378/**
379 * Given a file pointer to an open geometry database positioned on a
380 * serialized object, get a raw internal representation.
381 *
382 * Returns -
383 * 0 on success
384 * -1 on EOF
385 * -2 on error
386 */
387RT_EXPORT extern int db5_get_raw_internal_fp(struct db5_raw_internal *rip,
388 FILE *fp);
389
390
391/**
392 * Verify that this is a valid header for a BRL-CAD v5 database.
393 *
394 * Returns -
395 * 0 Not valid v5 header
396 * 1 Valid v5 header
397 */
398RT_EXPORT extern int db5_header_is_valid(const unsigned char *hp);
399
400
401/**
402 * write an ident header (title and units) to the provided file
403 * pointer.
404 *
405 * Returns -
406 * 0 Success
407 * -1 Error
408 */
409RT_EXPORT extern int db5_fwrite_ident(FILE *,
410 const char *,
411 double);
412
413
414/**
415 *
416 * Given that caller already has an external representation of the
417 * database object, update it to have a new name (taken from
418 * dp->d_namep) in that external representation, and write the new
419 * object into the database, obtaining different storage if the size
420 * has changed.
421 *
422 * Changing the name on a v5 object is a relatively expensive
423 * operation.
424 *
425 * Caller is responsible for freeing memory of external
426 * representation, using bu_free_external().
427 *
428 * This routine is used to efficiently support MGED's "cp" and "keep"
429 * commands, which don't need to import and decompress objects just to
430 * rename and copy them.
431 *
432 * Returns -
433 * -1 error
434 * 0 success
435 */
436RT_EXPORT extern int db_put_external5(struct bu_external *ep,
437 struct directory *dp,
438 struct db_i *dbip);
439
440/**
441 * As the v4 database does not really have the notion of "wrapping",
442 * this function writes the object name into the proper place (a
443 * standard location in all granules).
444 */
445RT_EXPORT extern void db_wrap_v4_external(struct bu_external *op,
446 const char *name);
447
448
449/* db_io.c */
450RT_EXPORT extern int db_write(struct db_i *dbip,
451 const void * addr,
452 size_t count,
453 b_off_t offset);
454
455/**
456 * Add name from dp->d_namep to external representation of solid, and
457 * write it into a file.
458 *
459 * Caller is responsible for freeing memory of external
460 * representation, using bu_free_external().
461 *
462 * The 'name' field of the external representation is modified to
463 * contain the desired name. The 'ep' parameter cannot be const.
464 *
465 * THIS ROUTINE ONLY SUPPORTS WRITING V4 GEOMETRY.
466 *
467 * Returns -
468 * <0 error
469 * 0 OK
470 *
471 * NOTE: Callers of this should be using wdb_export_external()
472 * instead.
473 */
474RT_EXPORT extern int db_fwrite_external(FILE *fp,
475 const char *name,
476 struct bu_external *ep);
477
478/* malloc & read records */
479
480/**
481 * Retrieve all records in the database pertaining to an object, and
482 * place them in malloc()'ed storage, which the caller is responsible
483 * for free()'ing.
484 *
485 * This loads the combination into a local record buffer. This is in
486 * external v4 format.
487 *
488 * Returns -
489 * union record * - OK
490 * (union record *)0 - FAILURE
491 */
492RT_EXPORT extern union record *db_getmrec(const struct db_i *,
493 const struct directory *dp);
494/* get several records from db */
495
496/**
497 * Retrieve 'len' records from the database, "offset" granules into
498 * this entry.
499 *
500 * Returns -
501 * 0 OK
502 * -1 FAILURE
503 */
504RT_EXPORT extern int db_get(const struct db_i *,
505 const struct directory *dp,
506 union record *where,
507 b_off_t offset,
508 size_t len);
509/* put several records into db */
510
511/**
512 * Store 'len' records to the database, "offset" granules into this
513 * entry.
514 *
515 * Returns:
516 * 0 OK
517 * non-0 FAILURE
518 */
519RT_EXPORT extern int db_put(struct db_i *,
520 const struct directory *dp,
521 union record *where,
522 b_off_t offset, size_t len);
523
524/**
525 * Obtains a object from the database, leaving it in external
526 * (on-disk) format.
527 *
528 * The bu_external structure represented by 'ep' is initialized here,
529 * the caller need not pre-initialize it. On error, 'ep' is left
530 * un-initialized and need not be freed, to simplify error recovery.
531 * On success, the caller is responsible for calling
532 * bu_free_external(ep);
533 *
534 * Returns -
535 * -1 error
536 * 0 success
537 */
538RT_EXPORT extern int db_get_external(struct bu_external *ep,
539 const struct directory *dp,
540 const struct db_i *dbip);
541
542/**
543 * Given that caller already has an external representation of the
544 * database object, update it to have a new name (taken from
545 * dp->d_namep) in that external representation, and write the new
546 * object into the database, obtaining different storage if the size
547 * has changed.
548 *
549 * Caller is responsible for freeing memory of external
550 * representation, using bu_free_external().
551 *
552 * This routine is used to efficiently support MGED's "cp" and "keep"
553 * commands, which don't need to import objects just to rename and
554 * copy them.
555 *
556 * Returns -
557 * <0 error
558 * 0 success
559 */
560RT_EXPORT extern int db_put_external(struct bu_external *ep,
561 struct directory *dp,
562 struct db_i *dbip);
563
564/* db_scan.c */
565/* read db (to build directory) */
566RT_EXPORT extern int db_scan(struct db_i *,
567 int (*handler)(struct db_i *,
568 const char *name,
569 b_off_t addr,
570 size_t nrec,
571 int flags,
572 void *client_data),
573 int do_old_matter,
574 void *client_data);
575/* update db unit conversions */
576#define db_ident(a, b, c) +++error+++
577
578/**
579 * Update the _GLOBAL object, which in v5 serves the place of the
580 * "ident" header record in v4 as the place to stash global
581 * information. Since every database will have one of these things,
582 * it's no problem to update it.
583 *
584 * Returns -
585 * 0 Success
586 * -1 Fatal Error
587 */
588RT_EXPORT extern int db_update_ident(struct db_i *dbip,
589 const char *title,
590 double local2mm);
591
592/**
593 * Create a header for a v5 database.
594 *
595 * This routine has the same calling sequence as db_fwrite_ident()
596 * which makes a v4 database header.
597 *
598 * In the v5 database, two database objects must be created to match
599 * the semantics of what was in the v4 header:
600 *
601 * First, a database header object.
602 *
603 * Second, create a specially named attribute-only object which
604 * contains the attributes "title=" and "units=" with the values of
605 * title and local2mm respectively.
606 *
607 * Note that the current working units are specified as a conversion
608 * factor to millimeters because database dimensional values are
609 * always stored as millimeters (mm). The units conversion factor
610 * only affects the display and conversion of input values. This
611 * helps prevent error accumulation and improves numerical stability
612 * when calculations are made.
613 *
614 * This routine should only be used by db_create(). Everyone else
615 * should use db5_update_ident().
616 *
617 * Returns -
618 * 0 Success
619 * -1 Fatal Error
620 */
621RT_EXPORT extern int db_fwrite_ident(FILE *fp,
622 const char *title,
623 double local2mm);
624
625/**
626 * Initialize conversion factors given the v4 database unit
627 */
628RT_EXPORT extern void db_conversions(struct db_i *,
629 int units);
630
631/**
632 * Given a string, return the V4 database code representing the user's
633 * preferred editing units. The v4 database format does not have many
634 * choices.
635 *
636 * Returns -
637 * -1 Not a legal V4 database code
638 * # The V4 database code number
639 */
640RT_EXPORT extern int db_v4_get_units_code(const char *str);
641
642/* db5_scan.c */
643
644/**
645 * A generic routine to determine the type of the database, (v4 or v5)
646 * and to invoke the appropriate db_scan()-like routine to build the
647 * in-memory directory.
648 *
649 * It is the caller's responsibility to close the database in case of
650 * error.
651 *
652 * Called from rt_dirbuild() and other places directly where a
653 * raytrace instance is not required.
654 *
655 * Returns -
656 * 0 OK
657 * -1 failure
658 */
659RT_EXPORT extern int db_dirbuild(struct db_i *dbip);
660RT_EXPORT extern int db_dirbuild_inmem(struct db_i *dbip, const void *data, b_off_t data_size);
661RT_EXPORT extern struct directory *db5_diradd(struct db_i *dbip,
662 const struct db5_raw_internal *rip,
663 b_off_t laddr,
664 void *client_data);
665
666/**
667 * Scan a v5 database, sending each object off to a handler.
668 *
669 * Returns -
670 * 0 Success
671 * -1 Fatal Error
672 */
673RT_EXPORT extern int db5_scan(struct db_i *dbip,
674 void (*handler)(struct db_i *,
675 const struct db5_raw_internal *,
676 b_off_t addr,
677 void *client_data),
678 void *client_data);
679RT_EXPORT extern int db5_scan_inmem(struct db_i *dbip,
680 void (*handler)(struct db_i *,
681 const struct db5_raw_internal *,
682 b_off_t addr,
683 void *client_data),
684 void *client_data,
685 const void *data,
686 b_off_t data_size);
687
688/**
689 * obtain the database version for a given database instance.
690 *
691 * presently returns only a 4 or 5 accordingly.
692 */
693RT_EXPORT extern int db_version(struct db_i *dbip);
694RT_EXPORT extern int db_version_inmem(struct db_i *dbip, const void *data, b_off_t data_size);
695
696
697/* db_corrupt.c */
698
699/**
700 * Detect whether a given geometry database file seems to be corrupt
701 * or invalid due to flipped endianness. Only relevant for v4
702 * geometry files that are binary-incompatible with the runtime
703 * platform.
704 *
705 * Returns true if flipping the endian type fixes all combination
706 * member matrices.
707 */
708RT_EXPORT extern int rt_db_flip_endian(struct db_i *dbip);
709
710
711/**
712 * "open" an in-memory-only database instance. this initializes a
713 * dbip for use, creating an inmem dbi_wdbp as the means to add
714 * geometry to the directory (use wdb_export_external()).
715 */
716RT_EXPORT extern struct db_i * db_open_inmem(void);
717
718
719/**
720 * creates an in-memory-only database. this is very similar to
721 * db_open_inmem() with the exception that the this routine adds a
722 * default _GLOBAL object.
723 */
724RT_EXPORT extern struct db_i * db_create_inmem(void);
725
726
727/**
728 * Transmogrify an existing directory entry to be an in-memory-only
729 * one, stealing the external representation from 'ext'.
730 */
731RT_EXPORT extern void db_inmem(struct directory *dp,
732 struct bu_external *ext,
733 int flags,
734 struct db_i *dbip);
735
736/* db_lookup.c */
737
738/**
739 * Return the number of "struct directory" nodes in the given
740 * database.
741 */
742RT_EXPORT extern size_t db_directory_size(const struct db_i *dbip);
743
744/**
745 * For debugging, ensure that all the linked-lists for the directory
746 * structure are intact.
747 */
748RT_EXPORT extern void db_ck_directory(const struct db_i *dbip);
749
750/**
751 * Returns -
752 * 0 if the in-memory directory is empty
753 * 1 if the in-memory directory has entries,
754 * which implies that a db_scan() has already been performed.
755 */
756RT_EXPORT extern int db_is_directory_non_empty(const struct db_i *dbip);
757
758/**
759 * Returns a hash index for a given string that corresponds with the
760 * head of that string's hash chain.
761 */
762RT_EXPORT extern int db_dirhash(const char *str);
763
764/**
765 * This routine ensures that ret_name is not already in the
766 * directory. If it is, it tries a fixed number of times to modify
767 * ret_name before giving up. Note - most of the time, the hash for
768 * ret_name is computed once.
769 *
770 * Inputs -
771 * dbip database instance pointer
772 * ret_name the original name
773 * noisy to blather or not
774 *
775 * Outputs -
776 * ret_name the name to use
777 * headp pointer to the first (struct directory *) in the bucket
778 *
779 * Returns -
780 * 0 success
781 * <0 fail
782 */
783RT_EXPORT extern int db_dircheck(struct db_i *dbip,
784 struct bu_vls *ret_name,
785 int noisy,
786 struct directory ***headp);
787/* convert name to directory ptr */
788
789/**
790 * This routine takes a path or a name and returns the current directory
791 * pointer (if any) associated with the object.
792 *
793 * If given an object name, it will look up the object name in the directory
794 * table. If the name is present, a pointer to the directory struct element is
795 * returned, otherwise NULL is returned.
796 *
797 * If given a path, it will validate that the path is a valid path in the
798 * current database. If it is, a pointer to the current directory in the path
799 * (i.e. the leaf object on the path) is returned, otherwise NULL is returned.
800 *
801 * If noisy is non-zero, a print occurs, else only the return code indicates
802 * failure.
803 *
804 * Returns -
805 * struct directory if name is found
806 * RT_DIR_NULL on failure
807 */
808RT_EXPORT extern struct directory *db_lookup(const struct db_i *,
809 const char *name,
810 int noisy);
811
812/* add entry to directory */
813
814/**
815 * Add an entry to the directory. Try to make the regular path
816 * through the code as fast as possible, to speed up building the
817 * table of contents.
818 *
819 * dbip is a pointer to a valid/opened database instance
820 *
821 * name is the string name of the object being added
822 *
823 * laddr is the offset into the file to the object
824 *
825 * len is the length of the object, number of db granules used
826 *
827 * flags are defined in raytrace.h (RT_DIR_SOLID, RT_DIR_COMB, RT_DIR_REGION,
828 * RT_DIR_INMEM, etc.) for db version 5, ptr is the minor_type
829 * (non-null pointer to valid unsigned char code)
830 *
831 * an laddr of RT_DIR_PHONY_ADDR means that database storage has not
832 * been allocated yet.
833 */
834RT_EXPORT extern struct directory *db_diradd(struct db_i *,
835 const char *name,
836 b_off_t laddr,
837 size_t len,
838 int flags,
839 void *ptr);
840RT_EXPORT extern struct directory *db_diradd5(struct db_i *dbip,
841 const char *name,
842 b_off_t laddr,
843 unsigned char major_type,
844 unsigned char minor_type,
845 unsigned char name_hidden,
846 size_t object_length,
847 struct bu_attribute_value_set *avs);
848
849/* delete entry from directory */
850
851/**
852 * Given a pointer to a directory entry, remove it from the linked
853 * list, and free the associated memory.
854 *
855 * It is the responsibility of the caller to have released whatever
856 * structures have been hung on the d_use_hd bu_list, first.
857 *
858 * Returns -
859 * 0 on success
860 * non-0 on failure
861 */
862RT_EXPORT extern int db_dirdelete(struct db_i *,
863 struct directory *dp);
864RT_EXPORT extern int db_fwrite_ident(FILE *,
865 const char *,
866 double);
867
868/**
869 * For debugging, print the entire contents of the database directory.
870 */
871RT_EXPORT extern void db_pr_dir(const struct db_i *dbip);
872
873/**
874 * Change the name string of a directory entry. Because of the
875 * hashing function, this takes some extra work.
876 *
877 * Returns -
878 * 0 on success
879 * non-0 on failure
880 */
881RT_EXPORT extern int db_rename(struct db_i *,
882 struct directory *,
883 const char *newname);
884
885
886/**
887 * Updates the d_nref fields (which count the number of times a given
888 * entry is referenced by a COMBination in the database).
889 *
890 */
891RT_EXPORT extern void db_update_nref(struct db_i *dbip,
892 struct resource *resp);
893
894
895/* db_flags.c */
896/**
897 * Given the internal form of a database object, return the
898 * appropriate 'flags' word for stashing in the in-memory directory of
899 * objects.
900 */
901RT_EXPORT extern int db_flags_internal(const struct rt_db_internal *intern);
902
903
904/* XXX - should use in db5_diradd() */
905/**
906 * Given a database object in "raw" internal form, return the
907 * appropriate 'flags' word for stashing in the in-memory directory of
908 * objects.
909 */
910RT_EXPORT extern int db_flags_raw_internal(const struct db5_raw_internal *intern);
911
912/* db_alloc.c */
913
914/* allocate "count" granules */
915RT_EXPORT extern int db_alloc(struct db_i *,
916 struct directory *dp,
917 size_t count);
918/* delete "recnum" from entry */
919RT_EXPORT extern int db_delrec(struct db_i *,
920 struct directory *dp,
921 int recnum);
922/* delete all granules assigned dp */
923RT_EXPORT extern int db_delete(struct db_i *,
924 struct directory *dp);
925/* write FREE records from 'start' */
926RT_EXPORT extern int db_zapper(struct db_i *,
927 struct directory *dp,
928 size_t start);
929
930/**
931 * This routine is called by the RT_GET_DIRECTORY macro when the
932 * freelist is exhausted. Rather than simply getting one additional
933 * structure, we get a whole batch, saving overhead.
934 */
935RT_EXPORT extern void db_alloc_directory_block(struct resource *resp);
936
937/**
938 * This routine is called by the GET_SEG macro when the freelist is
939 * exhausted. Rather than simply getting one additional structure, we
940 * get a whole batch, saving overhead. When this routine is called,
941 * the seg resource must already be locked. malloc() locking is done
942 * in bu_malloc.
943 */
944RT_EXPORT extern void rt_alloc_seg_block(struct resource *res);
945
946
947/**
948 * Read named MGED db, build toc.
949 */
950RT_EXPORT extern struct rt_i *rt_dirbuild(const char *filename, char *buf, int len);
951RT_EXPORT extern struct rt_i *rt_dirbuild_inmem(const void *data, b_off_t data_size, char *buf, int len);
952
953
954/* db5_types.c */
955RT_EXPORT extern int db5_type_tag_from_major(char **tag,
956 const int major);
957
958RT_EXPORT extern int db5_type_descrip_from_major(char **descrip,
959 const int major);
960
961RT_EXPORT extern int db5_type_tag_from_codes(char **tag,
962 const int major,
963 const int minor);
964
965RT_EXPORT extern int db5_type_descrip_from_codes(char **descrip,
966 const int major,
967 const int minor);
968
969RT_EXPORT extern int db5_type_codes_from_tag(int *major,
970 int *minor,
971 const char *tag);
972
973RT_EXPORT extern int db5_type_codes_from_descrip(int *major,
974 int *minor,
975 const char *descrip);
976
977RT_EXPORT extern size_t db5_type_sizeof_h_binu(const int minor);
978
979RT_EXPORT extern size_t db5_type_sizeof_n_binu(const int minor);
980
981__END_DECLS
982
983#endif /* RT_DB_IO_H */
984
985/*
986 * Local Variables:
987 * tab-width: 8
988 * mode: C
989 * indent-tabs-mode: t
990 * c-file-style: "stroustrup"
991 * End:
992 * ex: shiftwidth=4 tabstop=8
993 */
Header file for the BRL-CAD common definitions.
Definition of the BRL-CAD "v5" database format used for new ".g" files.
void db5_make_free_object_hdr(struct bu_external *ep, size_t length)
int db_put_external(struct bu_external *ep, struct directory *dp, struct db_i *dbip)
void db5_import_color_table(char *cp)
int db_get_external(struct bu_external *ep, const struct directory *dp, const struct db_i *dbip)
void db5_make_free_object(struct bu_external *ep, size_t length)
int db_wrap_v5_external(struct bu_external *ep, const char *name)
void db_close(struct db_i *dbip)
struct db_i * db_create_inmem(void)
int db5_write_free(struct db_i *dbip, struct directory *dp, size_t length)
void db_close_client(struct db_i *dbip, long *client)
struct directory * db5_diradd(struct db_i *dbip, const struct db5_raw_internal *rip, b_off_t laddr, void *client_data)
int db_version_inmem(struct db_i *dbip, const void *data, b_off_t data_size)
int db_update_ident(struct db_i *dbip, const char *title, double local2mm)
struct rt_i * rt_dirbuild_inmem(const void *data, b_off_t data_size, char *buf, int len)
int db_scan(struct db_i *, int(*handler)(struct db_i *, const char *name, b_off_t addr, size_t nrec, int flags, void *client_data), int do_old_matter, void *client_data)
int db5_type_descrip_from_major(char **descrip, const int major)
int db_rename(struct db_i *, struct directory *, const char *newname)
size_t db5_decode_length(size_t *lenp, const unsigned char *cp, int format)
int db_dirbuild(struct db_i *dbip)
int db5_type_tag_from_major(char **tag, const int major)
int db5_type_tag_from_codes(char **tag, const int major, const int minor)
size_t db5_type_sizeof_h_binu(const int minor)
int rt_db_put_internal5(struct directory *dp, struct db_i *dbip, struct rt_db_internal *ip, struct resource *resp, const int major)
int db_flags_raw_internal(const struct db5_raw_internal *intern)
struct directory * db_lookup(const struct db_i *, const char *name, int noisy)
int db_delete(struct db_i *, struct directory *dp)
int db_dirhash(const char *str)
struct rt_i * rt_dirbuild(const char *filename, char *buf, int len)
int db_write(struct db_i *dbip, const void *addr, size_t count, b_off_t offset)
struct directory * db_diradd5(struct db_i *dbip, const char *name, b_off_t laddr, unsigned char major_type, unsigned char minor_type, unsigned char name_hidden, size_t object_length, struct bu_attribute_value_set *avs)
int rt_db_external5_to_internal5(struct rt_db_internal *ip, const struct bu_external *ep, const char *name, const struct db_i *dbip, const mat_t mat, struct resource *resp)
void rt_alloc_seg_block(struct resource *res)
struct db_i * db_open_inmem(void)
int db_dirbuild_inmem(struct db_i *dbip, const void *data, b_off_t data_size)
int db_v4_get_units_code(const char *str)
int db_alloc(struct db_i *, struct directory *dp, size_t count)
union record * db_getmrec(const struct db_i *, const struct directory *dp)
int db_dirdelete(struct db_i *, struct directory *dp)
int db_put(struct db_i *, const struct directory *dp, union record *where, b_off_t offset, size_t len)
int db5_scan_inmem(struct db_i *dbip, void(*handler)(struct db_i *, const struct db5_raw_internal *, b_off_t addr, void *client_data), void *client_data, const void *data, b_off_t data_size)
int db5_realloc(struct db_i *dbip, struct directory *dp, struct bu_external *ep)
int db5_fwrite_ident(FILE *, const char *, double)
const unsigned char * db5_get_raw_internal_ptr(struct db5_raw_internal *rip, const unsigned char *ip)
struct directory * db_diradd(struct db_i *, const char *name, b_off_t laddr, size_t len, int flags, void *ptr)
int db_put_external5(struct bu_external *ep, struct directory *dp, struct db_i *dbip)
int db_fwrite_external(FILE *fp, const char *name, struct bu_external *ep)
int db5_select_length_encoding(size_t len)
int rt_db_flip_endian(struct db_i *dbip)
void db_sync(struct db_i *dbip)
int db_zapper(struct db_i *, struct directory *dp, size_t start)
int rt_db_cvt_to_external5(struct bu_external *ext, const char *name, const struct rt_db_internal *ip, double conv2mm, struct db_i *dbip, struct resource *resp, const int major)
int db_get(const struct db_i *, const struct directory *dp, union record *where, b_off_t offset, size_t len)
void db_update_nref(struct db_i *dbip, struct resource *resp)
int db_dump(struct rt_wdb *wdbp, struct db_i *dbip)
int db_flags_internal(const struct rt_db_internal *intern)
void db_ck_directory(const struct db_i *dbip)
size_t db5_decode_signed(size_t *lenp, const unsigned char *cp, int format)
int db5_type_codes_from_tag(int *major, int *minor, const char *tag)
int db5_type_codes_from_descrip(int *major, int *minor, const char *descrip)
void db_pr_dir(const struct db_i *dbip)
int db5_get_raw_internal_fp(struct db5_raw_internal *rip, FILE *fp)
int db_delrec(struct db_i *, struct directory *dp, int recnum)
void db_conversions(struct db_i *, int units)
void db_inmem(struct directory *dp, struct bu_external *ext, int flags, struct db_i *dbip)
int rt_db_get_internal5(struct rt_db_internal *ip, const struct directory *dp, const struct db_i *dbip, const mat_t mat, struct resource *resp)
struct db_i * db_create(const char *name, int version)
int db_is_directory_non_empty(const struct db_i *dbip)
struct db_i * db_open(const char *name, const char *mode)
struct db_i * db_clone_dbi(struct db_i *dbip, long *client)
int db5_header_is_valid(const unsigned char *hp)
int db_version(struct db_i *dbip)
void db_alloc_directory_block(struct resource *resp)
unsigned char * db5_encode_length(unsigned char *cp, size_t val, int format)
int db_dircheck(struct db_i *dbip, struct bu_vls *ret_name, int noisy, struct directory ***headp)
int db5_type_descrip_from_codes(char **descrip, const int major, const int minor)
void db5_export_object3(struct bu_external *out, int dli, const char *name, const unsigned char hidden, const struct bu_external *attrib, const struct bu_external *body, int major, int minor, int a_zzz, int b_zzz)
int db5_scan(struct db_i *dbip, void(*handler)(struct db_i *, const struct db5_raw_internal *, b_off_t addr, void *client_data), void *client_data)
size_t db5_type_sizeof_n_binu(const int minor)
size_t db_directory_size(const struct db_i *dbip)
int db_fwrite_ident(FILE *fp, const char *title, double local2mm)
void db_wrap_v4_external(struct bu_external *op, const char *name)
void int char * mode
Definition: tig.h:179
void int char int * length
Definition: tig.h:180
#define b_off_t
Definition: common.h:222
fastf_t mat_t[ELEMENTS_PER_MAT]
4x4 matrix
Definition: vmath.h:366
Definition: vls.h:53
void * ptr
ptr to in-memory-only obj
Definition: directory.h:64
Definition: wdb.h:62
Definition: db4.h:413
fundamental vector, matrix, quaternion math macros