-static const char *table_set_col_default_fmts[] = {
- [COL_TYPE_STR] = "%s",
- [COL_TYPE_INT] = "%d",
- [COL_TYPE_INTMAX] = "%jd",
- [COL_TYPE_UINT] = "%u",
- [COL_TYPE_UINTMAX] = "%ju",
- [COL_TYPE_BOOL] = "%d",
- [COL_TYPE_DOUBLE] = "%.2lf",
- [COL_TYPE_ANY] = NULL,
- [COL_TYPE_LAST] = NULL
-};
-
-#define TABLE_SET_COL(_name_, _type_, _typeconst_) void table_set_##_name_(struct table *tbl, int col, _type_ val) \
- {\
- const char *fmt = tbl->columns[col].fmt;\
- if(tbl->columns[col].type == COL_TYPE_ANY) {\
- fmt = table_set_col_default_fmts[_typeconst_];\
- }\
- table_set_##_name_##_fmt(tbl, col, fmt, val);\
- }
-
-#define TABLE_SET_COL_STR(_name_, _type_, _typeconst_) void table_set_##_name_##_name(struct table *tbl, const char *col_name, _type_ val) \
- {\
- int col = table_get_col_idx(tbl, col_name);\
- table_set_##_name_(tbl, col, val);\
- }
-
-#define TABLE_SET_COL_FMT(_name_, _type_, _typeconst_) void table_set_##_name_##_fmt(struct table *tbl, int col, const char *fmt, _type_ val)\
- {\
- ASSERT_MSG(col < tbl->column_count && col >= 0, "Table column %d does not exist.", col);\
- ASSERT(tbl->columns[col].type == COL_TYPE_ANY || _typeconst_ == tbl->columns[col].type);\
- ASSERT(fmt != NULL);\
- tbl->last_printed_col = col;\
- tbl->row_printing_started = 1;\
- tbl->col_str_ptrs[col] = mp_printf(tbl->pool, fmt, val);\
- }
-
-#define TABLE_SET(_name_, _type_, _typeconst_) TABLE_SET_COL(_name_, _type_, _typeconst_);\
- TABLE_SET_COL_STR(_name_, _type_, _typeconst_);\
- TABLE_SET_COL_FMT(_name_, _type_, _typeconst_);
-
-TABLE_SET(int, int, COL_TYPE_INT)
-TABLE_SET(uint, uint, COL_TYPE_UINT)
-TABLE_SET(double, double, COL_TYPE_DOUBLE)
-TABLE_SET(str, const char *, COL_TYPE_STR)
-TABLE_SET(intmax, intmax_t, COL_TYPE_INTMAX)
-TABLE_SET(uintmax, uintmax_t, COL_TYPE_UINTMAX)
-#undef TABLE_SET_COL_FMT
-#undef TABLE_SET_COL_STR
-#undef TABLE_SET_COL
-#undef TABLE_SET
-
-void table_set_bool(struct table *tbl, int col, uint val)
-{
- table_set_bool_fmt(tbl, col, tbl->columns[col].fmt, val);
-}