BRL-CAD
db_diff.h
Go to the documentation of this file.
1 /* D B _ D I F F . H
2  * BRL-CAD
3  *
4  * Copyright (c) 2014-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 /** @file db_diff.h
21  *
22  * Diff interface for comparing geometry.
23  *
24  */
25 
26 #ifndef RT_DB_DIFF_H
27 #define RT_DB_DIFF_H
28 
29 #include "common.h"
30 #include "bu/avs.h"
31 #include "bu/ptbl.h"
32 #include "bn/tol.h"
33 #include "rt/defines.h"
34 #include "rt/db_instance.h"
35 
36 __BEGIN_DECLS
37 
38 /**
39  * DIFF bit flags to select various types of results
40  */
41 #define DIFF_EMPTY 0
42 #define DIFF_UNCHANGED 1
43 #define DIFF_REMOVED 2
44 #define DIFF_ADDED 4
45 #define DIFF_CHANGED 8
46 #define DIFF_CONFLICT 16
47 
48 /*
49  * Results for a diff between two objects are held in a set
50  * of avs-like structures.
51  */
52 struct diff_avp {
53  char *name;
54  int state;
55  char *left_value;
57  char *right_value;
58 };
59 RT_EXPORT extern void diff_init_avp(struct diff_avp *attr_result);
60 RT_EXPORT extern void diff_free_avp(struct diff_avp *attr_result);
61 struct diff_result {
62  char *obj_name;
63  struct bn_tol *diff_tol;
64  const struct directory *dp_left;
65  const struct directory *dp_ancestor;
66  const struct directory *dp_right;
67  int param_state; /* results of diff for all parameters */
68  int attr_state; /* results of diff for all attributes */
69  struct bu_ptbl *param_diffs; /* ptbl of diff_avps of parameters */
70  struct bu_ptbl *attr_diffs; /* ptbl of diff_avps of attributes */
71 };
72 RT_EXPORT extern void diff_init_result(struct diff_result *result, const struct bn_tol *curr_diff_tol, const char *object_name);
73 RT_EXPORT extern void diff_free_result(struct diff_result *result);
74 
75 /**
76  * The flags parameter is a bitfield is used to specify whether
77  * to process internal object parameter differences
78  * (DB_COMPARE_PARAM), attribute differences (DB_COMPARE_ATTRS), or
79  * both (DB_COMPARE_ALL).
80  */
81 typedef enum {
84  DB_COMPARE_ATTRS=0x02
86 
87 /**
88  * Compare two attribute sets.
89  *
90  * This function is useful for comparing the contents
91  * of two attribute/value sets. */
92 RT_EXPORT extern int
93 db_avs_diff(const struct bu_attribute_value_set *left_set,
94  const struct bu_attribute_value_set *right_set,
95  const struct bn_tol *diff_tol,
96  int (*add_func)(const char *attr_name, const char *attr_val, void *data),
97  int (*del_func)(const char *attr_name, const char *attr_val, void *data),
98  int (*chgd_func)(const char *attr_name, const char *attr_val_left, const char *attr_val_right, void *data),
99  int (*unchgd_func)(const char *attr_name, const char *attr_val, void *data),
100  void *client_data);
101 
102 /**
103  * Compare three attribute sets.
104  */
105 RT_EXPORT extern int
106 db_avs_diff3(const struct bu_attribute_value_set *left_set,
107  const struct bu_attribute_value_set *ancestor_set,
108  const struct bu_attribute_value_set *right_set,
109  const struct bn_tol *diff_tol,
110  int (*add_func)(const char *attr_name,
111  const char *attr_val_left,
112  const char *attr_val_right,
113  void *data),
114  int (*del_func)(const char *attr_name,
115  const char *attr_val_left,
116  const char *attr_val_ancestor,
117  const char *attr_val_right,
118  void *data),
119  int (*chgd_func)(const char *attr_name,
120  const char *attr_val_left,
121  const char *attr_val_ancestor,
122  const char *attr_val_right,
123  void *data),
124  int (*conflict_func)(const char *attr_name,
125  const char *attr_val_left,
126  const char *attr_val_ancestor,
127  const char *attr_val_right,
128  void *data),
129  int (*unchgd_func)(const char *attr_name,
130  const char *attr_val_ancestor,
131  void *data),
132  void *client_data);
133 
134 
135 /**
136  * Compare two database objects.
137  *
138  * This function is useful for comparing two geometry objects and
139  * inspecting their differences. Differences are recorded in
140  * key=value form based on whether there is a difference added in the
141  * right, removed in the right, changed going from left to right, or
142  * unchanged.
143  *
144  * The flags parameter is a bitfield specifying what type of
145  * comparisons to perform. The default is to compare everything and
146  * report on any differences encountered.
147  *
148  * The same bu_attribute_value_set container may be passed to any of
149  * the provided containers to aggregate results. NULL may be passed
150  * to not inspect or record information for that type of comparison.
151  *
152  * Returns an int with bit flags set according to the above
153  * four diff categories.
154  *
155  * Negative returns indicate an error.
156  */
157 RT_EXPORT extern int
158 db_diff_dp(const struct db_i *left_dbip,
159  const struct db_i *right_dbip,
160  const struct directory *left_dp,
161  const struct directory *right_dp,
162  const struct bn_tol *diff_tol,
163  db_compare_criteria_t flags,
164  struct diff_result *result);
165 
166 
167 /**
168  * Compare three database objects.
169  *
170  * The flags parameter is a bitfield specifying what type of
171  * comparisons to perform. The default is to compare everything and
172  * report on any differences encountered.
173  *
174  * The same bu_attribute_value_set container may be passed to any of
175  * the provided containers to aggregate results. NULL may be passed
176  * to not inspect or record information for that type of comparison.
177  *
178  * Returns an int with bit flags set according to the above
179  * diff3 categories.
180  *
181  * Negative returns indicate an error.
182  *
183  */
184 
185 RT_EXPORT extern int
186 db_diff3_dp(const struct db_i *left,
187  const struct db_i *ancestor,
188  const struct db_i *right,
189  const struct directory *left_dp,
190  const struct directory *ancestor_dp,
191  const struct directory *right_dp,
192  const struct bn_tol *diff_tol,
193  db_compare_criteria_t flags,
194  struct diff_result *result);
195 
196 /**
197  * Compare two database instances.
198  *
199  * All objects in dbip_left are compared against the objects in
200  * dbip_right. Every object results in one of four callback functions
201  * getting called. Any objects in dbip_right but not in dbip_left
202  * cause add_func() to get called. Any objects in dbip_left but not
203  * in dbip_right cause del_func() to get called. Objects existing in
204  * both (i.e., with the same name) but differing in some fashion
205  * cause chgd_func() to get called. If the object exists in both
206  * but is unchanged, unch_func() is called. NULL may be
207  * passed to skip any callback.
208  *
209  * Returns an int with bit flags set according to the above
210  * four diff categories.
211  *
212  * Negative returns indicate an error.
213  */
214 RT_EXPORT extern int
215 db_diff(const struct db_i *dbip_left,
216  const struct db_i *dbip_right,
217  const struct bn_tol *diff_tol,
218  db_compare_criteria_t flags,
219  struct bu_ptbl *diff_results);
220 
221 
222 /**
223  * Compare three database instances.
224  *
225  * This does a "3-way" diff to identify changes in the left and
226  * right databases relative to the ancestor database, and provides
227  * functional hooks for the various cases.
228  *
229  * Returns an int with bit flags set according to the above
230  * diff3 categories.
231  *
232  * Negative returns indicate an error.
233  */
234 RT_EXPORT extern int
235 db_diff3(const struct db_i *dbip_left,
236  const struct db_i *dbip_ancestor,
237  const struct db_i *dbip_right,
238  const struct bn_tol *diff_tol,
239  db_compare_criteria_t flags,
240  struct bu_ptbl *diff3_results);
241 
242 __END_DECLS
243 
244 #endif /*RT_DB_DIFF_H*/
245 
246 /*
247  * Local Variables:
248  * tab-width: 8
249  * mode: C
250  * indent-tabs-mode: t
251  * c-file-style: "stroustrup"
252  * End:
253  * ex: shiftwidth=4 tabstop=8
254  */
Header file for the BRL-CAD common definitions.
int db_avs_diff(const struct bu_attribute_value_set *left_set, const struct bu_attribute_value_set *right_set, const struct bn_tol *diff_tol, int(*add_func)(const char *attr_name, const char *attr_val, void *data), int(*del_func)(const char *attr_name, const char *attr_val, void *data), int(*chgd_func)(const char *attr_name, const char *attr_val_left, const char *attr_val_right, void *data), int(*unchgd_func)(const char *attr_name, const char *attr_val, void *data), void *client_data)
void diff_init_avp(struct diff_avp *attr_result)
void diff_free_avp(struct diff_avp *attr_result)
int db_diff3(const struct db_i *dbip_left, const struct db_i *dbip_ancestor, const struct db_i *dbip_right, const struct bn_tol *diff_tol, db_compare_criteria_t flags, struct bu_ptbl *diff3_results)
void diff_free_result(struct diff_result *result)
int db_diff(const struct db_i *dbip_left, const struct db_i *dbip_right, const struct bn_tol *diff_tol, db_compare_criteria_t flags, struct bu_ptbl *diff_results)
void diff_init_result(struct diff_result *result, const struct bn_tol *curr_diff_tol, const char *object_name)
int db_avs_diff3(const struct bu_attribute_value_set *left_set, const struct bu_attribute_value_set *ancestor_set, const struct bu_attribute_value_set *right_set, const struct bn_tol *diff_tol, int(*add_func)(const char *attr_name, const char *attr_val_left, const char *attr_val_right, void *data), int(*del_func)(const char *attr_name, const char *attr_val_left, const char *attr_val_ancestor, const char *attr_val_right, void *data), int(*chgd_func)(const char *attr_name, const char *attr_val_left, const char *attr_val_ancestor, const char *attr_val_right, void *data), int(*conflict_func)(const char *attr_name, const char *attr_val_left, const char *attr_val_ancestor, const char *attr_val_right, void *data), int(*unchgd_func)(const char *attr_name, const char *attr_val_ancestor, void *data), void *client_data)
db_compare_criteria_t
Definition: db_diff.h:81
@ DB_COMPARE_ALL
Definition: db_diff.h:82
@ DB_COMPARE_ATTRS
Definition: db_diff.h:84
@ DB_COMPARE_PARAM
Definition: db_diff.h:83
int db_diff3_dp(const struct db_i *left, const struct db_i *ancestor, const struct db_i *right, const struct directory *left_dp, const struct directory *ancestor_dp, const struct directory *right_dp, const struct bn_tol *diff_tol, db_compare_criteria_t flags, struct diff_result *result)
int db_diff_dp(const struct db_i *left_dbip, const struct db_i *right_dbip, const struct directory *left_dp, const struct directory *right_dp, const struct bn_tol *diff_tol, db_compare_criteria_t flags, struct diff_result *result)
Definition: tol.h:72
Definition: ptbl.h:53
char * name
Definition: db_diff.h:53
char * ancestor_value
Definition: db_diff.h:56
int state
Definition: db_diff.h:54
char * right_value
Definition: db_diff.h:57
char * left_value
Definition: db_diff.h:55
const struct directory * dp_ancestor
Definition: db_diff.h:65
struct bu_ptbl * param_diffs
Definition: db_diff.h:69
int attr_state
Definition: db_diff.h:68
char * obj_name
Definition: db_diff.h:62
const struct directory * dp_left
Definition: db_diff.h:64
int param_state
Definition: db_diff.h:67
struct bu_ptbl * attr_diffs
Definition: db_diff.h:70
const struct directory * dp_right
Definition: db_diff.h:66
struct bn_tol * diff_tol
Definition: db_diff.h:63