Teuchos Package Browser (Single Doxygen Collection) Version of the Day
Teuchos_ArrayRCPDecl.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 
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 
00071 template<class T>
00072 class ArrayRCP {
00073 public:
00074 
00076 
00077 
00079   typedef Teuchos_Ordinal Ordinal;
00080 
00082   typedef Ordinal size_type;
00084   typedef Ordinal difference_type;
00086   typedef std::random_access_iterator_tag iterator_category;
00088   typedef  T* iterator_type;
00090   typedef  T value_type;
00092   typedef T& reference; 
00094   typedef const T& const_reference; 
00096   typedef T* pointer;
00098   typedef T* const_pointer;
00100   typedef T  element_type;
00101 
00102 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK
00103 
00104   typedef ArrayRCP<T> iterator;
00106   typedef ArrayRCP<const T> const_iterator;
00107 #else
00108   typedef T* iterator;
00109   typedef const T* const_iterator;
00110 #endif
00111 
00113 
00115 
00116 
00129   inline ArrayRCP( ENull null_arg = null );
00130 
00143   inline ArrayRCP( T* p, size_type lowerOffset, size_type size,
00144     bool has_ownership, const ERCPNodeLookup rcpNodeLookup = RCP_ENABLE_NODE_LOOKUP );
00145 
00158   template<class Dealloc_T>
00159   inline ArrayRCP( T* p, size_type lowerOffset, size_type size, Dealloc_T dealloc,
00160     bool has_ownership );
00161 
00170   inline explicit ArrayRCP( size_type size, const T& val = T() );
00171 
00189   inline ArrayRCP(const ArrayRCP<T>& r_ptr);
00190 
00203   inline ~ArrayRCP();
00204 
00222   inline ArrayRCP<T>& operator=(const ArrayRCP<T>& r_ptr);
00223 
00225 
00227 
00228 
00230   inline bool is_null() const;
00231 
00241   inline T* operator->() const;
00242 
00252   inline T& operator*() const;
00253 
00261   inline T* get() const;
00262 
00270   inline T* getRawPtr() const;
00271 
00279   inline T& operator[](size_type offset) const;
00280 
00282 
00284 
00285 
00296   inline ArrayRCP<T>& operator++();
00297 
00308   inline ArrayRCP<T> operator++(int);
00309 
00320   inline ArrayRCP<T>& operator--();
00321 
00332   inline ArrayRCP<T> operator--(int);
00333 
00344   inline ArrayRCP<T>& operator+=(size_type offset);
00345 
00356   inline ArrayRCP<T>& operator-=(size_type offset);
00357 
00372   inline ArrayRCP<T> operator+(size_type offset) const;
00373 
00388   inline ArrayRCP<T> operator-(size_type offset) const;
00389 
00391 
00393 
00394 
00407   inline iterator begin() const;
00408 
00421   inline iterator end() const;
00422 
00424 
00426 
00427 
00433   inline ArrayRCP<const T> getConst() const;
00434 
00449   inline ArrayRCP<T> persistingView( size_type lowerOffset, size_type size ) const;
00450 
00452 
00454 
00455 
00457   inline size_type lowerOffset() const;
00458 
00460   inline size_type upperOffset() const;
00461 
00465   inline size_type size() const;
00466 
00468 
00470 
00471 
00486   inline ArrayView<T> view( size_type lowerOffset, size_type size ) const;
00487 
00491   inline ArrayView<T> operator()( size_type lowerOffset, size_type size ) const;
00492 
00497   inline ArrayView<T> operator()() const;
00498 
00500 
00502 
00503 
00505   inline operator ArrayRCP<const T>() const;
00506 
00508 
00510 
00511 
00516   inline void assign(size_type n, const T &val);
00517 
00525   template<class Iter>
00526   inline void assign(Iter first, Iter last);
00527 
00533   inline void deepCopy(const ArrayView<const T>& av);
00534 
00538   inline void resize(const size_type n, const T &val = T());
00539 
00544   inline void clear();
00545 
00547 
00549 
00550 
00562   inline ERCPStrength strength() const;
00563 
00573   inline bool is_valid_ptr() const;
00574 
00580   inline int strong_count() const;
00581 
00587   inline int weak_count() const;
00588 
00590   inline int total_count() const;
00591 
00609   inline void set_has_ownership();
00610 
00622   inline bool has_ownership() const;
00623 
00644   inline T* release();
00645 
00662   inline ArrayRCP<T> create_weak() const;
00663 
00680   inline ArrayRCP<T> create_strong() const;
00681 
00688   template<class T2>
00689   inline bool shares_resource(const ArrayRCP<T2>& r_ptr) const;
00690 
00692 
00694 
00695 
00699   inline const ArrayRCP<T>& assert_not_null() const;
00700 
00706   inline const ArrayRCP<T>& assert_in_range( size_type lowerOffset, size_type size ) const;
00707 
00717   inline const ArrayRCP<T>& assert_valid_ptr() const;
00718 
00720 
00723 
00725   inline int count() const;
00726 
00728 
00729 private:
00730 
00731   // //////////////////////////////////////////////////////////////
00732   // Private data members
00733 
00734   T *ptr_; // NULL if this pointer is null
00735   RCPNodeHandle node_; // NULL if this pointer is null
00736   size_type lowerOffset_; // 0 if this pointer is null
00737   size_type upperOffset_; // -1 if this pointer is null
00738 
00739   inline void debug_assert_not_null() const
00740     {
00741 #ifdef TEUCHOS_REFCOUNTPTR_ASSERT_NONNULL
00742       assert_not_null();
00743 #endif
00744     }
00745 
00746   inline void debug_assert_in_range( size_type lowerOffset_in,
00747     size_type 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   inline void debug_assert_valid_ptr() const
00756     {
00757 #ifdef TEUCHOS_DEBUG
00758       assert_valid_ptr();
00759 #endif
00760     }
00761 
00762 public:
00763 
00766 
00769   TEUCHOS_DEPRECATED operator ArrayView<T>() const;
00770 
00772 
00773 #ifndef DOXYGEN_COMPILE
00774   // These constructors should be private but I have not had good luck making
00775   // this portable (i.e. using friendship etc.) in the past
00776   // This is a very bad breach of encapsulation that is needed since MS VC++
00777   // 5.0 will not allow me to declare template functions as friends.
00778   ArrayRCP( T* p, size_type lowerOffset, size_type size,
00779     const RCPNodeHandle& node );
00780   T* access_private_ptr() const;
00781   RCPNodeHandle& nonconst_access_private_node();
00782   const RCPNodeHandle& access_private_node() const;
00783 #endif
00784 
00785 };  // end class ArrayRCP<...>
00786 
00787 
00797 template<>
00798 class ArrayRCP<void> {
00799 public:
00800 
00802 
00803 
00805   typedef Teuchos_Ordinal Ordinal;
00806 
00808   typedef Ordinal size_type;
00810   typedef Ordinal difference_type;
00812   typedef std::random_access_iterator_tag iterator_category;
00814   typedef  void* iterator_type;
00816   typedef  void value_type;
00818   // typedef T& reference;              // these are not valid
00820   // typedef const T& const_reference;  // these are not valid
00822   typedef void* pointer;
00824   typedef void* const_pointer;
00826   typedef void  element_type;
00827 
00830   inline ArrayRCP( );
00831 
00833 
00834 };  // end class ArrayRCP<void>
00835 
00840 template<>
00841 class ArrayRCP<const void> {
00842 public:
00843 
00845 
00846 
00848   typedef Teuchos_Ordinal Ordinal;
00849 
00851   typedef Ordinal size_type;
00853   typedef Ordinal difference_type;
00855   typedef std::random_access_iterator_tag iterator_category;
00857   typedef  const void* iterator_type;
00859   typedef  const void value_type;
00861   // typedef T& reference;              // these are not valid
00863   // typedef const T& const_reference;  // these are not valid
00865   typedef const void* pointer;
00867   typedef const void* const_pointer;
00869   typedef const void  element_type;
00870 
00873   inline ArrayRCP( );
00874 
00876 
00877 };  // end class ArrayRCP<void>
00878 
00879 // 2008/09/22: rabartl: NOTE: I removed the TypeNameTraits<ArrayRCP<T> >
00880 // specialization since I want to be able to print the type name of an
00881 // ArrayRCP that does not have the type T fully defined!
00882 
00883 
00888 template<typename T>
00889 class NullIteratorTraits<ArrayRCP<T> > {
00890 public:
00891   static ArrayRCP<T> getNull() { return null; }
00892 };
00893 
00894 
00900 template<class T>
00901 ArrayRCP<T> arcp(
00902   T* p,
00903   typename ArrayRCP<T>::size_type lowerOffset,
00904   typename ArrayRCP<T>::size_type size,
00905   bool owns_mem = true
00906   );
00907 
00908 
00914 template<class T, class Dealloc_T>
00915 ArrayRCP<T> arcp(
00916   T* p,
00917   typename ArrayRCP<T>::size_type lowerOffset,
00918   typename ArrayRCP<T>::size_type size,
00919   Dealloc_T dealloc, bool owns_mem
00920   );
00921 
00922  
00933 template<class T>
00934 ArrayRCP<T> arcp( typename ArrayRCP<T>::size_type size );
00935 
00936  
00950 template<class T>
00951 ArrayRCP<T> arcpCloneNode( const ArrayRCP<T> &a );
00952 
00953  
00958 template<class T>
00959 ArrayRCP<T> arcpClone( const ArrayView<const T> &v );
00960 
00961 
00972 template<class T, class Embedded>
00973 ArrayRCP<T>
00974 arcpWithEmbeddedObjPreDestroy(
00975   T* p,
00976   typename ArrayRCP<T>::size_type lowerOffset,
00977   typename ArrayRCP<T>::size_type size,
00978   const Embedded &embedded,
00979   bool owns_mem = true
00980   );
00981 
00982 
00993 template<class T, class Embedded>
00994 ArrayRCP<T>
00995 arcpWithEmbeddedObjPostDestroy(
00996   T* p,
00997   typename ArrayRCP<T>::size_type lowerOffset,
00998   typename ArrayRCP<T>::size_type size,
00999   const Embedded &embedded,
01000   bool owns_mem = true
01001   );
01002 
01003 
01015 template<class T, class Embedded>
01016 ArrayRCP<T>
01017 arcpWithEmbeddedObj(
01018   T* p,
01019   typename ArrayRCP<T>::size_type lowerOffset,
01020   typename ArrayRCP<T>::size_type size,
01021   const Embedded &embedded,
01022   bool owns_mem = true
01023   );
01024 
01025 
01031 template<class T>
01032 ArrayRCP<T> arcp( const RCP<std::vector<T> > &v );
01033 
01034 
01040 template<class T>
01041 ArrayRCP<const T> arcp( const RCP<const std::vector<T> > &v );
01042 
01043 
01052 template<class T>
01053 ArrayRCP<T> arcpFromArrayView(const ArrayView<T> &av);
01054 
01055 
01062 template<class T>
01063 RCP<std::vector<T> > get_std_vector( const ArrayRCP<T> &ptr );
01064 
01065 
01072 template<class T>
01073 RCP<const std::vector<T> > get_std_vector( const ArrayRCP<const T> &ptr );
01074 
01075 
01080 template<class T>
01081 bool is_null( const ArrayRCP<T> &p );
01082 
01083 
01088 template<class T>
01089 bool nonnull( const ArrayRCP<T> &p );
01090 
01091 
01096 template<class T>
01097 bool operator==( const ArrayRCP<T> &p, ENull );
01098 
01099 
01104 template<class T>
01105 bool operator!=( const ArrayRCP<T> &p, ENull );
01106 
01107 
01112 template<class T1, class T2>
01113 bool operator==( const ArrayRCP<T1> &p1, const ArrayRCP<T2> &p2 );
01114 
01115 
01120 template<class T1, class T2>
01121 bool operator!=( const ArrayRCP<T1> &p1, const ArrayRCP<T2> &p2 );
01122 
01123 
01128 template<class T1, class T2>
01129 bool operator<( const ArrayRCP<T1> &p1, const ArrayRCP<T2> &p2 );
01130 
01131 
01136 template<class T1, class T2>
01137 bool operator<=( const ArrayRCP<T1> &p1, const ArrayRCP<T2> &p2 );
01138 
01139 
01144 template<class T1, class T2>
01145 bool operator>( const ArrayRCP<T1> &p1, const ArrayRCP<T2> &p2 );
01146 
01147 
01152 template<class T1, class T2>
01153 bool operator>=( const ArrayRCP<T1> &p1, const ArrayRCP<T2> &p2 );
01154 
01155 
01160 template<class T>
01161 typename ArrayRCP<T>::difference_type
01162 operator-( const ArrayRCP<T> &p1, const ArrayRCP<T> &p2 );
01163 
01164 
01173 template<class T2, class T1>
01174 inline
01175 ArrayRCP<T2> arcp_const_cast(const ArrayRCP<T1>& p1);
01176 
01177 
01190 template<class T2, class T1>
01191 ArrayRCP<T2> arcp_reinterpret_cast(const ArrayRCP<T1>& p1);
01192 
01193 
01212 template<class T2, class T1>
01213 ArrayRCP<T2> arcp_reinterpret_cast_nonpod(const ArrayRCP<T1>& p1, const T2& val=T2());
01214 
01215 
01241 template<class T2, class T1>
01242 inline
01243 ArrayRCP<T2> arcp_implicit_cast(const ArrayRCP<T1>& p1);
01244 
01245 
01304 template<class T1, class T2>
01305 void set_extra_data(
01306   const T1 &extra_data, const std::string& name,
01307   const Ptr<ArrayRCP<T2> > &p, EPrePostDestruction destroy_when = POST_DESTROY,
01308   bool force_unique = true );
01309 
01310 
01330 template<class T1, class T2>
01331 T1& get_extra_data( ArrayRCP<T2>& p, const std::string& name );
01332 
01333 
01359 template<class T1, class T2>
01360 const T1& get_extra_data( const ArrayRCP<T2>& p, const std::string& name );
01361 
01362 
01387 template<class T1, class T2>
01388 T1* get_optional_extra_data( ArrayRCP<T2>& p, const std::string& name );
01389 
01390 
01420 template<class T1, class T2>
01421 const T1* get_optional_extra_data( const ArrayRCP<T2>& p, const std::string& name );
01422 
01423 
01434 template<class Dealloc_T, class T>
01435 Dealloc_T& get_nonconst_dealloc( const ArrayRCP<T>& p );
01436 
01437 
01455 template<class Dealloc_T, class T>
01456 const Dealloc_T& get_dealloc( const ArrayRCP<T>& p );
01457 
01458 
01473 template<class Dealloc_T, class T>
01474 const Dealloc_T* get_optional_dealloc( const ArrayRCP<T>& p );
01475 
01476 
01498 template<class Dealloc_T, class T>
01499 Dealloc_T* get_optional_nonconst_dealloc( const ArrayRCP<T>& p );
01500 
01501 
01508 template<class TOrig, class Embedded, class T>
01509 const Embedded& getEmbeddedObj( const ArrayRCP<T>& p );
01510 
01511 
01518 template<class TOrig, class Embedded, class T>
01519 Embedded& getNonconstEmbeddedObj( const ArrayRCP<T>& p );
01520 
01521 
01529 template<class T>
01530 std::ostream& operator<<( std::ostream& out, const ArrayRCP<T>& p );
01531 
01532 
01533 } // end namespace Teuchos
01534 
01535 
01536 #endif  // TEUCHOS_ARRAY_RCP_DECL_HPP
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines