simgear/structure/SGSharedPtr.hxx: reformatted to make it readable.

This commit is contained in:
Julian Smith 2021-05-04 07:36:22 +01:00
parent 46e79aba11
commit 0b6678f745

View File

@ -54,27 +54,52 @@ public:
SGSharedPtr(void) noexcept
: _ptr(0)
{}
SGSharedPtr(T* ptr) : _ptr(ptr)
{ get(_ptr); }
SGSharedPtr(const SGSharedPtr& p) : _ptr(p.get())
{ get(_ptr); }
{
get(_ptr);
}
SGSharedPtr(const SGSharedPtr& p)
: _ptr(p.get())
{
get(_ptr);
}
SGSharedPtr(SGSharedPtr&& other) noexcept
: SGSharedPtr()
{ swap(other); }
{
swap(other);
}
template<typename U>
SGSharedPtr(const SGSharedPtr<U>& p) : _ptr(p.get())
{ get(_ptr); }
SGSharedPtr(const SGSharedPtr<U>& p)
: _ptr(p.get())
{
get(_ptr);
}
template<typename U>
explicit SGSharedPtr(const SGWeakPtr<U>& p): _ptr(0)
{ reset(p.lock().get()); }
explicit SGSharedPtr(const SGWeakPtr<U>& p)
: _ptr(0)
{
reset(p.lock().get());
}
~SGSharedPtr(void)
{ reset(); }
{
reset();
}
SGSharedPtr& operator=(const SGSharedPtr& p)
{ reset(p.get()); return *this; }
{
reset(p.get());
return *this;
}
SGSharedPtr& operator=(SGSharedPtr&& p) noexcept
{ // Whether self-move is to be supported at all is controversial, let's
{
// Whether self-move is to be supported at all is controversial, let's
// take the conservative approach for now
if (this != &p) {
swap(p);
@ -85,47 +110,99 @@ public:
template<typename U>
SGSharedPtr& operator=(const SGSharedPtr<U>& p)
{ reset(p.get()); return *this; }
{
reset(p.get());
return *this;
}
template<typename U>
SGSharedPtr& operator=(U* p)
{ reset(p); return *this; }
{
reset(p);
return *this;
}
T* operator->(void) const
{ return _ptr; }
{
return _ptr;
}
T& operator*(void) const
{ return *_ptr; }
{
return *_ptr;
}
operator T*(void) const
{ return _ptr; }
{
return _ptr;
}
T* ptr(void) const
{ return _ptr; }
{
return _ptr;
}
T* get(void) const
{ return _ptr; }
{
return _ptr;
}
T* release()
{ T* tmp = _ptr; _ptr = 0; T::put(tmp); return tmp; }
{
T* tmp = _ptr;
_ptr = 0;
T::put(tmp);
return tmp;
}
void reset() noexcept
{ if (!T::put(_ptr)) delete _ptr; _ptr = 0; }
{
if (!T::put(_ptr)) delete _ptr;
_ptr = 0;
}
void reset(T* p)
{ SGSharedPtr(p).swap(*this); }
{
SGSharedPtr(p).swap(*this);
}
bool isShared(void) const
{ return T::shared(_ptr); }
{
return T::shared(_ptr);
}
unsigned getNumRefs(void) const
{ return T::count(_ptr); }
{
return T::count(_ptr);
}
bool valid(void) const
{ return _ptr != (T*)0; }
{
return _ptr != (T*)0;
}
void clear()
{ reset(); }
{
reset();
}
void swap(SGSharedPtr& other) noexcept
{ simgear::noexceptSwap(_ptr, other._ptr); }
{
simgear::noexceptSwap(_ptr, other._ptr);
}
private:
void assignNonRef(T* p)
{ reset(); _ptr = p; }
{
reset();
_ptr = p;
}
void get(const T* p) const
{ T::get(p); }
{
T::get(p);
}
// The reference itself.
T* _ptr;