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 <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
|
|
|
|
|
|
|
inline panda::string_view to_key (const std::string& value) { return panda::string_view(value.data(), value.size()); } |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
template <typename T> |
17
|
|
|
|
|
|
|
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
|
2
|
50
|
|
|
|
|
auto out = Array::create(data.size()); |
23
|
4
|
100
|
|
|
|
|
for(const auto& i : data){ |
24
|
3
|
50
|
|
|
|
|
out.push(xs::out(i)); |
|
|
50
|
|
|
|
|
|
25
|
|
|
|
|
|
|
} |
26
|
2
|
50
|
|
|
|
|
return Ref::create(out); |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
static std::vector<T> in (Array arg){ |
30
|
|
|
|
|
|
|
std::vector<T> out; |
31
|
|
|
|
|
|
|
out.reserve(arg.size()); |
32
|
|
|
|
|
|
|
for(const auto& i : arg){ |
33
|
|
|
|
|
|
|
out.emplace_back(xs::in<T>(i)); |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
static Sv out (const std::map<K,V>& 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<K,V> in (Hash arg) { |
52
|
|
|
|
|
|
|
std::map<K,V> out; |
53
|
|
|
|
|
|
|
for (const auto& element : arg){ |
54
|
|
|
|
|
|
|
K key = xs::in<K>(Simple(element.key())); |
55
|
|
|
|
|
|
|
V value = xs::in<V>(element.value()); |
56
|
|
|
|
|
|
|
out.emplace(key, value); |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
} |