Revision: 56366
http://sourceforge.net/p/brlcad/code/56366
Author: starseeker
Date: 2013-07-31 02:19:48 +0000 (Wed, 31 Jul 2013)
Log Message:
-----------
This needs some careful tests - I'm not sure that I'm properly interpreting the
meaning of the left/right tree walk for all the boolean cases - but add an
array to db_full_path that lets us stash the boolean states all along the tree.
The f_bool test can now query based on the current path, which should let
options like -above do the right thing.
Modified Paths:
--------------
brlcad/trunk/include/raytrace.h
brlcad/trunk/src/librt/db_fullpath.c
brlcad/trunk/src/librt/search.c
brlcad/trunk/src/librt/search.h
Modified: brlcad/trunk/include/raytrace.h
===================================================================
--- brlcad/trunk/include/raytrace.h 2013-07-30 20:59:53 UTC (rev 56365)
+++ brlcad/trunk/include/raytrace.h 2013-07-31 02:19:48 UTC (rev 56366)
@@ -208,20 +208,31 @@
/**
* D B _ F U L L _ P A T H
*
- * For collecting paths through the database tree
+ * For collecting paths through the database tree.
+ * The fp_bool array can optionally hold a boolean flag
+ * associated with each corresponding dp in fp_names. This
+ * array must be manually maintained by the client code in
+ * order for it to have valid data - many functions using
+ * full paths (for example, conversion from strings) don't
+ * have knowledge of a specific boolean tree.
*/
struct db_full_path {
uint32_t magic;
size_t fp_len;
size_t fp_maxlen;
struct directory ** fp_names; /**< @brief array of dir
pointers */
+ int * fp_bool; /**< @brief array of boolean
flags */
};
#define DB_FULL_PATH_POP(_pp) { \
(_pp)->fp_len--; \
}
#define DB_FULL_PATH_CUR_DIR(_pp) ((_pp)->fp_names[(_pp)->fp_len-1])
+#define DB_FULL_PATH_CUR_BOOL(_pp) ((_pp)->fp_bool[(_pp)->fp_len-1])
+#define DB_FULL_PATH_SET_CUR_BOOL(_pp, _i) ((_pp)->fp_bool[(_pp)->fp_len-1] =
_i)
#define DB_FULL_PATH_ROOT_DIR(_pp) ((_pp)->fp_names[0])
#define DB_FULL_PATH_GET(_pp, _i) ((_pp)->fp_names[(_i)])
+#define DB_FULL_PATH_GET_BOOL(_pp, _i) ((_pp)->fp_bool[(_i)])
+#define DB_FULL_PATH_SET_BOOL(_pp, _i, _j) ((_pp)->fp_bool[(_i)] = _j)
#define RT_CK_FULL_PATH(_p) BU_CKMAG(_p, DB_FULL_PATH_MAGIC, "db_full_path")
/**
Modified: brlcad/trunk/src/librt/db_fullpath.c
===================================================================
--- brlcad/trunk/src/librt/db_fullpath.c 2013-07-30 20:59:53 UTC (rev
56365)
+++ brlcad/trunk/src/librt/db_fullpath.c 2013-07-31 02:19:48 UTC (rev
56366)
@@ -42,6 +42,7 @@
pathp->fp_len = 0;
pathp->fp_maxlen = 0;
pathp->fp_names = (struct directory **)NULL;
+ pathp->fp_bool = (int *)NULL;
pathp->magic = DB_FULL_PATH_MAGIC;
}
@@ -56,12 +57,19 @@
pp->fp_names = (struct directory **)bu_malloc(
pp->fp_maxlen * sizeof(struct directory *),
"db_full_path array");
+ pp->fp_bool = (int *)bu_calloc(
+ pp->fp_maxlen, sizeof(int),
+ "db_full_path bool array");
} else if (pp->fp_len >= pp->fp_maxlen) {
pp->fp_maxlen *= 4;
pp->fp_names = (struct directory **)bu_realloc(
(char *)pp->fp_names,
pp->fp_maxlen * sizeof(struct directory *),
"enlarged db_full_path array");
+ pp->fp_bool = (int *)bu_realloc(
+ (char *)pp->fp_bool,
+ pp->fp_maxlen * sizeof(int),
+ "enlarged db_full_path bool array");
}
pp->fp_names[pp->fp_len++] = dp;
}
@@ -76,12 +84,17 @@
newp->fp_len = oldp->fp_len;
if (oldp->fp_len <= 0) {
newp->fp_names = (struct directory **)0;
+ newp->fp_bool = (int *)0;
return;
}
newp->fp_names = (struct directory **)bu_malloc(
newp->fp_maxlen * sizeof(struct directory *),
"db_full_path array (duplicate)");
memcpy((char *)newp->fp_names, (char *)oldp->fp_names, newp->fp_len *
sizeof(struct directory *));
+ newp->fp_bool = (int *)bu_malloc(
+ newp->fp_maxlen * sizeof(int),
+ "db_full_path bool array (duplicate)");
+ memcpy((char *)newp->fp_bool, (char *)oldp->fp_bool, newp->fp_len *
sizeof(int));
}
void
@@ -97,6 +110,9 @@
pathp->fp_names = (struct directory **)bu_malloc(
pathp->fp_maxlen * sizeof(struct directory *),
"empty fp_names extension");
+ pathp->fp_bool = (int *)bu_malloc(
+ pathp->fp_maxlen * sizeof(int),
+ "empty fp_bool bool extension");
return;
}
@@ -107,6 +123,10 @@
(char *)pathp->fp_names,
pathp->fp_maxlen * sizeof(struct directory *),
"fp_names extension");
+ pathp->fp_bool = (int *)bu_realloc(
+ (char *)pathp->fp_bool,
+ pathp->fp_maxlen * sizeof(int),
+ "fp_names bool extension");
}
}
@@ -120,6 +140,9 @@
memcpy((char *)&dest->fp_names[dest->fp_len],
(char *)&src->fp_names[0],
src->fp_len * sizeof(struct directory *));
+ memcpy((char *)&dest->fp_bool[dest->fp_len],
+ (char *)&src->fp_bool[0],
+ src->fp_len * sizeof(int));
dest->fp_len += src->fp_len;
}
@@ -135,12 +158,17 @@
newp->fp_maxlen = newp->fp_len = oldp->fp_len - start;
if (newp->fp_len <= 0) {
newp->fp_names = (struct directory **)0;
+ newp->fp_bool = (int *)0;
return;
}
newp->fp_names = (struct directory **)bu_malloc(
newp->fp_maxlen * sizeof(struct directory *),
"db_full_path array (duplicate)");
memcpy((char *)newp->fp_names, (char *)&oldp->fp_names[start],
newp->fp_len * sizeof(struct directory *));
+ newp->fp_bool = (int *)bu_malloc(
+ newp->fp_maxlen * sizeof(int),
+ "db_full_path bool array (duplicate)");
+ memcpy((char *)newp->fp_bool, (char *)&oldp->fp_bool[start], newp->fp_len
* sizeof(int));
}
char *
@@ -258,6 +286,9 @@
pp->fp_names = (struct directory **)bu_malloc(
pp->fp_maxlen * sizeof(struct directory *),
"db_string_to_path path array");
+ pp->fp_bool = (int *)bu_calloc(
+ pp->fp_maxlen, sizeof(int),
+ "db_string_to_path bool array");
/* Build up path array */
cp = copy;
@@ -298,7 +329,11 @@
pp->fp_names = (struct directory **)bu_malloc(
pp->fp_maxlen * sizeof(struct directory *),
"db_argv_to_path path array");
+ pp->fp_bool = (int *)bu_calloc(
+ pp->fp_maxlen, sizeof(int),
+ "db_argv_to_path bool array");
+
for (i=0; i<argc; i++) {
if ((dp = db_lookup(dbip, argv[i], LOOKUP_NOISY)) == RT_DIR_NULL) {
bu_log("db_argv_to_path() failed on element %d='%s'\n",
@@ -318,6 +353,7 @@
if (pp->fp_maxlen > 0) {
bu_free((char *)pp->fp_names, "db_full_path array");
+ bu_free((char *)pp->fp_bool, "db_full_path bool array");
pp->fp_maxlen = pp->fp_len = 0;
pp->fp_names = (struct directory **)0;
}
Modified: brlcad/trunk/src/librt/search.c
===================================================================
--- brlcad/trunk/src/librt/search.c 2013-07-30 20:59:53 UTC (rev 56365)
+++ brlcad/trunk/src/librt/search.c 2013-07-31 02:19:48 UTC (rev 56366)
@@ -178,27 +178,29 @@
if ((dp=db_lookup(dbip, tp->tr_l.tl_name, LOOKUP_QUIET)) ==
RT_DIR_NULL) {
return;
} else {
+ int curr_bool = DB_FULL_PATH_CUR_BOOL(db_node->path);
db_add_node_to_full_path(db_node->path, dp);
+ DB_FULL_PATH_SET_CUR_BOOL(db_node->path, curr_bool);
traverse_func(dbip, wdbp, results, db_node, comb_func,
leaf_func, resp, client_data);
DB_FULL_PATH_POP(db_node->path);
break;
}
case OP_UNION:
- db_node->bool_type = 2;
+ DB_FULL_PATH_SET_CUR_BOOL(db_node->path, 2);
db_fullpath_traverse_subtree(tp->tr_b.tb_left, traverse_func, dbip,
wdbp, results, db_node, comb_func, leaf_func, resp, client_data);
- db_node->bool_type = 2;
+ DB_FULL_PATH_SET_CUR_BOOL(db_node->path, 2);
db_fullpath_traverse_subtree(tp->tr_b.tb_right, traverse_func,
dbip, wdbp, results, db_node, comb_func, leaf_func, resp, client_data);
break;
case OP_INTERSECT:
- db_node->bool_type = 2;
+ DB_FULL_PATH_SET_CUR_BOOL(db_node->path, 2);
db_fullpath_traverse_subtree(tp->tr_b.tb_left, traverse_func, dbip,
wdbp, results, db_node, comb_func, leaf_func, resp, client_data);
- db_node->bool_type = 3;
+ DB_FULL_PATH_SET_CUR_BOOL(db_node->path, 3);
db_fullpath_traverse_subtree(tp->tr_b.tb_right, traverse_func,
dbip, wdbp, results, db_node, comb_func, leaf_func, resp, client_data);
break;
case OP_SUBTRACT:
- db_node->bool_type = 2;
+ DB_FULL_PATH_SET_CUR_BOOL(db_node->path, 2);
db_fullpath_traverse_subtree(tp->tr_b.tb_left, traverse_func, dbip,
wdbp, results, db_node, comb_func, leaf_func, resp, client_data);
- db_node->bool_type = 4;
+ DB_FULL_PATH_SET_CUR_BOOL(db_node->path, 4);
db_fullpath_traverse_subtree(tp->tr_b.tb_right, traverse_func,
dbip, wdbp, results, db_node, comb_func, leaf_func, resp, client_data);
break;
case OP_XOR:
@@ -461,10 +463,10 @@
}
break;
case OP_UNION:
- db_node->bool_type = 2;
+ DB_FULL_PATH_SET_CUR_BOOL(db_node->path, 2);
state = db_fullpath_stateful_traverse_subtree(tp->tr_b.tb_left,
traverse_func, dbip, wdbp, results, db_node, comb_func, leaf_func, resp,
client_data);
if (state == 1) return 1;
- db_node->bool_type = 2;
+ DB_FULL_PATH_SET_CUR_BOOL(db_node->path, 2);
state = db_fullpath_stateful_traverse_subtree(tp->tr_b.tb_right,
traverse_func, dbip, wdbp, results, db_node, comb_func, leaf_func, resp,
client_data);
if (state == 1) {
return 1;
@@ -474,10 +476,10 @@
break;
case OP_INTERSECT:
- db_node->bool_type = 2;
+ DB_FULL_PATH_SET_CUR_BOOL(db_node->path, 2);
state = db_fullpath_stateful_traverse_subtree(tp->tr_b.tb_left,
traverse_func, dbip, wdbp, results, db_node, comb_func, leaf_func, resp,
client_data);
if (state == 1) return 1;
- db_node->bool_type = 3;
+ DB_FULL_PATH_SET_CUR_BOOL(db_node->path, 3);
state = db_fullpath_stateful_traverse_subtree(tp->tr_b.tb_right,
traverse_func, dbip, wdbp, results, db_node, comb_func, leaf_func, resp,
client_data);
if (state == 1) {
return 1;
@@ -487,10 +489,10 @@
break;
case OP_SUBTRACT:
- db_node->bool_type = 2;
+ DB_FULL_PATH_SET_CUR_BOOL(db_node->path, 2);
state = db_fullpath_stateful_traverse_subtree(tp->tr_b.tb_left,
traverse_func, dbip, wdbp, results, db_node, comb_func, leaf_func, resp,
client_data);
if (state == 1) return 1;
- db_node->bool_type = 4;
+ DB_FULL_PATH_SET_CUR_BOOL(db_node->path, 4);
state = db_fullpath_stateful_traverse_subtree(tp->tr_b.tb_right,
traverse_func, dbip, wdbp, results, db_node, comb_func, leaf_func, resp,
client_data);
if (state == 1) {
return 1;
@@ -1321,7 +1323,8 @@
f_bool(struct db_plan_t *plan, struct db_node_t *db_node, struct db_i
*UNUSED(dbip), struct rt_wdb *UNUSED(wdbp), struct db_full_path_list
*UNUSED(results))
{
int bool_match = 0;
- if (plan->bool_data == db_node->bool_type) bool_match = 1;
+ int bool_type = DB_FULL_PATH_CUR_BOOL(db_node->path);
+ if (plan->bool_data == bool_type) bool_match = 1;
return bool_match;
}
@@ -2155,8 +2158,9 @@
}
for (BU_LIST_FOR(currentpath, db_full_path_list, &(pathnames->l))) {
struct db_node_t curr_node;
- curr_node.path = currentpath->path;
- curr_node.bool_type = 2; /* by convention, the top level node is
"unioned" into the global database */
+ curr_node.path = currentpath->path;
+ /* by convention, the top level node is "unioned" into the global
database */
+ DB_FULL_PATH_SET_CUR_BOOL(curr_node.path, 2);
db_fullpath_traverse(dbip, wdbp, searchresults, &curr_node,
find_execute_plans, find_execute_plans, wdbp->wdb_resp, (struct db_plan_t
*)searchplan);
}
return searchresults;
Modified: brlcad/trunk/src/librt/search.h
===================================================================
--- brlcad/trunk/src/librt/search.h 2013-07-30 20:59:53 UTC (rev 56365)
+++ brlcad/trunk/src/librt/search.h 2013-07-31 02:19:48 UTC (rev 56366)
@@ -58,7 +58,6 @@
/* node struct - holds data specific to each node under consideration */
struct db_node_t {
struct db_full_path *path;
- int bool_type;
};
/* search node type */
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
------------------------------------------------------------------------------
Get your SQL database under version control now!
Version control is standard for application code, but databases havent
caught up. So what steps can you take to put your SQL databases under
version control? Why should you start doing it? Read more to find out.
http://pubads.g.doubleclick.net/gampad/clk?id=49501711&iu=/4140/ostg.clktrk
_______________________________________________
BRL-CAD Source Commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/brlcad-commits