#ifndef MAPMAP_HPP #define MAPMAP_HPP #include #include #include struct mapmap_instance { std::map m; }; static inline mapmap_instance mapmap_create() { mapmap_instance ret; return ret; } static inline void* mapmap(void *amap_instance, AMAP_OP op, const char *key, void *ptr) { mapmap_instance *map = (mapmap_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::map()); return (void *)((uint8_t)(NULL) - 1L); } } #endif // MAPMAP_HPP