fw4spl
ArrayGetter.cpp
1 /* ***** BEGIN LICENSE BLOCK *****
2  * FW4SPL - Copyright (C) IRCAD, 2009-2016.
3  * Distributed under the terms of the GNU Lesser General Public License (LGPL) as
4  * published by the Free Software Foundation.
5  * ****** END LICENSE BLOCK ****** */
6 
7 #include "fwDataTools/helper/ArrayGetter.hpp"
8 
9 namespace fwDataTools
10 {
11 
12 namespace helper
13 {
14 
15 ArrayGetter::ArrayGetter( ::fwData::Array::csptr array ) : m_array (array)
16 {
17  SLM_ASSERT("Array ptr is null.", array);
18  m_lock = array->getBufferObject()->lock();
19 }
20 
21 //-----------------------------------------------------------------------------
22 
23 ArrayGetter::~ArrayGetter()
24 {
25 
26 }
27 
28 //-----------------------------------------------------------------------------
29 
30 const void* ArrayGetter::getBuffer() const
31 {
32  return m_lock.getBuffer();
33 }
34 
35 //------------------------------------------------------------------------------
36 
37 const char* ArrayGetter::begin() const
38 {
39  return static_cast<const char*>(this->getBuffer());
40 }
41 
42 //------------------------------------------------------------------------------
43 
44 const char* ArrayGetter::end() const
45 {
46  return reinterpret_cast<const char*> (static_cast<const char*>(this->getBuffer()) + m_array->getSizeInBytes());
47 }
48 
49 //-----------------------------------------------------------------------------
50 
51 const char* ArrayGetter::getBufferPtr( const ::fwData::Array::IndexType& id, size_t component, size_t sizeOfType ) const
52 {
53  size_t sizeOf = m_array->getType().sizeOf();
54  size_t offset = m_array->getBufferOffset(id, component, sizeOf);
55  const char* item = static_cast<const char*>(this->getBuffer()) + offset;
56  return item;
57 }
58 
59 //------------------------------------------------------------------------------
60 
61 const void* ArrayGetter::getItem(const ::fwData::Array::IndexType& id, const size_t component) const
62 {
63  size_t sizeOf = m_array->getType().sizeOf();
64  const char* item = this->getBufferPtr(id, component, sizeOf);
65  return item;
66 }
67 
68 //------------------------------------------------------------------------------
69 
70 void ArrayGetter::getItem(const ::fwData::Array::IndexType& id, void* value) const
71 {
72  size_t sizeOf = m_array->getType().sizeOf();
73  const char* item = this->getBufferPtr(id, 0, sizeOf);
74  char* val = static_cast<char*>(value);
75  std::copy(item, item + m_array->getNumberOfComponents()*sizeOf, val);
76 }
77 
78 //------------------------------------------------------------------------------
79 
80 void ArrayGetter::getItem(const ::fwData::Array::IndexType& id, const size_t component, void* value) const
81 {
82  size_t sizeOf = m_array->getType().sizeOf();
83  const char* item = this->getBufferPtr(id, component, sizeOf);
84  char* val = static_cast<char*>(value);
85  std::copy(item, item + m_array->getNumberOfComponents()*sizeOf, val);
86 }
87 
88 //------------------------------------------------------------------------------
89 
91 {
92  return m_lock;
93 }
94 
95 //------------------------------------------------------------------------------
96 
97 } // namespace helper
98 
99 } // namespace fwDataTools
FWDATATOOLS_API char * getBufferPtr(const ::fwData::Array::IndexType &id, size_t component, size_t sizeOfType)
Get a pointer to the value described by given parameters.
virtual FWDATATOOLS_API const void * getBuffer() const
Getter for the array buffer.
Definition: ArrayGetter.cpp:30
FWDATATOOLS_API const char * getBufferPtr(const ::fwData::Array::IndexType &id, size_t component, size_t sizeOfType) const
Get a pointer to the value described by given parameters.
Definition: ArrayGetter.cpp:51
The namespace fwDataTools contains classes which provide helpers to manipulate fwData::Object. *.
virtual FWDATATOOLS_API void * getBuffer()
Getter for the array buffer.
base class for BufferObject Lock
virtual FWDATATOOLS_API const char * begin() const
Returns the begining/end of the buffer interpreted as a char buffer.
Definition: ArrayGetter.cpp:37
LockBase< T >::BufferType getBuffer() const
Returns BufferObject&#39;s buffer pointer.
#define SLM_ASSERT(message, cond)
work like &#39;assert&#39; from &#39;cassert&#39;, with in addition a message logged by spylog (with FATAL loglevel) ...
Definition: spyLog.hpp:308
FWDATATOOLS_API::fwMemory::BufferObject::Lock getLock() const
Returns a copy of current lock on array.
Definition: ArrayGetter.cpp:90
virtual FWDATATOOLS_API const void * getItem(const ::fwData::Array::IndexType &id, const size_t component=0) const
Getter for a buffer item. pointer to the requested item in the buffer.
Definition: ArrayGetter.cpp:61