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