File Coverage

/usr/local/lib/perl5/site_perl/5.26.1/x86_64-linux/XS/Framework.x/i/xs/typemap/containers.h
Criterion Covered Total %
statement 6 6 100.0
branch 9 16 56.2
condition n/a
subroutine n/a
pod n/a
total 15 22 68.1


line stmt bran cond sub pod time code
1             #pragma once
2             #include "base.h"
3             #include "../Hash.h"
4             #include "../Array.h"
5             #include "../Simple.h"
6             #include
7             #include
8             #include
9              
10             namespace xs {
11              
12             namespace typemap { namespace containers {
13             inline const panda::string& to_key (const panda::string& value) { return value; }
14             inline panda::string_view to_key (const std::string& value) { return panda::string_view(value.data(), value.size()); }
15              
16             template
17             panda::string to_key (T&& value) { return panda::to_string(std::forward(value)); }
18             }}
19              
20             template struct VectorTypemap : TypemapBase> {
21             static Sv out(const std::vector& data, const Sv& = {}){
22             auto out = Array::create(data.size());
23             for(const auto& i : data){
24             out.push(xs::out(i));
25             }
26             return Ref::create(out);
27             }
28              
29 2           static std::vector in (Array arg){
30 2           std::vector out;
31 2 50         out.reserve(arg.size());
    50          
32 10 50         for(const auto& i : arg){
    50          
    100          
    50          
33 8 50         out.emplace_back(xs::in(i));
    50          
34             }
35 2           return out;
36             }
37             };
38              
39             template struct Typemap> : VectorTypemap {};
40              
41             template struct Typemap, std::map> : TypemapBase> {
42             static Sv out (const std::map& data, const Sv& = {}) {
43             auto out = Hash::create(data.size());
44             for(const auto& i : data){
45             auto key = typemap::containers::to_key(i.first);
46             out.store(key, xs::out(i.second));
47             }
48             return Ref::create(out);
49             }
50              
51             static std::map in (Hash arg) {
52             std::map out;
53             for (const auto& element : arg){
54             K key = xs::in(Simple(element.key()));
55             V value = xs::in(element.value());
56             out.emplace(key, value);
57             }
58             return out;
59             }
60             };
61              
62             template struct Typemap, std::unordered_map> : TypemapBase> {
63             static Sv out (const std::unordered_map& data, const Sv& = {}) {
64             auto out = Hash::create(data.size());
65             for(const auto& i : data){
66             auto key = typemap::containers::to_key(i.first);
67             out.store(key, xs::out(i.second));
68             }
69             return Ref::create(out);
70             }
71              
72             static std::unordered_map in (Hash arg) {
73             std::unordered_map out;
74             for (const auto& element : arg){
75             K key = xs::in(Simple(element.key()));
76             V value = xs::in(element.value());
77             out.emplace(key, value);
78             }
79             return out;
80             }
81              
82             };
83              
84             }