| 1 |
|
| #include <dict.hpp> |
| 2 |
|
| #include <xs_helper.hpp> |
| 3 |
|
| #include <xs/export.h> |
| 4 |
|
| #include <xs/dict.h> |
| 5 |
|
| #include <panda/string.h> |
| 6 |
|
| |
| 7 |
|
| using namespace json_tree; |
| 8 |
|
| using namespace xs; |
| 9 |
|
| using panda::string; |
| 10 |
|
| |
| 11 |
|
| MODULE = JSON::Immutable::XS PACKAGE = JSON::Immutable::XS |
| 12 |
|
| PROTOTYPES: DISABLE |
| 13 |
|
| |
| 14 |
|
| Dict * new(SV* CLASS, panda::string filename){ |
| 15 |
2 |
| PROTO = CLASS; |
| 16 |
2 |
▶ | RETVAL = new Dict(filename); |
Branch: 1 branch
| Branch | True | False | Total |
| RETVAL = new Dict(filename); |
2 |
0 |
2 |
|
| 17 |
2 |
▶ | } |
Branch: 1 branch
| Branch | True | False | Total |
| } |
2 |
0 |
2 |
|
| 18 |
2 |
▶ | |
Branch: 5 branches
| Branch | True | False | Total |
|
2 |
0 |
2 |
|
2 |
0 |
2 |
|
2 |
0 |
2 |
|
2 |
0 |
2 |
|
0 |
0 |
0 |
|
| 19 |
0 |
▶ | void Dict::load_dict( panda::string filename ) |
Branch: 2 branches
| Branch | True | False | Total |
| void Dict::load_dict( panda::string filename ) |
0 |
0 |
0 |
| void Dict::load_dict( panda::string filename ) |
0 |
0 |
0 |
|
| 20 |
|
| |
| 21 |
1 |
| void Dict::dump() : const |
| 22 |
|
| |
| 23 |
|
| Sv Dict::keys() : const { |
| 24 |
2 |
▶ | Array ret = Array::create(); |
Branch: 1 branch
| Branch | True | False | Total |
| Array ret = Array::create(); |
2 |
0 |
2 |
|
| 25 |
2 |
▶ | std::vector<panda::string> keys = THIS->keys(); |
Branch: 1 branch
| Branch | True | False | Total |
| std::vector<panda::string> keys = THIS->keys(); |
2 |
0 |
2 |
|
| 26 |
5 |
▶ | for ( auto k = keys.begin(); k != keys.end(); ++k ){ |
Branch: 1 branch
| Branch | True | False | Total |
| for ( auto k = keys.begin(); k != keys.end(); ++k ){ |
3 |
2 |
5 |
|
| 27 |
3 |
▶ | ret.push(xs::out<panda::string>(*k)); |
Branch: 2 branches
| Branch | True | False | Total |
| ret.push(xs::out<panda::string>(*k)); |
3 |
0 |
3 |
| ret.push(xs::out<panda::string>(*k)); |
3 |
0 |
3 |
|
| 28 |
|
| } |
| 29 |
2 |
▶ | RETVAL = Ref::create(ret); |
Branch: 1 branch
| Branch | True | False | Total |
| RETVAL = Ref::create(ret); |
2 |
0 |
2 |
|
| 30 |
|
| } |
| 31 |
|
| |
| 32 |
|
| const Dict* Dict::get( ... ) : const { |
| 33 |
26 |
| RETVAL = THIS->get(StringArgsRange{&ST(1), items-1}, 0 ); |
| 34 |
26 |
▶ | } |
Branch: 2 branches
| Branch | True | False | Total |
| } |
26 |
0 |
26 |
| } |
26 |
0 |
26 |
|
| 35 |
|
| |
| 36 |
|
| Sv Dict::get_value( ... ) : const { |
| 37 |
7 |
▶ | RETVAL = dict2sv(THIS->get( StringArgsRange{&ST(1), items-1}, 0 )); |
Branch: 2 branches
| Branch | True | False | Total |
| RETVAL = dict2sv(THIS->get( StringArgsRange{&ST(1), items-1}, 0 )); |
7 |
0 |
7 |
| RETVAL = dict2sv(THIS->get( StringArgsRange{&ST(1), items-1}, 0 )); |
7 |
0 |
7 |
|
| 38 |
|
| } |
| 39 |
|
| |
| 40 |
|
| Sv Dict::slice( ... ) : const { |
| 41 |
5 |
▶ | if ( items < 2) XSRETURN_UNDEF; |
Branch: 1 branch
| Branch | True | False | Total |
| if ( items < 2) XSRETURN_UNDEF; |
2 |
3 |
5 |
|
| 42 |
3 |
| StringArgsRange args = StringArgsRange{&ST(1), items-2}; |
| 43 |
3 |
▶ | panda::string field = xs::in<panda::string>(ST(items-1)); |
Branch: 1 branch
| Branch | True | False | Total |
| panda::string field = xs::in<panda::string>(ST(items-1)); |
3 |
0 |
3 |
|
| 44 |
3 |
| RETVAL = std::visit(overloaded{ |
| 45 |
2 |
| [&](const Dict::ObjectMap& m) -> Sv { |
| 46 |
2 |
▶ | auto ret = Hash::create(m.size()); |
Branch: 1 branch
| Branch | True | False | Total |
| auto ret = Hash::create(m.size()); |
2 |
0 |
2 |
|
| 47 |
8 |
▶ | for (const auto& r : m){ |
Branch: 1 branch
| Branch | True | False | Total |
| for (const auto& r : m){ |
6 |
2 |
8 |
|
| 48 |
6 |
▶ | ret[r.first.c_str()] = dict2sv_slice(r.second.get(args,0), field); |
Branch: 7 branches
| Branch | True | False | Total |
| ret[r.first.c_str()] = dict2sv_slice(r.second.get(args,0), field); |
6 |
0 |
6 |
| ret[r.first.c_str()] = dict2sv_slice(r.second.get(args,0), field); |
6 |
0 |
6 |
| ret[r.first.c_str()] = dict2sv_slice(r.second.get(args,0), field); |
6 |
0 |
6 |
| ret[r.first.c_str()] = dict2sv_slice(r.second.get(args,0), field); |
6 |
0 |
6 |
| ret[r.first.c_str()] = dict2sv_slice(r.second.get(args,0), field); |
6 |
0 |
6 |
| ret[r.first.c_str()] = dict2sv_slice(r.second.get(args,0), field); |
6 |
0 |
6 |
| ret[r.first.c_str()] = dict2sv_slice(r.second.get(args,0), field); |
6 |
0 |
6 |
|
| 49 |
|
| } |
| 50 |
4 |
▶ | return Ref::create(ret); |
Branch: 1 branch
| Branch | True | False | Total |
| return Ref::create(ret); |
2 |
0 |
2 |
|
| 51 |
2 |
| }, |
| 52 |
1 |
| [&](const Dict::ObjectArr& a) -> Sv { |
| 53 |
1 |
▶ | auto ret = Array::create(a.size()); |
Branch: 1 branch
| Branch | True | False | Total |
| auto ret = Array::create(a.size()); |
1 |
0 |
1 |
|
| 54 |
4 |
▶ | for ( const auto& r : a ){ |
Branch: 1 branch
| Branch | True | False | Total |
| for ( const auto& r : a ){ |
3 |
1 |
4 |
|
| 55 |
3 |
▶ | ret.push( dict2sv_slice( r.get(args,0), field ) ); |
Branch: 4 branches
| Branch | True | False | Total |
| ret.push( dict2sv_slice( r.get(args,0), field ) ); |
3 |
0 |
3 |
| ret.push( dict2sv_slice( r.get(args,0), field ) ); |
3 |
0 |
3 |
| ret.push( dict2sv_slice( r.get(args,0), field ) ); |
3 |
0 |
3 |
| ret.push( dict2sv_slice( r.get(args,0), field ) ); |
3 |
0 |
3 |
|
| 56 |
|
| } |
| 57 |
2 |
▶ | return Ref::create(ret); |
Branch: 1 branch
| Branch | True | False | Total |
| return Ref::create(ret); |
1 |
0 |
1 |
|
| 58 |
1 |
| }, |
| 59 |
0 |
| [](auto) -> Sv { |
| 60 |
0 |
| return Sv::undef; |
| 61 |
|
| } |
| 62 |
|
| }, |
| 63 |
3 |
▶ | THIS->value); |
Branch: 1 branch
| Branch | True | False | Total |
| THIS->value); |
3 |
0 |
3 |
|
| 64 |
|
| } |
| 65 |
|
| |
| 66 |
|
| Sv Dict::size( ... ) : const { |
| 67 |
6 |
▶ | const Dict* d = THIS->get(StringArgsRange{&ST(1), items-1},0); |
Branch: 1 branch
| Branch | True | False | Total |
| const Dict* d = THIS->get(StringArgsRange{&ST(1), items-1},0); |
6 |
0 |
6 |
|
| 68 |
6 |
▶ | if (d == nullptr) XSRETURN_UNDEF; |
Branch: 1 branch
| Branch | True | False | Total |
| if (d == nullptr) XSRETURN_UNDEF; |
0 |
6 |
6 |
|
| 69 |
6 |
| RETVAL = std::visit(overloaded{ |
| 70 |
2 |
| [&](const Dict::ObjectMap& m) -> Sv { |
| 71 |
2 |
▶ | return Simple(m.size()); |
Branch: 1 branch
| Branch | True | False | Total |
| return Simple(m.size()); |
2 |
0 |
2 |
|
| 72 |
|
| }, |
| 73 |
3 |
| [&](const Dict::ObjectArr& a) -> Sv { |
| 74 |
3 |
▶ | return Simple(a.size()); |
Branch: 1 branch
| Branch | True | False | Total |
| return Simple(a.size()); |
3 |
0 |
3 |
|
| 75 |
|
| }, |
| 76 |
0 |
| [](auto) -> Sv { |
| 77 |
0 |
| return Sv::undef; |
| 78 |
|
| } |
| 79 |
|
| }, |
| 80 |
6 |
▶ | d->value); |
Branch: 1 branch
| Branch | True | False | Total |
| d->value); |
6 |
0 |
6 |
|
| 81 |
|
| } |
| 82 |
|
| |
| 83 |
|
| uint Dict::exists( ... ) : const { |
| 84 |
5 |
| RETVAL=(THIS->get(StringArgsRange{&ST(1), items-1},0) == nullptr) ? 0 : 1; |
| 85 |
5 |
▶ | } |
Branch: 2 branches
| Branch | True | False | Total |
| } |
5 |
0 |
5 |
| } |
5 |
0 |
5 |
|
| 86 |
|
| |
| 87 |
|
| Sv Dict::export() : const { |
| 88 |
9 |
▶ | RETVAL = dict2sv( THIS ); |
Branch: 1 branch
| Branch | True | False | Total |
| RETVAL = dict2sv( THIS ); |
9 |
0 |
9 |
|
| 89 |
|
| } |