src/xs/typemap/containers.h

filter: Statementstmt 100% 56 / 56 Branchbran 57.3% 47 / 82 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 74.6% 103 / 138 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« t/typemap/object/avhv.xsi ↑ Summary t/typemap/container.xsi »
1 #pragma once
2 #include "base.h"
3 #include "../Hash.h"
4 #include "../Array.h"
5 #include "../Simple.h"
6 #include <map>
7 #include <unordered_map>
8 #include <vector>
9  
10 namespace xs {
11  
12 namespace typemap { namespace containers {
13 inline const panda::string& to_key (const panda::string& value) { return value; }
14 3 inline panda::string_view to_key (const std::string& value) { return panda::string_view(value.data(), value.size()); }
15  
16 template <typename T>
17 4 panda::string to_key (T&& value) { return panda::to_string(std::forward<T>(value)); }
18 }}
19  
20 template <typename T> struct VectorTypemap : TypemapBase<std::vector<T>> {
21 1 static Sv out(const std::vector<T>& data, const Sv& = {}){
22 1 ▶ auto out = Array::create(data.size());
Branch: 1 branch
BranchTrueFalseTotal
auto out = Array::create(data.size()); 1 0 1
23 6 ▶ for(const auto& i : data){
Branch: 1 branch
BranchTrueFalseTotal
for(const auto& i : data){ 5 1 6
24 5 ▶ out.push(xs::out(i));
Branch: 2 branches
BranchTrueFalseTotal
out.push(xs::out(i)); 5 0 5
out.push(xs::out(i)); 5 0 5
25 }
26 2 ▶ return Ref::create(out);
Branch: 1 branch
BranchTrueFalseTotal
return Ref::create(out); 1 0 1
27 1 }
28  
29 1 static std::vector<T> in (Array arg){
30 1 std::vector<T> out;
31 1 ▶ out.reserve(arg.size());
Branch: 2 branches
BranchTrueFalseTotal
out.reserve(arg.size()); 1 0 1
out.reserve(arg.size()); 1 0 1
32 7 ▶ for(const auto& i : arg){
Branch: 4 branches
BranchTrueFalseTotal
for(const auto& i : arg){ 1 0 1
for(const auto& i : arg){ 1 0 1
for(const auto& i : arg){ 5 0 5
for(const auto& i : arg){ 5 1 6
33 5 ▶ out.emplace_back(xs::in<T>(i));
Branch: 2 branches
BranchTrueFalseTotal
out.emplace_back(xs::in<T>(i)); 5 0 5
out.emplace_back(xs::in<T>(i)); 5 0 5
34 }
35 1 return out;
36 }
37 };
38  
39 template <typename T> struct Typemap<std::vector<T>> : VectorTypemap<T> {};
40  
41 template <typename K, typename V> struct Typemap<std::map<K,V>, std::map<K,V>> : TypemapBase<std::map<K,V>> {
42 2 static Sv out (const std::map<K,V>& data, const Sv& = {}) {
43 2 ▶ auto out = Hash::create(data.size());
Branch: 2 branches
BranchTrueFalseTotal
auto out = Hash::create(data.size()); 1 0 1
auto out = Hash::create(data.size()); 1 0 1
44 9 ▶ for(const auto& i : data){
Branch: 2 branches
BranchTrueFalseTotal
for(const auto& i : data){ 4 1 5
for(const auto& i : data){ 3 1 4
45 7 ▶ auto key = typemap::containers::to_key(i.first);
Branch: 2 branches
BranchTrueFalseTotal
auto key = typemap::containers::to_key(i.first); 4 0 4
auto key = typemap::containers::to_key(i.first); 3 0 3
46 7 ▶ out.store(key, xs::out(i.second));
Branch: 4 branches
BranchTrueFalseTotal
out.store(key, xs::out(i.second)); 4 0 4
out.store(key, xs::out(i.second)); 4 0 4
out.store(key, xs::out(i.second)); 3 0 3
out.store(key, xs::out(i.second)); 3 0 3
47 }
48 4 ▶ return Ref::create(out);
Branch: 2 branches
BranchTrueFalseTotal
return Ref::create(out); 1 0 1
return Ref::create(out); 1 0 1
49 2 }
50  
51 2 static std::map<K,V> in (Hash arg) {
52 2 std::map<K,V> out;
53 9 ▶ for (const auto& element : arg){
Branch: 4 branches
BranchTrueFalseTotal
for (const auto& element : arg){ 1 0 1
for (const auto& element : arg){ 4 1 5
for (const auto& element : arg){ 1 0 1
for (const auto& element : arg){ 3 1 4
54 7 ▶ K key = xs::in<K>(Simple(element.key()));
Branch: 6 branches
BranchTrueFalseTotal
K key = xs::in<K>(Simple(element.key())); 4 0 4
K key = xs::in<K>(Simple(element.key())); 4 0 4
K key = xs::in<K>(Simple(element.key())); 4 0 4
K key = xs::in<K>(Simple(element.key())); 3 0 3
K key = xs::in<K>(Simple(element.key())); 3 0 3
K key = xs::in<K>(Simple(element.key())); 3 0 3
55 7 ▶ V value = xs::in<V>(element.value());
Branch: 4 branches
BranchTrueFalseTotal
V value = xs::in<V>(element.value()); 4 0 4
V value = xs::in<V>(element.value()); 4 0 4
V value = xs::in<V>(element.value()); 3 0 3
V value = xs::in<V>(element.value()); 3 0 3
56 7 ▶ out.emplace(key, value);
Branch: 2 branches
BranchTrueFalseTotal
out.emplace(key, value); 4 0 4
out.emplace(key, value); 3 0 3
57 }
58 2 return out;
59 }
60 };
61  
62 template <typename K, typename V> struct Typemap<std::unordered_map<K, V>, std::unordered_map<K,V>> : TypemapBase<std::unordered_map<K,V>> {
63 static Sv out (const std::unordered_map<K,V>& 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<K,V> in (Hash arg) {
73 std::unordered_map<K,V> out;
74 for (const auto& element : arg){
75 K key = xs::in<K>(Simple(element.key()));
76 V value = xs::in<V>(element.value());
77 out.emplace(key, value);
78 }
79 return out;
80 }
81  
82 };
83  
84 }
« t/typemap/object/avhv.xsi ↑ Summary t/typemap/container.xsi »