File Coverage

/usr/local/lib/perl5/site_perl/5.26.1/x86_64-linux/XS/Framework.x/i/xs/typemap/optional.h
Criterion Covered Total %
statement 4 4 100.0
branch 1 2 50.0
condition n/a
subroutine n/a
pod n/a
total 5 6 83.3


line stmt bran cond sub pod time code
1             #pragma once
2             #include "base.h"
3             #include
4              
5             namespace xs {
6              
7             // typemap for optional
8             template struct Typemap> : Typemap {
9             static panda::optional in (SV* arg) {
10             if (!SvOK(arg)) return {};
11             return Typemap::in(arg);
12             }
13             static Sv out (const panda::optional& var, const Sv& = {}) {
14             if (!var) return Sv::undef;
15             return Typemap::out(*var);
16             }
17             };
18              
19             // not-null wrapper for use in input typemaps
20             template
21             struct nn {
22             nn () {}
23             nn (const nn&) = default;
24             nn (nn&&) = default;
25              
26             template
27             nn (const nn& oth) : val(oth.val) {}
28              
29             template
30             nn (nn&& oth) : val(std::move(oth.val)) {}
31              
32             template
33             nn (U&& val) : val(std::forward(val)) {}
34              
35             nn& operator= (const nn&) = default;
36             nn& operator= (nn&&) = default;
37              
38             template
39             nn& operator= (U&& v) {
40             val = std::forward(v);
41             return *this;
42             }
43              
44             decltype(*T()) operator* () { return *val; }
45             T& operator-> () { return val; }
46              
47             operator T () { return val; }
48              
49             private:
50             T val;
51             };
52              
53             template struct Typemap> : Typemap {
54 4           static TYPE in (SV* arg) {
55 4           auto ret = Typemap::in(arg);
56 4 50         if (!ret) throw "invalid value: undef not allowed";
57 4           return ret;
58             }
59             static Sv out (TYPE& var, const Sv& = {}) = delete;
60             };
61              
62             }