ChipMaster's trial hacks on C++CMS starting with v1.2.1. Not sure I'll follow on with the v2 since it looks to be breaking and mostly frivolous.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

89 lines
1.6 KiB

  1. ///////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (C) 2008-2012 Artyom Beilis (Tonkikh) <artyomtnk@yahoo.com>
  4. //
  5. // See accompanying file COPYING.TXT file for licensing details.
  6. //
  7. ///////////////////////////////////////////////////////////////////////////////
  8. #ifndef CPPCMS_IMPL_BASIC_ALLOCATOR_H
  9. #define CPPCMS_IMPL_BASIC_ALLOCATOR_H
  10. #include <limits>
  11. namespace cppcms {
  12. namespace impl {
  13. template<typename Base,typename T>
  14. class basic_allocator {
  15. public :
  16. Base &self()
  17. {
  18. return static_cast<Base &>(*this);
  19. }
  20. Base const &self() const
  21. {
  22. return static_cast<Base const &>(*this);
  23. }
  24. typedef T value_type;
  25. typedef T *pointer;
  26. typedef T &reference;
  27. typedef const T &const_reference;
  28. typedef const T *const_pointer;
  29. typedef std::size_t size_type;
  30. typedef std::ptrdiff_t difference_type;
  31. basic_allocator() {}
  32. pointer allocate(size_type cnt, std::allocator<void>::const_pointer = 0) const
  33. {
  34. void *memory=self().malloc(cnt*sizeof(T));
  35. if(!memory) {
  36. throw std::bad_alloc();
  37. }
  38. return (pointer)memory;
  39. };
  40. void deallocate(pointer p, size_type) const
  41. {
  42. self().free(p);
  43. };
  44. void construct(pointer p, const T& t) const
  45. {
  46. new(p) T(t);
  47. }
  48. void destroy(pointer p) const
  49. {
  50. p->~T();
  51. }
  52. pointer address(reference x) const
  53. {
  54. return &x;
  55. }
  56. const_pointer address(const_reference x) const
  57. {
  58. return &x;
  59. }
  60. bool operator==(basic_allocator const&) const
  61. {
  62. return true;
  63. }
  64. bool operator!=(basic_allocator const&) const
  65. {
  66. return false;
  67. }
  68. size_type max_size() const throw()
  69. {
  70. return std::numeric_limits<size_t>::max();
  71. }
  72. };
  73. } // impl
  74. } // cppcms
  75. #endif