会员
周边
众包
新闻
博问
闪存
赞助商
所有博客
当前博客
我的博客
我的园子
账号设置
简洁模式
...
退出登录
注册
登录
zengqh
GameStd
/***************************************************************************************************** * File name: GameStd.h * Create time: 2015/03/02 * Module: View * Author: zengqh * Blog: http://blog.csdn.net/aimyton * --------------------------------------------------------------------------------------------------- * Memo: * *****************************************************************************************************/ #ifndef GameStd_h__ #define GameStd_h__ #include <stdlib.h> #include <stdio.h> #include <string.h> #include <math.h> #include <iostream> #include <vector> #include <map> #include <list> #include <deque> #include <queue> #include <set> #include <stack> #include <string> #include <algorithm> #include <functional> /***************************************************************************************************** * Macro and Struct definition *****************************************************************************************************/ /* assert thing */ #define MY_ASSERT(exp) { if (!(exp)) {__asm int 3} } #ifdef _DEBUG #define game_assert MY_ASSERT #else #define game_assert #endif /* safe delete */ #define safe_delete(p) { if((p) != NULL) { delete (p); (p) = NULL; } } #define safe_delete_array(p) { if((p) != NULL) { delete [] (p); (p) = NULL; } } #define safe_release(p) { if((p) != NULL) { (p)->Release(); } } /***************************************************************************************************** * Global variables *****************************************************************************************************/ /***************************************************************************************************** * Global function declare *****************************************************************************************************/ /***************************************************************************************************** * Global function definition *****************************************************************************************************/ inline void* impl_malloc(unsigned int size) { return ::malloc(size); } inline void impl_free(void* ptr) { return ::free(ptr); } /***************************************************************************************************** * Class declare ******************************************************************************************************/ class GameObject { public: virtual ~GameObject() {} void* operator new(unsigned int size) { return impl_malloc(size); } void* operator new(unsigned int size, void* ptr) { size; return ptr; } void operator delete(void* ptr) { impl_free(ptr); } void* operator new[](unsigned int size) { return impl_malloc(size); } void operator delete[](void* ptr) { impl_free(ptr); } void* malloc(unsigned int size) { return impl_malloc(size); } void free(void* ptr) { impl_free(ptr); } }; namespace std { template<class _T> class game_allocator { public: typedef std::size_t size_type; typedef std::ptrdiff_t difference_type; typedef _T* pointer; typedef const _T* const_pointer; typedef _T& reference; typedef const _T& const_reference; typedef _T value_type; template<class _Other> struct rebind { typedef game_allocator<_Other> other; }; game_allocator() { } game_allocator(const game_allocator<_T>&) { } template<class _Y> game_allocator(const game_allocator<_Y>&) { } pointer address(reference _val) const { return (&_val); } const_pointer address(const_reference _val) const { return (&_val); } pointer allocate(size_type _count) { return ((pointer)impl_malloc(_count * sizeof(_T))); } pointer allocate(size_type _count, const void* p) { return allocate(_count); } void deallocate(pointer _ptr, size_type) { impl_free(_ptr); } void construct(pointer _ptr, const _T& _val) { new ((void*)_ptr) _T(_val) } void destroy(pointer _ptr) { _ptr->~_T(); } size_type max_size() const { size_type _n = (size_type)(-1) / sizeof(_T); return (0 < _n ? _n : 1); } bool operator==(const game_allocator<_T>&) const { return true; } }; }; template <class T> class game_vector : public std::vector<T, std::game_allocator<T> > {}; template <class T> class game_list : public std::list<T, std::game_allocator<T> > {}; template <class T> class game_deque : public std::deque<T, std::game_allocator<T> > {}; template <class K, class C = std::less<K> > class game_set : public std::set<K, C, std::game_allocator<K> > {}; template <class K, class T, class C = std::less<K> > class game_map : public std::map<K, T, C, std::game_allocator<T> > {}; template <class T> class game_stack : public std::stack<T, game_deque<T> > {}; template <class T> class game_queue : public std::queue<T, game_deque<T> > {}; template <class T> class game_priority_queue : public std::priority_queue<T, game_vector<T> > {}; typedef std::basic_string<char, std::char_traits<char>, std::game_allocator<char> > game_string; /***************************************************************************************************** * Class definition *****************************************************************************************************/ #endif /* GameStd_h__ */ /***********************************End of File*******************************************************/
posted on
2012-03-01 23:54
zengqh
阅读(
144
) 评论(
0
)
编辑
收藏
举报
刷新页面
返回顶部
导航
博客园
首页
联系
订阅
管理
公告