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.
 
 
 
 
 
 

61 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_CLONE_PTR_H
  9. #define BOOSTER_CLONE_PTR_H
  10. namespace booster {
  11. ///
  12. /// \brief a smart pointer similar to std::auto_ptr but it clones (by calling T::clone())
  13. /// underlying object on copy instead of moving its ownership.
  14. ///
  15. template<typename T>
  16. class clone_ptr {
  17. T *ptr_;
  18. public:
  19. clone_ptr() : ptr_(0) {}
  20. explicit clone_ptr(T *v) : ptr_(v) {}
  21. clone_ptr(clone_ptr const &other) : ptr_(0)
  22. {
  23. if(other.ptr_)
  24. ptr_=other.ptr_->clone();
  25. }
  26. clone_ptr const &operator=(clone_ptr const &other)
  27. {
  28. if(this != &other) {
  29. clone_ptr tmp(other);
  30. swap(tmp);
  31. }
  32. return *this;
  33. }
  34. ~clone_ptr() {
  35. if(ptr_) delete ptr_;
  36. }
  37. T *get() const { return ptr_; }
  38. T &operator *() const { return *ptr_; }
  39. T *operator->() const { return ptr_; }
  40. T *release() { T *tmp=ptr_; ptr_=0; return tmp; }
  41. void reset(T *p=0)
  42. {
  43. if(ptr_) delete ptr_;
  44. ptr_=p;
  45. }
  46. void swap(clone_ptr &other)
  47. {
  48. T *tmp=other.ptr_;
  49. other.ptr_=ptr_;
  50. ptr_=tmp;
  51. }
  52. };
  53. } // booster
  54. #endif