BRL-CAD
Loading...
Searching...
No Matches
db_internal.h
Go to the documentation of this file.
1/* D B _ I N T E R N A L . H
2 * BRL-CAD
3 *
4 * Copyright (c) 1993-2026 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_internal.h
21 *
22 */
23
24#ifndef RT_DB_INTERNAL_H
25#define RT_DB_INTERNAL_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/avs.h"
35#include "bn/mat.h"
36#include "rt/defines.h"
37
39
40struct rt_functab; /* forward declaration */
41struct db_i; /* forward declaration */
42struct directory; /* forward declaration */
43
44/**
45 * A handle on the internal format of a BRL-CAD database object.
46 *
47 * Note that the d_minor_type of any directory structure associated with a rt_db_internal should
48 * match the value of the rt_db_internal's idb_minor_type.
49 *
50 * TODO - right now, rt_db_internal doesn't encode any notion of data version,
51 * which appears to be a major reason some APIs need to pass a dbip through in
52 * addition to the rt_db_internal. Should we add an idb_version entry here to
53 * indicate idb_ptr data versioning?
54 */
55struct rt_db_internal {
58 int idb_minor_type; /**< @brief ID_xxx */
59 const struct rt_functab *idb_meth; /**< @brief for ft_ifree(), etc. */
60 void * idb_ptr;
62};
63#define idb_type idb_minor_type
64#define RT_DB_INTERNAL_INIT(_p) { \
65 (_p)->idb_magic = RT_DB_INTERNAL_MAGIC; \
66 (_p)->idb_major_type = -1; \
67 (_p)->idb_minor_type = -1; \
68 (_p)->idb_meth = (const struct rt_functab *) ((void *)0); \
69 (_p)->idb_ptr = ((void *)0); \
70 bu_avs_init_empty(&(_p)->idb_avs); \
71 }
72#define RT_DB_INTERNAL_INIT_ZERO {RT_DB_INTERNAL_MAGIC, -1, -1, NULL, NULL, BU_AVS_INIT_ZERO}
73#define RT_CK_DB_INTERNAL(_p) BU_CKMAG(_p, RT_DB_INTERNAL_MAGIC, "rt_db_internal")
75/**
76 * Get an object from the database, and convert it into its internal
77 * (i.e., unserialized in-memory) representation. Applies the
78 * provided matrix transform only to the in-memory internal being
79 * returned.
80 *
81 * Returns -
82 * <0 On error
83 * id On success.
84 */
86 const struct directory *dp,
87 const struct db_i *dbip,
88 const mat_t mat);
89
90/**
91 * Convert the internal representation of a solid to the external one,
92 * and write it into the database. On success only, the internal
93 * representation is freed.
94 *
95 * Returns -
96 * <0 error
97 * 0 success
98 */
99RT_EXPORT extern int rt_db_put_internal(struct directory *dp,
100 struct db_i *dbip,
101 struct rt_db_internal *ip);
102
103/**
104 * Put an object in internal format out onto a file in external
105 * format. Used by LIBWDB.
106 *
107 * Can't really require a dbip parameter, as many callers won't have
108 * one.
109 *
110 * THIS ROUTINE ONLY SUPPORTS WRITING V4 GEOMETRY.
111 *
112 * Returns -
113 * 0 OK
114 * <0 error
115 */
116RT_EXPORT extern int rt_fwrite_internal(FILE *fp,
117 const char *name,
118 const struct rt_db_internal *ip,
119 double conv2mm);
122/**
123 * Convert an object name to a rt_db_internal pointer
124 *
125 * Looks up the named object in the directory of the specified model,
126 * obtaining a directory pointer. Then gets that object from the
127 * database and constructs its internal representation. Returns
128 * ID_NULL on error, otherwise returns the type of the object.
129 */
130RT_EXPORT extern int rt_db_lookup_internal(struct db_i *dbip,
131 const char *obj_name,
132 struct directory **dpp,
133 struct rt_db_internal *ip,
134 int noisy);
135
136
137
139
140#endif /* RT_DB_INTERNAL_H */
141
142/*
143 * Local Variables:
144 * tab-width: 8
145 * mode: C
146 * indent-tabs-mode: t
147 * c-file-style: "stroustrup"
148 * End:
149 * ex: shiftwidth=4 tabstop=8
150 */
Definition dvec.h:74
Header file for the BRL-CAD common definitions.
int rt_fwrite_internal(FILE *fp, const char *name, const struct rt_db_internal *ip, double conv2mm)
void rt_db_free_internal(struct rt_db_internal *ip)
int rt_db_lookup_internal(struct db_i *dbip, const char *obj_name, struct directory **dpp, struct rt_db_internal *ip, int noisy)
int rt_db_get_internal(struct rt_db_internal *ip, const struct directory *dp, const struct db_i *dbip, const mat_t mat)
int rt_db_put_internal(struct directory *dp, struct db_i *dbip, struct rt_db_internal *ip)
fastf_t mat_t[ELEMENTS_PER_MAT]
4x4 matrix
Definition vmath.h:369
Global registry of recognized magic numbers.
struct bu_attribute_value_set idb_avs
Definition db_internal.h:62
uint32_t idb_magic
Definition db_internal.h:57
const struct rt_functab * idb_meth
for ft_ifree(), etc.
Definition db_internal.h:60
int idb_minor_type
ID_xxx.
Definition db_internal.h:59