/* * * Copyright (c) 1994 * Hewlett-Packard Company * */ #ifndef MEMORY_HANDLER_H #define MEMORY_HANDLER_H #include #include #include inline void errorFunction(char* s) { printf(s); exit(1); } inline void* operator new(size_t, void* p) {return p;} inline void* memalloc(size_t size) { void* tmp = ::operator new (size); if (tmp == 0) errorFunction("out of memory\n"); return tmp; } template class Allocator { public: Allocator() {} int operator==(Allocator&) { return 1; } int operator!=(Allocator&) { return 0; } T* operator()(size_t n) { T* tmp = new T[n]; if (tmp == 0) errorFunction("out of memory\n"); return tmp; } }; template class ExplicitDestructor { public: ExplicitDestructor() {} int operator==(ExplicitDestructor&) { return 1; } int operator!=(ExplicitDestructor&) { return 0; } void operator()(T& /* x */) { // (&x)->T::~T(); } }; template class PointerToRawStorage { protected: T* p; public: PointerToRawStorage(T* x) : p(x) {} PointerToRawStorage& operator*() { return *this; } PointerToRawStorage& operator=(T& element) { new (p++) T(element); return *this; } PointerToRawStorage& operator++() { p++; return *this; } PointerToRawStorage operator++(int) { PointerToRawStorage tmp = *this; p++; return tmp; } PointerToRawStorage& operator--() { p--; return *this; } PointerToRawStorage operator--(int) { PointerToRawStorage tmp = *this; p--; return tmp; } int operator==(PointerToRawStorage& x) const { return p == x.p; } int operator!=(PointerToRawStorage& x) const { return !(*this == x); } }; #endif