Revert "Quick fix to allow PK and libzypp-bindings build with gcc-4.7"
[platform/upstream/libzypp.git] / zypp / base / PtrTypes.h
index 5081ce7..452c483 100644 (file)
@@ -122,6 +122,14 @@ namespace std
       return str << *obj;
     return str << std::string("NULL");
   }
+  /** \relates zypp::shared_ptr Stream output. */
+  template<class _D>
+  inline std::ostream & dumpOn( std::ostream & str, const zypp::shared_ptr<_D> & obj )
+  {
+    if ( obj )
+      return dumpOn( str, *obj );
+    return str << std::string("NULL");
+  }
 
   /** \relates zypp::intrusive_ptr Stream output. */
   template<class _D>
@@ -131,6 +139,14 @@ namespace std
       return str << *obj;
     return str << std::string("NULL");
   }
+  /** \relates zypp::intrusive_ptr Stream output. */
+  template<class _D>
+  inline std::ostream & dumpOn( std::ostream & str, const zypp::intrusive_ptr<_D> & obj )
+  {
+    if ( obj )
+      return dumpOn( str, *obj );
+    return str << std::string("NULL");
+  }
   /////////////////////////////////////////////////////////////////
 } // namespace std
 ///////////////////////////////////////////////////////////////////
@@ -183,7 +199,25 @@ namespace zypp
           long use_count( const _Ptr & ptr_r ) const
           { return ptr_r ? ptr_r->refCount() : 0; }
         };
-    }
+
+       template<class _D>
+        struct Scoped
+        {
+          typedef scoped_ptr<_D>       _Ptr;
+          typedef scoped_ptr<const _D> _constPtr;
+          /** Check whether pointer is not shared. */
+          bool unique( const _constPtr & ptr_r )
+          { return true; }
+          bool unique( const _Ptr & ptr_r )
+          { return true; }
+          /** Return number of references. */
+          long use_count( const _constPtr & ptr_r ) const
+          { return ptr_r ? 1 : 0; }
+          long use_count( const _Ptr & ptr_r ) const
+          { return ptr_r ? 1 : 0; }
+        };
+
+   }
     ///////////////////////////////////////////////////////////////////
 
     ///////////////////////////////////////////////////////////////////
@@ -290,6 +324,9 @@ namespace zypp
         _Ptr getPtr()
         { return _dptr; }
 
+        _constPtr cgetPtr()
+        { return _dptr; }
+
       private:
         _Ptr _dptr;
       };
@@ -301,14 +338,56 @@ namespace zypp
      * if the pointer is \c NULL.
     */
     template<class _D, class _Ptr>
-      inline std::ostream &
-      operator<<( std::ostream & str, const RW_pointer<_D, _Ptr> & obj )
+      inline std::ostream & operator<<( std::ostream & str, const RW_pointer<_D, _Ptr> & obj )
       {
         if ( obj.get() )
           return str << *obj.get();
         return str << std::string("NULL");
       }
 
+    /** \relates RW_pointer */
+    template<class _D, class _Ptr>
+      inline bool operator==( const RW_pointer<_D, _Ptr> & lhs, const RW_pointer<_D, _Ptr> & rhs )
+      { return( lhs.get() == rhs.get() ); }
+    /** \relates RW_pointer */
+     template<class _D, class _Ptr>
+       inline bool operator==( const RW_pointer<_D, _Ptr> & lhs, const typename _Ptr::_Ptr & rhs )
+       { return( lhs.get() == rhs.get() ); }
+    /** \relates RW_pointer */
+     template<class _D, class _Ptr>
+       inline bool operator==( const typename _Ptr::_Ptr & lhs, const RW_pointer<_D, _Ptr> & rhs )
+       { return( lhs.get() == rhs.get() ); }
+    /** \relates RW_pointer */
+     template<class _D, class _Ptr>
+       inline bool operator==( const RW_pointer<_D, _Ptr> & lhs, const typename _Ptr::_constPtr & rhs )
+       { return( lhs.get() == rhs.get() ); }
+    /** \relates RW_pointer */
+     template<class _D, class _Ptr>
+       inline bool operator==( const typename _Ptr::_constPtr & lhs, const RW_pointer<_D, _Ptr> & rhs )
+       { return( lhs.get() == rhs.get() ); }
+
+
+    /** \relates RW_pointer */
+    template<class _D, class _Ptr>
+      inline bool operator!=( const RW_pointer<_D, _Ptr> & lhs, const RW_pointer<_D, _Ptr> & rhs )
+      { return ! ( lhs == rhs ); }
+    /** \relates RW_pointer */
+     template<class _D, class _Ptr>
+       inline bool operator!=( const RW_pointer<_D, _Ptr> & lhs, const typename _Ptr::_Ptr & rhs )
+       { return ! ( lhs == rhs ); }
+    /** \relates RW_pointer */
+     template<class _D, class _Ptr>
+       inline bool operator!=( const typename _Ptr::_Ptr & lhs, const RW_pointer<_D, _Ptr> & rhs )
+       { return ! ( lhs == rhs ); }
+    /** \relates RW_pointer */
+     template<class _D, class _Ptr>
+       inline bool operator!=( const RW_pointer<_D, _Ptr> & lhs, const typename _Ptr::_constPtr & rhs )
+       { return ! ( lhs == rhs ); }
+    /** \relates RW_pointer */
+     template<class _D, class _Ptr>
+       inline bool operator!=( const typename _Ptr::_constPtr & lhs, const RW_pointer<_D, _Ptr> & rhs )
+       { return ! ( lhs == rhs ); }
+
     ///////////////////////////////////////////////////////////////////
 
     ///////////////////////////////////////////////////////////////////
