]> mj.ucw.cz Git - libucw.git/blob - ucw/xtypes-extra.h
bgets_mp(): Added a non-intuitive warning to documentation.
[libucw.git] / ucw / xtypes-extra.h
1 /*
2  *      UCW Library -- Extended types - extra types
3  *
4  *      (c) 2014 Robert Kessl <robert.kessl@economia.cz>
5  */
6
7 #ifndef _UCW_XTYPES_EXTRA_H
8 #define _UCW_XTYPES_EXTRA_H
9
10 #include <ucw/xtypes.h>
11 #include <ucw/table.h>
12
13 #ifdef CONFIG_UCW_CLEAN_ABI
14 #define table_col_size ucw_table_col_size
15 #define table_col_timestamp ucw_table_col_timestamp
16 #define xt_size ucw_xt_size
17 #define xt_timestamp ucw_xt_timestamp
18 #endif
19
20 /***
21  * Size
22  * ~~~~
23  *
24  * `xt_size` is a size, possibly with a unit. Internally, it is represented
25  * as a `u64`.
26  ***/
27
28 extern const struct xtype xt_size;
29
30 /** Units **/
31 enum size_units {
32   XT_SIZE_UNIT_BYTE,
33   XT_SIZE_UNIT_KILOBYTE,
34   XT_SIZE_UNIT_MEGABYTE,
35   XT_SIZE_UNIT_GIGABYTE,
36   XT_SIZE_UNIT_TERABYTE,
37   XT_SIZE_UNIT_AUTO
38 };
39
40 /**
41  * Custom formatting mode: use a specified unit (`XT_SIZE_UNIT_`'xxx').
42  * Textual representation of the mode is the name of the unit (case-insensitive).
43  **/
44 #define XT_SIZE_FMT_UNIT(_unit) (_unit | XT_SIZE_FMT_FIXED_UNIT)
45 #define XT_SIZE_FMT_FIXED_UNIT XTYPE_FMT_CUSTOM
46
47 #define TBL_COL_SIZE(_name, _width)       { .name = _name, .width = _width, .fmt = XTYPE_FMT_DEFAULT, .type_def = &xt_size }
48 #define TBL_COL_SIZE_FMT(_name, _width, _fmt)      { .name = _name, .width = _width, .fmt = _fmt, .type_def = &xt_size }
49
50 TABLE_COL_PROTO(size, u64)
51
52 /***
53  * Time
54  * ~~~~
55  *
56  * `xt_timestamp` is a timestamp, internally represented as `time_t`.
57  ***/
58
59 /**
60  * Custom formatting mode: seconds since Unix epoch. Currently,
61  * this is the same as the raw format. Textual representation: `timestamp` or `epoch`.
62  **/
63 #define XT_TIMESTAMP_FMT_EPOCH     XTYPE_FMT_RAW
64
65 /**
66  * Custom formatting mode: date and time. Currently, this is the same
67  * as the human-readable format. Textual representation: `datetime`.
68  **/
69 #define XT_TIMESTAMP_FMT_DATETIME  XTYPE_FMT_PRETTY
70
71 extern const struct xtype xt_timestamp;
72
73 #define TBL_COL_TIMESTAMP(_name, _width)  { .name = _name, .width = _width, .fmt = XTYPE_FMT_DEFAULT, .type_def = &xt_timestamp }
74 #define TBL_COL_TIMESTAMP_FMT(_name, _width, _fmt) { .name = _name, .width = _width, .fmt = _fmt, .type_def = &xt_timestamp }
75
76 TABLE_COL_PROTO(timestamp, u64)
77
78 #endif