| 1 |
|
| #pragma once |
| 2 |
|
| #include <xs/Scalar.h> |
| 3 |
|
| |
| 4 |
|
| namespace xs { |
| 5 |
|
| |
| 6 |
|
| using xs::my_perl; |
| 7 |
|
| |
| 8 |
|
| struct HashEntry { |
| 9 |
83 |
| HashEntry (HE* he = NULL) : he(he) {} |
| 10 |
|
| |
| 11 |
6 |
| U32 hash () const { return HeHASH(he); } |
| 12 |
|
| |
| 13 |
19 |
| panda::string_view key () const { return panda::string_view(HeKEY(he), HeKLEN(he)); } |
| 14 |
|
| |
| 15 |
|
| HEK* hek () const { return HeKEY_hek(he); } |
| 16 |
|
| |
| 17 |
19 |
| Scalar value () const { |
| 18 |
19 |
| Scalar ret; |
| 19 |
19 |
▶ | ret.set(HeVAL(he)); |
Branch: 1 branch
| Branch | True | False | Total |
| ret.set(HeVAL(he)); |
19 |
0 |
19 |
|
| 20 |
19 |
| return ret; |
| 21 |
|
| } |
| 22 |
|
| |
| 23 |
3 |
| void value (const Scalar& val) { |
| 24 |
3 |
▶ | SvREFCNT_inc_simple_void(val.get()); |
Branch: 1 branch
| Branch | True | False | Total |
| SvREFCNT_inc_simple_void(val.get()); |
3 |
0 |
3 |
|
| 25 |
3 |
| auto old = HeVAL(he); |
| 26 |
3 |
| HeVAL(he) = val.get(); |
| 27 |
3 |
| SvREFCNT_dec(old); |
| 28 |
3 |
| } |
| 29 |
3 |
▶ | void value (SV* v) { value(Scalar(v)); } |
Branch: 2 branches
| Branch | True | False | Total |
| void value (SV* v) { value(Scalar(v)); } |
3 |
0 |
3 |
| void value (SV* v) { value(Scalar(v)); } |
3 |
0 |
3 |
|
| 30 |
|
| void value (const Sv& v) { value(Scalar(v)); } |
| 31 |
|
| void value (const Array&) = delete; |
| 32 |
|
| void value (const Hash&) = delete; |
| 33 |
|
| void value (const Sub&) = delete; |
| 34 |
|
| void value (const Io&) = delete; |
| 35 |
|
| |
| 36 |
4 |
| bool operator== (const HashEntry& oth) const { return he == oth.he; } |
| 37 |
|
| |
| 38 |
|
| explicit |
| 39 |
97 |
| operator bool () const { return he; } |
| 40 |
|
| |
| 41 |
42 |
| operator HE* () const { return he; } |
| 42 |
|
| |
| 43 |
16 |
| HE* operator-> () const { return he; } |
| 44 |
|
| |
| 45 |
|
| private: |
| 46 |
|
| HE* he; |
| 47 |
|
| }; |
| 48 |
|
| |
| 49 |
|
| } |
| 50 |
|
| |
| 51 |
|
| #if (__cplusplus >= 201703L) |
| 52 |
|
| // structured bindings for C++17 and newer |
| 53 |
|
| namespace std |
| 54 |
|
| { |
| 55 |
|
| |
| 56 |
|
| template<> |
| 57 |
|
| struct tuple_size<xs::HashEntry> |
| 58 |
|
| { |
| 59 |
|
| static constexpr size_t value = 2; |
| 60 |
|
| }; |
| 61 |
|
| |
| 62 |
|
| template<> |
| 63 |
|
| struct tuple_element<0, xs::HashEntry> |
| 64 |
|
| { |
| 65 |
|
| using type = panda::string_view; |
| 66 |
|
| }; |
| 67 |
|
| |
| 68 |
|
| template<> |
| 69 |
|
| struct tuple_element<1, xs::HashEntry> |
| 70 |
|
| { |
| 71 |
|
| using type = xs::Scalar; |
| 72 |
|
| }; |
| 73 |
|
| |
| 74 |
|
| }//namespace std |
| 75 |
|
| |
| 76 |
|
| namespace xs { |
| 77 |
|
| |
| 78 |
|
| template<std::size_t Index> |
| 79 |
|
| std::tuple_element_t<Index, xs::HashEntry> get(const xs::HashEntry& he) |
| 80 |
|
| { |
| 81 |
|
| if constexpr (Index == 0) return he.key(); |
| 82 |
|
| if constexpr (Index == 1) return he.value(); |
| 83 |
|
| } |
| 84 |
|
| |
| 85 |
|
| } |
| 86 |
|
| #endif |