7 #include "fwDataTools/helper/Array.hpp" 15 Array::Array( ::fwData::Array::sptr array ) :
19 m_lock = array->getBufferObject()->lock();
31 void* Array::getBuffer()
33 return m_lock.getBuffer();
38 const void* Array::getBuffer()
const 40 return m_lock.getBuffer();
45 void Array::setBuffer(
void* buf,
bool takeOwnership, ::fwMemory::BufferAllocationPolicy::sptr policy)
47 if(m_array->getIsBufferOwner())
49 if(!m_array->getBufferObject()->isEmpty())
51 m_array->getBufferObject()->destroy();
56 ::fwMemory::BufferObject::sptr newBufferObject = ::fwMemory::BufferObject::New();
57 ::fwMemory::BufferObject::sptr oldBufferObject = m_array->getBufferObject();
58 oldBufferObject->swap(newBufferObject);
60 m_array->getBufferObject()->setBuffer(buf, (buf == NULL) ? 0 : m_array->getSizeInBytes(), policy);
61 m_array->setIsBufferOwner(takeOwnership);
66 void Array::setBuffer(
69 const ::fwTools::Type& type,
70 const ::fwData::Array::SizeType& size,
71 size_t nbOfComponents,
72 ::fwMemory::BufferAllocationPolicy::sptr policy)
74 m_array->resize( type, size, nbOfComponents,
false);
75 this->setBuffer(buf, takeOwnership, policy);
82 void* v = this->getBuffer();
83 return static_cast<char*
>(v);
90 return reinterpret_cast<char*
> (
static_cast<char*
>(this->getBuffer()) + m_array->getSizeInBytes());
94 const char* Array::begin()
const 96 return static_cast<const char*
>(this->getBuffer());
101 const char* Array::end()
const 103 return reinterpret_cast<const char*
> (
static_cast<const char*
>(this->getBuffer()) + m_array->getSizeInBytes());
108 char* Array::getBufferPtr( const ::fwData::Array::IndexType&
id,
size_t component,
size_t sizeOfType )
110 size_t sizeOf = m_array->getType().sizeOf();
111 size_t offset = m_array->getBufferOffset(
id, component, sizeOf);
112 char* item =
static_cast<char*
>(this->getBuffer()) + offset;
118 const char* Array::getBufferPtr( const ::fwData::Array::IndexType&
id,
size_t component,
size_t sizeOfType )
const 120 size_t sizeOf = m_array->getType().sizeOf();
121 size_t offset = m_array->getBufferOffset(
id, component, sizeOf);
122 const char* item =
static_cast<const char*
>(this->getBuffer()) + offset;
128 void Array::setItem(const ::fwData::Array::IndexType&
id,
const void* value)
130 size_t sizeOf = m_array->getType().sizeOf();
131 const char* val =
static_cast<const char*
>(value);
132 char* item = this->getBufferPtr(
id, 0, sizeOf);
133 std::copy(val, val + m_array->getNumberOfComponents()*sizeOf, item);
137 void Array::setItem(const ::fwData::Array::IndexType&
id,
const size_t component,
const void* value)
139 size_t sizeOf = m_array->getType().sizeOf();
140 const char* val =
static_cast<const char*
>(value);
141 char* item = this->getBufferPtr(
id, component, sizeOf);
142 std::copy(val, val + sizeOf, item);
147 void* Array::getItem(const ::fwData::Array::IndexType&
id,
const size_t component)
149 size_t sizeOf = m_array->getType().sizeOf();
150 char* item = this->getBufferPtr(
id, component, sizeOf);
156 void Array::getItem(const ::fwData::Array::IndexType&
id,
void* value)
const 158 size_t sizeOf = m_array->getType().sizeOf();
159 const char* item = this->getBufferPtr(
id, 0, sizeOf);
160 char* val =
static_cast<char*
>(value);
161 std::copy(item, item + m_array->getNumberOfComponents()*sizeOf, val);
166 void Array::getItem(const ::fwData::Array::IndexType&
id,
const size_t component,
void* value)
const 168 size_t sizeOf = m_array->getType().sizeOf();
169 const char* item = this->getBufferPtr(
id, component, sizeOf);
170 char* val =
static_cast<char*
>(value);
171 std::copy(item, item + m_array->getNumberOfComponents()*sizeOf, val);
base class for BufferObject Lock
#define SLM_ASSERT(message, cond)
work like 'assert' from 'cassert', with in addition a message logged by spylog (with FATAL loglevel) ...