+/*
+ * UCW Library -- Table printer
+ *
+ * (c) 2014 Robert Kessl <robert.kessl@economia.cz>
+ */
+
#ifndef _UCW_TABLE_TYPES_H
#define _UCW_TABLE_TYPES_H
#include <ucw/table.h>
enum size_units {
- UNIT_BYTE,
- UNIT_KILOBYTE,
- UNIT_MEGABYTE,
- UNIT_GIGABYTE,
- UNIT_TERABYTE,
- UNIT_AUTO
+ SIZE_UNIT_BYTE,
+ SIZE_UNIT_KILOBYTE,
+ SIZE_UNIT_MEGABYTE,
+ SIZE_UNIT_GIGABYTE,
+ SIZE_UNIT_TERABYTE,
+ SIZE_UNIT_AUTO
};
-enum timestamp_format {
- TIMESTAMP_EPOCH,
- TIMESTAMP_DATETIME
-};
+#define TIMESTAMP_EPOCH XTYPE_FMT_RAW
+#define TIMESTAMP_DATETIME XTYPE_FMT_PRETTY
+
+#define SIZE_UNITS_FIXED 0x40000000
-#define COL_TYPE_SIZE COL_TYPE_CUSTOM
-#define COL_TYPE_TIMESTAMP (COL_TYPE_CUSTOM+1)
+extern const struct xtype xt_size;
+extern const struct xtype xt_timestamp;
-extern struct table_user_type table_type_timestamp;
-extern struct table_user_type table_type_size;
+int table_set_col_opt_size(struct table *tbl, uint col_inst_idx, const char *col_arg, char **err);
+int table_set_col_opt_timestamp(struct table *tbl, uint col_inst_idx, const char *col_arg, char **err);
-#define TBL_COL_SIZE(_name, _width) { .name = _name, .width = _width, .fmt = "%llu", .type = COL_TYPE_SIZE, .type_def = &table_type_size }
-#define TBL_COL_TIMESTAMP(_name, _width) { .name = _name, .width = _width, .fmt = "%lld", .type = COL_TYPE_TIMESTAMP, .type_def = &table_type_timestamp }
+#define TBL_COL_SIZE(_name, _width) { .name = _name, .width = _width, .fmt = XTYPE_FMT_DEFAULT, .type_def = &xt_size, .set_col_instance_option = table_set_col_opt_size }
+#define TBL_COL_TIMESTAMP(_name, _width) { .name = _name, .width = _width, .fmt = XTYPE_FMT_DEFAULT, .type_def = &xt_timestamp, .set_col_instance_option = table_set_col_opt_timestamp }
-#define TBL_COL_SIZE_FMT(_name, _width, _units) { .name = _name, .width = _width, .fmt = "%llu", .type = COL_TYPE_SIZE }
-#define TBL_COL_TIMESTAMP_FMT(_name, _width, _fmt) { .name = _name, .width = _width, .fmt = "%lld", .type = COL_TYPE_TIMESTAMP }
+#define TBL_COL_SIZE_FMT(_name, _width, _units) { .name = _name, .width = _width, .fmt = XTYPE_FMT_DEFAULT, .type_def = &xt_size, .set_col_instance_option = table_set_col_opt_size }
+#define TBL_COL_TIMESTAMP_FMT(_name, _width, _fmt) { .name = _name, .width = _width, .fmt = XTYPE_FMT_DEFAULT, .type_def = &xt_timestamp, .set_col_instance_option = table_set_col_opt_timestamp }
-void table_col_size_name(struct table *tbl, const char *col_name, u64 val);
-void table_col_timestamp_name(struct table *tbl, const char * col_name, u64 val);
-void table_col_size(struct table *tbl, int col, u64 val);
-void table_col_timestamp(struct table *tbl, int col, u64 val);
+TABLE_COL_PROTO(size, u64)
+TABLE_COL_PROTO(timestamp, u64)
#endif