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-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
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};
62#define RT_CK_FULL_PATH(_p) BU_CKMAG(_p, DB_FULL_PATH_MAGIC, "db_full_path")
63
64#define DB_FULL_PATH_CUR_DIR(_pp) (((_pp)->fp_len > 0) ? (_pp)->fp_names[(_pp)->fp_len-1] : NULL)
65#define DB_FULL_PATH_CUR_BOOL(_pp) ((_pp)->fp_bool[(_pp)->fp_len-1])
66#define DB_FULL_PATH_SET_CUR_BOOL(_pp, _i) ((_pp)->fp_bool[(_pp)->fp_len-1]) = _i
67
68#define DB_FULL_PATH_LEN(_pp) ((_pp)->fp_len)
69#define DB_FULL_PATH_POP(_pp) ((_pp)->fp_len > 0) ? (_pp)->fp_len-- : (_pp)->fp_len
70
71#define DB_FULL_PATH_GET(_pp, _i) ((_pp)->fp_names[(_i)])
72#define DB_FULL_PATH_GET_BOOL(_pp, _i) ((_pp)->fp_bool[(_i)])
73#define DB_FULL_PATH_SET_BOOL(_pp, _i, _j) ((_pp)->fp_bool[(_i)] = _j)
74
75#define DB_FULL_PATH_ROOT_DIR(_pp) ((_pp)->fp_names[0])
76
77
78
79/* db_fullpath.c */
80RT_EXPORT extern void db_full_path_init(struct db_full_path *pathp);
81
82RT_EXPORT extern void db_add_node_to_full_path(struct db_full_path *pp,
83 struct directory *dp);
84
85RT_EXPORT extern void db_dup_full_path(struct db_full_path *newp,
86 const struct db_full_path *oldp);
87
88/**
89 * Extend "pathp" so that it can grow from current fp_len by incr more names.
90 *
91 * This is intended primarily as an internal method.
92 */
93RT_EXPORT extern void db_extend_full_path(struct db_full_path *pathp,
94 size_t incr);
95
96RT_EXPORT extern void db_append_full_path(struct db_full_path *dest,
97 const struct db_full_path *src);
98
99/**
100 * Dup old path from starting index to end.
101 */
102RT_EXPORT extern void db_dup_path_tail(struct db_full_path *newp,
103 const struct db_full_path *oldp,
104 b_off_t start);
105
106
107/**
108 * Unlike rt_path_str(), this version can be used in parallel.
109 * Caller is responsible for freeing the returned buffer.
110 */
111RT_EXPORT extern char *db_path_to_string(const struct db_full_path *pp);
112
113/**
114 * Append a string representation of the path onto the vls. Must have
115 * exactly the same formatting conventions as db_path_to_string().
116 */
117RT_EXPORT extern void db_path_to_vls(struct bu_vls *str,
118 const struct db_full_path *pp);
119
120/**
121 * Append a string representation of the path onto the vls, with
122 * options to decorate nodes with additional information.
123 */
124#define DB_FP_PRINT_BOOL 0x1 /* print boolean operations */
125#define DB_FP_PRINT_TYPE 0x2 /* print object types */
126#define DB_FP_PRINT_MATRIX 0x4 /* print notice that a matrix is present */
127RT_EXPORT extern void db_fullpath_to_vls(struct bu_vls *vls,
128 const struct db_full_path *full_path,
129 const struct db_i *dbip, /* needed for type determination */
130 int fp_flags);
131
132
133RT_EXPORT extern void db_pr_full_path(const char *msg,
134 const struct db_full_path *pathp);
135
136
137/**
138 * Reverse the effects of db_path_to_string().
139 *
140 * The db_full_path structure will be initialized. If it was already
141 * in use, user should call db_free_full_path() first.
142 *
143 * Returns -
144 * -1 One or more components of path did not exist in the directory.
145 * 0 OK
146 */
147RT_EXPORT extern int db_string_to_path(struct db_full_path *pp,
148 const struct db_i *dbip,
149 const char *str);
150
151
152/**
153 * Treat elements from argv[0] to argv[argc-1] as a path specification.
154 *
155 * The path structure will be fully initialized. If it was already in
156 * use, user should call db_free_full_path() first.
157 *
158 * Returns -
159 * -1 One or more components of path did not exist in the directory.
160 * 0 OK
161 */
162RT_EXPORT extern int db_argv_to_path(struct db_full_path *pp,
163 struct db_i *dbip,
164 int argc,
165 const char *const*argv);
166
167
168/**
169 * Free the contents of the db_full_path structure, but not the
170 * structure itself, which might be automatic.
171 */
172RT_EXPORT extern void db_free_full_path(struct db_full_path *pp);
173
174
175/**
176 * Returns -
177 * 1 match
178 * 0 different
179 */
180RT_EXPORT extern int db_identical_full_paths(const struct db_full_path *a,
181 const struct db_full_path *b);
182
183
184/**
185 * Returns -
186 * 1 if 'b' is a proper subset of 'a'
187 * 0 if not.
188 */
189RT_EXPORT extern int db_full_path_subset(const struct db_full_path *a,
190 const struct db_full_path *b,
191 const int skip_first);
192
193/**
194 * Returns -
195 * 1 if 'a' matches the top part of 'b'
196 * 0 if not.
197 *
198 * For example, /a/b matches both the top part of /a/b/c and /a/b.
199 */
200RT_EXPORT extern int db_full_path_match_top(const struct db_full_path *a,
201 const struct db_full_path *b);
202
203
204/**
205 * Returns -
206 * 1 'dp' is found on this path
207 * 0 not found
208 */
209RT_EXPORT extern int db_full_path_search(const struct db_full_path *a,
210 const struct directory *dp);
211
212
213/**
214 * Function to test whether a path has a cyclic entry in it.
215 *
216 * @param fp [i] Full path to test
217 * @param lname [i] String to use when checking path (optional). If NULL, use the name of the current directory pointer in fp.
218 * @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.
219 * @return 1 if the path is cyclic, 0 if it is not.
220 *
221 * By default, only the leaf (or test_name if supplied) will be used to test if
222 * the path is cyclic. If full_check is set, all object names in the path will
223 * be checked, as well as lname if set. This more expensive check is not
224 * necessary if calling code is checking for cyclic paths as paths are being
225 * built, but is necessary to fully "clear" a db_full_path from an arbitrary
226 * source. Calling code must use its knowledge of the origins of the full path
227 * (or lack thereof) to determine how much validation work is needed.
228 */
229RT_EXPORT extern int db_full_path_cyclic(const struct db_full_path *fp, const char *lname, int full_check);
230
231/**
232 * Build the transformation matrix obtained when traversing the path
233 * to the specified depth.
234 *
235 * Returns -
236 * 1 OK, path matrix written into 'mat'.
237 * 0 FAIL
238 *
239 * Called in librt/db_tree.c, mged/dodraw.c, and mged/animedit.c
240 */
241RT_EXPORT extern int db_path_to_mat(struct db_i *dbip,
242 struct db_full_path *pathp,
243 mat_t mat, /* result */
244 int depth, /* number of arcs */
245 struct resource *resp);
246
247/**
248 * Determine the color operative at the current directory pointer (the leaf
249 * node) of the path according to available information and rules.
250 *
251 * If nothing can be determined default color is set.
252 */
253RT_EXPORT extern void db_full_path_color(struct bu_color *c,
254 struct db_full_path *pathp,
255 struct db_i *dbip,
256 struct resource *resp);
257
258
259/** @} */
260
261__END_DECLS
262
263#endif /*RT_DB_FULLPATH_H*/
264
265/*
266 * Local Variables:
267 * tab-width: 8
268 * mode: C
269 * indent-tabs-mode: t
270 * c-file-style: "stroustrup"
271 * End:
272 * ex: shiftwidth=4 tabstop=8
273 */
Header file for the BRL-CAD common definitions.
void int * c
Definition: tig.h:139
#define b_off_t
Definition: common.h:231
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)
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_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