LAMA
|
00001 00033 #ifndef LAMA_WRITE_ACCESS_HPP_ 00034 #define LAMA_WRITE_ACCESS_HPP_ 00035 00036 // for dll_import 00037 #include <lama/config.hpp> 00038 00039 // base classes 00040 #include <lama/BaseAccess.hpp> 00041 00042 // others 00043 #include <lama/LAMAArray.hpp> 00044 #include <lama/LAMAArrayView.hpp> 00045 #include <lama/Context.hpp> 00046 #include <lama/SyncToken.hpp> 00047 00048 #include <lama/exception/Exception.hpp> 00049 00050 // logging 00051 #include <logging/logging.hpp> 00052 00053 namespace lama 00054 { 00055 00063 template<typename T> 00064 class LAMA_DLL_IMPORTEXPORT WriteAccess : public BaseAccess 00065 { 00066 public: 00070 typedef T ValueType; 00071 00084 WriteAccess( LAMAArray<ValueType>& array, ContextPtr context ); 00085 00109 WriteAccess( LAMAArray<ValueType>& array, ContextPtr context, 00110 const IndexType size, const bool keep ); 00111 00122 explicit WriteAccess( LAMAArray<ValueType>& array ); 00123 00124 //WriteAccess( LAMAArray<ValueType>& array, ContextType context, const bool keep = true ); 00125 00126 WriteAccess( LAMAArrayView<ValueType>& view, ContextPtr context, const bool keep = true ); 00127 00128 WriteAccess( LAMAArrayView<ValueType>& view, ContextPtr context, const IndexType size, const bool keep = true ); 00129 00130 //WriteAccess( LAMAArrayView<ValueType>& view, ContextType context, const bool keep = true ); 00131 00135 virtual ~WriteAccess(); 00136 00142 ValueType* get(); 00143 00164 void clear(); 00165 00175 void resize( const IndexType newSize ); 00176 00182 void reserve( const IndexType capacity ); 00183 00187 IndexType capacity() const; 00188 00192 virtual void release(); 00193 00194 virtual void writeAt(std::ostream& stream) const; 00195 00201 inline IndexType size() const; 00202 00203 protected: 00204 00205 ValueType* mData; // pointer to the context data 00206 00207 LAMA_LOG_DECL_STATIC_LOGGER(logger); 00208 00209 LAMAArrayView<ValueType>* mArrayView; 00210 00211 size_t mIndex; // index for this context access 00212 }; 00213 00222 template<typename T> 00223 class LAMA_DLL_IMPORTEXPORT WriteOnlyAccess : public WriteAccess<T> 00224 { 00225 public: 00226 00230 typedef T ValueType; 00231 00234 WriteOnlyAccess( LAMAArray<ValueType>& array, ContextPtr context ) 00235 00236 : WriteAccess<ValueType>( array, context, false ) 00237 00238 { 00239 } 00240 00243 WriteOnlyAccess( LAMAArray<ValueType>& array, ContextPtr context, const IndexType size ) 00244 00245 : WriteAccess<ValueType>( array, context, size, false ) 00246 00247 { 00248 } 00249 00252 WriteOnlyAccess( LAMAArrayView<ValueType>& view, ContextPtr context, const IndexType size ) 00253 00254 : WriteAccess<ValueType>( view, context, size, false ) 00255 00256 { 00257 } 00258 00259 ~WriteOnlyAccess() 00260 { 00261 LAMA_LOG_TRACE( WriteAccess<T>::logger, "~WriteOnlyAccess" ); 00262 } 00263 }; 00264 00265 template<typename T> 00266 inline IndexType WriteAccess<T>::size() const 00267 { 00268 if ( mArrayView ) 00269 { 00270 return mArrayView->size(); 00271 } 00272 else 00273 { 00274 LAMA_THROWEXCEPTION("cannot call size on released array"); 00275 } 00276 } 00277 00278 } 00279 00280 #endif // LAMA_WRITE_ACCESS_HPP_