diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2023-10-08 16:21:00 +0100 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2023-10-08 16:21:00 +0100 |
commit | b7d3b265af36ea309483678aa57e0cd30026aa29 (patch) | |
tree | ee0cf81f13ea722f8646380fcf7435ce59ffc5a9 /libpqpp | |
parent | Use unique_ptr for handling unescaped bytea column buffer (diff) | |
download | libdbpp-postgresql-b7d3b265af36ea309483678aa57e0cd30026aa29.tar.bz2 libdbpp-postgresql-b7d3b265af36ea309483678aa57e0cd30026aa29.tar.xz libdbpp-postgresql-b7d3b265af36ea309483678aa57e0cd30026aa29.zip |
Make pq_deleter a generic helper
Diffstat (limited to 'libpqpp')
-rw-r--r-- | libpqpp/pq-column.h | 11 | ||||
-rw-r--r-- | libpqpp/pq-helpers.h | 14 |
2 files changed, 16 insertions, 9 deletions
diff --git a/libpqpp/pq-column.h b/libpqpp/pq-column.h index d3400bf..6bf2669 100644 --- a/libpqpp/pq-column.h +++ b/libpqpp/pq-column.h @@ -1,6 +1,7 @@ #ifndef PG_COLUMN_H #define PG_COLUMN_H +#include "pq-helpers.h" #include <column.h> #include <cstring> #include <libpq-fe.h> @@ -32,15 +33,7 @@ namespace PQ { const Oid oid; // Buffer for PQunescapeBytea - struct pq_deleter { - void - operator()(unsigned char * p) - { - PQfreemem(p); - } - }; - - using BufPtr = std::unique_ptr<unsigned char, pq_deleter>; + using BufPtr = std::unique_ptr<unsigned char, pq_deleter<PQfreemem>>; mutable BufPtr buf; }; } diff --git a/libpqpp/pq-helpers.h b/libpqpp/pq-helpers.h new file mode 100644 index 0000000..76e5057 --- /dev/null +++ b/libpqpp/pq-helpers.h @@ -0,0 +1,14 @@ +#ifndef PQ_HELPERS_H +#define PQ_HELPERS_H + +namespace PQ { + template<auto func> struct pq_deleter { + void + operator()(auto p) const + { + func(p); + } + }; +} + +#endif |