X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=simgear%2Fstructure%2FSGSharedPtr.hxx;h=081d5eb943b1bcb43cf89661228b4477ea94a7ab;hb=10375086ed794770fcb97591ec19c60c0fcdaff1;hp=98b72f22c902a37dfd43c07b2f8418a36687ebbe;hpb=1f6555c9ad3fb75cb474fbf99b46333830285514;p=simgear.git diff --git a/simgear/structure/SGSharedPtr.hxx b/simgear/structure/SGSharedPtr.hxx index 98b72f22..081d5eb9 100644 --- a/simgear/structure/SGSharedPtr.hxx +++ b/simgear/structure/SGSharedPtr.hxx @@ -1,6 +1,6 @@ /* -*-c++-*- * - * Copyright (C) 2005-2009 Mathias Froehlich + * Copyright (C) 2005-2012 Mathias Froehlich * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as @@ -48,6 +48,8 @@ class SGWeakPtr; template class SGSharedPtr { public: + typedef T element_type; + SGSharedPtr(void) : _ptr(0) {} SGSharedPtr(T* ptr) : _ptr(ptr) @@ -88,7 +90,7 @@ public: { return T::count(_ptr); } bool valid(void) const - { return _ptr != NULL; } + { return _ptr != (T*)0; } void clear() { put(); } @@ -104,7 +106,7 @@ private: void get(const T* p) const { T::get(p); } void put(void) - { if (!T::put(_ptr)) { delete _ptr; _ptr = 0; } } + { if (!T::put(_ptr)) delete _ptr; _ptr = 0; } // The reference itself. T* _ptr; @@ -121,4 +123,51 @@ T* get_pointer(SGSharedPtr const & p) { return p.ptr(); } + +/** + * static_cast for SGSharedPtr + */ +template +SGSharedPtr static_pointer_cast(SGSharedPtr const & r) +{ + return SGSharedPtr( static_cast(r.get()) ); +} + +/** + * Compare two SGSharedPtr objects for equality. + * + * @note Only pointer values are compared, not the actual objects they are + * pointing at. + */ +template +bool operator==(const SGSharedPtr& lhs, const SGSharedPtr& rhs) +{ + return lhs.get() == rhs.get(); +} + +/** + * Compare two SGSharedPtr objects for equality. + * + * @note Only pointer values are compared, not the actual objects they are + * pointing at. + */ +template +bool operator!=(const SGSharedPtr& lhs, const SGSharedPtr& rhs) +{ + return lhs.get() != rhs.get(); +} + +/** + * Compare two SGSharedPtr objects for weak ordering. + * + * @note Only pointer values are compared, not the actual objects they are + * pointing at. + * @note This allows using SGSharedPtr as key in associative containers like for + * example std::map and std::set. + */ +template +bool operator<(const SGSharedPtr& lhs, const SGSharedPtr& rhs) +{ + return lhs.get() < rhs.get(); +} #endif