@@ -385,6 +464,9 @@ namespace zypp
         _Ptr getPtr()
         { assertUnshared(); return _dptr; }
 
+        _constPtr cgetPtr()
+        { return _dptr; }
+
       private:
 
         void assertUnshared()
@@ -415,14 +497,55 @@ namespace zypp
      * if the pointer is \c NULL.
     */
     template<class _D, class _Ptr>
-      inline std::ostream &
-      operator<<( std::ostream & str, const RWCOW_pointer<_D, _Ptr> & obj )
+      inline std::ostream & operator<<( std::ostream & str, const RWCOW_pointer<_D, _Ptr> & obj )
       {
         if ( obj.get() )
           return str << *obj.get();
         return str << std::string("NULL");
       }
 
+    /** \relates RWCOW_pointer */
+    template<class _D, class _Ptr>
+      inline bool operator==( const RWCOW_pointer<_D, _Ptr> & lhs, const RWCOW_pointer<_D, _Ptr> & rhs )
+      { return( lhs.get() == rhs.get() ); }
+    /** \relates RWCOW_pointer */
+    template<class _D, class _Ptr>
+      inline bool operator==( const RWCOW_pointer<_D, _Ptr> & lhs, const typename _Ptr::_Ptr & rhs )
+      { return( lhs.get() == rhs.get() ); }
+    /** \relates RWCOW_pointer */
+    template<class _D, class _Ptr>
+      inline bool operator==( const typename _Ptr::_Ptr & lhs, const RWCOW_pointer<_D, _Ptr> & rhs )
+      { return( lhs.get() == rhs.get() ); }
+    /** \relates RWCOW_pointer */
+    template<class _D, class _Ptr>
+      inline bool operator==( const RWCOW_pointer<_D, _Ptr> & lhs, const typename _Ptr::_constPtr & rhs )
+      { return( lhs.get() == rhs.get() ); }
+    /** \relates RWCOW_pointer */
+    template<class _D, class _Ptr>
+      inline bool operator==( const typename _Ptr::_constPtr & lhs, const RWCOW_pointer<_D, _Ptr> & rhs )
+      { return( lhs.get() == rhs.get() ); }
+
+    /** \relates RWCOW_pointer */
+    template<class _D, class _Ptr>
+      inline bool operator!=( const RWCOW_pointer<_D, _Ptr> & lhs, const RWCOW_pointer<_D, _Ptr> & rhs )
+      { return ! ( lhs == rhs ); }
+    /** \relates RWCOW_pointer */
+    template<class _D, class _Ptr>
+      inline bool operator!=( const RWCOW_pointer<_D, _Ptr> & lhs, const typename _Ptr::_Ptr & rhs )
+      { return ! ( lhs == rhs ); }
+    /** \relates RWCOW_pointer */
+    template<class _D, class _Ptr>
+      inline bool operator!=( const typename _Ptr::_Ptr & lhs, const RWCOW_pointer<_D, _Ptr> & rhs )
+      { return ! ( lhs == rhs ); }
+    /** \relates RWCOW_pointer */
+    template<class _D, class _Ptr>
+      inline bool operator!=( const RWCOW_pointer<_D, _Ptr> & lhs, const typename _Ptr::_constPtr & rhs )
+      { return ! ( lhs == rhs ); }
+    /** \relates RWCOW_pointer */
+    template<class _D, class _Ptr>
+      inline bool operator!=( const typename _Ptr::_constPtr & lhs, const RWCOW_pointer<_D, _Ptr> & rhs )
+      { return ! ( lhs == rhs ); }
+
     ///////////////////////////////////////////////////////////////////
 
     /*@}*/