summaryrefslogtreecommitdiffstats
path: root/src/icalraii.h
diff options
context:
space:
mode:
authorDanilo M. <danix@danix.xyz>2026-09-24 15:58:31 +0200
committerDanilo M. <danix@danix.xyz>2026-09-24 15:58:31 +0200
commit0a26a0b3968486b3769ab42b2966fff6d2db1fb0 (patch)
tree55c5446f2371f09475e7d4c5fa07cf7894b8c00f /src/icalraii.h
parentc3822fedfae813efda52f131368f0017f6b28a87 (diff)
downloadqtmaildir-0a26a0b3968486b3769ab42b2966fff6d2db1fb0.tar.gz
qtmaildir-0a26a0b3968486b3769ab42b2966fff6d2db1fb0.zip
feat: parse one calendar event with libical (item 206)
Diffstat (limited to 'src/icalraii.h')
-rw-r--r--src/icalraii.h48
1 files changed, 48 insertions, 0 deletions
diff --git a/src/icalraii.h b/src/icalraii.h
new file mode 100644
index 0000000..b296db3
--- /dev/null
+++ b/src/icalraii.h
@@ -0,0 +1,48 @@
+/*
+ * qtmaildir - a Qt6 mail client for notmuch-indexed Maildirs
+ * Copyright (C) 2026 Danilo M. <danix@danix.xyz>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#pragma once
+
+#include <libical/ical.h>
+
+#include <cstdlib>
+#include <memory>
+
+/// Owners for libical handles, the calendar's counterpart to nmraii.h.
+///
+/// The same rule as notmuch's: no libical pointer leaves calendarstore.cpp,
+/// the one file that includes this header. unique_ptr rather than NmHandle's
+/// template because every libical handle here has exactly one destroy
+/// function and no aliasing, which is what unique_ptr already expresses.
+struct IcalComponentFree {
+ void operator()(icalcomponent *c) const { icalcomponent_free(c); }
+};
+using IcalComponent = std::unique_ptr<icalcomponent, IcalComponentFree>;
+
+struct IcalRecurFree {
+ void operator()(icalrecur_iterator *i) const { icalrecur_iterator_free(i); }
+};
+using IcalRecurIterator = std::unique_ptr<icalrecur_iterator, IcalRecurFree>;
+
+/// For strings returned by the `*_r` functions, which the caller must free().
+/// The plain variants return a ring buffer libical reuses, so a pointer kept
+/// from one is overwritten by a later call.
+struct IcalStringFree {
+ void operator()(char *s) const { std::free(s); }
+};
+using IcalString = std::unique_ptr<char, IcalStringFree>;