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 
00041 
00072 template<class T>
00073 class ArrayRCP {
00074 public:
00075 
00077 
00078 
00080   typedef Teuchos_Ordinal Ordinal;
00081 
00083   typedef Ordinal size_type;
00085   typedef Ordinal difference_type;
00087   typedef std::random_access_iterator_tag iterator_category;
00089   typedef  T* iterator_type;
00091   typedef  T value_type;
00093   typedef T& reference; 
00095   typedef const T& const_reference; 
00097   typedef T* pointer;
00099   typedef T* const_pointer;
00101   typedef T  element_type;
00102 
00103 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK
00104 
00105   typedef ArrayRCP<T> iterator;
00107   typedef ArrayRCP<const T> const_iterator;
00108 #else
00109   typedef T* iterator;
00110   typedef const T* const_iterator;
00111 #endif
00112 
00114 
00116 
00117 
00130   inline ArrayRCP( ENull null_arg = null );
00131 
00144   inline ArrayRCP( T* p, size_type lowerOffset, size_type size,
00145     bool has_ownership, const ERCPNodeLookup rcpNodeLookup = RCP_ENABLE_NODE_LOOKUP );
00146 
00159   template<class Dealloc_T>
00160   inline ArrayRCP( T* p, size_type lowerOffset, size_type size, Dealloc_T dealloc,
00161     bool has_ownership );
00162 
00171   inline explicit ArrayRCP( size_type size, const T& val = T() );
00172 
00190   inline ArrayRCP(const ArrayRCP<T>& r_ptr);
00191 
00204   inline ~ArrayRCP();
00205 
00223   inline ArrayRCP<T>& operator=(const ArrayRCP<T>& r_ptr);
00224 
00226 
00228 
00229 
00231   inline bool is_null() const;
00232 
00242   inline T* operator->() const;
00243 
00253   inline T& operator*() const;
00254 
00262   inline T* get() const;
00263 
00271   inline T* getRawPtr() const;
00272 
00280   inline T& operator[](size_type offset) const;
00281 
00283 
00285 
00286 
00297   inline ArrayRCP<T>& operator++();
00298 
00309   inline ArrayRCP<T> operator++(int);
00310 
00321   inline ArrayRCP<T>& operator--();
00322 
00333   inline ArrayRCP<T> operator--(int);
00334 
00345   inline ArrayRCP<T>& operator+=(size_type offset);
00346 
00357   inline ArrayRCP<T>& operator-=(size_type offset);
00358 
00373   inline ArrayRCP<T> operator+(size_type offset) const;
00374 
00389   inline ArrayRCP<T> operator-(size_type offset) const;
00390 
00392 
00394 
00395 
00408   inline iterator begin() const;
00409 
00422   inline iterator end() const;
00423 
00425 
00427 
00428 
00434   inline ArrayRCP<const T> getConst() const;
00435 
00450   inline ArrayRCP<T> persistingView( size_type lowerOffset, size_type size ) const;
00451 
00453 
00455 
00456 
00458   inline size_type lowerOffset() const;
00459 
00461   inline size_type upperOffset() const;
00462 
00466   inline size_type size() const;
00467 
00469 
00471 
00472 
00487   inline ArrayView<T> view( size_type lowerOffset, size_type size ) const;
00488 
00492   inline ArrayView<T> operator()( size_type lowerOffset, size_type size ) const;
00493 
00498   inline ArrayView<T> operator()() const;
00499 
00501 
00503 
00504 
00506   inline operator ArrayRCP<const T>() const;
00507 
00509 
00511 
00512 
00517   inline void assign(size_type n, const T &val);
00518 
00526   template<class Iter>
00527   inline void assign(Iter first, Iter last);
00528 
00534   inline void deepCopy(const ArrayView<const T>& av);
00535 
00539   inline void resize(const size_type n, const T &val = T());
00540 
00545   inline void clear();
00546 
00548 
00550 
00551 
00563   inline ERCPStrength strength() const;
00564 
00574   inline bool is_valid_ptr() const;
00575 
00581   inline int strong_count() const;
00582 
00588   inline int weak_count() const;
00589 
00591   inline int total_count() const;
00592 
00610   inline void set_has_ownership();
00611 
00623   inline bool has_ownership() const;
00624 
00645   inline T* release();
00646 
00663   inline ArrayRCP<T> create_weak() const;
00664 
00681   inline ArrayRCP<T> create_strong() const;
00682 
00689   template<class T2>
00690   inline bool shares_resource(const ArrayRCP<T2>& r_ptr) const;
00691 
00693 
00695 
00696 
00700   inline const ArrayRCP<T>& assert_not_null() const;
00701 
00707   inline const ArrayRCP<T>& assert_in_range( size_type lowerOffset, size_type size ) const;
00708 
00718   inline const ArrayRCP<T>& assert_valid_ptr() const;
00719 
00721 
00724 
00726   inline 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   size_type lowerOffset_; // 0 if this pointer is null
00738   size_type upperOffset_; // -1 if this pointer is null
00739 
00740   inline void debug_assert_not_null() const
00741     {
00742 #ifdef TEUCHOS_REFCOUNTPTR_ASSERT_NONNULL
00743       assert_not_null();
00744 #endif
00745     }
00746 
00747   inline void debug_assert_in_range( size_type lowerOffset_in,
00748     size_type size_in ) const
00749     {
00750       (void)lowerOffset_in; (void)size_in;
00751 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK
00752       assert_in_range(lowerOffset_in, size_in);
00753 #endif
00754     }
00755 
00756   inline void debug_assert_valid_ptr() const
00757     {
00758 #ifdef TEUCHOS_DEBUG
00759       assert_valid_ptr();
00760 #endif
00761     }
00762 
00763 public:
00764 
00767 
00770   TEUCHOS_DEPRECATED operator ArrayView<T>() const;
00771 
00773 
00774 #ifndef DOXYGEN_COMPILE
00775   // These constructors should be private but I have not had good luck making
00776   // this portable (i.e. using friendship etc.) in the past
00777   // This is a very bad breach of encapsulation that is needed since MS VC++
00778   // 5.0 will not allow me to declare template functions as friends.
00779   ArrayRCP( T* p, size_type lowerOffset, size_type size,
00780     const RCPNodeHandle& node );
00781   T* access_private_ptr() const;
00782   RCPNodeHandle& nonconst_access_private_node();
00783   const RCPNodeHandle& access_private_node() const;
00784 #endif
00785 
00786 };  // end class ArrayRCP<...>
00787 
00788 
00789 // 2008/09/22: rabartl: NOTE: I removed the TypeNameTraits<ArrayRCP<T> >
00790 // specialization since I want to be able to print the type name of an
00791 // ArrayRCP that does not have the type T fully defined!
00792 
00793 
00798 template<typename T>
00799 class NullIteratorTraits<ArrayRCP<T> > {
00800 public:
00801   static ArrayRCP<T> getNull() { return null; }
00802 };
00803 
00804 
00810 template<class T>
00811 ArrayRCP<T> arcp(
00812   T* p,
00813   typename ArrayRCP<T>::size_type lowerOffset,
00814   typename ArrayRCP<T>::size_type size,
00815   bool owns_mem = true
00816   );
00817 
00818 
00824 template<class T, class Dealloc_T>
00825 ArrayRCP<T> arcp(
00826   T* p,
00827   typename ArrayRCP<T>::size_type lowerOffset,
00828   typename ArrayRCP<T>::size_type size,
00829   Dealloc_T dealloc, bool owns_mem
00830   );
00831 
00832  
00843 template<class T>
00844 ArrayRCP<T> arcp( typename ArrayRCP<T>::size_type size );
00845 
00846  
00860 template<class T>
00861 ArrayRCP<T> arcpCloneNode( const ArrayRCP<T> &a );
00862 
00863  
00868 template<class T>
00869 ArrayRCP<T> arcpClone( const ArrayView<const T> &v );
00870 
00871 
00882 template<class T, class Embedded>
00883 ArrayRCP<T>
00884 arcpWithEmbeddedObjPreDestroy(
00885   T* p,
00886   typename ArrayRCP<T>::size_type lowerOffset,
00887   typename ArrayRCP<T>::size_type size,
00888   const Embedded &embedded,
00889   bool owns_mem = true
00890   );
00891 
00892 
00903 template<class T, class Embedded>
00904 ArrayRCP<T>
00905 arcpWithEmbeddedObjPostDestroy(
00906   T* p,
00907   typename ArrayRCP<T>::size_type lowerOffset,
00908   typename ArrayRCP<T>::size_type size,
00909   const Embedded &embedded,
00910   bool owns_mem = true
00911   );
00912 
00913 
00925 template<class T, class Embedded>
00926 ArrayRCP<T>
00927 arcpWithEmbeddedObj(
00928   T* p,
00929   typename ArrayRCP<T>::size_type lowerOffset,
00930   typename ArrayRCP<T>::size_type size,
00931   const Embedded &embedded,
00932   bool owns_mem = true
00933   );
00934 
00935 
00941 template<class T>
00942 ArrayRCP<T> arcp( const RCP<std::vector<T> > &v );
00943 
00944 
00950 template<class T>
00951 ArrayRCP<const T> arcp( const RCP<const std::vector<T> > &v );
00952 
00953 
00962 template<class T>
00963 ArrayRCP<T> arcpFromArrayView(const ArrayView<T> &av);
00964 
00965 
00972 template<class T>
00973 RCP<std::vector<T> > get_std_vector( const ArrayRCP<T> &ptr );
00974 
00975 
00982 template<class T>
00983 RCP<const std::vector<T> > get_std_vector( const ArrayRCP<const T> &ptr );
00984 
00985 
00990 template<class T>
00991 bool is_null( const ArrayRCP<T> &p );
00992 
00993 
00998 template<class T>
00999 bool nonnull( const ArrayRCP<T> &p );
01000 
01001 
01006 template<class T>
01007 bool operator==( const ArrayRCP<T> &p, ENull );
01008 
01009 
01014 template<class T>
01015 bool operator!=( const ArrayRCP<T> &p, ENull );
01016 
01017 
01022 template<class T1, class T2>
01023 bool operator==( const ArrayRCP<T1> &p1, const ArrayRCP<T2> &p2 );
01024 
01025 
01030 template<class T1, class T2>
01031 bool operator!=( const ArrayRCP<T1> &p1, const ArrayRCP<T2> &p2 );
01032 
01033 
01038 template<class T1, class T2>
01039 bool operator<( const ArrayRCP<T1> &p1, const ArrayRCP<T2> &p2 );
01040 
01041 
01046 template<class T1, class T2>
01047 bool operator<=( const ArrayRCP<T1> &p1, const ArrayRCP<T2> &p2 );
01048 
01049 
01054 template<class T1, class T2>
01055 bool operator>( const ArrayRCP<T1> &p1, const ArrayRCP<T2> &p2 );
01056 
01057 
01062 template<class T1, class T2>
01063 bool operator>=( const ArrayRCP<T1> &p1, const ArrayRCP<T2> &p2 );
01064 
01065 
01070 template<class T>
01071 typename ArrayRCP<T>::difference_type
01072 operator-( const ArrayRCP<T> &p1, const ArrayRCP<T> &p2 );
01073 
01074 
01083 template<class T2, class T1>
01084 inline
01085 ArrayRCP<T2> arcp_const_cast(const ArrayRCP<T1>& p1);
01086 
01087 
01100 template<class T2, class T1>
01101 ArrayRCP<T2> arcp_reinterpret_cast(const ArrayRCP<T1>& p1);
01102 
01103 
01122 template<class T2, class T1>
01123 ArrayRCP<T2> arcp_reinterpret_cast_nonpod(const ArrayRCP<T1>& p1, const T2& val=T2());
01124 
01125 
01151 template<class T2, class T1>
01152 inline
01153 ArrayRCP<T2> arcp_implicit_cast(const ArrayRCP<T1>& p1);
01154 
01155 
01214 template<class T1, class T2>
01215 void set_extra_data(
01216   const T1 &extra_data, const std::string& name,
01217   const Ptr<ArrayRCP<T2> > &p, EPrePostDestruction destroy_when = POST_DESTROY,
01218   bool force_unique = true );
01219 
01220 
01240 template<class T1, class T2>
01241 T1& get_extra_data( ArrayRCP<T2>& p, const std::string& name );
01242 
01243 
01269 template<class T1, class T2>
01270 const T1& get_extra_data( const ArrayRCP<T2>& p, const std::string& name );
01271 
01272 
01297 template<class T1, class T2>
01298 T1* get_optional_extra_data( ArrayRCP<T2>& p, const std::string& name );
01299 
01300 
01330 template<class T1, class T2>
01331 const T1* get_optional_extra_data( const ArrayRCP<T2>& p, const std::string& name );
01332 
01333 
01344 template<class Dealloc_T, class T>
01345 Dealloc_T& get_nonconst_dealloc( const ArrayRCP<T>& p );
01346 
01347 
01365 template<class Dealloc_T, class T>
01366 const Dealloc_T& get_dealloc( const ArrayRCP<T>& p );
01367 
01368 
01383 template<class Dealloc_T, class T>
01384 const Dealloc_T* get_optional_dealloc( const ArrayRCP<T>& p );
01385 
01386 
01408 template<class Dealloc_T, class T>
01409 Dealloc_T* get_optional_nonconst_dealloc( const ArrayRCP<T>& p );
01410 
01411 
01418 template<class TOrig, class Embedded, class T>
01419 const Embedded& getEmbeddedObj( const ArrayRCP<T>& p );
01420 
01421 
01428 template<class TOrig, class Embedded, class T>
01429 Embedded& getNonconstEmbeddedObj( const ArrayRCP<T>& p );
01430 
01431 
01439 template<class T>
01440 std::ostream& operator<<( std::ostream& out, const ArrayRCP<T>& p );
01441 
01442 
01443 } // end namespace Teuchos
01444 
01445 
01446 #endif  // TEUCHOS_ARRAY_RCP_DECL_HPP
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
Generated on Wed Apr 13 09:57:29 2011 for Teuchos Package Browser (Single Doxygen Collection) by  doxygen 1.6.3