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.
 
 
 
 
 
 

67 lines
1.5 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_UTIL_COPY_PTR_H
  9. #define BOOSTER_UTIL_COPY_PTR_H
  10. namespace booster {
  11. ///
  12. /// \brief a smart pointer similar to std::auto_ptr but it copies
  13. /// underlying object on pointer copy instead of moving its ownership.
  14. ///
  15. /// Note: Underlying object has same constness as the pointer itself (not like in ordinary pointer).
  16. ///
  17. /// Don't use it with polymorphic classes. Prefer clone_ptr instead.
  18. ///
  19. template<typename T>
  20. class copy_ptr {
  21. T *ptr_;
  22. public:
  23. copy_ptr() : ptr_(0) {}
  24. explicit copy_ptr(T *v) : ptr_(v) {}
  25. copy_ptr(copy_ptr const &other) :
  26. ptr_(other.ptr_ ? new T(*other.ptr_) : 0)
  27. {
  28. }
  29. copy_ptr const &operator=(copy_ptr const &other)
  30. {
  31. if(this != &other) {
  32. copy_ptr tmp(other);
  33. swap(tmp);
  34. }
  35. return *this;
  36. }
  37. ~copy_ptr() {
  38. if(ptr_) delete ptr_;
  39. }
  40. T const *get() const { return ptr_; }
  41. T *get() { return ptr_; }
  42. T const &operator *() const { return *ptr_; }
  43. T &operator *() { return *ptr_; }
  44. T const *operator->() const { return ptr_; }
  45. T *operator->() { return ptr_; }
  46. T *release() { T *tmp=ptr_; ptr_=0; return tmp; }
  47. void reset(T *p=0)
  48. {
  49. if(ptr_) delete ptr_;
  50. ptr_=p;
  51. }
  52. void swap(copy_ptr &other)
  53. {
  54. T *tmp=other.ptr_;
  55. other.ptr_=ptr_;
  56. ptr_=tmp;
  57. }
  58. };
  59. } // booster
  60. #endif