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_VIEW_DECL_HPP
00030 #define TEUCHOS_ARRAY_VIEW_DECL_HPP
00031
00032
00033 #include "Teuchos_RCPNode.hpp"
00034 #include "Teuchos_ENull.hpp"
00035 #include "Teuchos_NullIteratorTraits.hpp"
00036 #include "Teuchos_ConstTypeTraits.hpp"
00037
00038
00039 namespace Teuchos {
00040
00041
00042 template<class T> class ArrayRCP;
00043
00044
00063 template<class T>
00064 class ArrayView {
00065 public:
00066
00069
00071 typedef Teuchos_Index Ordinal;
00072
00074 typedef T value_type;
00076 typedef T* pointer;
00078 typedef const T* const_pointer;
00080 typedef T& reference;
00082 typedef const T& const_reference;
00083
00084 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK
00085
00086 typedef ArrayRCP<T> iterator;
00087 #else
00088
00089 typedef pointer iterator;
00090 #endif
00091
00093 typedef size_t size_type;
00095 typedef ptrdiff_t difference_type;
00096
00098
00100
00101
00103 ArrayView( ENull null_arg = null );
00104
00124 ArrayView( T* p, Ordinal size );
00125
00140 ArrayView(const ArrayView<T>& array);
00141
00143 ArrayView(
00144 std::vector<typename ConstTypeTraits<T>::NonConstType>& vec
00145 );
00146
00148 ArrayView(
00149 const std::vector<typename ConstTypeTraits<T>::NonConstType>& vec
00150 );
00151
00153 ArrayView<T>& operator=(const ArrayView<T>& array);
00154
00157 ~ArrayView();
00158
00160
00162
00163
00165 bool is_null() const;
00166
00168 Ordinal size() const;
00169
00171 std::string toString() const;
00172
00174
00176
00177
00179 inline T* getRawPtr() const;
00180
00188 T& operator[](Ordinal i) const;
00189
00191 T& front() const;
00192
00194 T& back() const;
00195
00197
00199
00200
00212 ArrayView<T> view( Ordinal offset, Ordinal size ) const;
00213
00216 ArrayView<T> operator()( Ordinal offset, Ordinal size ) const;
00217
00220 const ArrayView<T>& operator()() const;
00221
00227 ArrayView<const T> getConst() const;
00228
00229
00230
00231
00232
00233 #ifdef __INTEL_COMPILER
00234 # pragma warning(disable : 597)
00235 #endif
00236
00242 operator ArrayView<const T>() const;
00243
00245
00248
00265 void assign(const ArrayView<const T>& array) const;
00266
00268
00270
00271
00284 iterator begin() const;
00285
00298 iterator end() const;
00299
00301
00303
00304
00308 const ArrayView<T>& assert_not_null() const;
00309
00314 const ArrayView<T>& assert_in_range( Ordinal offset, Ordinal size ) const;
00315
00317
00318 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK
00319
00320
00321
00322
00323
00324 explicit ArrayView( const ArrayRCP<T> &arcp );
00325
00326 explicit ArrayView( T* p, Ordinal size, const ArrayRCP<T> &arcp );
00327
00328 #endif
00329
00330 private:
00331
00332
00333
00334
00335 T *ptr_;
00336 int size_;
00337 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK
00338 ArrayRCP<T> arcp_;
00339 #endif
00340
00341 void setUpIterators();
00342
00343
00344
00345
00346 void debug_assert_not_null() const
00347 {
00348 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK
00349 assert_not_null();
00350 #endif
00351 }
00352
00353 void debug_assert_in_range( Ordinal offset, Ordinal size_in ) const
00354 {
00355 (void)offset; (void)size_in;
00356 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK
00357 assert_in_range(offset, size_in);
00358 #endif
00359 }
00360
00361 void debug_assert_valid_ptr() const
00362 {
00363 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK
00364 arcp_.access_private_node().assert_valid_ptr(*this);
00365 #endif
00366 }
00367
00368 public:
00369
00370
00371
00372 T* access_private_ptr() const
00373 { return ptr_; }
00374
00375 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK
00376 ArrayRCP<T> access_private_arcp() const
00377 { return arcp_; }
00378 #endif
00379
00380 };
00381
00382
00387 template<class T>
00388 ArrayView<T> arrayView( T* p, typename ArrayView<T>::Ordinal size );
00389
00390
00395 template<class T>
00396 ArrayView<T> arrayViewFromVector( std::vector<T>& vec );
00397
00398
00403 template<class T>
00404 ArrayView<const T> arrayViewFromVector( const std::vector<T>& vec );
00405
00406
00407 #ifndef __sun
00408
00409
00410
00411
00412
00413
00414
00415
00423 template<class T>
00424 std::vector<T> createVector( const ArrayView<T> &av );
00425
00426
00427 #endif // __sun
00428
00429
00437 template<class T>
00438 std::vector<T> createVector( const ArrayView<const T> &av );
00439
00440
00445 template<class T>
00446 bool is_null( const ArrayView<T> &av );
00447
00448
00456 template<class T>
00457 std::ostream& operator<<( std::ostream& out, const ArrayView<T>& av );
00458
00459
00472 template<class T2, class T1>
00473 ArrayView<T2> av_reinterpret_cast(const ArrayView<T1>& p1);
00474
00475
00476 }
00477
00478
00479
00480
00481
00482
00483
00484
00485
00486
00487 #endif // TEUCHOS_ARRAY_VIEW_DECL_HPP