BRL-CAD
defines.h
Go to the documentation of this file.
1 /* D E F I N E S . H
2  * BRL-CAD
3  *
4  * Copyright (c) 2004-2024 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 /*----------------------------------------------------------------------*/
22 /** @addtogroup nmg_defines
23  * @brief
24  * Common definitions for the headers used in nmg.h (i.e. the headers found in include/nmg)
25  *
26  * * NOTE: We rely on the fact that the first 32 bits in a struct is the
27  * magic number (which is used to identify the struct type). This may
28  * be either a magic value, or an rt_list structure, which starts with
29  * a magic number.
30  *
31  * To these ends, there is a standard ordering for fields in
32  * "object-use" structures. That ordering is:
33  *
34  * 1) magic number, or rt_list structure
35  * 2) pointer to parent
36  * 5) pointer to mate
37  * 6) pointer to geometry
38  * 7) pointer to attributes
39  * 8) pointer to child(ren)
40  */
41 /** @{ */
42 /** @file nmg/defines.h */
43 
44 #ifndef NMG_DEFINES_H
45 #define NMG_DEFINES_H
46 
47 #include "common.h"
48 
49 #ifndef NMG_EXPORT
50 # if defined(NMG_DLL_EXPORTS) && defined(NMG_DLL_IMPORTS)
51 # error "Only NMG_DLL_EXPORTS or NMG_DLL_IMPORTS can be defined, not both."
52 # elif defined(NMG_DLL_EXPORTS)
53 # define NMG_EXPORT COMPILER_DLLEXPORT
54 # elif defined(NMG_DLL_IMPORTS)
55 # define NMG_EXPORT COMPILER_DLLIMPORT
56 # else
57 # define NMG_EXPORT
58 # endif
59 #endif
60 
61 /* Boolean operations */
62 #define NMG_BOOL_SUB 1 /**< @brief subtraction */
63 #define NMG_BOOL_ADD 2 /**< @brief addition/union */
64 #define NMG_BOOL_ISECT 4 /**< @brief intersection */
65 
66 /* Boolean classifications */
67 #define NMG_CLASS_Unknown -1
68 #define NMG_CLASS_AinB 0
69 #define NMG_CLASS_AonBshared 1
70 #define NMG_CLASS_AonBanti 2
71 #define NMG_CLASS_AoutB 3
72 #define NMG_CLASS_BinA 4
73 #define NMG_CLASS_BonAshared 5
74 #define NMG_CLASS_BonAanti 6
75 #define NMG_CLASS_BoutA 7
76 
77 /* orientations available. All topological elements are orientable. */
78 #define OT_NONE 0 /**< @brief no orientation (error) */
79 #define OT_SAME 1 /**< @brief orientation same */
80 #define OT_OPPOSITE 2 /**< @brief orientation opposite */
81 #define OT_UNSPEC 3 /**< @brief orientation unspecified */
82 #define OT_BOOLPLACE 4 /**< @brief object is intermediate data for boolean ops */
83 
84 /** values for the "allhits" argument to mg_class_pt_fu_except() */
85 #define NMG_FPI_FIRST 0 /**< @brief return after finding first
86  * touch
87  */
88 #define NMG_FPI_PERGEOM 1 /**< @brief find all touches, call
89  * user funcs once for each geometry
90  * element touched.
91  */
92 #define NMG_FPI_PERUSE 2 /**< @brief find all touches, call
93  * user funcs once for each use of
94  * geom elements touched.
95  */
96 
97 /**
98  * storage allocation/deallocation support
99  */
100 #define NMG_GETSTRUCT(p, str) p = (struct str *)bu_calloc(1, sizeof(struct str), "NMG_GETSTRUCT")
101 #define NMG_FREESTRUCT(p, str) bu_free(p, "NMG_FREESTRUCT")
102 #define NMG_ALLOC(_ptr, _type) _ptr = (_type *)bu_calloc(1, sizeof(_type), #_type " (NMG_ALLOC) " CPP_FILELINE)
103 
104 /**
105  * macros to check/validate a structure pointer
106  */
107 #define NMG_CKMAG(_ptr, _magic, _str) BU_CKMAG(_ptr, _magic, _str)
108 #define NMG_CK2MAG(_ptr, _magic1, _magic2, _str) \
109  if (!(_ptr) || (*((uint32_t *)(_ptr)) != (_magic1) && *((uint32_t *)(_ptr)) != (_magic2))) { \
110  bu_badmagic((uint32_t *)(_ptr), _magic1, _str, __FILE__, __LINE__); \
111  }
112 
113 #define NMG_CK_LIST(_p) BU_CKMAG(_p, BU_LIST_HEAD_MAGIC, "bu_list")
114 #define NMG_CK_RADIAL(_p) NMG_CKMAG(_p, NMG_RADIAL_MAGIC, "nmg_radial")
115 #define NMG_CK_INTER_STRUCT(_p) NMG_CKMAG(_p, NMG_INTER_STRUCT_MAGIC, "nmg_inter_struct")
116 
117 /*
118  * Macros to create and destroy storage for the NMG data structures.
119  * Since nmg_mk.c and g_nmg.c are the only source file which should
120  * perform these most fundamental operations, the macros do not belong
121  * in nmg.h In particular, application code should NEVER do these
122  * things. Any need to do so should be handled by extending nmg_mk.c
123  */
124 #define NMG_INCR_INDEX(_p, _m) \
125  NMG_CK_MODEL(_m); (_p)->index = ((_m)->maxindex)++
126 
127 
128 #endif /* NMG_DEFINES_H */
129 /** @} */
130 /*
131  * Local Variables:
132  * mode: C
133  * tab-width: 8
134  * indent-tabs-mode: t
135  * c-file-style: "stroustrup"
136  * End:
137  * ex: shiftwidth=4 tabstop=8
138  */
Header file for the BRL-CAD common definitions.