00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #ifndef TEUCHOS_ARRAY_RCP_DECL_HPP
00030 #define TEUCHOS_ARRAY_RCP_DECL_HPP
00031
00032 #include "Teuchos_RCP.hpp"
00033
00034 namespace Teuchos {
00035
00062 template<class T>
00063 class ArrayRCP {
00064 public:
00065
00067
00068
00070 typedef T element_type;
00072 typedef Teuchos_Index Ordinal;
00073 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK
00074
00075 typedef ArrayRCP<T> iterator;
00076 #else
00077 typedef T* iterator;
00078 #endif
00079 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK
00080
00081 typedef ArrayRCP<T> const_iterator;
00082 #else
00083 typedef T* const_iterator;
00084 #endif
00085
00087
00089
00090
00103 ArrayRCP( ENull null_arg = null );
00104
00122 ArrayRCP(const ArrayRCP<T>& r_ptr);
00123
00136 ~ArrayRCP();
00137
00155 ArrayRCP<T>& operator=(const ArrayRCP<T>& r_ptr);
00156
00158
00160
00161
00171 T* operator->() const;
00172
00182 T& operator*() const;
00183
00191 T* get() const;
00192
00200 T& operator[](Ordinal offset) const;
00201
00203
00205
00206
00217 ArrayRCP<T>& operator++();
00218
00229 ArrayRCP<T> operator++(int);
00230
00241 ArrayRCP<T>& operator--();
00242
00253 ArrayRCP<T> operator--(int);
00254
00265 ArrayRCP<T>& operator+=(Ordinal offset);
00266
00277 ArrayRCP<T>& operator-=(Ordinal offset);
00278
00293 ArrayRCP<T> operator+(Ordinal offset) const;
00294
00309 ArrayRCP<T> operator-(Ordinal offset) const;
00310
00312
00314
00315
00321 ArrayRCP<const T> getConst() const;
00322
00337 ArrayRCP<T> subview( Ordinal lowerOffset, Ordinal size ) const;
00338
00340
00342
00343
00350 int count() const;
00351
00358 template<class T2>
00359 bool shares_resource(const ArrayRCP<T2>& r_ptr) const;
00360
00362 Ordinal lowerOffset() const;
00363
00365 Ordinal upperOffset() const;
00366
00370 Ordinal size() const;
00371
00373
00375
00376
00389 const_iterator begin() const;
00390
00403 const_iterator end() const;
00404
00406
00408
00409
00430 T* release();
00431
00449 void set_has_ownership();
00450
00462 bool has_ownership() const;
00463
00465
00467
00468
00472 const ArrayRCP<T>& assert_not_null() const;
00473
00479 const ArrayRCP<T>& assert_in_range( Ordinal lowerOffset, Ordinal size ) const;
00480
00482
00483 public:
00484
00485
00486
00487
00488 typedef PrivateUtilityPack::RCP_node node_t;
00489
00490 private:
00491
00492
00493
00494
00495 T *ptr_;
00496 node_t *node_;
00497 Ordinal lowerOffset_;
00498 Ordinal upperOffset_;
00499
00500 public:
00501 #ifndef DOXYGEN_COMPILE
00502
00503
00504 ArrayRCP( T* p, Ordinal lowerOffset, Ordinal upperOffset, bool has_ownership );
00505 template<class Dealloc_T>
00506 ArrayRCP( T* p, Ordinal lowerOffset, Ordinal upperOffset, Dealloc_T dealloc, bool has_ownership );
00507
00508
00509 ArrayRCP( T* p, Ordinal lowerOffset, Ordinal upperOffset, node_t* node);
00510 T*& access_ptr();
00511 T* access_ptr() const;
00512 node_t*& access_node();
00513 node_t* access_node() const;
00514 #endif
00515
00516 };
00517
00522 template<typename T>
00523 class TypeNameTraits<ArrayRCP<T> > {
00524 public:
00525 static std::string name() { return "ArrayRCP<"+TypeNameTraits<T>::name()+">"; }
00526 };
00527
00533 template<class T>
00534 ArrayRCP<T> arcp(
00535 T* p, typename ArrayRCP<T>::Ordinal lowerOffset
00536 ,typename ArrayRCP<T>::Ordinal size
00537 , bool owns_mem = true
00538 );
00539
00545 template<class T, class Dealloc_T>
00546 ArrayRCP<T> arcp(
00547 T* p, typename ArrayRCP<T>::Ordinal lowerOffset
00548 ,typename ArrayRCP<T>::Ordinal size
00549 , Dealloc_T dealloc, bool owns_mem
00550 );
00551
00560 template<class T>
00561 ArrayRCP<T> arcp( typename ArrayRCP<T>::Ordinal size );
00562
00568 template<class T>
00569 ArrayRCP<T> arcp( const RCP<std::vector<T> > &v );
00570
00576 template<class T>
00577 ArrayRCP<const T> arcp( const RCP<const std::vector<T> > &v );
00578
00585 template<class T>
00586 RCP<std::vector<T> > get_std_vector( const ArrayRCP<T> &ptr );
00587
00594 template<class T>
00595 RCP<const std::vector<T> > get_std_vector( const ArrayRCP<const T> &ptr );
00596
00601 template<class T>
00602 bool is_null( const ArrayRCP<T> &p );
00603
00608 template<class T>
00609 bool operator==( const ArrayRCP<T> &p, ENull );
00610
00615 template<class T>
00616 bool operator!=( const ArrayRCP<T> &p, ENull );
00617
00622 template<class T1, class T2>
00623 bool operator==( const ArrayRCP<T1> &p1, const ArrayRCP<T2> &p2 );
00624
00629 template<class T1, class T2>
00630 bool operator!=( const ArrayRCP<T1> &p1, const ArrayRCP<T2> &p2 );
00631
00636 template<class T1, class T2>
00637 bool operator<( const ArrayRCP<T1> &p1, const ArrayRCP<T2> &p2 );
00638
00643 template<class T1, class T2>
00644 bool operator<=( const ArrayRCP<T1> &p1, const ArrayRCP<T2> &p2 );
00645
00650 template<class T1, class T2>
00651 bool operator>( const ArrayRCP<T1> &p1, const ArrayRCP<T2> &p2 );
00652
00657 template<class T1, class T2>
00658 bool operator>=( const ArrayRCP<T1> &p1, const ArrayRCP<T2> &p2 );
00659
00672 template<class T2, class T1>
00673 ArrayRCP<T2> arcp_reinterpret_cast(const ArrayRCP<T1>& p1);
00674
00700 template<class T2, class T1>
00701 ArrayRCP<T2> arcp_implicit_cast(const ArrayRCP<T1>& p1);
00702
00759 template<class T1, class T2>
00760 void set_extra_data( const T1 &extra_data, const std::string& name, ArrayRCP<T2> *p
00761 ,EPrePostDestruction destroy_when
00762 #ifndef __sun
00763 = POST_DESTROY
00764 #endif
00765 ,bool force_unique
00766 #ifndef __sun
00767 = true
00768 #endif
00769 );
00770 #ifdef __sun
00771 template<class T1, class T2>
00772 inline void set_extra_data( const T1 &extra_data, const std::string& name, ArrayRCP<T2> *p )
00773 { set_extra_data( extra_data, name, p, POST_DESTROY, true ); }
00774 template<class T1, class T2>
00775 inline void set_extra_data( const T1 &extra_data, const std::string& name, ArrayRCP<T2> *p, EPrePostDestruction destroy_when )
00776 { set_extra_data( extra_data, name, p, destroy_when, true ); }
00777 #endif
00778
00797 template<class T1, class T2>
00798 T1& get_extra_data( ArrayRCP<T2>& p, const std::string& name );
00799
00824 template<class T1, class T2>
00825 const T1& get_extra_data( const ArrayRCP<T2>& p, const std::string& name );
00826
00850 template<class T1, class T2>
00851 T1* get_optional_extra_data( ArrayRCP<T2>& p, const std::string& name );
00852
00881 template<class T1, class T2>
00882 const T1* get_optional_extra_data( const ArrayRCP<T2>& p, const std::string& name );
00883
00894 template<class Dealloc_T, class T>
00895 Dealloc_T& get_dealloc( ArrayRCP<T>& p );
00896
00914 template<class Dealloc_T, class T>
00915 const Dealloc_T& get_dealloc( const ArrayRCP<T>& p );
00916
00931 template<class Dealloc_T, class T>
00932 Dealloc_T* get_optional_dealloc( ArrayRCP<T>& p );
00933
00955 template<class Dealloc_T, class T>
00956 const Dealloc_T* get_optional_dealloc( const ArrayRCP<T>& p );
00957
00965 template<class T>
00966 std::ostream& operator<<( std::ostream& out, const ArrayRCP<T>& p );
00967
00968 }
00969
00970 #endif // TEUCHOS_ARRAY_RCP_DECL_HPP