| 654 | // Behaves like TIntrusivePtr but returns const T* to prevent user from accidentally modifying the referenced object. |
| 655 | template <class T, class Ops> |
| 656 | class TIntrusiveConstPtr: public TPointerBase<TIntrusiveConstPtr<T, Ops>, const T> { |
| 657 | public: |
| 658 | inline TIntrusiveConstPtr(T* t = nullptr) noexcept // we need a non-const pointer to Ref(), UnRef() and eventually delete it. |
| 659 | : T_(t) |
| 660 | { |
| 661 | Ops(); |
| 662 | Ref(); |
| 663 | } |
| 664 | |
| 665 | inline ~TIntrusiveConstPtr() { |
| 666 | UnRef(); |
| 667 | } |
| 668 | |
| 669 | inline TIntrusiveConstPtr(const TIntrusiveConstPtr& p) noexcept |
| 670 | : T_(p.T_) |
| 671 | { |
| 672 | Ref(); |
| 673 | } |
| 674 | |
| 675 | inline TIntrusiveConstPtr(TIntrusiveConstPtr&& p) noexcept |
| 676 | : T_(nullptr) |
| 677 | { |
| 678 | Swap(p); |
| 679 | } |
| 680 | |
| 681 | inline TIntrusiveConstPtr(TIntrusivePtr<T> p) noexcept |
| 682 | : T_(p.T_) |
| 683 | { |
| 684 | p.T_ = nullptr; |
| 685 | } |
| 686 | |
| 687 | template <class U, class = TGuardConversion<T, U>> |
| 688 | inline TIntrusiveConstPtr(const TIntrusiveConstPtr<U>& p) noexcept |
| 689 | : T_(p.T_) |
| 690 | { |
| 691 | Ref(); |
| 692 | } |
| 693 | |
| 694 | template <class U, class = TGuardConversion<T, U>> |
| 695 | inline TIntrusiveConstPtr(TIntrusiveConstPtr<U>&& p) noexcept |
| 696 | : T_(p.T_) |
| 697 | { |
| 698 | p.T_ = nullptr; |
| 699 | } |
| 700 | |
| 701 | inline TIntrusiveConstPtr& operator=(TIntrusiveConstPtr p) noexcept { |
| 702 | p.Swap(*this); |
| 703 | |
| 704 | return *this; |
| 705 | } |
| 706 | |
| 707 | // Effectively replace both: |
| 708 | // Reset(const TIntrusiveConstPtr&) |
| 709 | // Reset(TIntrusiveConstPtr&&) |
| 710 | Y_REINITIALIZES_OBJECT inline void Reset(TIntrusiveConstPtr t) noexcept { |
| 711 | Swap(t); |
| 712 | } |
| 713 | |