BRL-CAD
db_instance.h
Go to the documentation of this file.
1/* D B _ I N S T A N C E . 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 db_instance.h
21 *
22 */
23
24#ifndef RT_DB_INSTANCE_H
25#define RT_DB_INSTANCE_H
26
27#include "common.h"
28
29/* system headers */
30#include <stdio.h> /* for FILE */
31
32/* interface headers */
33#include "bu/magic.h"
34#include "bu/file.h"
35#include "bu/mapped_file.h"
36#include "bu/ptbl.h"
37#include "bn/tol.h"
38#include "rt/mem.h"
39#include "rt/op.h"
40#include "rt/directory.h"
41#include "rt/anim.h"
42#include "rt/tol.h"
43
44__BEGIN_DECLS
45
46struct db_i; /* forward declaration */
47struct rt_wdb; /* forward declaration */
48
49/* Callback called when database objects are changed. The int indicates
50 * the change type (0 = mod, 1 = add, 2 = rm). ctx is a user
51 * supplied context and is passed back as the last argument to db_change.
52 */
53typedef void (*dbi_changed_t)(struct db_i *, struct directory *, int, void *);
54
55
56/* Callback called when references are updated. Args are:
57 *
58 * 1. parent dp,
59 * 2. child dp referenced by parent dp
60 * 3. the child name (should be available even if the child dp is null, which can happen with references to
61 * non-existent objects)
62 * 4. the boolean operation used to include the child
63 * 5. the matrix above the child (NULL == IDN matrix)
64 * 6. dbi_u_data (generally application context set for use in these callbacks)
65 *
66 * There are two particular sets of callback args that have special significance:
67 *
68 * NULL, NULL, NULL, DB_OP_UNION, NULL == the beginning of a db_update_nref cycle
69 * NULL, NULL, NULL, DB_OP_SUBTRACT, NULL == the end of a db_update_nref cycle
70 *
71 * NOTE: the contents of the child name and matrix should be copied by the
72 * caller if they want to make use of them - they are not references to
73 * stable storage.
74 *
75 * NOTE: the parent may be a non-comb object, if extrudes or other primitives
76 * that reference other primitives are present in the .g - the caller should
77 * be aware of that when processing the results.
78 *
79 * librt only stores the reference count in d_nref, but applications may
80 * need more explicit awareness of the parent/child relationships. Since
81 * db_update_nref must be called in any case for librt to function
82 * properly, this callback lets the parent application benefit from the
83 * work db_update_nref is already doing to figure out these relationships.
84 * */
85typedef void (*dbi_update_nref_t)(struct db_i *, struct directory *, struct directory *, const char *, db_op_t, matp_t, void *);
86
87/**
88 * One of these structures is used to describe each separate instance
89 * of a BRL-CAD model database ".g" file.
90 *
91 * dbi_filepath is a C-style argv array of places to search when
92 * opening related files (such as data files for EBM solids or
93 * texture-maps). The array and strings are all dynamically
94 * allocated.
95 *
96 * Note that the current working units are specified as a conversion
97 * factor to/from millimeters (they are the 'base' in local2base and
98 * base2local) because database dimensional values are always stored
99 * as millimeters (mm). The units conversion factor only affects the
100 * display and conversion of input values. This helps prevent error
101 * accumulation and improves numerical stability when calculations are
102 * made.
103 *
104 */
105struct db_i {
106 uint32_t dbi_magic; /**< @brief magic number */
107
108 /* THESE ELEMENTS ARE AVAILABLE FOR APPLICATIONS TO READ */
109
110 char * dbi_filename; /**< @brief file name */
111 int dbi_read_only; /**< @brief !0 => read only file */
112 double dbi_local2base; /**< @brief local2mm */
113 double dbi_base2local; /**< @brief unit conversion factors */
114 char * dbi_title; /**< @brief title from IDENT rec */
115 char ** dbi_filepath; /**< @brief search path for aux file opens (convenience var) */
116
117 /* THESE ELEMENTS ARE FOR LIBRT ONLY, AND MAY CHANGE */
118
119 struct directory * dbi_Head[RT_DBNHASH]; /** @brief PRIVATE: object hash table */
120 FILE * dbi_fp; /**< @brief PRIVATE: standard file pointer */
121 b_off_t dbi_eof; /**< @brief PRIVATE: End+1 pos after db_scan() */
122 size_t dbi_nrec; /**< @brief PRIVATE: # records after db_scan() */
123 int dbi_uses; /**< @brief PRIVATE: # of uses of this struct */
124 struct mem_map * dbi_freep; /**< @brief PRIVATE: map of free granules */
125 void *dbi_inmem; /**< @brief PRIVATE: ptr to in-memory copy */
126 struct animate * dbi_anroot; /**< @brief PRIVATE: heads list of anim at root lvl */
127 struct bu_mapped_file * dbi_mf; /**< @brief PRIVATE: Only in read-only mode */
128 struct bu_ptbl dbi_clients; /**< @brief PRIVATE: List of rtip's using this db_i */
129 int dbi_version; /**< @brief PRIVATE: use db_version() */
130 struct rt_wdb * dbi_wdbp; /**< @brief PRIVATE: disk rt_wdb */
131 struct rt_wdb * dbi_wdbp_a; /**< @brief PRIVATE: disk append-only rt_wdb */
132 struct rt_wdb * dbi_wdbp_inmem; /**< @brief PRIVATE: inmem rt_wdb */
133 struct rt_wdb * dbi_wdbp_inmem_a; /**< @brief PRIVATE: inmem append-only rt_wdb */
134 struct bu_ptbl dbi_changed_clbks; /**< @brief PRIVATE: dbi_changed_t callbacks registered with dbi */
135 struct bu_ptbl dbi_update_nref_clbks; /**< @brief PRIVATE: dbi_update_nref_t callbacks registered with dbi */
136 int dbi_use_comb_instance_ids; /**< @brief PRIVATE: flag to enable/disable comb instance tracking in full paths */
137};
138#define DBI_NULL ((struct db_i *)0)
139#define RT_CHECK_DBI(_p) BU_CKMAG(_p, DBI_MAGIC, "struct db_i")
140#define RT_CK_DBI(_p) RT_CHECK_DBI(_p)
141
142/* Functions for registering and unregistering callbacks with a dbip */
143extern RT_EXPORT int db_add_changed_clbk(struct db_i *dbip, dbi_changed_t c, void *u_data);
144extern RT_EXPORT int db_rm_changed_clbk(struct db_i *dbip, dbi_changed_t c, void *u_data);
145
146extern RT_EXPORT int db_add_update_nref_clbk(struct db_i *dbip, dbi_update_nref_t c, void *u_data);
147extern RT_EXPORT int db_rm_update_nref_clbk(struct db_i *dbip, dbi_update_nref_t c, void *u_data);
148
149__END_DECLS
150
151#endif /* RT_DB_INSTANCE_H */
152
153/*
154 * Local Variables:
155 * tab-width: 8
156 * mode: C
157 * indent-tabs-mode: t
158 * c-file-style: "stroustrup"
159 * End:
160 * ex: shiftwidth=4 tabstop=8
161 */
Header file for the BRL-CAD common definitions.
int db_rm_update_nref_clbk(struct db_i *dbip, dbi_update_nref_t c, void *u_data)
int db_add_changed_clbk(struct db_i *dbip, dbi_changed_t c, void *u_data)
void(* dbi_changed_t)(struct db_i *, struct directory *, int, void *)
Definition: db_instance.h:53
void(* dbi_update_nref_t)(struct db_i *, struct directory *, struct directory *, const char *, db_op_t, matp_t, void *)
Definition: db_instance.h:85
int db_rm_changed_clbk(struct db_i *dbip, dbi_changed_t c, void *u_data)
int db_add_update_nref_clbk(struct db_i *dbip, dbi_update_nref_t c, void *u_data)
void int * c
Definition: tig.h:139
#define b_off_t
Definition: common.h:222
#define RT_DBNHASH
hash table is an array of linked lists with this many array pointer elements (Memory use for 32-bit: ...
Definition: defines.h:148
fastf_t * matp_t
pointer to a 4x4 matrix
Definition: vmath.h:369
Global registry of recognized magic numbers.
db_op_t
Definition: op.h:55
Definition: anim.h:76
Definition: ptbl.h:53
b_off_t dbi_eof
PRIVATE: End+1 pos after db_scan()
Definition: db_instance.h:121
size_t dbi_nrec
PRIVATE: # records after db_scan()
Definition: db_instance.h:122
double dbi_base2local
unit conversion factors
Definition: db_instance.h:113
void * dbi_inmem
PRIVATE: ptr to in-memory copy.
Definition: db_instance.h:125
FILE * dbi_fp
PRIVATE: object hash table.
Definition: db_instance.h:120
int dbi_uses
PRIVATE: # of uses of this struct.
Definition: db_instance.h:123
char ** dbi_filepath
search path for aux file opens (convenience var)
Definition: db_instance.h:115
struct mem_map * dbi_freep
PRIVATE: map of free granules.
Definition: db_instance.h:124
struct rt_wdb * dbi_wdbp_a
PRIVATE: disk append-only rt_wdb.
Definition: db_instance.h:131
double dbi_local2base
local2mm
Definition: db_instance.h:112
struct rt_wdb * dbi_wdbp_inmem
PRIVATE: inmem rt_wdb.
Definition: db_instance.h:132
struct animate * dbi_anroot
PRIVATE: heads list of anim at root lvl.
Definition: db_instance.h:126
struct bu_mapped_file * dbi_mf
PRIVATE: Only in read-only mode.
Definition: db_instance.h:127
int dbi_read_only
!0 => read only file
Definition: db_instance.h:111
int dbi_version
PRIVATE: use db_version()
Definition: db_instance.h:129
char * dbi_filename
file name
Definition: db_instance.h:110
int dbi_use_comb_instance_ids
PRIVATE: flag to enable/disable comb instance tracking in full paths.
Definition: db_instance.h:136
struct bu_ptbl dbi_changed_clbks
PRIVATE: dbi_changed_t callbacks registered with dbi.
Definition: db_instance.h:134
struct bu_ptbl dbi_update_nref_clbks
PRIVATE: dbi_update_nref_t callbacks registered with dbi.
Definition: db_instance.h:135
struct directory * dbi_Head[RT_DBNHASH]
Definition: db_instance.h:119
struct rt_wdb * dbi_wdbp
PRIVATE: disk rt_wdb.
Definition: db_instance.h:130
struct rt_wdb * dbi_wdbp_inmem_a
PRIVATE: inmem append-only rt_wdb.
Definition: db_instance.h:133
uint32_t dbi_magic
magic number
Definition: db_instance.h:106
struct bu_ptbl dbi_clients
PRIVATE: List of rtip's using this db_i.
Definition: db_instance.h:128
char * dbi_title
title from IDENT rec
Definition: db_instance.h:114
Definition: mem.h:37
Definition: wdb.h:62