]> git.mxchange.org Git - simgear.git/blobdiff - simgear/structure/SGSharedPtr.hxx
Some Linux platforms need <cstdio> for snprintf.
[simgear.git] / simgear / structure / SGSharedPtr.hxx
index b8553b06c7a85944c3b12a208b47f5507cfda829..081d5eb943b1bcb43cf89661228b4477ea94a7ab 100644 (file)
@@ -48,6 +48,8 @@ class SGWeakPtr;
 template<typename T>
 class SGSharedPtr {
 public:
+  typedef T element_type;
+
   SGSharedPtr(void) : _ptr(0)
   {}
   SGSharedPtr(T* ptr) : _ptr(ptr)
@@ -121,4 +123,51 @@ T* get_pointer(SGSharedPtr<T> const & p)
 {
   return p.ptr();
 }
+
+/**
+ * static_cast for SGSharedPtr
+ */
+template<class T, class U>
+SGSharedPtr<T> static_pointer_cast(SGSharedPtr<U> const & r)
+{
+  return SGSharedPtr<T>( static_cast<T*>(r.get()) );
+}
+
+/**
+ * Compare two SGSharedPtr<T> objects for equality.
+ *
+ * @note Only pointer values are compared, not the actual objects they are
+ *       pointing at.
+ */
+template<class T, class U>
+bool operator==(const SGSharedPtr<T>& lhs, const SGSharedPtr<U>& rhs)
+{
+  return lhs.get() == rhs.get();
+}
+
+/**
+ * Compare two SGSharedPtr<T> objects for equality.
+ *
+ * @note Only pointer values are compared, not the actual objects they are
+ *       pointing at.
+ */
+template<class T, class U>
+bool operator!=(const SGSharedPtr<T>& lhs, const SGSharedPtr<U>& rhs)
+{
+  return lhs.get() != rhs.get();
+}
+
+/**
+ * Compare two SGSharedPtr<T> 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<class T, class U>
+bool operator<(const SGSharedPtr<T>& lhs, const SGSharedPtr<U>& rhs)
+{
+  return lhs.get() < rhs.get();
+}
 #endif