From 34786132fed0a776d4cd314c44ed62e29ff75328 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ingo=20Kl=C3=B6cker?= Date: Mon, 2 May 2022 15:50:18 +0200 Subject: cpp: Add RAII class for saving/restoring the key list mode * lang/cpp/src/context.h, lang/cpp/src/context.cpp (class Context): Add nested class KeyListModeSaver. -- This RAII-style class can be used to save the currently used key list mode in case it needs to be changed temporarily. On destruction, it will restore the key list mode that was active at construction time. GnuPG-bug-id: 5951 --- lang/cpp/src/context.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'lang/cpp/src/context.cpp') diff --git a/lang/cpp/src/context.cpp b/lang/cpp/src/context.cpp index 89bc3fd7..568e0458 100644 --- a/lang/cpp/src/context.cpp +++ b/lang/cpp/src/context.cpp @@ -195,6 +195,19 @@ std::ostream &operator<<(std::ostream &os, const Error &err) return os << "GpgME::Error(" << err.encodedError() << " (" << err.asString() << "))"; } +Context::KeyListModeSaver::KeyListModeSaver(Context *ctx) + : mCtx{ctx} + , mKeyListMode{ctx ? ctx->keyListMode() : 0} +{ +} + +Context::KeyListModeSaver::~KeyListModeSaver() +{ + if (mCtx) { + mCtx->setKeyListMode(mKeyListMode); + } +} + Context::Context(gpgme_ctx_t ctx) : d(new Private(ctx)) { } -- cgit v1.2.3