aboutsummaryrefslogtreecommitdiff
path: root/macro.h
diff options
context:
space:
mode:
authorHugo Hörnquist <hugo@hornquist.se>2019-02-10 00:47:02 +0100
committerHugo Hörnquist <hugo@hornquist.se>2019-02-10 00:53:24 +0100
commitf8cfe5e8806cfd84dc83714e495b58890ef4bb02 (patch)
treed154ea27de49e169817263d2a28f097e67760e22 /macro.h
parentAdd param field to content_line. (diff)
downloadcalp-f8cfe5e8806cfd84dc83714e495b58890ef4bb02.tar.gz
calp-f8cfe5e8806cfd84dc83714e495b58890ef4bb02.tar.xz
Add formatting macros.
Diffstat (limited to 'macro.h')
-rw-r--r--macro.h15
1 files changed, 15 insertions, 0 deletions
diff --git a/macro.h b/macro.h
index bd421260..e1bff786 100644
--- a/macro.h
+++ b/macro.h
@@ -109,5 +109,20 @@
#define GET(T) TEMPL(get , T)
#define RESET(T) TEMPL(reset , T)
+/*
+ * Formatting macros.
+ * Transform objects into string representation of themselves.
+ * buf should be a suffisiently large memmory location, if it's to
+ * small then bad stuff might happen.
+ *
+ * Should return the number of bytes written (like sprintf).
+ */
+
+#define FMT_T(T) TEMPL(format , T)
+#define FMT_F(T) int FMT_T(T)(T* this, char* buf, ...)
+// TODO change order of buf and item
+#define __FMT_HELP(item, buf, ...) ((item), (buf), VA_ARGS_NUM(__VA_ARGS__), ## __VA_ARGS__)
+#define FMT(T) FMT_T(T) __FMT_HELP
+#define fmtf(...) seek += sprintf(buf + seek, __VA_ARGS__)
#endif /* MACRO_H */