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.
 
 
 
 
 
 

53 lines
1.2 KiB

  1. //
  2. // Copyright (C) 2009-2012 Artyom Beilis (Tonkikh)
  3. //
  4. // Distributed under the Boost Software License, Version 1.0. (See
  5. // accompanying file LICENSE_1_0.txt or copy at
  6. // http://www.boost.org/LICENSE_1_0.txt)
  7. //
  8. #ifndef BOOSTER_HOLD_PTR_H
  9. #define BOOSTER_HOLD_PTR_H
  10. namespace booster {
  11. ///
  12. /// \brief a smart pointer similar to std::auto_ptr but it is non-copyable and
  13. /// underlying object has same constness as the pointer itself (not like in ordinary pointer).
  14. ///
  15. template<typename T>
  16. class hold_ptr {
  17. T *ptr_;
  18. hold_ptr(hold_ptr const &other); // non copyable
  19. hold_ptr const &operator=(hold_ptr const &other); // non assignable
  20. public:
  21. hold_ptr() : ptr_(0) {}
  22. explicit hold_ptr(T *v) : ptr_(v) {}
  23. ~hold_ptr()
  24. {
  25. if(ptr_) delete ptr_;
  26. }
  27. T const *get() const { return ptr_; }
  28. T *get() { return ptr_; }
  29. T const &operator *() const { return *ptr_; }
  30. T &operator *() { return *ptr_; }
  31. T const *operator->() const { return ptr_; }
  32. T *operator->() { return ptr_; }
  33. T *release() { T *tmp=ptr_; ptr_=0; return tmp; }
  34. void reset(T *p=0)
  35. {
  36. if(ptr_) delete ptr_;
  37. ptr_=p;
  38. }
  39. void swap(hold_ptr &other)
  40. {
  41. T *tmp=other.ptr_;
  42. other.ptr_=ptr_;
  43. ptr_=tmp;
  44. }
  45. };
  46. } // booster
  47. #endif