diff options
author | John Ankarström <john@ankarstrom.se> | 2022-07-30 03:14:13 +0200 |
---|---|---|
committer | John Ankarström <john@ankarstrom.se> | 2022-07-30 03:14:13 +0200 |
commit | ebabd34385feb629b759216c1f7d85edc20bf2fd (patch) | |
tree | 432e68a6a58bcaf4bc1dd3c5ae438157f09f4d4a /c/pl.h | |
parent | d485eb2bf7e0a82702afec9387f21bf0f89c985f (diff) | |
download | EpisodeBrowser-ebabd34385feb629b759216c1f7d85edc20bf2fd.tar.gz |
Add wstring_owner, replacing std::wstring.
std::basic_string is nice, but it is not very ergonomic if everything
you really need is to automatically free C strings at end of scope.
I suppose I could have used std::unique_ptr for this, but I suspect
the ergonomics would be worse.
Diffstat (limited to 'c/pl.h')
-rw-r--r-- | c/pl.h | 16 |
1 files changed, 4 insertions, 12 deletions
@@ -7,7 +7,7 @@ #include "common.h" -int PlString(term_t t, std::wstring* pWs, int iFlags = CVT_WRITE); +wstring_owner PlString(const term_t t, const int iFlags = CVT_WRITE); struct Frame { @@ -54,8 +54,7 @@ inline int PlPut(term_t, long*) { return -1; } inline int PlPut(term_t, long long*) { return -1; } inline int PlPut(term_t, atom_t*) { return -1; } inline int PlPut(term_t, char**) { return -1; } -inline int PlPut(term_t, std::string*) { return -1; } -inline int PlPut(term_t, std::wstring*) { return -1; } +inline int PlPut(term_t, wstring_owner*) { return -1; } inline int PlGet(term_t, int) { return -1; } inline int PlGet(term_t, long) { return -1; } @@ -68,18 +67,11 @@ inline int PlGet(term_t t, long* x) { return PL_get_long(t, x); } inline int PlGet(term_t t, long long* x) { return PL_get_int64(t, x); } inline int PlGet(term_t t, atom_t* x) { return PL_get_atom(t, x); } inline int PlGet(term_t t, char** x) { return PL_get_atom_chars(t, x); } -inline int PlGet(term_t t, std::string* x) { +inline int PlGet(term_t t, wstring_owner* x) { Mark m; char* sz; if (!PlGet(t, &sz)) return 0; - *x = sz; - return 1; -} -inline int PlGet(term_t t, std::wstring* x) { - Mark m; - char* sz; - if (!PlGet(t, &sz)) return 0; - *x = WsFromSz(sz); + *x = WsoFromSz(sz); return 1; /* or catch potential exception from BstrFromSz? */ } |