src/xs/typemap/error.h

filter: Statementstmt 0.0% 0 / 9 Branchbran 0.0% 0 / 24 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 0.0% 0 / 33 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« src/xs/typemap/base.h ↑ Summary src/xs/typemap/numeric.h »
1 #pragma once
2 #include "object.h"
3 #include "../Object.h"
4 #include <system_error>
5 #include <panda/exception.h>
6 #include <panda/error.h>
7  
8 namespace xs {
9
10 template <> struct Typemap<const std::error_category*> : TypemapObject<const std::error_category*, const std::error_category*, ObjectTypeForeignPtr, ObjectStorageMG> {
11 static panda::string_view package () { return "XS::STL::ErrorCategory"; }
12 };
13  
14 template <> struct Typemap<std::error_code> : TypemapBase<std::error_code> {
15 static HV* stash();
16  
17 static std::error_code in (const Sv& arg) {
18 if (!arg.defined()) return {};
19 SV* sv = SvROK(arg) ? SvRV(arg) : arg.get();
20 if (!SvOBJECT(sv)) throw panda::exception("invalid std::error_code");
21 if (!SvPOK(sv) || SvCUR(sv) < sizeof(std::error_code)) throw panda::exception("invalid std::error_code");
22 return *((std::error_code*)SvPVX(sv));
23 }
24  
25 0 static Sv out (const std::error_code& var, const Sv& = {}) {
26 0 ▶ if (!var) return Sv::undef;
Branch: 2 branches
BranchTrueFalseTotal
if (!var) return Sv::undef; 0 0 0
if (!var) return Sv::undef; 0 0 0
27 0 ▶ auto base = Simple(panda::string_view(reinterpret_cast<const char*>(&var), sizeof(var)));
Branch: 1 branch
BranchTrueFalseTotal
auto base = Simple(panda::string_view(reinterpret_cast<const char*>(&var), sizeof(var))); 0 0 0
28 0 ▶ return Stash(stash()).bless(base).ref();
Branch: 5 branches
BranchTrueFalseTotal
return Stash(stash()).bless(base).ref(); 0 0 0
return Stash(stash()).bless(base).ref(); 0 0 0
return Stash(stash()).bless(base).ref(); 0 0 0
return Stash(stash()).bless(base).ref(); 0 0 0
return Stash(stash()).bless(base).ref(); 0 0 0
29 0 }
30 };
31  
32 template <> struct Typemap<panda::ErrorCode*> : TypemapObject<panda::ErrorCode*, panda::ErrorCode*, ObjectTypePtr, ObjectStorageMG> {
33 0 static panda::string_view package () { return "XS::ErrorCode"; }
34 };
35  
36 template <> struct Typemap<panda::ErrorCode> : Typemap<panda::ErrorCode*> {
37 using Super = Typemap<panda::ErrorCode*>;
38  
39 static panda::ErrorCode in (const Sv& arg) {
40 if (!arg.defined()) return {};
41 if (!arg.is_object_ref()) throw panda::exception("invalid XS::ErrorCode object");
42 if (Object(arg).stash() == Typemap<std::error_code>::stash()) return xs::in<std::error_code>(arg);
43 return *Super::in(arg);
44 }
45  
46 0 static Sv out (const panda::ErrorCode& var, const Sv& proto = {}) {
47 0 ▶ if (!var) return Sv::undef;
Branch: 1 branch
BranchTrueFalseTotal
if (!var) return Sv::undef; 0 0 0
48 0 ▶ return Super::out(new panda::ErrorCode(var), proto);
Branch: 3 branches
BranchTrueFalseTotal
return Super::out(new panda::ErrorCode(var), proto); 0 0 0
return Super::out(new panda::ErrorCode(var), proto); 0 0 0
return Super::out(new panda::ErrorCode(var), proto); 0 0 0
49 }
50 };
51  
52 }
« src/xs/typemap/base.h ↑ Summary src/xs/typemap/numeric.h »