#ifndef UNOMAP_HPP #define UNOMAP_HPP #include #include #include struct unomap_instance { std::unordered_map m; }; static inline unomap_instance unomap_create() { unomap_instance ret; return ret; } static inline void* unomap(void *amap_instance, AMAP_OP op, const char *key, void *ptr) { unomap_instance *map = (unomap_instance *) amap_instance; if(op == AMAP_GET) { try { return map->m[key]; } catch(...) { return ptr; } } else if(op == AMAP_SET) { try { map->m[key] = ptr; return map; // non-null } catch(...) { return NULL; } } else { // if(op == AMAP_ERASE) { assert(op == AMAP_ERASE); map->m = std::move(std::unordered_map()); return (void *)((uint8_t)(NULL) - 1L); } } #endif // MAPMAP_HPP