| 1 |
|
| #pragma once |
| 2 |
|
| #include <xs/Io.h> |
| 3 |
|
| #include <xs/Sub.h> |
| 4 |
|
| #include <xs/Hash.h> |
| 5 |
|
| #include <xs/Array.h> |
| 6 |
|
| #include <xs/Scalar.h> |
| 7 |
|
| |
| 8 |
|
| namespace xs { |
| 9 |
|
| |
| 10 |
|
| using xs::my_perl; |
| 11 |
|
| |
| 12 |
|
| struct Glob : Scalar { |
| 13 |
|
| static Glob create (const Stash& stash, panda::string_view name, U32 flags = 0); |
| 14 |
|
| |
| 15 |
0 |
| Glob (std::nullptr_t = nullptr) {} |
| 16 |
|
| Glob (SV* sv, bool policy = INCREMENT) : Scalar(sv, policy) { _validate(); } |
| 17 |
0 |
| Glob (GV* sv, bool policy = INCREMENT) : Scalar(sv, policy) {} |
| 18 |
|
| |
| 19 |
|
| Glob (const Glob& oth) : Scalar(oth) {} |
| 20 |
|
| Glob (Glob&& oth) : Scalar(std::move(oth)) {} |
| 21 |
|
| Glob (const Scalar& oth) : Scalar(oth) { _validate(); } |
| 22 |
|
| Glob (Scalar&& oth) : Scalar(std::move(oth)) { _validate(); } |
| 23 |
|
| Glob (const Sv& oth) : Scalar(oth) { _validate(); } |
| 24 |
|
| Glob (Sv&& oth) : Scalar(std::move(oth)) { _validate(); } |
| 25 |
|
| |
| 26 |
|
| Glob (const Simple&) = delete; |
| 27 |
|
| Glob (const Ref&) = delete; |
| 28 |
|
| Glob (const Array&) = delete; |
| 29 |
|
| Glob (const Hash&) = delete; |
| 30 |
|
| Glob (const Sub&) = delete; |
| 31 |
|
| Glob (const Io&) = delete; |
| 32 |
|
| |
| 33 |
|
| Glob& operator= (SV* val) { Scalar::operator=(val); _validate(); return *this; } |
| 34 |
|
| Glob& operator= (GV* val) { Scalar::operator=(val); return *this; } |
| 35 |
|
| Glob& operator= (const Glob& oth) { Scalar::operator=(oth); return *this; } |
| 36 |
|
| Glob& operator= (Glob&& oth) { Scalar::operator=(std::move(oth)); return *this; } |
| 37 |
|
| Glob& operator= (const Scalar& oth) { Scalar::operator=(oth); _validate(); return *this; } |
| 38 |
|
| Glob& operator= (Scalar&& oth) { Scalar::operator=(std::move(oth)); _validate(); return *this; } |
| 39 |
|
| Glob& operator= (const Sv& oth) { return operator=(oth.get()); } |
| 40 |
|
| Glob& operator= (Sv&& oth) { Sv::operator=(std::move(oth)); _validate(); return *this; } |
| 41 |
|
| Glob& operator= (const Simple&) = delete; |
| 42 |
|
| Glob& operator= (const Ref&) = delete; |
| 43 |
|
| Glob& operator= (const Array&) = delete; |
| 44 |
|
| Glob& operator= (const Hash&) = delete; |
| 45 |
|
| Glob& operator= (const Sub&) = delete; |
| 46 |
|
| Glob& operator= (const Io&) = delete; |
| 47 |
|
| |
| 48 |
0 |
| void set (SV* val) { Sv::operator=(val); } |
| 49 |
|
| |
| 50 |
|
| operator AV* () const = delete; |
| 51 |
|
| operator HV* () const = delete; |
| 52 |
|
| operator CV* () const = delete; |
| 53 |
|
| operator IO* () const = delete; |
| 54 |
|
| operator GV* () const { return (GV*)sv; } |
| 55 |
|
| |
| 56 |
|
| GV* operator->() const { return (GV*)sv; } |
| 57 |
|
| |
| 58 |
0 |
| template <typename T = SV> panda::enable_if_one_of_t<T,SV,GV>* get () const { return (T*)sv; } |
| 59 |
|
| |
| 60 |
|
| template <typename T> panda::enable_if_one_of_t<T,Scalar,Array,Hash,Sub,Io> slot () const; |
| 61 |
|
| |
| 62 |
0 |
▶ | Scalar scalar () const { return sv ? GvSV((GV*)sv) : nullptr; } |
Branch: 1 branch
| Branch | True | False | Total |
| Scalar scalar () const { return sv ? GvSV((GV*)sv) : nullptr; } |
0 |
0 |
0 |
|
| 63 |
0 |
▶ | Array array () const { return sv ? GvAV((GV*)sv) : nullptr; } |
Branch: 1 branch
| Branch | True | False | Total |
| Array array () const { return sv ? GvAV((GV*)sv) : nullptr; } |
0 |
0 |
0 |
|
| 64 |
0 |
▶ | Hash hash () const { return sv ? GvHV((GV*)sv) : nullptr; } |
Branch: 1 branch
| Branch | True | False | Total |
| Hash hash () const { return sv ? GvHV((GV*)sv) : nullptr; } |
0 |
0 |
0 |
|
| 65 |
0 |
▶ | Sub sub () const { return sv ? GvCV((GV*)sv) : nullptr; } |
Branch: 1 branch
| Branch | True | False | Total |
| Sub sub () const { return sv ? GvCV((GV*)sv) : nullptr; } |
0 |
0 |
0 |
|
| 66 |
6 |
▶ | Io io () const { return sv ? GvIO((GV*)sv) : nullptr; } |
Branch: 5 branches
| Branch | True | False | Total |
| Io io () const { return sv ? GvIO((GV*)sv) : nullptr; } |
5 |
1 |
6 |
| Io io () const { return sv ? GvIO((GV*)sv) : nullptr; } |
5 |
0 |
5 |
| Io io () const { return sv ? GvIO((GV*)sv) : nullptr; } |
0 |
5 |
5 |
| Io io () const { return sv ? GvIO((GV*)sv) : nullptr; } |
0 |
0 |
0 |
| Io io () const { return sv ? GvIO((GV*)sv) : nullptr; } |
5 |
0 |
5 |
|
| 67 |
|
| |
| 68 |
|
| void slot (SV*); |
| 69 |
|
| void slot (AV*); |
| 70 |
|
| void slot (HV*); |
| 71 |
|
| void slot (CV*); |
| 72 |
|
| void slot (IO*); |
| 73 |
|
| void slot (const Scalar&); |
| 74 |
|
| void slot (const Sv& v) { slot(v.get()); } |
| 75 |
0 |
| void slot (const Array& v) { slot(v.get<AV>()); } |
| 76 |
0 |
| void slot (const Hash& v) { slot(v.get<HV>()); } |
| 77 |
0 |
| void slot (const Sub& v) { slot(v.get<CV>()); } |
| 78 |
2 |
| void slot (const Io& v) { slot(v.get<IO>()); } |
| 79 |
|
| void slot (GV*) = delete; |
| 80 |
|
| void slot (const Glob&) = delete; |
| 81 |
|
| |
| 82 |
0 |
| void scalar (const Scalar& val) { slot(val); } |
| 83 |
0 |
| void array (const Array& val) { slot(val); } |
| 84 |
0 |
| void hash (const Hash& val) { slot(val); } |
| 85 |
0 |
| void sub (const Sub& val) { slot(val); } |
| 86 |
|
| void io (const Io& val) { slot(val); } |
| 87 |
|
| |
| 88 |
|
| Sv get_const () const { return gv_const_sv((GV*)sv); } |
| 89 |
|
| |
| 90 |
|
| panda::string_view name () const { return panda::string_view(GvNAME((GV*)sv), GvNAMELEN((GV*)sv)); } |
| 91 |
|
| panda::string_view effective_name () const { return panda::string_view(GvENAME((GV*)sv), GvENAMELEN((GV*)sv)); } |
| 92 |
|
| |
| 93 |
|
| Stash stash () const; |
| 94 |
|
| Stash effective_stash () const; |
| 95 |
|
| |
| 96 |
|
| private: |
| 97 |
|
| void _validate () { |
| 98 |
|
| if (!sv) return; |
| 99 |
|
| if (type() == SVt_PVGV) return; |
| 100 |
|
| if (SvROK(sv)) { |
| 101 |
|
| SV* val = SvRV(sv); |
| 102 |
|
| if (SvTYPE(val) == SVt_PVGV) { |
| 103 |
|
| Sv::operator=(val); |
| 104 |
|
| return; |
| 105 |
|
| } |
| 106 |
|
| } |
| 107 |
|
| if (is_undef()) return reset(); |
| 108 |
|
| reset(); |
| 109 |
|
| throw std::invalid_argument("SV is not a Glob or Glob reference"); |
| 110 |
|
| } |
| 111 |
|
| }; |
| 112 |
|
| |
| 113 |
|
| template <> inline Scalar Glob::slot<Scalar> () const { return scalar(); } |
| 114 |
|
| template <> inline Array Glob::slot<Array> () const { return array(); } |
| 115 |
|
| template <> inline Hash Glob::slot<Hash> () const { return hash(); } |
| 116 |
|
| template <> inline Sub Glob::slot<Sub> () const { return sub(); } |
| 117 |
|
| template <> inline Io Glob::slot<Io> () const { return io(); } |
| 118 |
|
| |
| 119 |
|
| } |