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 SGSharedPtr(void) noexcept
: _ptr(0) : _ptr(0)
{} {}
SGSharedPtr(T* ptr) : _ptr(ptr) 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(SGSharedPtr&& other) noexcept
: SGSharedPtr() : SGSharedPtr()
{ swap(other); } {
swap(other);
}
template<typename U> template<typename U>
SGSharedPtr(const SGSharedPtr<U>& p) : _ptr(p.get()) SGSharedPtr(const SGSharedPtr<U>& p)
{ get(_ptr); } : _ptr(p.get())
{
get(_ptr);
}
template<typename U> template<typename U>
explicit SGSharedPtr(const SGWeakPtr<U>& p): _ptr(0) explicit SGSharedPtr(const SGWeakPtr<U>& p)
{ reset(p.lock().get()); } : _ptr(0)
{
reset(p.lock().get());
}
~SGSharedPtr(void) ~SGSharedPtr(void)
{ reset(); } {
reset();
}
SGSharedPtr& operator=(const SGSharedPtr& p) SGSharedPtr& operator=(const SGSharedPtr& p)
{ reset(p.get()); return *this; } {
reset(p.get());
return *this;
}
SGSharedPtr& operator=(SGSharedPtr&& p) noexcept 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 // take the conservative approach for now
if (this != &p) { if (this != &p) {
swap(p); swap(p);
@ -85,47 +110,99 @@ public:
template<typename U> template<typename U>
SGSharedPtr& operator=(const SGSharedPtr<U>& p) SGSharedPtr& operator=(const SGSharedPtr<U>& p)
{ reset(p.get()); return *this; } {
reset(p.get());
return *this;
}
template<typename U> template<typename U>
SGSharedPtr& operator=(U* p) SGSharedPtr& operator=(U* p)
{ reset(p); return *this; } {
reset(p);
return *this;
}
T* operator->(void) const T* operator->(void) const
{ return _ptr; } {
return _ptr;
}
T& operator*(void) const T& operator*(void) const
{ return *_ptr; } {
return *_ptr;
}
operator T*(void) const operator T*(void) const
{ return _ptr; } {
return _ptr;
}
T* ptr(void) const T* ptr(void) const
{ return _ptr; } {
return _ptr;
}
T* get(void) const T* get(void) const
{ return _ptr; } {
return _ptr;
}
T* release() 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 void reset() noexcept
{ if (!T::put(_ptr)) delete _ptr; _ptr = 0; } {
if (!T::put(_ptr)) delete _ptr;
_ptr = 0;
}
void reset(T* p) void reset(T* p)
{ SGSharedPtr(p).swap(*this); } {
SGSharedPtr(p).swap(*this);
}
bool isShared(void) const bool isShared(void) const
{ return T::shared(_ptr); } {
return T::shared(_ptr);
}
unsigned getNumRefs(void) const unsigned getNumRefs(void) const
{ return T::count(_ptr); } {
return T::count(_ptr);
}
bool valid(void) const bool valid(void) const
{ return _ptr != (T*)0; } {
return _ptr != (T*)0;
}
void clear() void clear()
{ reset(); } {
reset();
}
void swap(SGSharedPtr& other) noexcept void swap(SGSharedPtr& other) noexcept
{ simgear::noexceptSwap(_ptr, other._ptr); } {
simgear::noexceptSwap(_ptr, other._ptr);
}
private: private:
void assignNonRef(T* p) void assignNonRef(T* p)
{ reset(); _ptr = p; } {
reset();
_ptr = p;
}
void get(const T* p) const void get(const T* p) const
{ T::get(p); } {
T::get(p);
}
// The reference itself. // The reference itself.
T* _ptr; T* _ptr;