fw4spl
ArrayGetter.hpp
1 /* ***** BEGIN LICENSE BLOCK *****
2  * FW4SPL - Copyright (C) IRCAD, 2009-2017.
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 #ifndef __FWDATATOOLS_HELPER_ARRAYGETTER_HPP__
8 #define __FWDATATOOLS_HELPER_ARRAYGETTER_HPP__
9 
10 #include "fwDataTools/config.hpp"
11 
12 #include <fwData/Array.hpp>
13 
14 #include <fwMemory/BufferObject.hpp>
15 
16 #include <fwTools/Type.hpp>
17 
18 namespace fwDataTools
19 {
20 
21 namespace helper
22 {
23 
28 class FWDATATOOLS_CLASS_API ArrayGetter
29 {
30 
31 public:
32  fwCoreClassFactoryMacro((ArrayGetter), (((::fwData::Array::sptr))), new ArrayGetter );
33 
34  FWDATATOOLS_API ArrayGetter( ::fwData::Array::csptr array );
35 
36  FWDATATOOLS_API virtual ~ArrayGetter();
37 
39 
47  FWDATATOOLS_API virtual const void* getItem(const ::fwData::Array::IndexType& id, const size_t component = 0) const;
48 
58  template< typename T > const T* getItem(const ::fwData::Array::IndexType& id, const size_t component = 0) const;
59 
66  FWDATATOOLS_API virtual void getItem(const ::fwData::Array::IndexType& id, void* value) const;
67  FWDATATOOLS_API virtual void getItem(const ::fwData::Array::IndexType& id, const size_t component,
68  void* value) const;
69 
75  FWDATATOOLS_API virtual const void* getBuffer() const;
76 
78  FWDATATOOLS_API virtual const char* begin() const;
79  FWDATATOOLS_API virtual const char* end() const;
80 
82  template< typename T > const T* begin() const;
83  template< typename T > const T* end() const;
84 
94  FWDATATOOLS_API const char* getBufferPtr( const ::fwData::Array::IndexType& id, size_t component,
95  size_t sizeOfType ) const;
96 
98  FWDATATOOLS_API ::fwMemory::BufferObject::Lock getLock() const;
99 
100 protected:
101 
102  ::fwData::Array::csptr m_array;
104 
105 };
106 
107 //------------------------------------------------------------------------------
108 
109 template< typename T >
110 const T* ArrayGetter::begin() const
111 {
112  return static_cast<const T*>(this->getBuffer());
113 }
114 
115 //------------------------------------------------------------------------------
116 
117 template< typename T >
118 const T* ArrayGetter::end() const
119 {
120  return reinterpret_cast<const T*> (static_cast<const char*>(this->getBuffer()) + m_array->getSizeInBytes());
121 }
122 
123 //------------------------------------------------------------------------------
124 
125 template< typename T >
126 const T* ArrayGetter::getItem(const ::fwData::Array::IndexType& id, const size_t component) const
127 {
128  return static_cast<const T*> (this->getItem(id, component));
129 }
130 
131 } // namespace helper
132 
133 } // namespace fwData
134 
135 #endif // __FWDATATOOLS_HELPER_ARRAYGETTER_HPP__
The namespace fwDataTools contains classes which provide helpers to manipulate fwData::Object. *.
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
Helper to manage array buffer. Lock the buffer before to modify it.
Definition: ArrayGetter.hpp:28
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
#define fwCoreClassFactoryMacro(_classinfo_, _parameters_, _factory_)
Generate methods for classes with one factory.