Teuchos_ArrayRCPDecl.hpp

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 
00030 #ifndef TEUCHOS_ARRAY_RCP_DECL_HPP
00031 #define TEUCHOS_ARRAY_RCP_DECL_HPP
00032 
00033 
00034 #include "Teuchos_RCP.hpp"
00035 #include "Teuchos_Exceptions.hpp"
00036 #include "Teuchos_ArrayViewDecl.hpp"
00037 
00038 
00039 namespace Teuchos {
00040 
00041 
00072 template<class T>
00073 class ArrayRCP {
00074 public:
00075 
00077 
00078 
00080   typedef std::random_access_iterator_tag iterator_category;
00082   typedef  T* iterator_type;
00084   typedef  T value_type;
00086   typedef T& reference; 
00088   typedef T* pointer;
00090   typedef  ptrdiff_t difference_type;
00091 
00093   typedef T  element_type;
00095   typedef Teuchos_Index Ordinal;
00096 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK
00097 
00098   typedef ArrayRCP<T> iterator;
00099 #else
00100   typedef T* iterator;
00101 #endif
00102 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK
00103 
00104   typedef ArrayRCP<T> const_iterator;
00105 #else
00106   typedef T* const_iterator;
00107 #endif
00108 
00110 
00112 
00113 
00126   ArrayRCP( ENull null_arg = null );
00127 
00140   ArrayRCP( T* p, Ordinal lowerOffset, Ordinal upperOffset, bool has_ownership );
00141 
00154   template<class Dealloc_T>
00155   ArrayRCP( T* p, Ordinal lowerOffset, Ordinal upperOffset, Dealloc_T dealloc,
00156     bool has_ownership );
00157 
00166   explicit ArrayRCP( Ordinal lowerOffset, const T& val = T() );
00167 
00185   ArrayRCP(const ArrayRCP<T>& r_ptr);
00186 
00199   ~ArrayRCP();
00200 
00218   ArrayRCP<T>& operator=(const ArrayRCP<T>& r_ptr);
00219 
00221 
00223 
00224 
00226   bool is_null() const;
00227 
00237   T* operator->() const;
00238 
00248   T& operator*() const;
00249 
00257   T* get() const;
00258 
00266   T* getRawPtr() const;
00267 
00275   T& operator[](Ordinal offset) const;
00276 
00278 
00280 
00281 
00292   ArrayRCP<T>& operator++();
00293 
00304   ArrayRCP<T> operator++(int);
00305 
00316   ArrayRCP<T>& operator--();
00317 
00328   ArrayRCP<T> operator--(int);
00329 
00340   ArrayRCP<T>& operator+=(Ordinal offset);
00341 
00352   ArrayRCP<T>& operator-=(Ordinal offset);
00353 
00368   ArrayRCP<T> operator+(Ordinal offset) const;
00369 
00384   ArrayRCP<T> operator-(Ordinal offset) const;
00385 
00387 
00389 
00390 
00403   const_iterator begin() const;
00404 
00417   const_iterator end() const;
00418 
00420 
00422 
00423 
00429   ArrayRCP<const T> getConst() const;
00430 
00445   ArrayRCP<T> persistingView( Ordinal lowerOffset, Ordinal size ) const;
00446 
00448 
00450 
00451 
00453   Ordinal lowerOffset() const;
00454 
00456   Ordinal upperOffset() const;
00457 
00461   Ordinal size() const;
00462 
00464 
00466 
00467 
00482   ArrayView<T> view( Ordinal lowerOffset, Ordinal size ) const;
00483 
00487   ArrayView<T> operator()( Ordinal lowerOffset, Ordinal size ) const;
00488 
00493   ArrayView<T> operator()() const;
00494 
00496 
00498 
00499 
00503   operator ArrayView<T>() const;
00504 
00506   operator ArrayRCP<const T>() const;
00507 
00509 
00511 
00512 
00517   void assign(Ordinal n, const T &val);
00518 
00526   template<class Iter>
00527   void assign(Iter first, Iter last);
00528 
00534   void deepCopy(const ArrayView<const T>& av);
00535 
00539   void resize(const Ordinal n, const T &val = T());
00540 
00545   void clear();
00546 
00548 
00550 
00551 
00563   ERCPStrength strength() const;
00564 
00574   bool is_valid_ptr() const;
00575 
00581   int strong_count() const;
00582 
00588   int weak_count() const;
00589 
00591   int total_count() const;
00592 
00610   void set_has_ownership();
00611 
00623   bool has_ownership() const;
00624 
00645   T* release();
00646 
00663   ArrayRCP<T> create_weak() const;
00664 
00681   ArrayRCP<T> create_strong() const;
00682 
00689   template<class T2>
00690   bool shares_resource(const ArrayRCP<T2>& r_ptr) const;
00691 
00693 
00695 
00696 
00700   const ArrayRCP<T>& assert_not_null() const;
00701 
00707   const ArrayRCP<T>& assert_in_range( Ordinal lowerOffset, Ordinal size ) const;
00708 
00718   const ArrayRCP<T>& assert_valid_ptr() const;
00719 
00721 
00724 
00726   int count() const;
00727 
00729 
00730 private:
00731 
00732   // //////////////////////////////////////////////////////////////
00733   // Private data members
00734 
00735   T *ptr_; // NULL if this pointer is null
00736   RCPNodeHandle node_; // NULL if this pointer is null
00737   Ordinal lowerOffset_; // 0 if this pointer is null
00738   Ordinal upperOffset_; // -1 if this pointer is null
00739 
00740   void debug_assert_not_null() const
00741     {
00742 #ifdef TEUCHOS_REFCOUNTPTR_ASSERT_NONNULL
00743       assert_not_null();
00744 #endif
00745     }
00746 
00747   void debug_assert_in_range( Ordinal lowerOffset_in, Ordinal size_in ) const
00748     {
00749       (void)lowerOffset_in; (void)size_in;
00750 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK
00751       assert_in_range(lowerOffset_in, size_in);
00752 #endif
00753     }
00754 
00755   void debug_assert_valid_ptr() const
00756     {
00757 #ifdef TEUCHOS_DEBUG
00758       assert_valid_ptr();
00759 #endif
00760     }
00761 
00762 public:
00763 
00764 #ifndef DOXYGEN_COMPILE
00765   // These constructors should be private but I have not had good luck making
00766   // this portable (i.e. using friendship etc.) in the past
00767   // This is a very bad breach of encapsulation that is needed since MS VC++
00768   // 5.0 will not allow me to declare template functions as friends.
00769   ArrayRCP( T* p, Ordinal lowerOffset, Ordinal upperOffset,
00770     const RCPNodeHandle& node );
00771   T* access_private_ptr() const;
00772   RCPNodeHandle& nonconst_access_private_node();
00773   const RCPNodeHandle& access_private_node() const;
00774 #endif
00775 
00776 };  // end class ArrayRCP<...>
00777 
00778 
00779 // 2008/09/22: rabartl: NOTE: I removed the TypeNameTraits<ArrayRCP<T> >
00780 // specialization since I want to be able to print the type name of an
00781 // ArrayRCP that does not have the type T fully defined!
00782 
00783 
00788 template<typename T>
00789 class NullIteratorTraits<ArrayRCP<T> > {
00790 public:
00791   static ArrayRCP<T> getNull() { return null; }
00792 };
00793 
00794 
00800 template<class T>
00801 ArrayRCP<T> arcp(
00802   T* p,
00803   typename ArrayRCP<T>::Ordinal lowerOffset,
00804   typename ArrayRCP<T>::Ordinal size,
00805   bool owns_mem = true
00806   );
00807 
00808 
00814 template<class T, class Dealloc_T>
00815 ArrayRCP<T> arcp(
00816   T* p,
00817   typename ArrayRCP<T>::Ordinal lowerOffset,
00818   typename ArrayRCP<T>::Ordinal size,
00819   Dealloc_T dealloc, bool owns_mem
00820   );
00821 
00822  
00833 template<class T>
00834 ArrayRCP<T> arcp( typename ArrayRCP<T>::Ordinal size );
00835 
00836  
00841 template<class T>
00842 ArrayRCP<T> arcpClone( const ArrayView<const T> &v );
00843 
00844 
00855 template<class T, class Embedded>
00856 ArrayRCP<T>
00857 arcpWithEmbeddedObjPreDestroy(
00858   T* p,
00859   typename ArrayRCP<T>::Ordinal lowerOffset,
00860   typename ArrayRCP<T>::Ordinal size,
00861   const Embedded &embedded,
00862   bool owns_mem = true
00863   );
00864 
00865 
00876 template<class T, class Embedded>
00877 ArrayRCP<T>
00878 arcpWithEmbeddedObjPostDestroy(
00879   T* p,
00880   typename ArrayRCP<T>::Ordinal lowerOffset,
00881   typename ArrayRCP<T>::Ordinal size,
00882   const Embedded &embedded,
00883   bool owns_mem = true
00884   );
00885 
00886 
00898 template<class T, class Embedded>
00899 ArrayRCP<T>
00900 arcpWithEmbeddedObj(
00901   T* p,
00902   typename ArrayRCP<T>::Ordinal lowerOffset,
00903   typename ArrayRCP<T>::Ordinal size,
00904   const Embedded &embedded,
00905   bool owns_mem = true
00906   );
00907 
00908 
00914 template<class T>
00915 ArrayRCP<T> arcp( const RCP<std::vector<T> > &v );
00916 
00917 
00923 template<class T>
00924 ArrayRCP<const T> arcp( const RCP<const std::vector<T> > &v );
00925 
00926 
00935 template<class T>
00936 ArrayRCP<T> arcpFromArrayView(const ArrayView<T> &av);
00937 
00938 
00945 template<class T>
00946 RCP<std::vector<T> > get_std_vector( const ArrayRCP<T> &ptr );
00947 
00948 
00955 template<class T>
00956 RCP<const std::vector<T> > get_std_vector( const ArrayRCP<const T> &ptr );
00957 
00958 
00963 template<class T>
00964 bool is_null( const ArrayRCP<T> &p );
00965 
00966 
00971 template<class T>
00972 bool nonnull( const ArrayRCP<T> &p );
00973 
00974 
00979 template<class T>
00980 bool operator==( const ArrayRCP<T> &p, ENull );
00981 
00982 
00987 template<class T>
00988 bool operator!=( const ArrayRCP<T> &p, ENull );
00989 
00990 
00995 template<class T1, class T2>
00996 bool operator==( const ArrayRCP<T1> &p1, const ArrayRCP<T2> &p2 );
00997 
00998 
01003 template<class T1, class T2>
01004 bool operator!=( const ArrayRCP<T1> &p1, const ArrayRCP<T2> &p2 );
01005 
01006 
01011 template<class T1, class T2>
01012 bool operator<( const ArrayRCP<T1> &p1, const ArrayRCP<T2> &p2 );
01013 
01014 
01019 template<class T1, class T2>
01020 bool operator<=( const ArrayRCP<T1> &p1, const ArrayRCP<T2> &p2 );
01021 
01022 
01027 template<class T1, class T2>
01028 bool operator>( const ArrayRCP<T1> &p1, const ArrayRCP<T2> &p2 );
01029 
01030 
01035 template<class T1, class T2>
01036 bool operator>=( const ArrayRCP<T1> &p1, const ArrayRCP<T2> &p2 );
01037 
01038 
01043 template<class T>
01044 typename ArrayRCP<T>::difference_type
01045 operator-( const ArrayRCP<T> &p1, const ArrayRCP<T> &p2 );
01046 
01047 
01056 template<class T2, class T1>
01057 ArrayRCP<T2> arcp_const_cast(const ArrayRCP<T1>& p1);
01058 
01059 
01072 template<class T2, class T1>
01073 ArrayRCP<T2> arcp_reinterpret_cast(const ArrayRCP<T1>& p1);
01074 
01075 
01101 template<class T2, class T1>
01102 ArrayRCP<T2> arcp_implicit_cast(const ArrayRCP<T1>& p1);
01103 
01104 
01163 template<class T1, class T2>
01164 void set_extra_data(
01165   const T1 &extra_data, const std::string& name,
01166   const Ptr<ArrayRCP<T2> > &p, EPrePostDestruction destroy_when = POST_DESTROY,
01167   bool force_unique = true );
01168 
01169 
01189 template<class T1, class T2>
01190 T1& get_extra_data( ArrayRCP<T2>& p, const std::string& name );
01191 
01192 
01218 template<class T1, class T2>
01219 const T1& get_extra_data( const ArrayRCP<T2>& p, const std::string& name );
01220 
01221 
01246 template<class T1, class T2>
01247 T1* get_optional_extra_data( ArrayRCP<T2>& p, const std::string& name );
01248 
01249 
01279 template<class T1, class T2>
01280 const T1* get_optional_extra_data( const ArrayRCP<T2>& p, const std::string& name );
01281 
01282 
01293 template<class Dealloc_T, class T>
01294 Dealloc_T& get_nonconst_dealloc( const ArrayRCP<T>& p );
01295 
01296 
01314 template<class Dealloc_T, class T>
01315 const Dealloc_T& get_dealloc( const ArrayRCP<T>& p );
01316 
01317 
01332 template<class Dealloc_T, class T>
01333 const Dealloc_T* get_optional_dealloc( const ArrayRCP<T>& p );
01334 
01335 
01357 template<class Dealloc_T, class T>
01358 Dealloc_T* get_optional_nonconst_dealloc( const ArrayRCP<T>& p );
01359 
01360 
01367 template<class TOrig, class Embedded, class T>
01368 const Embedded& getEmbeddedObj( const ArrayRCP<T>& p );
01369 
01370 
01377 template<class TOrig, class Embedded, class T>
01378 Embedded& getNonconstEmbeddedObj( const ArrayRCP<T>& p );
01379 
01380 
01388 template<class T>
01389 std::ostream& operator<<( std::ostream& out, const ArrayRCP<T>& p );
01390 
01391 
01392 } // end namespace Teuchos
01393 
01394 
01395 #endif  // TEUCHOS_ARRAY_RCP_DECL_HPP

Generated on Wed May 12 21:24:40 2010 for Teuchos - Trilinos Tools Package by  doxygen 1.4.7