LAMA
|
00001 00033 #ifndef LAMA_LAMAARRAYVIEW_HPP_ 00034 #define LAMA_LAMAARRAYVIEW_HPP_ 00035 00036 // for dll_import 00037 #include <lama/config.hpp> 00038 00039 // base classes 00040 #include <lama/Printable.hpp> 00041 00042 // others 00043 #include <lama/LAMAArray.hpp> 00044 00045 namespace lama 00046 { 00047 00048 template<typename T> 00049 class ReadAccess; 00050 00051 template<typename T> 00052 class WriteAccess; 00053 00054 template<typename T> 00055 class LAMAArrayConstView; 00056 00060 template<typename T> 00061 class LAMA_DLL_IMPORTEXPORT LAMAArrayView : public Printable 00062 { 00063 friend class ReadAccess<T>; 00064 friend class WriteAccess<T>; 00065 friend class LAMAArrayConstView<T>; 00066 00067 public: 00071 typedef T ValueType; 00072 00078 LAMAArrayView( LAMAArray<T>& array ); 00079 00087 LAMAArrayView( LAMAArray<T>& array, const IndexType offset, const IndexType size ); 00088 00094 LAMAArrayView( const LAMAArrayView<T>& other ); 00095 00099 virtual ~LAMAArrayView(); 00100 00104 inline IndexType size() const; 00105 00106 virtual void writeAt(std::ostream& stream) const; 00107 00117 bool operator==( const LAMAArrayConstView<T>& other ) const; 00118 00128 bool operator!=( const LAMAArrayConstView<T>& other ) const; 00129 00139 bool operator==( const LAMAArrayView<T>& other ) const; 00140 00150 bool operator!=( const LAMAArrayView<T>& other ) const; 00151 00152 private: 00153 LAMAArrayView(); 00154 LAMAArrayView& operator=( const LAMAArrayView<T>& other ); 00155 00156 const ValueType* get(const size_t index) const; 00157 00158 ValueType* get(const size_t index); 00159 00160 int acquireReadAccess( ContextPtr context ) const; 00161 00162 void releaseReadAccess( const size_t index ) const; 00163 00164 int acquireWriteAccess( ContextPtr context, bool keepFlag ); 00165 00166 int acquireWriteAccess(); 00167 00168 void releaseWriteAccess( const size_t index ); 00169 00170 void clear( const size_t index ); 00171 00172 void resize( const size_t index, const IndexType newSize ); 00173 00174 void reserve( const size_t index, const IndexType capacity, bool copyFlag ); 00175 00176 IndexType capacity( const size_t index ) const; 00177 00178 LAMAArray<T>& mArray; 00179 const IndexType mOffset; 00180 IndexType mSize; 00181 }; 00182 00186 template<typename T> 00187 class LAMAArrayConstView : public Printable 00188 { 00189 friend class ReadAccess<T>; 00190 00191 public: 00195 typedef T ValueType; 00196 00202 LAMAArrayConstView( const LAMAArrayConstView<T>& other ); 00203 00209 LAMAArrayConstView( const LAMAArrayView<T>& view ); 00210 00216 LAMAArrayConstView( const LAMAArray<T>& array ); 00217 00225 LAMAArrayConstView( const LAMAArray<T>& array, const IndexType offset, const IndexType size ); 00226 00230 virtual ~LAMAArrayConstView(); 00231 00235 inline IndexType size() const; 00236 00237 virtual void writeAt(std::ostream& stream) const; 00238 00248 bool operator==( const LAMAArrayConstView<T>& other ) const; 00249 00259 bool operator!=( const LAMAArrayConstView<T>& other ) const; 00260 00270 bool operator==( const LAMAArrayView<T>& other ) const; 00271 00281 bool operator!=( const LAMAArrayView<T>& other ) const; 00282 00283 private: 00284 LAMAArrayConstView(); 00285 LAMAArrayConstView& operator=( const LAMAArrayConstView<T>& other ); 00286 00287 const ValueType* get(const size_t index) const; 00288 00289 int acquireReadAccess( ContextPtr context ) const; 00290 00291 void releaseReadAccess( const size_t index ) const; 00292 00293 const LAMAArray<T>& mArray; 00294 const IndexType mOffset; 00295 const IndexType mSize; 00296 }; 00297 00298 template<typename T> 00299 inline IndexType LAMAArrayView<T>::size() const 00300 { 00301 return mSize; 00302 } 00303 00304 template<typename T> 00305 inline IndexType LAMAArrayConstView<T>::size() const 00306 { 00307 return mSize; 00308 } 00309 00310 } /* namespace lama */ 00311 00312 #endif // LAMA_LAMAARRAYVIEW_HPP_