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 // Redistribution and use in source and binary forms, with or without
00011 // modification, are permitted provided that the following conditions are
00012 // met:
00013 //
00014 // 1. Redistributions of source code must retain the above copyright
00015 // notice, this list of conditions and the following disclaimer.
00016 //
00017 // 2. Redistributions in binary form must reproduce the above copyright
00018 // notice, this list of conditions and the following disclaimer in the
00019 // documentation and/or other materials provided with the distribution.
00020 //
00021 // 3. Neither the name of the Corporation nor the names of the
00022 // contributors may be used to endorse or promote products derived from
00023 // this software without specific prior written permission.
00024 //
00025 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
00026 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00027 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
00028 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
00029 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00030 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00031 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00032 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00033 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00034 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00035 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00036 //
00037 // Questions? Contact Michael A. Heroux (maherou@sandia.gov)
00038 //
00039 // ***********************************************************************
00040 // @HEADER
00041 
00042 
00043 #ifndef TEUCHOS_ARRAY_RCP_DECL_HPP
00044 #define TEUCHOS_ARRAY_RCP_DECL_HPP
00045 
00046 
00047 #include "Teuchos_RCP.hpp"
00048 #include "Teuchos_Exceptions.hpp"
00049 #include "Teuchos_ArrayViewDecl.hpp"
00050 
00051 
00052 namespace Teuchos {
00053 
00084 template<class T>
00085 class ArrayRCP {
00086 public:
00087 
00089 
00090 
00092   typedef Teuchos_Ordinal Ordinal;
00093 
00095   typedef Ordinal size_type;
00097   typedef Ordinal difference_type;
00099   typedef std::random_access_iterator_tag iterator_category;
00101   typedef  T* iterator_type;
00103   typedef  T value_type;
00105   typedef T& reference; 
00107   typedef const T& const_reference; 
00109   typedef T* pointer;
00111   typedef T* const_pointer;
00113   typedef T  element_type;
00114 
00115 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK
00116 
00117   typedef ArrayRCP<T> iterator;
00119   typedef ArrayRCP<const T> const_iterator;
00120 #else
00121   typedef T* iterator;
00122   typedef const T* const_iterator;
00123 #endif
00124 
00126 
00128 
00129 
00142   inline ArrayRCP( ENull null_arg = null );
00143 
00156   inline ArrayRCP( T* p, size_type lowerOffset, size_type size,
00157     bool has_ownership, const ERCPNodeLookup rcpNodeLookup = RCP_ENABLE_NODE_LOOKUP );
00158 
00171   template<class Dealloc_T>
00172   inline ArrayRCP( T* p, size_type lowerOffset, size_type size, Dealloc_T dealloc,
00173     bool has_ownership );
00174 
00183   inline explicit ArrayRCP( size_type size, const T& val = T() );
00184 
00202   inline ArrayRCP(const ArrayRCP<T>& r_ptr);
00203 
00216   inline ~ArrayRCP();
00217 
00235   inline ArrayRCP<T>& operator=(const ArrayRCP<T>& r_ptr);
00236 
00238 
00240 
00241 
00243   inline bool is_null() const;
00244 
00254   inline T* operator->() const;
00255 
00265   inline T& operator*() const;
00266 
00274   inline T* get() const;
00275 
00283   inline T* getRawPtr() const;
00284 
00292   inline T& operator[](size_type offset) const;
00293 
00295 
00297 
00298 
00309   inline ArrayRCP<T>& operator++();
00310 
00321   inline ArrayRCP<T> operator++(int);
00322 
00333   inline ArrayRCP<T>& operator--();
00334 
00345   inline ArrayRCP<T> operator--(int);
00346 
00357   inline ArrayRCP<T>& operator+=(size_type offset);
00358 
00369   inline ArrayRCP<T>& operator-=(size_type offset);
00370 
00385   inline ArrayRCP<T> operator+(size_type offset) const;
00386 
00401   inline ArrayRCP<T> operator-(size_type offset) const;
00402 
00404 
00406 
00407 
00420   inline iterator begin() const;
00421 
00434   inline iterator end() const;
00435 
00437 
00439 
00440 
00446   inline ArrayRCP<const T> getConst() const;
00447 
00465   inline ArrayRCP<T> persistingView( size_type lowerOffset, size_type size ) const;
00466 
00468 
00470 
00471 
00473   inline size_type lowerOffset() const;
00474 
00476   inline size_type upperOffset() const;
00477 
00481   inline size_type size() const;
00482 
00484 
00486 
00487 
00505   inline ArrayView<T> view( size_type lowerOffset, size_type size ) const;
00506 
00510   inline ArrayView<T> operator()( size_type lowerOffset, size_type size ) const;
00511 
00516   inline ArrayView<T> operator()() const;
00517 
00519 
00521 
00522 
00524   inline operator ArrayRCP<const T>() const;
00525 
00527 
00529 
00530 
00535   inline void assign(size_type n, const T &val);
00536 
00544   template<class Iter>
00545   inline void assign(Iter first, Iter last);
00546 
00552   inline void deepCopy(const ArrayView<const T>& av);
00553 
00557   inline void resize(const size_type n, const T &val = T());
00558 
00563   inline void clear();
00564 
00566 
00568 
00569 
00581   inline ERCPStrength strength() const;
00582 
00592   inline bool is_valid_ptr() const;
00593 
00599   inline int strong_count() const;
00600 
00606   inline int weak_count() const;
00607 
00609   inline int total_count() const;
00610 
00628   inline void set_has_ownership();
00629 
00641   inline bool has_ownership() const;
00642 
00663   inline T* release();
00664 
00681   inline ArrayRCP<T> create_weak() const;
00682 
00699   inline ArrayRCP<T> create_strong() const;
00700 
00707   template<class T2>
00708   inline bool shares_resource(const ArrayRCP<T2>& r_ptr) const;
00709 
00711 
00713 
00714 
00718   inline const ArrayRCP<T>& assert_not_null() const;
00719 
00725   inline const ArrayRCP<T>& assert_in_range( size_type lowerOffset, size_type size ) const;
00726 
00736   inline const ArrayRCP<T>& assert_valid_ptr() const;
00737 
00739 
00742 
00744   inline int count() const;
00745 
00747 
00748 private:
00749 
00750   // //////////////////////////////////////////////////////////////
00751   // Private data members
00752 
00753   T *ptr_; // NULL if this pointer is null
00754   RCPNodeHandle node_; // NULL if this pointer is null
00755   size_type lowerOffset_; // 0 if this pointer is null
00756   size_type upperOffset_; // -1 if this pointer is null
00757 
00758   inline void debug_assert_not_null() const
00759     {
00760 #ifdef TEUCHOS_REFCOUNTPTR_ASSERT_NONNULL
00761       assert_not_null();
00762 #endif
00763     }
00764 
00765   inline void debug_assert_in_range( size_type lowerOffset_in,
00766     size_type size_in ) const
00767     {
00768       (void)lowerOffset_in; (void)size_in;
00769 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK
00770       assert_in_range(lowerOffset_in, size_in);
00771 #endif
00772     }
00773 
00774   inline void debug_assert_valid_ptr() const
00775     {
00776 #ifdef TEUCHOS_DEBUG
00777       assert_valid_ptr();
00778 #endif
00779     }
00780 
00781 public:
00782 
00785 
00788   TEUCHOS_DEPRECATED operator ArrayView<T>() const;
00789 
00791 
00792 #ifndef DOXYGEN_COMPILE
00793   // These constructors should be private but I have not had good luck making
00794   // this portable (i.e. using friendship etc.) in the past
00795   // This is a very bad breach of encapsulation that is needed since MS VC++
00796   // 5.0 will not allow me to declare template functions as friends.
00797   ArrayRCP( T* p, size_type lowerOffset, size_type size,
00798     const RCPNodeHandle& node );
00799   T* access_private_ptr() const;
00800   RCPNodeHandle& nonconst_access_private_node();
00801   const RCPNodeHandle& access_private_node() const;
00802 #endif
00803 
00804 };  // end class ArrayRCP<...>
00805 
00806 
00816 template<>
00817 class ArrayRCP<void> {
00818 public:
00819 
00821 
00822 
00824   typedef Teuchos_Ordinal Ordinal;
00825 
00827   typedef Ordinal size_type;
00829   typedef Ordinal difference_type;
00831   typedef std::random_access_iterator_tag iterator_category;
00833   typedef  void* iterator_type;
00835   typedef  void value_type;
00837   // typedef T& reference;              // these are not valid
00839   // typedef const T& const_reference;  // these are not valid
00841   typedef void* pointer;
00843   typedef void* const_pointer;
00845   typedef void  element_type;
00846 
00849   inline ArrayRCP( );
00850 
00852 
00853 };  // end class ArrayRCP<void>
00854 
00859 template<>
00860 class ArrayRCP<const void> {
00861 public:
00862 
00864 
00865 
00867   typedef Teuchos_Ordinal Ordinal;
00868 
00870   typedef Ordinal size_type;
00872   typedef Ordinal difference_type;
00874   typedef std::random_access_iterator_tag iterator_category;
00876   typedef  const void* iterator_type;
00878   typedef  const void value_type;
00880   // typedef T& reference;              // these are not valid
00882   // typedef const T& const_reference;  // these are not valid
00884   typedef const void* pointer;
00886   typedef const void* const_pointer;
00888   typedef const void  element_type;
00889 
00892   inline ArrayRCP( );
00893 
00895 
00896 };  // end class ArrayRCP<void>
00897 
00898 // 2008/09/22: rabartl: NOTE: I removed the TypeNameTraits<ArrayRCP<T> >
00899 // specialization since I want to be able to print the type name of an
00900 // ArrayRCP that does not have the type T fully defined!
00901 
00902 
00907 template<typename T>
00908 class NullIteratorTraits<ArrayRCP<T> > {
00909 public:
00910   static ArrayRCP<T> getNull() { return null; }
00911 };
00912 
00913 
00919 template<class T>
00920 ArrayRCP<T> arcp(
00921   T* p,
00922   typename ArrayRCP<T>::size_type lowerOffset,
00923   typename ArrayRCP<T>::size_type size,
00924   bool owns_mem = true
00925   );
00926 
00927 
00933 template<class T, class Dealloc_T>
00934 ArrayRCP<T> arcp(
00935   T* p,
00936   typename ArrayRCP<T>::size_type lowerOffset,
00937   typename ArrayRCP<T>::size_type size,
00938   Dealloc_T dealloc, bool owns_mem
00939   );
00940 
00941  
00952 template<class T>
00953 ArrayRCP<T> arcp( typename ArrayRCP<T>::size_type size );
00954 
00955  
00969 template<class T>
00970 ArrayRCP<T> arcpCloneNode( const ArrayRCP<T> &a );
00971 
00972  
00977 template<class T>
00978 ArrayRCP<T> arcpClone( const ArrayView<const T> &v );
00979 
00980 
00991 template<class T, class Embedded>
00992 ArrayRCP<T>
00993 arcpWithEmbeddedObjPreDestroy(
00994   T* p,
00995   typename ArrayRCP<T>::size_type lowerOffset,
00996   typename ArrayRCP<T>::size_type size,
00997   const Embedded &embedded,
00998   bool owns_mem = true
00999   );
01000 
01001 
01012 template<class T, class Embedded>
01013 ArrayRCP<T>
01014 arcpWithEmbeddedObjPostDestroy(
01015   T* p,
01016   typename ArrayRCP<T>::size_type lowerOffset,
01017   typename ArrayRCP<T>::size_type size,
01018   const Embedded &embedded,
01019   bool owns_mem = true
01020   );
01021 
01022 
01034 template<class T, class Embedded>
01035 ArrayRCP<T>
01036 arcpWithEmbeddedObj(
01037   T* p,
01038   typename ArrayRCP<T>::size_type lowerOffset,
01039   typename ArrayRCP<T>::size_type size,
01040   const Embedded &embedded,
01041   bool owns_mem = true
01042   );
01043 
01044 
01050 template<class T>
01051 ArrayRCP<T> arcp( const RCP<std::vector<T> > &v );
01052 
01053 
01059 template<class T>
01060 ArrayRCP<const T> arcp( const RCP<const std::vector<T> > &v );
01061 
01062 
01071 template<class T>
01072 ArrayRCP<T> arcpFromArrayView(const ArrayView<T> &av);
01073 
01074 
01081 template<class T>
01082 RCP<std::vector<T> > get_std_vector( const ArrayRCP<T> &ptr );
01083 
01084 
01091 template<class T>
01092 RCP<const std::vector<T> > get_std_vector( const ArrayRCP<const T> &ptr );
01093 
01094 
01099 template<class T>
01100 bool is_null( const ArrayRCP<T> &p );
01101 
01102 
01107 template<class T>
01108 bool nonnull( const ArrayRCP<T> &p );
01109 
01110 
01115 template<class T>
01116 bool operator==( const ArrayRCP<T> &p, ENull );
01117 
01118 
01123 template<class T>
01124 bool operator!=( const ArrayRCP<T> &p, ENull );
01125 
01126 
01131 template<class T1, class T2>
01132 bool operator==( const ArrayRCP<T1> &p1, const ArrayRCP<T2> &p2 );
01133 
01134 
01139 template<class T1, class T2>
01140 bool operator!=( const ArrayRCP<T1> &p1, const ArrayRCP<T2> &p2 );
01141 
01142 
01147 template<class T1, class T2>
01148 bool operator<( const ArrayRCP<T1> &p1, const ArrayRCP<T2> &p2 );
01149 
01150 
01155 template<class T1, class T2>
01156 bool operator<=( const ArrayRCP<T1> &p1, const ArrayRCP<T2> &p2 );
01157 
01158 
01163 template<class T1, class T2>
01164 bool operator>( const ArrayRCP<T1> &p1, const ArrayRCP<T2> &p2 );
01165 
01166 
01171 template<class T1, class T2>
01172 bool operator>=( const ArrayRCP<T1> &p1, const ArrayRCP<T2> &p2 );
01173 
01174 
01179 template<class T>
01180 typename ArrayRCP<T>::difference_type
01181 operator-( const ArrayRCP<T> &p1, const ArrayRCP<T> &p2 );
01182 
01183 
01192 template<class T2, class T1>
01193 inline
01194 ArrayRCP<T2> arcp_const_cast(const ArrayRCP<T1>& p1);
01195 
01196 
01209 template<class T2, class T1>
01210 ArrayRCP<T2> arcp_reinterpret_cast(const ArrayRCP<T1>& p1);
01211 
01212 
01231 template<class T2, class T1>
01232 ArrayRCP<T2> arcp_reinterpret_cast_nonpod(const ArrayRCP<T1>& p1, const T2& val=T2());
01233 
01234 
01260 template<class T2, class T1>
01261 inline
01262 ArrayRCP<T2> arcp_implicit_cast(const ArrayRCP<T1>& p1);
01263 
01264 
01323 template<class T1, class T2>
01324 void set_extra_data(
01325   const T1 &extra_data, const std::string& name,
01326   const Ptr<ArrayRCP<T2> > &p, EPrePostDestruction destroy_when = POST_DESTROY,
01327   bool force_unique = true );
01328 
01329 
01349 template<class T1, class T2>
01350 T1& get_extra_data( ArrayRCP<T2>& p, const std::string& name );
01351 
01352 
01378 template<class T1, class T2>
01379 const T1& get_extra_data( const ArrayRCP<T2>& p, const std::string& name );
01380 
01381 
01406 template<class T1, class T2>
01407 T1* get_optional_extra_data( ArrayRCP<T2>& p, const std::string& name );
01408 
01409 
01439 template<class T1, class T2>
01440 const T1* get_optional_extra_data( const ArrayRCP<T2>& p, const std::string& name );
01441 
01442 
01453 template<class Dealloc_T, class T>
01454 Dealloc_T& get_nonconst_dealloc( const ArrayRCP<T>& p );
01455 
01456 
01474 template<class Dealloc_T, class T>
01475 const Dealloc_T& get_dealloc( const ArrayRCP<T>& p );
01476 
01477 
01492 template<class Dealloc_T, class T>
01493 const Dealloc_T* get_optional_dealloc( const ArrayRCP<T>& p );
01494 
01495 
01517 template<class Dealloc_T, class T>
01518 Dealloc_T* get_optional_nonconst_dealloc( const ArrayRCP<T>& p );
01519 
01520 
01527 template<class TOrig, class Embedded, class T>
01528 const Embedded& getEmbeddedObj( const ArrayRCP<T>& p );
01529 
01530 
01537 template<class TOrig, class Embedded, class T>
01538 Embedded& getNonconstEmbeddedObj( const ArrayRCP<T>& p );
01539 
01540 
01548 template<class T>
01549 std::ostream& operator<<( std::ostream& out, const ArrayRCP<T>& p );
01550 
01551 
01552 } // end namespace Teuchos
01553 
01554 
01555 #endif  // TEUCHOS_ARRAY_RCP_DECL_HPP
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines