Revision: 77820
http://sourceforge.net/p/brlcad/code/77820
Author: brlcad
Date: 2020-11-29 05:49:42 +0000 (Sun, 29 Nov 2020)
Log Message:
-----------
change the design to not be so focused on line/element pre-post printing.
merge formatting concepts into a simpler api that should be adaptable to most
of our existing use cases. was good to let this simmer.
Modified Paths:
--------------
brlcad/trunk/include/bu/tbl.h
Modified: brlcad/trunk/include/bu/tbl.h
===================================================================
--- brlcad/trunk/include/bu/tbl.h 2020-11-27 17:43:57 UTC (rev 77819)
+++ brlcad/trunk/include/bu/tbl.h 2020-11-29 05:49:42 UTC (rev 77820)
@@ -45,7 +45,7 @@
@code
double vals[16] = {-1.123123123123, 0, 0, 1.0/0.0, 0, 123, 0, 0, 0, -2345,
123123.123123123123, 0, 123123123.123123123, 21, 1.0/0.0, 1};
- bu_num_print
+
bu_num_print(vals, 16, 4, "my matrix\n[\n", "\t[", NULL, ", ", "]\n",
"]\n]\n");
-------------------------------------------------------------------------------
my matrix
@@ -87,95 +87,79 @@
*/
-struct bu_tbl_style {
- const char *before_tbl;
- const char *before_row;
- const char *before_col;
- const char *before_elm;
- const char *format_scan;
- const char *format_print;
- const char *after_elm;
- const char *after_col;
- const char *after_row;
- const char *after_tbl;
-};
+struct bu_tbl;
/**
- * set what to print at the beginning and end of the table.
- *
- * defaults: before="" after=""
+ * static-initializer for bu_tbl objects on the stack
*/
-BU_EXPORT extern struct bu_tbl_style *
-bu_tbl_style_tbl(struct bu_tbl_style *s, const char *before, const char
*after);
+#define BU_TBL_INIT_ZERO {0}
/**
- * set what to print before and after each table row and how many rows
- * to display.
- *
- * defaults: before="" after="" maxrows=-1 (unlimited)
+ * always returns a pointer to a newly allocated table
*/
-BU_EXPORT extern struct bu_tbl_style *
-bu_tbl_style_row(struct bu_tbl_style *s, const char *before, const char
*after, size_t maxrows);
+BU_EXPORT extern struct bu_tbl *
+bu_tbl_create();
-/**
- * set what to print before and after each table column and how many
- * columns to display.
- *
- * defaults: before="" after="" maxcols=1
- */
-BU_EXPORT extern struct bu_tbl_style *
-bu_tbl_style_col(struct bu_tbl_style *s, const char *before, const char
*after, size_t maxcols);
/**
- * set what to print before and after each table element.
- *
- * defaults: before="" after=""
+ * releases all dynamic memory associated with the specified table
*/
-BU_EXPORT extern struct bu_tbl_style *
-bu_tbl_style_elm(struct bu_tbl_style *s, const char *before, const char
*after);
+BU_EXPORT extern void
+bu_tbl_destroy(struct bu_tbl *);
+
/**
- * set scanf-style and printf-style format specifiers to use reading
- * and displaying table elements respectively
- *
- * defaults: scan="%lf" print="%.17g"
+ * erases all cells in a table, but doesn't erase the table itself
*/
-BU_EXPORT extern struct bu_tbl_style *
-bu_tbl_style_fmt(struct bu_tbl_style *s, const char *scan, const char *print);
+BU_EXPORT int
+bu_tbl_clear(struct bu_tbl *);
+enum bu_tbl_style {
+ BU_TBL_BORDER_NONE,
+ BU_TBL_BORDER_SINGLE,
+ BU_TBL_BORDER_DOUBLE,
+ BU_TBL_ALIGN_LEFT,
+ BU_TBL_ALIGN_CENTER,
+ BU_TBL_ALIGN_RIGHT,
+ BU_TBL_END
+};
+
/**
- *
- @code
-struct bu_tbl_style s = BU_TBL_STYLE_INIT_ZERO;
-bu_tbl_style_tbl(&s, "MATRIX [", "]\n");
-bu_tbl_style_row(&s, "\t[", "]\n");
-bu_tbl_print(s, vals, nvals, ncols);
- @endcode
+ * sets table styling or formatting on cells printed next.
*/
+BU_EXPORT struct bu_tbl *
+bu_tbl_style(struct bu_tbl *, enum bu_tbl_style);
/**
- * format a set of data into a given vls string
+ * set the table insertion point.
*/
-BU_EXPORT extern void
-bu_tbl_vls(struct bu_vls *str, const struct bu_tbl_style *s, const double
*vals, size_t nvals, size_t ncols);
+BU_EXPORT struct bu_tbl *
+bu_tbl_index(struct bu_tbl *, size_t row, size_t col);
/**
- * format a set of data into a given vls string
+ * print values into the table at the current insertion point.
+ *
+ * each column of the 'fmt' printf-style format specfier must be
+ * delimited by a '|' character.
+ *
+ * callers can specify bu_tbl_style parameters as arguments after
+ * 'fmt' in order to affect cell presentation. BU_TBL_END denotes the
+ * end of a row. any existing values will be overwritten.
*/
-BU_EXPORT extern void
-bu_tbl_str(char *str, size_t maxlen, const struct bu_tbl_style *s, const
double *vals, size_t nvals, size_t ncols);
+BU_EXPORT struct bu_tbl *
+bu_tbl_printf(struct bu_tbl *, const char *fmt, ...);
/**
- * format a set of data and print them to the given file descriptor
+ * print a table into a vls
*/
BU_EXPORT extern void
-bu_tbl_print(int fd, const struct bu_tbl_style *s, const void *elms, size_t
nelms, size_t selms);
+bu_tbl_vls(struct bu_vls *str, const struct bu_tbl *t);
__END_DECLS
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
_______________________________________________
BRL-CAD Source Commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/brlcad-commits