BRL-CAD
objects.h
Go to the documentation of this file.
1/* O B J E C T S . H
2 * BRL-CAD
3 *
4 * Copyright (c) 2008-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/** @addtogroup ged_objects
21 *
22 * Geometry EDiting Library Database Generic Object Functions.
23 *
24 * These are functions that operate on database objects.
25 */
26/** @{ */
27/** @file ged/objects.h */
28
29#ifndef GED_OBJECTS_H
30#define GED_OBJECTS_H
31
32#include "common.h"
33#include "ged/defines.h"
34
35__BEGIN_DECLS
36
37/** Check if the object is a combination */
38#define GED_CHECK_COMB(_gedp, _dp, _flags) \
39 if (((_dp)->d_flags & RT_DIR_COMB) == 0) { \
40 int ged_check_comb_quiet = (_flags) & GED_QUIET; \
41 if (!ged_check_comb_quiet) { \
42 bu_vls_printf((_gedp)->ged_result_str, "%s is not a combination", (_dp)->d_namep); \
43 } \
44 return (_flags); \
45 }
46
47/** Lookup database object */
48#define GED_CHECK_EXISTS(_gedp, _name, _noisy, _flags) \
49 if (db_lookup((_gedp)->dbip, (_name), (_noisy)) != RT_DIR_NULL) { \
50 int ged_check_exists_quiet = (_flags) & GED_QUIET; \
51 if (!ged_check_exists_quiet) { \
52 bu_vls_printf((_gedp)->ged_result_str, "%s already exists.", (_name)); \
53 } \
54 return (_flags); \
55 }
56
57/** Check if the database is read only */
58#define GED_CHECK_READ_ONLY(_gedp, _flags) \
59 if ((_gedp)->dbip->dbi_read_only) { \
60 int ged_check_read_only_quiet = (_flags) & GED_QUIET; \
61 if (!ged_check_read_only_quiet) { \
62 bu_vls_trunc((_gedp)->ged_result_str, 0); \
63 bu_vls_printf((_gedp)->ged_result_str, "Sorry, this database is READ-ONLY."); \
64 } \
65 return (_flags); \
66 }
67
68/** Check if the object is a region */
69#define GED_CHECK_REGION(_gedp, _dp, _flags) \
70 if (((_dp)->d_flags & RT_DIR_REGION) == 0) { \
71 int ged_check_region_quiet = (_flags) & GED_QUIET; \
72 if (!ged_check_region_quiet) { \
73 bu_vls_printf((_gedp)->ged_result_str, "%s is not a region.", (_dp)->d_namep); \
74 } \
75 return (_flags); \
76 }
77
78/** add a new directory entry to the currently open database */
79#define GED_DB_DIRADD(_gedp, _dp, _name, _laddr, _len, _dirflags, _ptr, _flags) \
80 if (((_dp) = db_diradd((_gedp)->dbip, (_name), (_laddr), (_len), (_dirflags), (_ptr))) == RT_DIR_NULL) { \
81 int ged_db_diradd_quiet = (_flags) & GED_QUIET; \
82 if (!ged_db_diradd_quiet) { \
83 bu_vls_printf((_gedp)->ged_result_str, "Unable to add %s to the database.", (_name)); \
84 } \
85 return (_flags); \
86 }
87
88/** Lookup database object */
89#define GED_DB_LOOKUP(_gedp, _dp, _name, _noisy, _flags) \
90 if (((_dp) = db_lookup((_gedp)->dbip, (_name), (_noisy))) == RT_DIR_NULL) { \
91 int ged_db_lookup_quiet = (_flags) & GED_QUIET; \
92 if (!ged_db_lookup_quiet) { \
93 bu_vls_printf((_gedp)->ged_result_str, "Unable to find %s in the database.", (_name)); \
94 } \
95 return (_flags); \
96 }
97
98/** Get internal representation */
99#define GED_DB_GET_INTERNAL(_gedp, _intern, _dp, _mat, _resource, _flags) \
100 if (rt_db_get_internal((_intern), (_dp), (_gedp)->dbip, (_mat), (_resource)) < 0) { \
101 int ged_db_get_internal_quiet = (_flags) & GED_QUIET; \
102 if (!ged_db_get_internal_quiet) { \
103 bu_vls_printf((_gedp)->ged_result_str, "Database read failure."); \
104 } \
105 return (_flags); \
106 }
107
108/** Put internal representation */
109#define GED_DB_PUT_INTERNAL(_gedp, _dp, _intern, _resource, _flags) \
110 if (rt_db_put_internal((_dp), (_gedp)->dbip, (_intern), (_resource)) < 0) { \
111 int ged_db_put_internal_quiet = (_flags) & GED_QUIET; \
112 if (!ged_db_put_internal_quiet) { \
113 bu_vls_printf((_gedp)->ged_result_str, "Database write failure."); \
114 } \
115 return (_flags); \
116 }
117
118__END_DECLS
119
120#endif /* GED_OBJECTS_H */
121
122/** @} */
123
124/*
125 * Local Variables:
126 * tab-width: 8
127 * mode: C
128 * indent-tabs-mode: t
129 * c-file-style: "stroustrup"
130 * End:
131 * ex: shiftwidth=4 tabstop=8
132 */
Header file for the BRL-CAD common definitions.