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.
 
 
 
 
 
 

46 lines
1.0 KiB

  1. #ifndef CPPCMS_UTIL_HOLD_PTR_H
  2. #define CPPCMS_UTIL_HOLD_PTR_H
  3. namespace cppcms { namespace util {
  4. ///
  5. /// \brief a smart pointer similar to std::auto_ptr but it is non-copyable and
  6. /// underlying object has same constness as the pointer itself (not like in ordinary pointer).
  7. ///
  8. template<typename T>
  9. class hold_ptr {
  10. T *ptr_;
  11. hold_ptr(hold_ptr const &other); // non copyable
  12. hold_ptr const &operator=(hold_ptr const &other); // non assignable
  13. public:
  14. hold_ptr() : ptr_(0) {}
  15. hold_ptr(T *v) : ptr_(v) {}
  16. ~hold_ptr()
  17. {
  18. if(ptr_) delete ptr_;
  19. }
  20. T const *get() const { return ptr_; }
  21. T *get() { return ptr_; }
  22. T const &operator *() const { return *ptr_; }
  23. T &operator *() { return *ptr_; }
  24. T const *operator->() const { return ptr_; }
  25. T *operator->() { return ptr_; }
  26. T *release() { T *tmp=ptr_; ptr_=0; return tmp; }
  27. void reset(T *p=0)
  28. {
  29. if(ptr_) delete ptr_;
  30. ptr_=p;
  31. }
  32. void swap(hold_ptr &other)
  33. {
  34. T *tmp=other.ptr_;
  35. other.ptr_=ptr_;
  36. ptr_=tmp;
  37. }
  38. };
  39. } } // cppcms::util;
  40. #endif