]> mj.ucw.cz Git - libucw.git/blobdiff - ucw/table-types.h
xtypes: overflow detection updated
[libucw.git] / ucw / table-types.h
index 7b8dec5ac0d28677da8de7251cac96f0b0a265f6..0220288d064686afdfd9b82df5ef94c4c4f1d9fa 100644 (file)
@@ -1,67 +1,52 @@
+/*
+ *     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
-};
-
-enum timestamp_format {
-  TIMESTAMP_EPOCH,
-  TIMESTAMP_DATETIME
-};
-
-
-#define COL_TYPE_SIZE       COL_TYPE_CUSTOM
-#define COL_TYPE_TIMESTAMP  (COL_TYPE_CUSTOM+1)
+#ifdef CONFIG_UCW_CLEAN_ABI
+#define table_col_size ucw_table_col_size
+#define table_col_timestamp ucw_table_col_timestamp
+#define xt_size ucw_xt_size
+#define xt_timestamp ucw_xt_timestamp
+#endif
 
-extern struct table_user_type table_type_timestamp;
-extern struct table_user_type table_type_size;
+/* Size, possibly with a unit. Internally represented as u64. */
 
-#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 }
+extern const struct xtype xt_size;
 
-#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 }
+enum size_units {
+  XT_SIZE_UNIT_BYTE,
+  XT_SIZE_UNIT_KILOBYTE,
+  XT_SIZE_UNIT_MEGABYTE,
+  XT_SIZE_UNIT_GIGABYTE,
+  XT_SIZE_UNIT_TERABYTE,
+  XT_SIZE_UNIT_AUTO
+};
 
-/*
-  union {
-    enum size_units units;
-    enum timestamp_format ts_fmt;
-  };
-*/
-/*
-#define TBL_COL_SIZE(_name, _width)           { .name = _name, .width = _width, .fmt = "%llu", .type = COL_TYPE_SIZE }
-#define TBL_COL_TIMESTAMP(_name, _width)      { .name = _name, .width = _width, .fmt = "%lld", .type = COL_TYPE_TIMESTAMP }
+#define XT_SIZE_FMT_UNIT(_unit) (_unit | XT_SIZE_FMT_FIXED_UNIT)
+#define XT_SIZE_FMT_FIXED_UNIT XTYPE_FMT_CUSTOM
 
-#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(_name, _width)       { .name = _name, .width = _width, .fmt = XTYPE_FMT_DEFAULT, .type_def = &xt_size }
+#define TBL_COL_SIZE_FMT(_name, _width, _fmt)      { .name = _name, .width = _width, .fmt = _fmt, .type_def = &xt_size }
 
-#define TABLE_COL_PROTO(_name_, _type_) void table_col_##_name_(struct table *tbl, int col, _type_ val);\
-  void table_col_##_name_##_name(struct table *tbl, const char *col_name, _type_ val);\
-  void table_col_##_name_##_fmt(struct table *tbl, int col, _type_ val) FORMAT_CHECK(printf, 3, 0);
-//TABLE_COL_PROTO(size, u64);
-//TABLE_COL_PROTO(timestamp, u64);
-#undef TABLE_COL_PROTO
-*/
+TABLE_COL_PROTO(size, u64)
 
-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);
+/* Timestamp. Internally represented as time_t. */
 
-void table_col_size(struct table *tbl, int col, u64 val);
-void table_col_timestamp(struct table *tbl, int col, u64 val);
+#define XT_TIMESTAMP_FMT_EPOCH     XTYPE_FMT_RAW
+#define XT_TIMESTAMP_FMT_DATETIME  XTYPE_FMT_PRETTY
 
-//TABLE_COL(size, u64, COL_TYPE_SIZE)
-//TABLE_COL_STR(size, u64, COL_TYPE_SIZE)
+extern const struct xtype xt_timestamp;
 
-//TABLE_COL(timestamp, u64, COL_TYPE_TIMESTAMP)
-//TABLE_COL_STR(timestamp, u64, COL_TYPE_TIMESTAMP)
+#define TBL_COL_TIMESTAMP(_name, _width)  { .name = _name, .width = _width, .fmt = XTYPE_FMT_DEFAULT, .type_def = &xt_timestamp }
+#define TBL_COL_TIMESTAMP_FMT(_name, _width, _fmt) { .name = _name, .width = _width, .fmt = _fmt, .type_def = &xt_timestamp }
 
+TABLE_COL_PROTO(timestamp, u64)
 
 #endif