19#ifndef INCLUDED_TOOLS_REF_HXX
20#define INCLUDED_TOOLS_REF_HXX
34template<
typename T>
class SAL_DLLPUBLIC_RTTI SvRef final {
36 SvRef(): pObj(nullptr) {}
38 SvRef(SvRef&& rObj)
noexcept
44 SvRef(SvRef
const & rObj): pObj(rObj.pObj)
46 if (pObj !=
nullptr) pObj->AddNextRef();
49 SvRef(T * pObjP): pObj(pObjP)
51 if (pObj !=
nullptr) pObj->AddFirstRef();
56 if (pObj !=
nullptr) pObj->ReleaseRef();
61 if (pObj !=
nullptr) {
64 pRefObj->ReleaseRef();
68 SvRef & operator =(SvRef
const & rObj)
70 if (rObj.pObj !=
nullptr) {
71 rObj.pObj->AddNextRef();
75 if (pRefObj !=
nullptr) {
76 pRefObj->ReleaseRef();
81 SvRef & operator =(SvRef && rObj)
83 if (pObj !=
nullptr) {
91 bool is()
const {
return pObj !=
nullptr; }
93 explicit operator bool()
const {
return is(); }
95 T *
get()
const {
return pObj; }
97 T * operator ->()
const { assert(pObj !=
nullptr);
return pObj; }
99 T &
operator *()
const { assert(pObj !=
nullptr);
return *pObj; }
101 bool operator ==(
const SvRef<T> &rhs)
const {
return pObj == rhs.pObj; }
102 bool operator !=(
const SvRef<T> &rhs)
const {
return !(*
this == rhs); }
111template<
typename T,
typename... Args>
142 assert(
nRefCount < (1 << 30) &&
"Do not add refs to dead objects" );
148 assert(
nRefCount < (1 << 30) &&
"Do not add refs to dead objects" );
217 {
if( pObj ) _xHdl = pObj->GetHdl(); }
218#if defined(__COVERITY__)
222 { _xHdl = pObj ? pObj->GetHdl() :
nullptr;
return *
this; }
224 {
return _xHdl.is() && _xHdl->GetObj(); }
225 explicit operator bool()
const {
return is(); }
226 T* operator -> ()
const
227 {
return _xHdl.is() ? _xHdl->GetObj() :
nullptr; }
229 {
return _xHdl.is() ? _xHdl->GetObj() :
nullptr; }
bool operator==(const BigInt &rVal1, const BigInt &rVal2)
We only have one place that extends this, in include/sfx2/frame.hxx, class SfxFrame.
SvCompatWeakBase(T *pObj)
Does not use initializer due to compiler warnings, because the lifetime of the _xHdl object can excee...
SvCompatWeakHdl< T > * GetHdl()
tools::SvRef< SvCompatWeakHdl< T > > _xHdl
SvCompatWeakHdl acts as an intermediary between SvCompatWeakRef<T> and T.
We only have one weak reference in LO, in include/sfx2/frame.hxx, class SfxFrameWeak.
tools::SvRef< SvCompatWeakHdl< T > > _xHdl
Classes that want to be referenced-counted via SvRef<T>, should extend this base class.
unsigned int GetRefCount() const
SvRefBase(const SvRefBase &)
SvRefBase & operator=(const SvRefBase &)
Fraction operator*(const Fraction &rVal1, const Fraction &rVal2)
bool operator!=(const Fraction &rVal1, const Fraction &rVal2)
css::uno::Reference< css::linguistic2::XProofreadingIterator > get(css::uno::Reference< css::uno::XComponentContext > const &context)