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
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 std::random_access_iterator_tag iterator_category;
00082 typedef T* iterator_type;
00084 typedef T value_type;
00086 typedef T& reference;
00088 typedef T* pointer;
00090 typedef ptrdiff_t difference_type;
00091
00093 typedef T element_type;
00095 typedef Teuchos_Index Ordinal;
00096 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK
00097
00098 typedef ArrayRCP<T> iterator;
00099 #else
00100 typedef T* iterator;
00101 #endif
00102 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK
00103
00104 typedef ArrayRCP<T> const_iterator;
00105 #else
00106 typedef T* const_iterator;
00107 #endif
00108
00110
00112
00113
00126 ArrayRCP( ENull null_arg = null );
00127
00145 ArrayRCP(const ArrayRCP<T>& r_ptr);
00146
00159 ~ArrayRCP();
00160
00178 ArrayRCP<T>& operator=(const ArrayRCP<T>& r_ptr);
00179
00181
00183
00184
00194 T* operator->() const;
00195
00205 T& operator*() const;
00206
00214 T* get() const;
00215
00223 T* getRawPtr() const;
00224
00232 T& operator[](Ordinal offset) const;
00233
00235
00237
00238
00249 ArrayRCP<T>& operator++();
00250
00261 ArrayRCP<T> operator++(int);
00262
00273 ArrayRCP<T>& operator--();
00274
00285 ArrayRCP<T> operator--(int);
00286
00297 ArrayRCP<T>& operator+=(Ordinal offset);
00298
00309 ArrayRCP<T>& operator-=(Ordinal offset);
00310
00325 ArrayRCP<T> operator+(Ordinal offset) const;
00326
00341 ArrayRCP<T> operator-(Ordinal offset) const;
00342
00344
00346
00347
00353 ArrayRCP<const T> getConst() const;
00354
00369 ArrayRCP<T> persistingView( Ordinal lowerOffset, Ordinal size ) const;
00370
00372
00374
00375
00382 int count() const;
00383
00390 template<class T2>
00391 bool shares_resource(const ArrayRCP<T2>& r_ptr) const;
00392
00394 Ordinal lowerOffset() const;
00395
00397 Ordinal upperOffset() const;
00398
00402 Ordinal size() const;
00403
00405
00407
00408
00421 const_iterator begin() const;
00422
00435 const_iterator end() const;
00436
00438
00440
00441
00456 ArrayView<T> view( Ordinal lowerOffset, Ordinal size ) const;
00457
00461 ArrayView<T> operator()( Ordinal lowerOffset, Ordinal size ) const;
00462
00467 ArrayView<T> operator()() const;
00468
00472 operator ArrayView<T>() const;
00473
00475 operator ArrayRCP<const T>() const;
00476
00478
00480
00481
00502 T* release();
00503
00521 void set_has_ownership();
00522
00534 bool has_ownership() const;
00535
00537
00539
00540
00544 const ArrayRCP<T>& assert_not_null() const;
00545
00551 const ArrayRCP<T>& assert_in_range( Ordinal lowerOffset, Ordinal size ) const;
00552
00554
00555 private:
00556
00557
00558
00559
00560 T *ptr_;
00561 RCPNode *node_;
00562 Ordinal lowerOffset_;
00563 Ordinal upperOffset_;
00564
00565 public:
00566 #ifndef DOXYGEN_COMPILE
00567
00568
00569 ArrayRCP( T* p, Ordinal lowerOffset, Ordinal upperOffset, bool has_ownership );
00570 template<class Dealloc_T>
00571 ArrayRCP( T* p, Ordinal lowerOffset, Ordinal upperOffset, Dealloc_T dealloc, bool has_ownership );
00572
00573
00574 ArrayRCP( T* p, Ordinal lowerOffset, Ordinal upperOffset, RCPNode* node);
00575 T*& access_ptr();
00576 T* access_ptr() const;
00577 RCPNode*& access_node();
00578 RCPNode* access_node() const;
00579 #endif
00580
00581 };
00582
00583
00588 template<typename T>
00589 class TypeNameTraits<ArrayRCP<T> > {
00590 public:
00591 static std::string name() { return "ArrayRCP<"+TypeNameTraits<T>::name()+">"; }
00592 static std::string concreteName( const ArrayRCP<T>& )
00593 { return name(); }
00594 };
00595
00596
00601 template<typename T>
00602 class NullIteratorTraits<ArrayRCP<T> > {
00603 public:
00604 static ArrayRCP<T> getNull() { return null; }
00605 };
00606
00607
00613 template<class T>
00614 ArrayRCP<T> arcp(
00615 T* p,
00616 typename ArrayRCP<T>::Ordinal lowerOffset,
00617 typename ArrayRCP<T>::Ordinal size,
00618 bool owns_mem = true
00619 );
00620
00621
00627 template<class T, class Dealloc_T>
00628 ArrayRCP<T> arcp(
00629 T* p,
00630 typename ArrayRCP<T>::Ordinal lowerOffset,
00631 typename ArrayRCP<T>::Ordinal size,
00632 Dealloc_T dealloc, bool owns_mem
00633 );
00634
00635
00644 template<class T>
00645 ArrayRCP<T> arcp( typename ArrayRCP<T>::Ordinal size );
00646
00647
00652 template<class T>
00653 ArrayRCP<T> arcpClone( const ArrayView<const T> &v );
00654
00655
00666 template<class T, class Embedded>
00667 ArrayRCP<T>
00668 arcpWithEmbeddedObjPreDestroy(
00669 T* p,
00670 typename ArrayRCP<T>::Ordinal lowerOffset,
00671 typename ArrayRCP<T>::Ordinal size,
00672 const Embedded &embedded,
00673 bool owns_mem = true
00674 );
00675
00676
00687 template<class T, class Embedded>
00688 ArrayRCP<T>
00689 arcpWithEmbeddedObjPostDestroy(
00690 T* p,
00691 typename ArrayRCP<T>::Ordinal lowerOffset,
00692 typename ArrayRCP<T>::Ordinal size,
00693 const Embedded &embedded,
00694 bool owns_mem = true
00695 );
00696
00697
00709 template<class T, class Embedded>
00710 ArrayRCP<T>
00711 arcpWithEmbeddedObj(
00712 T* p,
00713 typename ArrayRCP<T>::Ordinal lowerOffset,
00714 typename ArrayRCP<T>::Ordinal size,
00715 const Embedded &embedded,
00716 bool owns_mem = true
00717 );
00718
00719
00725 template<class T>
00726 ArrayRCP<T> arcp( const RCP<std::vector<T> > &v );
00727
00728
00734 template<class T>
00735 ArrayRCP<const T> arcp( const RCP<const std::vector<T> > &v );
00736
00737
00744 template<class T>
00745 RCP<std::vector<T> > get_std_vector( const ArrayRCP<T> &ptr );
00746
00747
00754 template<class T>
00755 RCP<const std::vector<T> > get_std_vector( const ArrayRCP<const T> &ptr );
00756
00757
00762 template<class T>
00763 bool is_null( const ArrayRCP<T> &p );
00764
00765
00770 template<class T>
00771 bool operator==( const ArrayRCP<T> &p, ENull );
00772
00773
00778 template<class T>
00779 bool operator!=( const ArrayRCP<T> &p, ENull );
00780
00781
00786 template<class T1, class T2>
00787 bool operator==( const ArrayRCP<T1> &p1, const ArrayRCP<T2> &p2 );
00788
00789
00794 template<class T1, class T2>
00795 bool operator!=( const ArrayRCP<T1> &p1, const ArrayRCP<T2> &p2 );
00796
00797
00802 template<class T1, class T2>
00803 bool operator<( const ArrayRCP<T1> &p1, const ArrayRCP<T2> &p2 );
00804
00805
00810 template<class T1, class T2>
00811 bool operator<=( const ArrayRCP<T1> &p1, const ArrayRCP<T2> &p2 );
00812
00813
00818 template<class T1, class T2>
00819 bool operator>( const ArrayRCP<T1> &p1, const ArrayRCP<T2> &p2 );
00820
00821
00826 template<class T1, class T2>
00827 bool operator>=( const ArrayRCP<T1> &p1, const ArrayRCP<T2> &p2 );
00828
00829
00834 template<class T>
00835 typename ArrayRCP<T>::difference_type
00836 operator-( const ArrayRCP<T> &p1, const ArrayRCP<T> &p2 );
00837
00838
00847 template<class T2, class T1>
00848 ArrayRCP<T2> arcp_const_cast(const ArrayRCP<T1>& p1);
00849
00850
00863 template<class T2, class T1>
00864 ArrayRCP<T2> arcp_reinterpret_cast(const ArrayRCP<T1>& p1);
00865
00866
00892 template<class T2, class T1>
00893 ArrayRCP<T2> arcp_implicit_cast(const ArrayRCP<T1>& p1);
00894
00895
00954 template<class T1, class T2>
00955 void set_extra_data(
00956 const T1 &extra_data, const std::string& name, ArrayRCP<T2> *p,
00957 EPrePostDestruction destroy_when = POST_DESTROY,
00958 bool force_unique = true
00959 );
00960
00961
00981 template<class T1, class T2>
00982 T1& get_extra_data( ArrayRCP<T2>& p, const std::string& name );
00983
00984
01010 template<class T1, class T2>
01011 const T1& get_extra_data( const ArrayRCP<T2>& p, const std::string& name );
01012
01013
01038 template<class T1, class T2>
01039 T1* get_optional_extra_data( ArrayRCP<T2>& p, const std::string& name );
01040
01041
01071 template<class T1, class T2>
01072 const T1* get_optional_extra_data( const ArrayRCP<T2>& p, const std::string& name );
01073
01074
01085 template<class Dealloc_T, class T>
01086 Dealloc_T& get_nonconst_dealloc( const ArrayRCP<T>& p );
01087
01088
01106 template<class Dealloc_T, class T>
01107 const Dealloc_T& get_dealloc( const ArrayRCP<T>& p );
01108
01109
01124 template<class Dealloc_T, class T>
01125 const Dealloc_T* get_optional_dealloc( const ArrayRCP<T>& p );
01126
01127
01149 template<class Dealloc_T, class T>
01150 Dealloc_T* get_optional_nonconst_dealloc( const ArrayRCP<T>& p );
01151
01152
01159 template<class TOrig, class Embedded, class T>
01160 const Embedded& getEmbeddedObj( const ArrayRCP<T>& p );
01161
01162
01169 template<class TOrig, class Embedded, class T>
01170 Embedded& getNonconstEmbeddedObj( const ArrayRCP<T>& p );
01171
01172
01180 template<class T>
01181 std::ostream& operator<<( std::ostream& out, const ArrayRCP<T>& p );
01182
01183
01184 }
01185
01186
01187 #endif // TEUCHOS_ARRAY_RCP_DECL_HPP