2 #ifndef HOBBES_UTIL_PTR_HPP_INCLUDED 3 #define HOBBES_UTIL_PTR_HPP_INCLUDED 8 #include <unordered_map> 16 template <
typename T,
typename ...
Args>
21 const std::shared_ptr<T>&
get(
const std::function<T*(
Args...)>& mk,
const Args&... args) {
22 std::lock_guard<std::mutex> lock(
mutex);
24 const auto&
r = this->
values[k];
27 this->
values[k] = std::shared_ptr<T>(mk(args...));
33 std::lock_guard<std::mutex> lock(
mutex);
34 for (
typename Values::iterator v = this->
values.begin(); v != this->
values.end();) {
35 if (v->second.use_count() == 1) {
50 template <
size_t i,
typename ... UniqueRefcMaps>
51 inline typename std::enable_if<i ==
sizeof...(UniqueRefcMaps),
size_t>::type
compactAll(std::tuple<UniqueRefcMaps...>&) {
55 template <
size_t i,
typename ... UniqueRefcMaps>
56 inline typename std::enable_if<i <
sizeof...(UniqueRefcMaps),
size_t>::type
compactAll(std::tuple<UniqueRefcMaps...>& ms) {
60 template <
size_t i,
typename T,
typename ... Ts>
62 static const size_t value = i;
65 template <
size_t i,
typename T,
typename ... Ts>
66 struct TypeIndex<i, T, T, Ts...> {
67 static const size_t value = i;
70 template <
size_t i,
typename T,
typename U,
typename ... Ts>
71 struct TypeIndex<i, T, U, Ts...> {
72 static const size_t value = TypeIndex<i+1, T, Ts...>::value;
75 template <
typename ... UniqueRefcMaps>
76 class unique_refc_maps {
78 typedef std::tuple<UniqueRefcMaps...> RefcMaps;
82 typename std::tuple_element<TypeIndex<0, T, UniqueRefcMaps...>::value, RefcMaps>::type&
at() {
89 size_t c = compactAll<0>(this->
refcMaps);
99 if (m == 0 || (x % m) == 0) {
102 return (1 + (x / m)) *
m;
106 template <
typename T,
typename S>
107 const T*
is(
const S* s) {
108 if (s && s->case_id() == T::type_case_id) {
115 template <
typename T,
typename S>
117 if (s && s->case_id() == T::type_case_id) {
124 template <
typename T,
typename S>
125 T*
is(
const std::shared_ptr<S>& s) {
126 return isM<T, S>(s.get());
T align(T x, T m)
Definition: ptr.H:98
std::mutex mutex
Definition: ptr.H:45
const T * is(const S *s)
Definition: ptr.H:107
size_t compact()
Definition: ptr.H:31
std::enable_if< i< sizeof...(UniqueRefcMaps), size_t >::type compactAll(std::tuple< UniqueRefcMaps... > &ms) { return std::get< i >ms).compact()+compactAll< i+1, UniqueRefcMaps... >ms);}template< size_t i, typename T, typename ... Ts > struct TypeIndex { static const size_t value=i;};template< size_t i, typename T, typename ... Ts > struct TypeIndex< i, T, T, Ts... > { static const size_t value=i;};template< size_t i, typename T, typename U, typename ... Ts > struct TypeIndex< i, T, U, Ts... > { static const size_t value=TypeIndex< i+1, T, Ts... >::value;};template< typename ... UniqueRefcMaps > class unique_refc_maps { private:typedef std::tuple< UniqueRefcMaps... > RefcMaps;RefcMaps refcMaps;public:template< typename T > typename std::tuple_element< TypeIndex< 0, T, UniqueRefcMaps... >::value, RefcMaps >::type &at() { return std::get< TypeIndex< 0, T, UniqueRefcMaps... >::value >this-> refcMaps
Definition: ptr.H:83
Values values
Definition: ptr.H:47
T * get(variant< Ctors... > &v)
Definition: variant.H:156
std::unordered_map< std::tuple< Args... >, std::shared_ptr< T >, genHash< std::tuple< Args... > > > Values
Definition: ptr.H:46
T * isM(S *s)
Definition: ptr.H:116
size_t r(const reader::MetaData &md, size_t o, T *t)
Definition: storage.H:1730
T object_type
Definition: ptr.H:19
std::enable_if< i==sizeof...(UniqueRefcMaps), size_t >::type compactAll(std::tuple< UniqueRefcMaps... > &)
Definition: ptr.H:51
constexpr char at(size_t i, const char(&s)[N])
Definition: storage.H:1456
std::map< std::string, llvm::Value * > Args
Definition: dfa.C:1276
MonoTypePtr tuple(const MonoTypes &mtys=MonoTypes())
Definition: type.H:1068
LexicalAnnotation m(const YYLTYPE &p)
Definition: hexpr.parse.C:127