BRL-CAD
Loading...
Searching...
No Matches
directory.h
Go to the documentation of this file.
1/* D I R E C T O R Y . H
2 * BRL-CAD
3 *
4 * Copyright (c) 1993-2025 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 directory.h
21 *
22 */
23
24#ifndef RT_DIRECTORY_H
25#define RT_DIRECTORY_H
26
27#include "common.h"
28#include "vmath.h"
29#include "bu/list.h"
30#include "rt/anim.h"
31
33
34/**
35 * One of these structures is allocated in memory to represent each
36 * named object in the database.
37 *
38 * Note that a d_addr of RT_DIR_PHONY_ADDR ((b_off_t)-1) means that
39 * database storage has not been allocated yet.
40 *
41 * Note that there is special handling for RT_DIR_INMEM "in memory"
42 * overrides.
43 *
44 * Construction should be done only by using RT_GET_DIRECTORY()
45 * Destruction should be done only by using db_dirdelete().
46 *
47 * Special note: In order to reduce the overhead of acquiring heap
48 * memory (e.g., via bu_strdup()) to stash the name in d_namep, we
49 * carry along enough storage for small names right in the structure
50 * itself (d_shortname). Thus, d_namep should never be assigned to
51 * directly, it should always be accessed using RT_DIR_SET_NAMEP() and
52 * RT_DIR_FREE_NAMEP().
53 *
54 * The in-memory name of an object should only be changed using
55 * db_rename(), so that it can be requeued on the correct linked list,
56 * based on new hash. This should be followed by rt_db_put_internal()
57 * on the object to modify the on-disk name.
58 *
59 * Note that d_minor_type and the corresponding idb_minor_type of an
60 * rt_db_internal associated with a given directory structure should match.
61 */
62struct directory {
63 uint32_t d_magic; /**< @brief Magic number */
64 char * d_namep; /**< @brief pointer to name string */
65 union {
66 b_off_t file_offset; /**< @brief disk address in obj file */
67 void *ptr; /**< @brief ptr to in-memory-only obj */
69 struct directory * d_forw; /**< @brief link to next dir entry */
70 struct animate * d_animate; /**< @brief link to animation */
71 long d_uses; /**< @brief number of uses, from instancing */
72 size_t d_len; /**< @brief number of of db granules used */
73 long d_nref; /**< @brief number of times ref'ed by COMBs */
74 int d_flags; /**< @brief flags */
75 unsigned char d_major_type; /**< @brief object major type */
76 unsigned char d_minor_type; /**< @brief object minor type */
77 struct bu_list d_use_hd; /**< @brief heads list of uses (struct soltab l2) */
78 char d_shortname[16]; /**< @brief Stash short names locally */
79 void *u_data; /**< @brief void pointer hook for user data. user is responsible for freeing. */
80};
81#define RT_DIR_NULL ((struct directory *)0)
82#define RT_CK_DIR(_dp) BU_CKMAG(_dp, RT_DIR_MAGIC, "(librt)directory")
83
84#define d_addr d_un.file_offset
85#define RT_DIR_PHONY_ADDR ((b_off_t)-1) /**< @brief Special marker for d_addr field */
86
87/* flags for db_diradd() and friends */
88#define RT_DIR_SOLID 0x1 /**< @brief this name is a solid */
89#define RT_DIR_COMB 0x2 /**< @brief combination */
90#define RT_DIR_REGION 0x4 /**< @brief region */
91#define RT_DIR_HIDDEN 0x8 /**< @brief object name is hidden */
92#define RT_DIR_NON_GEOM 0x10 /**< @brief object is not geometry (e.g. binary object) */
93#define RT_DIR_USED 0x80 /**< @brief One bit, used similar to d_nref */
94#define RT_DIR_INMEM 0x100 /**< @brief object is in memory (only) */
95
96/**< @brief Args to db_lookup() */
97#define LOOKUP_NOISY 1
98#define LOOKUP_QUIET 0
99
100#define FOR_ALL_DIRECTORY_START(_dp, _dbip) { int _i; \
101 for (_i = RT_DBNHASH-1; _i >= 0; _i--) { \
102 for ((_dp) = (_dbip)->dbi_Head[_i]; (_dp); (_dp) = (_dp)->d_forw) {
103
104#define FOR_ALL_DIRECTORY_END }}}
105
106#define RT_DIR_SET_NAMEP(_dp, _name) { \
107 if (strlen(_name) < sizeof((_dp)->d_shortname)) {\
108 bu_strlcpy((_dp)->d_shortname, (_name), sizeof((_dp)->d_shortname)); \
109 (_dp)->d_namep = (_dp)->d_shortname; \
110 } else { \
111 (_dp)->d_namep = bu_strdup(_name); /* Calls bu_malloc() */ \
112 } }
113
114
115/**
116 * Use this macro to free the d_namep member, which is sometimes not
117 * dynamic.
118 */
119#define RT_DIR_FREE_NAMEP(_dp) { \
120 if ((_dp)->d_namep != (_dp)->d_shortname) \
121 bu_free((_dp)->d_namep, "d_namep"); \
122 (_dp)->d_namep = NULL; }
123
124
125/**
126 * allocate and link in a new directory entry to the resource
127 * structure's freelist
128 */
129#define RT_GET_DIRECTORY(_p, _res) { \
130 while (((_p) = (_res)->re_directory_hd) == NULL) \
131 db_alloc_directory_block(_res); \
132 (_res)->re_directory_hd = (_p)->d_forw; \
133 (_p)->d_forw = NULL; }
134
135
136/**
137 * convert an argv list of names to a directory pointer array.
138 *
139 * If db_lookup fails for any individual argv, an empty directory
140 * structure is created and assigned the name and RT_DIR_PHONY_ADDR
141 *
142 * The returned directory ** structure is NULL terminated.
143 */
144RT_EXPORT extern struct directory **db_argv_to_dpv(const struct db_i *dbip,
145 const char **argv);
146
147
148/**
149 * convert a directory pointer array to an argv char pointer array.
150 */
151RT_EXPORT extern char **db_dpv_to_argv(struct directory **dpv);
152
153
154
156
157#endif /* RT_DIRECTORY_H */
158
159/*
160 * Local Variables:
161 * tab-width: 8
162 * mode: C
163 * indent-tabs-mode: t
164 * c-file-style: "stroustrup"
165 * End:
166 * ex: shiftwidth=4 tabstop=8
167 */
Definition dvec.h:74
Header file for the BRL-CAD common definitions.
struct directory ** db_argv_to_dpv(const struct db_i *dbip, const char **argv)
char ** db_dpv_to_argv(struct directory **dpv)
#define b_off_t
Definition common.h:223
Definition anim.h:76
union directory::@11 d_un
char * d_namep
pointer to name string
Definition directory.h:64
int d_flags
flags
Definition directory.h:74
uint32_t d_magic
Magic number.
Definition directory.h:63
b_off_t file_offset
disk address in obj file
Definition directory.h:66
char d_shortname[16]
Stash short names locally.
Definition directory.h:78
unsigned char d_minor_type
object minor type
Definition directory.h:76
long d_nref
number of times ref'ed by COMBs
Definition directory.h:73
size_t d_len
number of of db granules used
Definition directory.h:72
struct animate * d_animate
link to animation
Definition directory.h:70
void * u_data
void pointer hook for user data. user is responsible for freeing.
Definition directory.h:79
struct bu_list d_use_hd
heads list of uses (struct soltab l2)
Definition directory.h:77
unsigned char d_major_type
object major type
Definition directory.h:75
void * ptr
ptr to in-memory-only obj
Definition directory.h:67
struct directory * d_forw
link to next dir entry
Definition directory.h:69
long d_uses
number of uses, from instancing
Definition directory.h:71
fundamental vector, matrix, quaternion math macros