| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | #pragma once | 
| 2 |  |  |  |  |  |  | #include "string.h" | 
| 3 |  |  |  |  |  |  | #include "string_view.h" | 
| 4 |  |  |  |  |  |  | #include | 
| 5 |  |  |  |  |  |  | #include | 
| 6 |  |  |  |  |  |  | #include | 
| 7 |  |  |  |  |  |  |  | 
| 8 |  |  |  |  |  |  | /* | 
| 9 |  |  |  |  |  |  | * panda::unordered_string_map and panda::unordered_string_multimap are wrappers around STL's versions in case if keys are panda::string. | 
| 10 |  |  |  |  |  |  | * The goal is to make it possible to call some STL's methods with string_view | 
| 11 |  |  |  |  |  |  | */ | 
| 12 |  |  |  |  |  |  |  | 
| 13 |  |  |  |  |  |  | namespace panda { | 
| 14 |  |  |  |  |  |  |  | 
| 15 |  |  |  |  |  |  | template , class KeyEqual = std::equal_to, class Allocator = std::allocator>> | 
| 16 | 20 |  |  |  |  |  | class unordered_string_map : public std::unordered_map { | 
| 17 |  |  |  |  |  |  | private: | 
| 18 |  |  |  |  |  |  | template | 
| 19 |  |  |  |  |  |  | static inline std::true_type  _is_base_string (panda::basic_string const volatile) { return std::true_type(); } | 
| 20 |  |  |  |  |  |  | static inline std::false_type _is_base_string (...) { return std::false_type(); } | 
| 21 |  |  |  |  |  |  |  | 
| 22 |  |  |  |  |  |  | static_assert(decltype(_is_base_string(Key()))::value, "Key must be based on panda::basic_string"); | 
| 23 |  |  |  |  |  |  |  | 
| 24 |  |  |  |  |  |  | using Base  = std::unordered_map; | 
| 25 |  |  |  |  |  |  | using SVKey = basic_string_view; | 
| 26 |  |  |  |  |  |  |  | 
| 27 | 17 |  |  |  |  |  | static Key _key_from_sv (const SVKey& key) { | 
| 28 |  |  |  |  |  |  | typedef typename Key::value_type FakeCharLiteral[1]; | 
| 29 | 17 |  |  |  |  |  | Key tmp(*(const FakeCharLiteral*)key.data()); | 
| 30 | 17 |  |  |  |  |  | tmp.length(key.length()); | 
| 31 | 17 |  |  |  |  |  | return tmp; | 
| 32 |  |  |  |  |  |  | } | 
| 33 |  |  |  |  |  |  | public: | 
| 34 |  |  |  |  |  |  | using typename Base::key_type; | 
| 35 |  |  |  |  |  |  | using typename Base::mapped_type; | 
| 36 |  |  |  |  |  |  | using typename Base::value_type; | 
| 37 |  |  |  |  |  |  | using typename Base::size_type; | 
| 38 |  |  |  |  |  |  | using typename Base::difference_type; | 
| 39 |  |  |  |  |  |  | using typename Base::hasher; | 
| 40 |  |  |  |  |  |  | using typename Base::key_equal; | 
| 41 |  |  |  |  |  |  | using typename Base::allocator_type; | 
| 42 |  |  |  |  |  |  | using typename Base::reference; | 
| 43 |  |  |  |  |  |  | using typename Base::const_reference; | 
| 44 |  |  |  |  |  |  | using typename Base::pointer; | 
| 45 |  |  |  |  |  |  | using typename Base::const_pointer; | 
| 46 |  |  |  |  |  |  | using typename Base::iterator; | 
| 47 |  |  |  |  |  |  | using typename Base::const_iterator; | 
| 48 |  |  |  |  |  |  | using typename Base::local_iterator; | 
| 49 |  |  |  |  |  |  | using typename Base::const_local_iterator; | 
| 50 |  |  |  |  |  |  |  | 
| 51 |  |  |  |  |  |  | using Base::Base; | 
| 52 |  |  |  |  |  |  | using Base::at; | 
| 53 |  |  |  |  |  |  | using Base::find; | 
| 54 |  |  |  |  |  |  | using Base::count; | 
| 55 |  |  |  |  |  |  | using Base::erase; | 
| 56 |  |  |  |  |  |  | using Base::equal_range; | 
| 57 |  |  |  |  |  |  |  | 
| 58 |  |  |  |  |  |  | template ::value>::type> | 
| 59 | 5 | 100 |  |  |  |  | T& at (X key) { return at(_key_from_sv(key)); } | 
| 60 |  |  |  |  |  |  |  | 
| 61 |  |  |  |  |  |  | template ::value>::type> | 
| 62 |  |  |  |  |  |  | const T& at (X key) const { return at(_key_from_sv(key)); } | 
| 63 |  |  |  |  |  |  |  | 
| 64 |  |  |  |  |  |  | template ::value>::type> | 
| 65 | 4 | 50 |  |  |  |  | iterator find (X key) { return find(_key_from_sv(key)); } | 
| 66 |  |  |  |  |  |  |  | 
| 67 |  |  |  |  |  |  | template ::value>::type> | 
| 68 |  |  |  |  |  |  | const_iterator find (X key) const { return find(_key_from_sv(key)); } | 
| 69 |  |  |  |  |  |  |  | 
| 70 |  |  |  |  |  |  | template ::value>::type> | 
| 71 | 3 | 50 |  |  |  |  | size_type count (X key) const { return count(_key_from_sv(key)); } | 
| 72 |  |  |  |  |  |  |  | 
| 73 |  |  |  |  |  |  | template ::value>::type> | 
| 74 | 3 | 50 |  |  |  |  | size_type erase (X key) { return erase(_key_from_sv(key)); } | 
| 75 |  |  |  |  |  |  |  | 
| 76 |  |  |  |  |  |  | template ::value>::type> | 
| 77 | 3 | 50 |  |  |  |  | std::pair equal_range (X key) { return equal_range(_key_from_sv(key)); } | 
| 78 |  |  |  |  |  |  |  | 
| 79 |  |  |  |  |  |  | template ::value>::type> | 
| 80 |  |  |  |  |  |  | std::pair equal_range (X key) const { return equal_range(_key_from_sv(key)); } | 
| 81 |  |  |  |  |  |  |  | 
| 82 |  |  |  |  |  |  | }; | 
| 83 |  |  |  |  |  |  |  | 
| 84 |  |  |  |  |  |  | template , class KeyEqual = std::equal_to, class Allocator = std::allocator>> | 
| 85 | 16 |  |  |  |  |  | class unordered_string_multimap : public std::unordered_multimap { | 
| 86 |  |  |  |  |  |  | private: | 
| 87 |  |  |  |  |  |  | template | 
| 88 |  |  |  |  |  |  | static inline std::true_type  _is_base_string (panda::basic_string const volatile) { return std::true_type(); } | 
| 89 |  |  |  |  |  |  | static inline std::false_type _is_base_string (...) { return std::false_type(); } | 
| 90 |  |  |  |  |  |  |  | 
| 91 |  |  |  |  |  |  | static_assert(decltype(_is_base_string(Key()))::value, "Key must be based on panda::basic_string"); | 
| 92 |  |  |  |  |  |  |  | 
| 93 |  |  |  |  |  |  | using Base  = std::unordered_multimap; | 
| 94 |  |  |  |  |  |  | using SVKey = basic_string_view; | 
| 95 |  |  |  |  |  |  |  | 
| 96 | 14 |  |  |  |  |  | static Key _key_from_sv (const SVKey& key) { | 
| 97 |  |  |  |  |  |  | typedef typename Key::value_type FakeCharLiteral[1]; | 
| 98 | 14 |  |  |  |  |  | Key tmp(*(const FakeCharLiteral*)key.data()); | 
| 99 | 14 |  |  |  |  |  | tmp.length(key.length()); | 
| 100 | 14 |  |  |  |  |  | return tmp; | 
| 101 |  |  |  |  |  |  | } | 
| 102 |  |  |  |  |  |  | public: | 
| 103 |  |  |  |  |  |  | using typename Base::key_type; | 
| 104 |  |  |  |  |  |  | using typename Base::mapped_type; | 
| 105 |  |  |  |  |  |  | using typename Base::value_type; | 
| 106 |  |  |  |  |  |  | using typename Base::size_type; | 
| 107 |  |  |  |  |  |  | using typename Base::difference_type; | 
| 108 |  |  |  |  |  |  | using typename Base::hasher; | 
| 109 |  |  |  |  |  |  | using typename Base::key_equal; | 
| 110 |  |  |  |  |  |  | using typename Base::allocator_type; | 
| 111 |  |  |  |  |  |  | using typename Base::reference; | 
| 112 |  |  |  |  |  |  | using typename Base::const_reference; | 
| 113 |  |  |  |  |  |  | using typename Base::pointer; | 
| 114 |  |  |  |  |  |  | using typename Base::const_pointer; | 
| 115 |  |  |  |  |  |  | using typename Base::iterator; | 
| 116 |  |  |  |  |  |  | using typename Base::const_iterator; | 
| 117 |  |  |  |  |  |  | using typename Base::local_iterator; | 
| 118 |  |  |  |  |  |  | using typename Base::const_local_iterator; | 
| 119 |  |  |  |  |  |  |  | 
| 120 |  |  |  |  |  |  | using Base::Base; | 
| 121 |  |  |  |  |  |  | using Base::find; | 
| 122 |  |  |  |  |  |  | using Base::count; | 
| 123 |  |  |  |  |  |  | using Base::erase; | 
| 124 |  |  |  |  |  |  | using Base::equal_range; | 
| 125 |  |  |  |  |  |  |  | 
| 126 |  |  |  |  |  |  | template ::value>::type> | 
| 127 | 5 | 50 |  |  |  |  | iterator find (X key) { return find(_key_from_sv(key)); } | 
| 128 |  |  |  |  |  |  |  | 
| 129 |  |  |  |  |  |  | template ::value>::type> | 
| 130 |  |  |  |  |  |  | const_iterator find (X key) const { return find(_key_from_sv(key)); } | 
| 131 |  |  |  |  |  |  |  | 
| 132 |  |  |  |  |  |  | template ::value>::type> | 
| 133 | 3 | 50 |  |  |  |  | size_type count (X key) const { return count(_key_from_sv(key)); } | 
| 134 |  |  |  |  |  |  |  | 
| 135 |  |  |  |  |  |  | template ::value>::type> | 
| 136 | 3 | 50 |  |  |  |  | size_type erase (X key) { return erase(_key_from_sv(key)); } | 
| 137 |  |  |  |  |  |  |  | 
| 138 |  |  |  |  |  |  | template ::value>::type> | 
| 139 | 3 | 50 |  |  |  |  | std::pair equal_range (X key) { return equal_range(_key_from_sv(key)); } | 
| 140 |  |  |  |  |  |  |  | 
| 141 |  |  |  |  |  |  | template ::value>::type> | 
| 142 |  |  |  |  |  |  | std::pair equal_range (X key) const { return equal_range(_key_from_sv(key)); } | 
| 143 |  |  |  |  |  |  |  | 
| 144 |  |  |  |  |  |  | }; | 
| 145 |  |  |  |  |  |  |  | 
| 146 |  |  |  |  |  |  | } |