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 
00462   inline ArrayRCP<T> persistingView( size_type lowerOffset, size_type size ) const;
00463 
00465 
00467 
00468 
00470   inline size_type lowerOffset() const;
00471 
00473   inline size_type upperOffset() const;
00474 
00478   inline size_type size() const;
00479 
00481 
00483 
00484 
00499   inline ArrayView<T> view( size_type lowerOffset, size_type size ) const;
00500 
00504   inline ArrayView<T> operator()( size_type lowerOffset, size_type size ) const;
00505 
00510   inline ArrayView<T> operator()() const;
00511 
00513 
00515 
00516 
00518   inline operator ArrayRCP<const T>() const;
00519 
00521 
00523 
00524 
00529   inline void assign(size_type n, const T &val);
00530 
00538   template<class Iter>
00539   inline void assign(Iter first, Iter last);
00540 
00546   inline void deepCopy(const ArrayView<const T>& av);
00547 
00551   inline void resize(const size_type n, const T &val = T());
00552 
00557   inline void clear();
00558 
00560 
00562 
00563 
00575   inline ERCPStrength strength() const;
00576 
00586   inline bool is_valid_ptr() const;
00587 
00593   inline int strong_count() const;
00594 
00600   inline int weak_count() const;
00601 
00603   inline int total_count() const;
00604 
00622   inline void set_has_ownership();
00623 
00635   inline bool has_ownership() const;
00636 
00657   inline T* release();
00658 
00675   inline ArrayRCP<T> create_weak() const;
00676 
00693   inline ArrayRCP<T> create_strong() const;
00694 
00701   template<class T2>
00702   inline bool shares_resource(const ArrayRCP<T2>& r_ptr) const;
00703 
00705 
00707 
00708 
00712   inline const ArrayRCP<T>& assert_not_null() const;
00713 
00719   inline const ArrayRCP<T>& assert_in_range( size_type lowerOffset, size_type size ) const;
00720 
00730   inline const ArrayRCP<T>& assert_valid_ptr() const;
00731 
00733 
00736 
00738   inline int count() const;
00739 
00741 
00742 private:
00743 
00744   // //////////////////////////////////////////////////////////////
00745   // Private data members
00746 
00747   T *ptr_; // NULL if this pointer is null
00748   RCPNodeHandle node_; // NULL if this pointer is null
00749   size_type lowerOffset_; // 0 if this pointer is null
00750   size_type upperOffset_; // -1 if this pointer is null
00751 
00752   inline void debug_assert_not_null() const
00753     {
00754 #ifdef TEUCHOS_REFCOUNTPTR_ASSERT_NONNULL
00755       assert_not_null();
00756 #endif
00757     }
00758 
00759   inline void debug_assert_in_range( size_type lowerOffset_in,
00760     size_type size_in ) const
00761     {
00762       (void)lowerOffset_in; (void)size_in;
00763 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK
00764       assert_in_range(lowerOffset_in, size_in);
00765 #endif
00766     }
00767 
00768   inline void debug_assert_valid_ptr() const
00769     {
00770 #ifdef TEUCHOS_DEBUG
00771       assert_valid_ptr();
00772 #endif
00773     }
00774 
00775 public:
00776 
00779 
00782   TEUCHOS_DEPRECATED operator ArrayView<T>() const;
00783 
00785 
00786 #ifndef DOXYGEN_COMPILE
00787   // These constructors should be private but I have not had good luck making
00788   // this portable (i.e. using friendship etc.) in the past
00789   // This is a very bad breach of encapsulation that is needed since MS VC++
00790   // 5.0 will not allow me to declare template functions as friends.
00791   ArrayRCP( T* p, size_type lowerOffset, size_type size,
00792     const RCPNodeHandle& node );
00793   T* access_private_ptr() const;
00794   RCPNodeHandle& nonconst_access_private_node();
00795   const RCPNodeHandle& access_private_node() const;
00796 #endif
00797 
00798 };  // end class ArrayRCP<...>
00799 
00800 
00810 template<>
00811 class ArrayRCP<void> {
00812 public:
00813 
00815 
00816 
00818   typedef Teuchos_Ordinal Ordinal;
00819 
00821   typedef Ordinal size_type;
00823   typedef Ordinal difference_type;
00825   typedef std::random_access_iterator_tag iterator_category;
00827   typedef  void* iterator_type;
00829   typedef  void value_type;
00831   // typedef T& reference;              // these are not valid
00833   // typedef const T& const_reference;  // these are not valid
00835   typedef void* pointer;
00837   typedef void* const_pointer;
00839   typedef void  element_type;
00840 
00843   inline ArrayRCP( );
00844 
00846 
00847 };  // end class ArrayRCP<void>
00848 
00853 template<>
00854 class ArrayRCP<const void> {
00855 public:
00856 
00858 
00859 
00861   typedef Teuchos_Ordinal Ordinal;
00862 
00864   typedef Ordinal size_type;
00866   typedef Ordinal difference_type;
00868   typedef std::random_access_iterator_tag iterator_category;
00870   typedef  const void* iterator_type;
00872   typedef  const void value_type;
00874   // typedef T& reference;              // these are not valid
00876   // typedef const T& const_reference;  // these are not valid
00878   typedef const void* pointer;
00880   typedef const void* const_pointer;
00882   typedef const void  element_type;
00883 
00886   inline ArrayRCP( );
00887 
00889 
00890 };  // end class ArrayRCP<void>
00891 
00892 // 2008/09/22: rabartl: NOTE: I removed the TypeNameTraits<ArrayRCP<T> >
00893 // specialization since I want to be able to print the type name of an
00894 // ArrayRCP that does not have the type T fully defined!
00895 
00896 
00901 template<typename T>
00902 class NullIteratorTraits<ArrayRCP<T> > {
00903 public:
00904   static ArrayRCP<T> getNull() { return null; }
00905 };
00906 
00907 
00913 template<class T>
00914 ArrayRCP<T> arcp(
00915   T* p,
00916   typename ArrayRCP<T>::size_type lowerOffset,
00917   typename ArrayRCP<T>::size_type size,
00918   bool owns_mem = true
00919   );
00920 
00921 
00927 template<class T, class Dealloc_T>
00928 ArrayRCP<T> arcp(
00929   T* p,
00930   typename ArrayRCP<T>::size_type lowerOffset,
00931   typename ArrayRCP<T>::size_type size,
00932   Dealloc_T dealloc, bool owns_mem
00933   );
00934 
00935  
00946 template<class T>
00947 ArrayRCP<T> arcp( typename ArrayRCP<T>::size_type size );
00948 
00949  
00963 template<class T>
00964 ArrayRCP<T> arcpCloneNode( const ArrayRCP<T> &a );
00965 
00966  
00971 template<class T>
00972 ArrayRCP<T> arcpClone( const ArrayView<const T> &v );
00973 
00974 
00985 template<class T, class Embedded>
00986 ArrayRCP<T>
00987 arcpWithEmbeddedObjPreDestroy(
00988   T* p,
00989   typename ArrayRCP<T>::size_type lowerOffset,
00990   typename ArrayRCP<T>::size_type size,
00991   const Embedded &embedded,
00992   bool owns_mem = true
00993   );
00994 
00995 
01006 template<class T, class Embedded>
01007 ArrayRCP<T>
01008 arcpWithEmbeddedObjPostDestroy(
01009   T* p,
01010   typename ArrayRCP<T>::size_type lowerOffset,
01011   typename ArrayRCP<T>::size_type size,
01012   const Embedded &embedded,
01013   bool owns_mem = true
01014   );
01015 
01016 
01028 template<class T, class Embedded>
01029 ArrayRCP<T>
01030 arcpWithEmbeddedObj(
01031   T* p,
01032   typename ArrayRCP<T>::size_type lowerOffset,
01033   typename ArrayRCP<T>::size_type size,
01034   const Embedded &embedded,
01035   bool owns_mem = true
01036   );
01037 
01038 
01044 template<class T>
01045 ArrayRCP<T> arcp( const RCP<std::vector<T> > &v );
01046 
01047 
01053 template<class T>
01054 ArrayRCP<const T> arcp( const RCP<const std::vector<T> > &v );
01055 
01056 
01065 template<class T>
01066 ArrayRCP<T> arcpFromArrayView(const ArrayView<T> &av);
01067 
01068 
01075 template<class T>
01076 RCP<std::vector<T> > get_std_vector( const ArrayRCP<T> &ptr );
01077 
01078 
01085 template<class T>
01086 RCP<const std::vector<T> > get_std_vector( const ArrayRCP<const T> &ptr );
01087 
01088 
01093 template<class T>
01094 bool is_null( const ArrayRCP<T> &p );
01095 
01096 
01101 template<class T>
01102 bool nonnull( const ArrayRCP<T> &p );
01103 
01104 
01109 template<class T>
01110 bool operator==( const ArrayRCP<T> &p, ENull );
01111 
01112 
01117 template<class T>
01118 bool operator!=( const ArrayRCP<T> &p, ENull );
01119 
01120 
01125 template<class T1, class T2>
01126 bool operator==( const ArrayRCP<T1> &p1, const ArrayRCP<T2> &p2 );
01127 
01128 
01133 template<class T1, class T2>
01134 bool operator!=( const ArrayRCP<T1> &p1, const ArrayRCP<T2> &p2 );
01135 
01136 
01141 template<class T1, class T2>
01142 bool operator<( const ArrayRCP<T1> &p1, const ArrayRCP<T2> &p2 );
01143 
01144 
01149 template<class T1, class T2>
01150 bool operator<=( const ArrayRCP<T1> &p1, const ArrayRCP<T2> &p2 );
01151 
01152 
01157 template<class T1, class T2>
01158 bool operator>( const ArrayRCP<T1> &p1, const ArrayRCP<T2> &p2 );
01159 
01160 
01165 template<class T1, class T2>
01166 bool operator>=( const ArrayRCP<T1> &p1, const ArrayRCP<T2> &p2 );
01167 
01168 
01173 template<class T>
01174 typename ArrayRCP<T>::difference_type
01175 operator-( const ArrayRCP<T> &p1, const ArrayRCP<T> &p2 );
01176 
01177 
01186 template<class T2, class T1>
01187 inline
01188 ArrayRCP<T2> arcp_const_cast(const ArrayRCP<T1>& p1);
01189 
01190 
01203 template<class T2, class T1>
01204 ArrayRCP<T2> arcp_reinterpret_cast(const ArrayRCP<T1>& p1);
01205 
01206 
01225 template<class T2, class T1>
01226 ArrayRCP<T2> arcp_reinterpret_cast_nonpod(const ArrayRCP<T1>& p1, const T2& val=T2());
01227 
01228 
01254 template<class T2, class T1>
01255 inline
01256 ArrayRCP<T2> arcp_implicit_cast(const ArrayRCP<T1>& p1);
01257 
01258 
01317 template<class T1, class T2>
01318 void set_extra_data(
01319   const T1 &extra_data, const std::string& name,
01320   const Ptr<ArrayRCP<T2> > &p, EPrePostDestruction destroy_when = POST_DESTROY,
01321   bool force_unique = true );
01322 
01323 
01343 template<class T1, class T2>
01344 T1& get_extra_data( ArrayRCP<T2>& p, const std::string& name );
01345 
01346 
01372 template<class T1, class T2>
01373 const T1& get_extra_data( const ArrayRCP<T2>& p, const std::string& name );
01374 
01375 
01400 template<class T1, class T2>
01401 T1* get_optional_extra_data( ArrayRCP<T2>& p, const std::string& name );
01402 
01403 
01433 template<class T1, class T2>
01434 const T1* get_optional_extra_data( const ArrayRCP<T2>& p, const std::string& name );
01435 
01436 
01447 template<class Dealloc_T, class T>
01448 Dealloc_T& get_nonconst_dealloc( const ArrayRCP<T>& p );
01449 
01450 
01468 template<class Dealloc_T, class T>
01469 const Dealloc_T& get_dealloc( const ArrayRCP<T>& p );
01470 
01471 
01486 template<class Dealloc_T, class T>
01487 const Dealloc_T* get_optional_dealloc( const ArrayRCP<T>& p );
01488 
01489 
01511 template<class Dealloc_T, class T>
01512 Dealloc_T* get_optional_nonconst_dealloc( const ArrayRCP<T>& p );
01513 
01514 
01521 template<class TOrig, class Embedded, class T>
01522 const Embedded& getEmbeddedObj( const ArrayRCP<T>& p );
01523 
01524 
01531 template<class TOrig, class Embedded, class T>
01532 Embedded& getNonconstEmbeddedObj( const ArrayRCP<T>& p );
01533 
01534 
01542 template<class T>
01543 std::ostream& operator<<( std::ostream& out, const ArrayRCP<T>& p );
01544 
01545 
01546 } // end namespace Teuchos
01547 
01548 
01549 #endif  // TEUCHOS_ARRAY_RCP_DECL_HPP
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines