LAMA
/home/brandes/workspace/LAMA/src/lama/HostWriteAccess.hpp
Go to the documentation of this file.
00001 
00033 #ifndef LAMA_HOSTWRITEACCESS_HPP_
00034 #define LAMA_HOSTWRITEACCESS_HPP_
00035 
00036 // for dll_import
00037 #include <lama/config.hpp>
00038 
00039 // base classes
00040 #include <lama/WriteAccess.hpp>
00041 
00042 // others
00043 #include <lama/ContextFactory.hpp>
00044 
00045 namespace lama
00046 {
00047 
00051 template<typename T>
00052 class HostWriteAccess : public WriteAccess<T>
00053 {
00054 public:
00055 
00059     typedef T ValueType;
00060 
00070     HostWriteAccess( LAMAArray<ValueType>& array );
00071 
00072     HostWriteAccess( LAMAArray<ValueType>& array, const IndexType size, const bool keep );
00073 
00074     HostWriteAccess( LAMAArrayView<ValueType>& view, const bool keep = true );
00075 
00079     virtual ~HostWriteAccess();
00080 
00087     inline ValueType& operator[] (const IndexType i);
00088 
00094     inline operator ValueType*();
00095 
00101     void push_back(const ValueType val);
00102 
00103     using WriteAccess<ValueType>::size;
00104 
00105     using WriteAccess<ValueType>::resize;
00106 
00107     using WriteAccess<ValueType>::reserve;
00108 
00109 protected:
00110 
00111     using WriteAccess<ValueType>::mData;
00112 };
00113 
00122 template<typename T>
00123 class HostWriteOnlyAccess : public HostWriteAccess<T>
00124 {
00125 public:
00126 
00130     typedef T ValueType;
00131 
00134     HostWriteOnlyAccess( LAMAArray<ValueType>& array )
00135 
00136       : HostWriteAccess<ValueType>( array, false )
00137 
00138     {
00139     }
00140 
00143     HostWriteOnlyAccess( LAMAArray<ValueType>& array, const IndexType size )
00144 
00145       : HostWriteAccess<ValueType>( array, size, false )
00146 
00147     {
00148     }
00149 
00150     ~HostWriteOnlyAccess()
00151     {
00152     }
00153 };
00154 
00155 template<typename T>
00156 HostWriteAccess<T>::HostWriteAccess( LAMAArray<ValueType>& array )
00157     : WriteAccess<T>( array, ContextFactory::getContext( Context::Host ) )
00158 {
00159 }
00160 
00161 template<typename T>
00162 HostWriteAccess<T>::HostWriteAccess( LAMAArray<ValueType>& array, const IndexType size, const bool keep )
00163     : WriteAccess<T>(array, ContextFactory::getContext( Context::Host ), size, keep)
00164 {
00165 }
00166 
00167 template<typename T>
00168 HostWriteAccess<T>::HostWriteAccess( LAMAArrayView<ValueType>& view, const bool keep /* = true */)
00169     : WriteAccess<T>(view, ContextFactory::getContext( Context::Host ), keep)
00170 {
00171 }
00172 
00173 template<typename T>
00174 HostWriteAccess<T>::~HostWriteAccess()
00175 {
00176 }
00177 
00178 template<typename T>
00179 T& HostWriteAccess<T>::operator[] ( const IndexType i )
00180 {
00181     LAMA_ASSERT_ERROR( mData, "[" << i << "]: HostWriteAccess has already"
00182                        << " been released or has not been allocated." );
00183 
00184     return mData[i];
00185 }
00186 
00187 template<typename T>
00188 inline HostWriteAccess<T>::operator ValueType*()
00189 {
00190     return mData;
00191 }
00192 
00193 template<typename T>
00194 void HostWriteAccess<T>::push_back( const ValueType val )
00195 {
00196     const IndexType currentSize = size();
00197     resize( currentSize + 1 );
00198     mData[ currentSize ] = val;
00199 }
00200 
00201 }
00202 
00203 #endif // LAMA_HOSTWRITEACCESS_HPP_