X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=gdb%2Fregistry.h;h=683d905f7636884203b6d477f18185919c5e587a;hb=0670413d0eb264302e10a1baa163bc9c8c279a21;hp=3881e29b54fcb95fa7edce92e3efc4febed64759;hpb=42a4f53d2bf8938c2aeda9f52be7a20534b214a9;p=external%2Fbinutils.git diff --git a/gdb/registry.h b/gdb/registry.h index 3881e29..683d905 100644 --- a/gdb/registry.h +++ b/gdb/registry.h @@ -20,6 +20,8 @@ #ifndef REGISTRY_H #define REGISTRY_H +#include + /* The macros here implement a template type and functions for associating some user data with a container object. @@ -243,11 +245,65 @@ typedef void (*registry_ ## TAG ## _callback) (struct TAG *, void *); \ extern const struct TAG ## _data *register_ ## TAG ## _data (void); \ extern const struct TAG ## _data *register_ ## TAG ## _data_with_cleanup \ (registry_ ## TAG ## _callback save, registry_ ## TAG ## _callback free); \ -extern void clear_ ## TAG ## _data (struct TAG *); \ -extern void set_ ## TAG ## _data (struct TAG *, \ - const struct TAG ## _data *data, \ - void *value); \ -extern void *TAG ## _data (struct TAG *, \ - const struct TAG ## _data *data); +extern void clear_ ## TAG ## _data (struct TAG *); \ +extern void set_ ## TAG ## _data (struct TAG *, \ + const struct TAG ## _data *data, \ + void *value); \ +extern void *TAG ## _data (struct TAG *, \ + const struct TAG ## _data *data); \ + \ +template> \ +class TAG ## _key \ +{ \ +public: \ + \ + TAG ## _key () \ + : m_key (register_ ## TAG ## _data_with_cleanup (nullptr, \ + cleanup)) \ + { \ + } \ + \ + DATA *get (struct TAG *obj) const \ + { \ + return (DATA *) TAG ## _data (obj, m_key); \ + } \ + \ + void set (struct TAG *obj, DATA *data) const \ + { \ + set_ ## TAG ## _data (obj, m_key, data); \ + } \ + \ + template \ + typename std::enable_if>::value, \ + Dummy>::type \ + emplace (struct TAG *obj, Args &&...args) const \ + { \ + DATA *result = new DATA (std::forward (args)...); \ + set (obj, result); \ + return result; \ + } \ + \ + void clear (struct TAG *obj) const \ + { \ + DATA *datum = get (obj); \ + if (datum != nullptr) \ + { \ + cleanup (obj, datum); \ + set (obj, nullptr); \ + } \ + } \ + \ +private: \ + \ + static void cleanup (struct TAG *obj, void *arg) \ + { \ + DATA *datum = (DATA *) arg; \ + Deleter d; \ + d (datum); \ + } \ + \ + const struct TAG ## _data *m_key; \ +}; #endif /* REGISTRY_H */