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