#ifndef DB_H #define DB_H class DB; extern thread_local PGF_INTERNAL_DECL unsigned char* current_base; extern thread_local PGF_INTERNAL_DECL DB* current_db; typedef size_t moffset; struct malloc_state; template class ref { size_t offset; public: ref() { } ref(size_t o) { offset = o; } inline A* operator->() const { return (A*) (current_base+offset); } inline operator A*() const { return (A*) (current_base+offset); } inline bool operator ==(ref& other) const { return offset==other->offset; } inline operator size_t() { return offset; } }; class PGF_INTERNAL_DECL DB { int fd; malloc_state* ms; public: DB(const char* pathname); ~DB(); template ref malloc() { return malloc(sizeof(A)); } moffset malloc(size_t bytes); template ref get_root() { return get_root_offset(); } template void set_root(ref root) { set_root_offset(root); } private: void init_state(size_t size); void free(moffset o); moffset get_root_offset(); void set_root_offset(moffset root); }; #endif