BRL-CAD
db_fullpath.h
Go to the documentation of this file.
1/* D B _ F U L L P A T H . H
2 * BRL-CAD
3 *
4 * Copyright (c) 2014-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
21#ifndef RT_DB_FULLPATH_H
22#define RT_DB_FULLPATH_H
23
24#include "common.h"
25
26#include "vmath.h"
27
28#include "bu/color.h"
29#include "bu/vls.h"
30#include "rt/defines.h"
31
32__BEGIN_DECLS
33
34struct resource; /* forward declaration */
35struct db_i; /* forward declaration */
36struct directory; /* forward declaration */
37
38/** @addtogroup db_fullpath
39 *
40 * @brief
41 * Structures and routines for collecting and manipulating paths through the database tree.
42 *
43 */
44/** @{ */
45/** @file rt/db_fullpath.h */
46
47/**
48 * The fp_bool array can optionally hold a boolean flag
49 * associated with each corresponding dp in fp_names. This
50 * array must be manually maintained by the client code in
51 * order for it to have valid data - many functions using
52 * full paths (for example, conversion from strings) don't
53 * have knowledge of a specific boolean tree.
54 */
56 uint32_t magic;
57 size_t fp_len;
58 size_t fp_maxlen;
59 struct directory ** fp_names; /**< @brief array of dir pointers */
60 int * fp_bool; /**< @brief array of boolean flags */
61 int * fp_cinst; /**< @brief array of comb tree instance specifiers */
62};
63#define RT_CK_FULL_PATH(_p) BU_CKMAG(_p, DB_FULL_PATH_MAGIC, "db_full_path")
64
65#define DB_FULL_PATH_CUR_DIR(_pp) (((_pp)->fp_len > 0) ? (_pp)->fp_names[(_pp)->fp_len-1] : NULL)
66#define DB_FULL_PATH_CUR_BOOL(_pp) ((_pp)->fp_bool[(_pp)->fp_len-1])
67#define DB_FULL_PATH_SET_CUR_BOOL(_pp, _i) ((_pp)->fp_bool[(_pp)->fp_len-1]) = _i
68
69#define DB_FULL_PATH_CUR_COMB_INST(_pp) ((_pp)->fp_cinst[(_pp)->fp_len-1])
70#define DB_FULL_PATH_SET_CUR_COMB_INST(_pp, _i) ((_pp)->fp_cinst[(_pp)->fp_len-1]) = _i
71
72#define DB_FULL_PATH_LEN(_pp) ((_pp)->fp_len)
73#define DB_FULL_PATH_POP(_pp) ((_pp)->fp_len > 0) ? (_pp)->fp_len-- : (_pp)->fp_len
74
75#define DB_FULL_PATH_GET(_pp, _i) ((_pp)->fp_names[(_i)])
76#define DB_FULL_PATH_GET_BOOL(_pp, _i) ((_pp)->fp_bool[(_i)])
77#define DB_FULL_PATH_SET_BOOL(_pp, _i, _j) ((_pp)->fp_bool[(_i)] = _j)
78#define DB_FULL_PATH_GET_COMB_INST(_pp, _i) ((_pp)->fp_cinst[(_i)])
79#define DB_FULL_PATH_SET_COMB_INST(_pp, _i, _j) ((_pp)->fp_cinst[(_i)] = _j)
80
81#define DB_FULL_PATH_ROOT_DIR(_pp) ((_pp)->fp_names[0])
82
83
84
85/* db_fullpath.c */
86RT_EXPORT extern void db_full_path_init(struct db_full_path *pathp);
87
88RT_EXPORT extern void db_add_node_to_full_path(struct db_full_path *pp,
89 struct directory *dp);
90
91RT_EXPORT extern void db_dup_full_path(struct db_full_path *newp,
92 const struct db_full_path *oldp);
93
94/**
95 * Extend "pathp" so that it can grow from current fp_len by incr more names.
96 *
97 * This is intended primarily as an internal method.
98 */
99RT_EXPORT extern void db_extend_full_path(struct db_full_path *pathp,
100 size_t incr);
101
102RT_EXPORT extern void db_append_full_path(struct db_full_path *dest,
103 const struct db_full_path *src);
104
105/**
106 * Dup old path from starting index to end.
107 */
108RT_EXPORT extern void db_dup_path_tail(struct db_full_path *newp,
109 const struct db_full_path *oldp,
110 b_off_t start);
111
112
113/**
114 * Unlike rt_path_str(), this version can be used in parallel.
115 * Caller is responsible for freeing the returned buffer.
116 */
117RT_EXPORT extern char *db_path_to_string(const struct db_full_path *pp);
118
119/**
120 * Append a string representation of the path onto the vls. Must have
121 * exactly the same formatting conventions as db_path_to_string().
122 */
123RT_EXPORT extern void db_path_to_vls(struct bu_vls *str,
124 const struct db_full_path *pp);
125
126/**
127 * Append a string representation of the path onto the vls, with
128 * options to decorate nodes with additional information.
129 */
130#define DB_FP_PRINT_BOOL 0x1 /* print boolean operations */
131#define DB_FP_PRINT_TYPE 0x2 /* print object types */
132#define DB_FP_PRINT_MATRIX 0x4 /* print notice that a matrix is present */
133#define DB_FP_PRINT_COMB_INDEX 0x8 /* print non-zero comb tree instance specifiers */
134RT_EXPORT extern void db_fullpath_to_vls(struct bu_vls *vls,
135 const struct db_full_path *full_path,
136 const struct db_i *dbip, /* needed for type determination */
137 int fp_flags);
138
139
140RT_EXPORT extern void db_pr_full_path(const char *msg,
141 const struct db_full_path *pathp);
142
143
144/**
145 * Reverse the effects of db_path_to_string().
146 *
147 * The db_full_path structure will be initialized. If it was already
148 * in use, user should call db_free_full_path() first.
149 *
150 * Returns -
151 * -1 One or more components of path did not exist in the directory.
152 * 0 OK
153 */
154RT_EXPORT extern int db_string_to_path(struct db_full_path *pp,
155 const struct db_i *dbip,
156 const char *str);
157
158
159/**
160 * Treat elements from argv[0] to argv[argc-1] as a path specification.
161 *
162 * The path structure will be fully initialized. If it was already in
163 * use, user should call db_free_full_path() first.
164 *
165 * Returns -
166 * -1 One or more components of path did not exist in the directory.
167 * 0 OK
168 */
169RT_EXPORT extern int db_argv_to_path(struct db_full_path *pp,
170 struct db_i *dbip,
171 int argc,
172 const char *const*argv);
173
174
175/**
176 * Free the contents of the db_full_path structure, but not the
177 * structure itself, which might be automatic.
178 */
179RT_EXPORT extern void db_free_full_path(struct db_full_path *pp);
180
181
182/**
183 * Returns -
184 * 1 match
185 * 0 different
186 */
187RT_EXPORT extern int db_identical_full_paths(const struct db_full_path *a,
188 const struct db_full_path *b);
189
190
191/**
192 * Returns -
193 * 1 if 'b' is a proper subset of 'a'
194 * 0 if not.
195 */
196RT_EXPORT extern int db_full_path_subset(const struct db_full_path *a,
197 const struct db_full_path *b,
198 const int skip_first);
199
200/**
201 * Returns -
202 * 1 if 'a' matches the top part of 'b'
203 * 0 if not.
204 *
205 * For example, /a/b matches both the top part of /a/b/c and /a/b.
206 */
207RT_EXPORT extern int db_full_path_match_top(const struct db_full_path *a,
208 const struct db_full_path *b);
209
210
211/**
212 * Returns -
213 * 1 'dp' is found on this path
214 * 0 not found
215 */
216RT_EXPORT extern int db_full_path_search(const struct db_full_path *a,
217 const struct directory *dp);
218
219
220/**
221 * Function to test whether a path has a cyclic entry in it.
222 *
223 * @param fp [i] Full path to test
224 * @param lname [i] String to use when checking path (optional). If NULL, use the name of the current directory pointer in fp.
225 * @param full_check [i] Flag to instruct the cyclic test to check using all directory pointers in fp, not just the lname/current dp test.
226 * @return 1 if the path is cyclic, 0 if it is not.
227 *
228 * By default, only the leaf (or test_name if supplied) will be used to test if
229 * the path is cyclic. If full_check is set, all object names in the path will
230 * be checked, as well as lname if set. This more expensive check is not
231 * necessary if calling code is checking for cyclic paths as paths are being
232 * built, but is necessary to fully "clear" a db_full_path from an arbitrary
233 * source. Calling code must use its knowledge of the origins of the full path
234 * (or lack thereof) to determine how much validation work is needed.
235 */
236RT_EXPORT extern int db_full_path_cyclic(const struct db_full_path *fp, const char *lname, int full_check);
237
238/**
239 * Build the transformation matrix obtained when traversing the path
240 * to the specified depth.
241 *
242 * Returns -
243 * 1 OK, path matrix written into 'mat'.
244 * 0 FAIL
245 *
246 * Called in librt/db_tree.c, mged/dodraw.c, and mged/animedit.c
247 */
248RT_EXPORT extern int db_path_to_mat(struct db_i *dbip,
249 struct db_full_path *pathp,
250 mat_t mat, /* result */
251 int depth, /* number of arcs */
252 struct resource *resp);
253
254/**
255 * For a given path, return the "net" boolean operation of the
256 * path. If a subtraction is found along the path, overall path
257 * is regarded as a subtraction. Else, if an intersection is found
258 * op is reported as an intersection. Else, union is reported.
259 */
260RT_EXPORT extern int
261db_fp_op(const struct db_full_path *pathp,
262 struct db_i *dbip,
263 int depth, /* number of arcs - 0 == all */
264 struct resource *resp);
265
266/**
267 * Determine the color operative at the current directory pointer (the leaf
268 * node) of the path according to available information and rules.
269 *
270 * If nothing can be determined default color is set.
271 */
272RT_EXPORT extern void db_full_path_color(struct bu_color *c,
273 struct db_full_path *pathp,
274 struct db_i *dbip,
275 struct resource *resp);
276
277
278/** @} */
279
280__END_DECLS
281
282#endif /*RT_DB_FULLPATH_H*/
283
284/*
285 * Local Variables:
286 * tab-width: 8
287 * mode: C
288 * indent-tabs-mode: t
289 * c-file-style: "stroustrup"
290 * End:
291 * ex: shiftwidth=4 tabstop=8
292 */
Header file for the BRL-CAD common definitions.
void int * c
Definition: tig.h:139
#define b_off_t
Definition: common.h:222
void db_pr_full_path(const char *msg, const struct db_full_path *pathp)
void db_add_node_to_full_path(struct db_full_path *pp, struct directory *dp)
void db_extend_full_path(struct db_full_path *pathp, size_t incr)
int db_full_path_subset(const struct db_full_path *a, const struct db_full_path *b, const int skip_first)
int db_full_path_cyclic(const struct db_full_path *fp, const char *lname, int full_check)
void db_fullpath_to_vls(struct bu_vls *vls, const struct db_full_path *full_path, const struct db_i *dbip, int fp_flags)
void db_dup_full_path(struct db_full_path *newp, const struct db_full_path *oldp)
int db_fp_op(const struct db_full_path *pathp, struct db_i *dbip, int depth, struct resource *resp)
void db_dup_path_tail(struct db_full_path *newp, const struct db_full_path *oldp, b_off_t start)
int db_string_to_path(struct db_full_path *pp, const struct db_i *dbip, const char *str)
void db_path_to_vls(struct bu_vls *str, const struct db_full_path *pp)
int db_full_path_search(const struct db_full_path *a, const struct directory *dp)
int db_argv_to_path(struct db_full_path *pp, struct db_i *dbip, int argc, const char *const *argv)
void db_full_path_init(struct db_full_path *pathp)
char * db_path_to_string(const struct db_full_path *pp)
int db_path_to_mat(struct db_i *dbip, struct db_full_path *pathp, mat_t mat, int depth, struct resource *resp)
int db_identical_full_paths(const struct db_full_path *a, const struct db_full_path *b)
void db_free_full_path(struct db_full_path *pp)
void db_full_path_color(struct bu_color *c, struct db_full_path *pathp, struct db_i *dbip, struct resource *resp)
int db_full_path_match_top(const struct db_full_path *a, const struct db_full_path *b)
void db_append_full_path(struct db_full_path *dest, const struct db_full_path *src)
fastf_t mat_t[ELEMENTS_PER_MAT]
4x4 matrix
Definition: vmath.h:366
Definition: color.h:54
Definition: vls.h:53
size_t fp_len
Definition: db_fullpath.h:57
int * fp_cinst
array of comb tree instance specifiers
Definition: db_fullpath.h:61
int * fp_bool
array of boolean flags
Definition: db_fullpath.h:60
uint32_t magic
Definition: db_fullpath.h:56
size_t fp_maxlen
Definition: db_fullpath.h:58
struct directory ** fp_names
array of dir pointers
Definition: db_fullpath.h:59
fundamental vector, matrix, quaternion math macros