-void table_set_printf(struct table *tbl, int col, const char *fmt, ...)
-{
- ASSERT_MSG(col < tbl->column_count && col >= 0, "Table column %d does not exist.", col);
- tbl->last_printed_col = col;
- tbl->row_printing_started = 1;
- va_list args;
- va_start(args, fmt);
- tbl->col_str_ptrs[col] = mp_vprintf(tbl->pool, fmt, args);
- va_end(args);
-}
-
-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
+/**
+ * The TBL_COL_ITER_START macro are used for iterating over all instances of a particular column in
+ * table _tbl. _colidx is the column index in _tbl, _instptr is the pointer to the column instance
+ * (struct table_col_instance *), _idxval is the index of current column index. The variables are
+ * enclosed in a block, so they do not introduce variable name collisions.
+ *
+ * The TBL_COL_ITER_END macro must close the block started with TBL_COL_ITER_START.
+ *
+ * These macros are usually used to hide the implementation details of the column instances linked
+ * list. This is usefull for definition of new types.
+ **/
+#define TBL_COL_ITER_START(_tbl, _colidx, _instptr, _idxval) { struct table_col_instance *_instptr = NULL; int _idxval = _tbl->ll_headers[_colidx]; \
+ for(_idxval = _tbl->ll_headers[_colidx], _instptr = _tbl->column_order + _idxval; _idxval != -1; _idxval = _tbl->column_order[_idxval].next_column, _instptr = _tbl->column_order + _idxval)