aboutsummaryrefslogtreecommitdiff
path: root/pair.inc.h
diff options
context:
space:
mode:
authorHugo Hörnquist <hugo@hornquist.se>2019-02-10 18:58:35 +0100
committerHugo Hörnquist <hugo@lysator.liu.se>2019-02-15 20:03:43 +0100
commitf865f1554dec3d6fb71eab9c02ecbb6f0bfcb821 (patch)
treececc4eda62b8892828d67253b411ae5c1c79803f /pair.inc.h
parentMerge strbuf copy functions. (diff)
downloadcalp-f865f1554dec3d6fb71eab9c02ecbb6f0bfcb821.tar.gz
calp-f865f1554dec3d6fb71eab9c02ecbb6f0bfcb821.tar.xz
Replace key_val type with templatized PAIR(T, V).
Diffstat (limited to 'pair.inc.h')
-rw-r--r--pair.inc.h33
1 files changed, 33 insertions, 0 deletions
diff --git a/pair.inc.h b/pair.inc.h
new file mode 100644
index 00000000..53f746bd
--- /dev/null
+++ b/pair.inc.h
@@ -0,0 +1,33 @@
+#if ! (defined(T) && defined(V))
+#error "Both T and V must be defiend here"
+#else
+
+INIT_F(PAIR(T, V)) {
+ INIT(T, &this->left);
+ INIT(V, &this->right);
+
+ return 0;
+}
+
+FREE_F(PAIR(T, V)) {
+ FREE(T)(&this->left);
+ FREE(V)(&this->right);
+ return 0;
+}
+
+FMT_F(PAIR(T, V)) {
+ char lbuf[100];
+ char rbuf[100];
+ FMT(T)(&this->left, lbuf);
+ FMT(V)(&this->right, rbuf);
+
+ return sprintf(buf, "<%s, %s>", lbuf, rbuf);
+}
+
+int DEEP_COPY(PAIR(T, V)) (PAIR(T, V)* dest, PAIR(T, V)* src) {
+ DEEP_COPY(T)(&dest->left, &src->left);
+ DEEP_COPY(V)(&dest->right, &src->right);
+ return 0;
+}
+
+#endif /* T & V */