diff options
| author | John Baldwin <jhb@FreeBSD.org> | 2025-08-04 19:38:07 +0000 |
|---|---|---|
| committer | John Baldwin <jhb@FreeBSD.org> | 2025-08-04 19:38:07 +0000 |
| commit | 63ffcf6971a36e00efc138c3261b499aa48e102f (patch) | |
| tree | bd712b569695bb492a7f988d42a89af2fe44cca2 /lib/libutil++ | |
| parent | 5b0f19262952e7d39fe9a94a0e21c739275e643b (diff) | |
Diffstat (limited to 'lib/libutil++')
| -rw-r--r-- | lib/libutil++/Makefile | 1 | ||||
| -rw-r--r-- | lib/libutil++/freebsd::nvlist_up.3 | 37 | ||||
| -rw-r--r-- | lib/libutil++/libutil++.hh | 14 |
3 files changed, 52 insertions, 0 deletions
diff --git a/lib/libutil++/Makefile b/lib/libutil++/Makefile index e64c9fe6cb75..3389e7e21b11 100644 --- a/lib/libutil++/Makefile +++ b/lib/libutil++/Makefile @@ -8,6 +8,7 @@ MAN+= freebsd::FILE_up.3 \ freebsd::addrinfo_up.3 \ freebsd::fd_up.3 \ freebsd::malloc_up.3 \ + freebsd::nvlist_up.3 \ freebsd::stringf.3 .include <src.opts.mk> diff --git a/lib/libutil++/freebsd::nvlist_up.3 b/lib/libutil++/freebsd::nvlist_up.3 new file mode 100644 index 000000000000..43f76cf3ead3 --- /dev/null +++ b/lib/libutil++/freebsd::nvlist_up.3 @@ -0,0 +1,37 @@ +.\" +.\" SPDX-License-Identifier: BSD-2-Clause +.\" +.\" Copyright (c) 2025 Chelsio Communications, Inc. +.\" Written by: John Baldwin <jhb@FreeBSD.org> +.\" +.Dd July 31, 2025 +.Dt FREEBSD::NVLIST_UP 3 +.Os +.Sh NAME +.Nm freebsd::nvlist_up +.Nd std::unique_ptr specialization for name/value pairs +.Sh LIBRARY +.Lb libutil++ +.Sh SYNOPSIS +.In libutil++.hh +.Ft using nvlist_up = std::unique_ptr<nvlist, nvlist_deleter>; +.Sh DESCRIPTION +This class is a specialization of +.Vt std::unique_ptr +for +.Vt nvlist_t +objects. +When an +.Vt nvlist_t +object managed by an instance of this class is disposed, +.Xr nvlist_destroy 3 +is invoked to dispose of the object. +.Sh EXAMPLES +.Bd -literal -offset indent +freebsd::nvlist_up nvl(nvlist_create(0)); +nvlist_add_number(nvl.get(), "answer", 42); +nvlist_add_bool(nvl.get(), "valid", true); +// `nvl' is implicitly destroyed +.Ed +.Sh SEE ALSO +.Xr nvlist_destroy 3 diff --git a/lib/libutil++/libutil++.hh b/lib/libutil++/libutil++.hh index 616bbecd8a12..121633c4deea 100644 --- a/lib/libutil++/libutil++.hh +++ b/lib/libutil++/libutil++.hh @@ -8,6 +8,7 @@ #ifndef __LIBUTILPP_HH__ #define __LIBUTILPP_HH__ +#include <sys/nv.h> #include <netdb.h> #include <unistd.h> @@ -132,6 +133,19 @@ namespace freebsd { using malloc_up = std::unique_ptr<T, free_deleter<T>>; /* + * nvlist_up is a std::unique_ptr<> for nvlist_t objects which + * uses nvlist_destroy() to destroy the wrapped pointer. + */ + struct nvlist_deleter { + void operator() (nvlist_t *nvl) const + { + nvlist_destroy(nvl); + } + }; + + using nvlist_up = std::unique_ptr<nvlist_t, nvlist_deleter>; + + /* * Returns a std::string containing the same output as * sprintf(). Throws std::bad_alloc if an error occurs. */ |
