Teuchos_RefCountPtrDecl.hpp

Go to the documentation of this file.
00001 // @HEADER
00002 // ***********************************************************************
00003 // 
00004 //                    Teuchos: Common Tools Package
00005 //                 Copyright (2004) Sandia Corporation
00006 // 
00007 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
00008 // license for use of this work by or on behalf of the U.S. Government.
00009 // 
00010 // This library is free software; you can redistribute it and/or modify
00011 // it under the terms of the GNU Lesser General Public License as
00012 // published by the Free Software Foundation; either version 2.1 of the
00013 // License, or (at your option) any later version.
00014 //  
00015 // This library is distributed in the hope that it will be useful, but
00016 // WITHOUT ANY WARRANTY; without even the implied warranty of
00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00018 // Lesser General Public License for more details.
00019 //  
00020 // You should have received a copy of the GNU Lesser General Public
00021 // License along with this library; if not, write to the Free Software
00022 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
00023 // USA
00024 // Questions? Contact Michael A. Heroux (maherou@sandia.gov) 
00025 // 
00026 // ***********************************************************************
00027 // @HEADER
00028 
00029 #ifndef TEUCHOS_REFCOUNTPTR_DECL_H
00030 #define TEUCHOS_REFCOUNTPTR_DECL_H
00031 
00037 #include "Teuchos_any.hpp"
00038 
00039 #ifdef REFCOUNTPTR_INLINE_FUNCS
00040 #define REFCOUNTPTR_INLINE inline
00041 #else
00042 #define REFCOUNTPTR_INLINE
00043 #endif
00044 
00045 #ifndef DOXYGEN_SHOULD_SKIP_THIS
00046 namespace MemMngPack {} // ToDo: Take out latter!
00047 #endif
00048 
00073 namespace Teuchos {
00074 
00075 namespace PrivateUtilityPack {
00076   class RefCountPtr_node;
00077 }
00078 
00085 
00087 enum ENull { null };
00088 
00090 template<class T>
00091 class DeallocDelete
00092 {
00093 public:
00095   typedef T ptr_t;
00097   void free( T* ptr ) { if(ptr) delete ptr; }
00098 };
00099 
00101 template<class T>
00102 class RefCountPtr {
00103 public:
00105   typedef T element_type;
00107 
00119   RefCountPtr( ENull null_arg = null );
00121 
00138   RefCountPtr(const RefCountPtr<T>& r_ptr);
00140 
00153   template<class T2>
00154   RefCountPtr(const RefCountPtr<T2>& r_ptr);
00156 
00166   ~RefCountPtr();
00168 
00184   RefCountPtr<T>& operator=(const RefCountPtr<T>& r_ptr);
00186 
00193   T* operator->() const;
00195 
00202   T& operator*() const;
00204 
00206   T* get() const;
00208 
00228   T* release();
00230 
00236   int count() const;
00238 
00256   void set_has_ownership();
00258 
00267   bool has_ownership() const;
00269 
00275   bool shares_resource(const RefCountPtr<T>& r_ptr) const;
00276 
00277 private:
00278 
00279   // //////////////////////////////////////
00280   // Private types
00281 
00282   typedef PrivateUtilityPack::RefCountPtr_node      node_t;
00283 
00284   // //////////////////////////////////////////////////////////////
00285   // Private data members
00286 
00287   T       *ptr_;  // NULL if this pointer is null
00288   node_t  *node_; // NULL if this pointer is null
00289 
00290   // /////////////////////////////////////
00291   // Private member functions
00292 
00293   void assert_not_null() const;
00294 
00295 public:
00296 #ifndef DOXYGEN_COMPILE
00297   // These constructors should be private but I have not had good luck making
00298   // this portable (i.e. using friendship etc.) in the past
00299   RefCountPtr( T* p, bool has_ownership );
00300   template<class Dealloc_T>
00301   RefCountPtr( T* p, Dealloc_T dealloc, bool has_ownership );
00302   // This is a very bad breach of encapsulation that is needed since MS VC++ 5.0 will
00303   // not allow me to declare template functions as friends.
00304   RefCountPtr( T* p, node_t* node);
00305   T*&           access_ptr();
00306   node_t*&      access_node();
00307   node_t*       access_node() const;
00308 #endif
00309 
00310 };  // end class RefCountPtr<...>
00311 
00313 
00334 template<class T>
00335 RefCountPtr<T> rcp( T* p, bool owns_mem
00336 #ifndef __sun
00337   = true
00338 #endif
00339   );
00340 #ifdef __sun // RAB: 20040303: Sun needs to fixe there &^**%F$ compiler
00341 template<class T> inline RefCountPtr<T> rcp( T* p ) { return rcp(p,true); }
00342 #endif
00343 
00345 
00385 template<class T, class Dealloc_T>
00386 RefCountPtr<T> rcp( T* p, Dealloc_T dealloc, bool owns_mem );
00387 
00389 
00396 template<class T2, class T1>
00397 RefCountPtr<T2> rcp_implicit_cast(const RefCountPtr<T1>& p1);
00398 
00400 
00408 template<class T2, class T1>
00409 RefCountPtr<T2> rcp_static_cast(const RefCountPtr<T1>& p1);
00410 
00412 
00416 template<class T2, class T1>
00417 RefCountPtr<T2> rcp_const_cast(const RefCountPtr<T1>& p1);
00418 
00420 
00424 template<class T2, class T1>
00425 RefCountPtr<T2> rcp_dynamic_cast(const RefCountPtr<T1>& p1);
00426 
00428 
00473 template<class T1, class T2>
00474 void set_extra_data( const T1 &extra_data, const std::string& name, RefCountPtr<T2> *p, bool force_unique
00475 #ifndef __sun
00476    = true
00477 #endif
00478   );
00479 #ifdef __sun
00480 template<class T1, class T2>
00481 inline void set_extra_data( const T1 &extra_data, const std::string& name, RefCountPtr<T2> *p )
00482 { set_extra_data( extra_data, name, p, true ); }
00483 #endif
00484 
00486 
00502 template<class T1, class T2>
00503 T1& get_extra_data( RefCountPtr<T2>& p, const std::string& name );
00504 
00506 
00528 template<class T1, class T2>
00529 const T1& get_extra_data( const RefCountPtr<T2>& p, const std::string& name );
00530 
00532 
00541 template<class Dealloc_T, class T>
00542 Dealloc_T& get_dealloc( RefCountPtr<T>& p );
00543 
00545 
00560 template<class Dealloc_T, class T>
00561 const Dealloc_T& get_dealloc( const RefCountPtr<T>& p );
00562 
00564 
00565 } // end namespace Teuchos
00566 
00567 #endif  // TEUCHOS_REFCOUNTPTR_DECL_H

Generated on Thu Sep 18 12:42:50 2008 for Teuchos - Trilinos Tools Package by doxygen 1.3.9.1