fw4spl
include/fwData/Array.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 __FWDATA_ARRAY_HPP__
8 #define __FWDATA_ARRAY_HPP__
9 
10 #include "fwData/config.hpp"
11 #include "fwData/Exception.hpp"
12 #include "fwData/factory/new.hpp"
13 #include "fwData/Object.hpp"
14 
15 #include <fwMemory/BufferObject.hpp>
16 
17 #include <fwTools/Type.hpp>
18 
19 fwCampAutoDeclareDataMacro((fwData)(Array), FWDATA_API);
20 
21 namespace fwData
22 {
23 
32 class FWDATA_CLASS_API Array : public ::fwData::Object
33 {
34 public:
35 
36  fwCoreClassDefinitionsWithFactoryMacro( (Array)(::fwData::Object), (()), ::fwData::factory::New< Array >);
37 
38  fwCampMakeFriendDataMacro((fwData)(Array));
39 
43  typedef std::vector<size_t> SizeType;
47  typedef std::vector<size_t> OffsetType;
51  typedef OffsetType IndexType;
52 
53  /*
54  * public API
55  */
56 
61  FWDATA_API Array( ::fwData::Object::Key key );
62 
63  FWDATA_API virtual ~Array();
64 
66  FWDATA_API void cachedDeepCopy(const Object::csptr& _source, DeepCopyCacheType& cache) override;
67 
92  FWDATA_API virtual size_t resize(const ::fwTools::Type& type, const SizeType& size, size_t nbOfComponents,
93  bool reallocate = false);
94 
96  FWDATA_API virtual size_t resize(const std::string& type, const SizeType& size, size_t nbOfComponents,
97  bool reallocate = false);
98  FWDATA_API virtual size_t resize(const SizeType& size, size_t nbOfComponents, bool reallocate =
99  false);
100  FWDATA_API virtual size_t resize(const SizeType& size, bool reallocate = false);
101 
106  FWDATA_API virtual void clear();
107 
114  FWDATA_API virtual bool empty() const;
115 
122  FWDATA_API virtual size_t getElementSizeInBytes() const;
123 
129  FWDATA_API virtual size_t getNumberOfElements() const;
130 
136  FWDATA_API virtual size_t getSizeInBytes() const;
137 
143  FWDATA_API virtual const SizeType& getSize() const;
144 
150  FWDATA_API virtual const OffsetType& getStrides() const;
151 
158  FWDATA_API virtual void setNumberOfComponents(size_t nb);
159 
165  FWDATA_API virtual size_t getNumberOfComponents() const;
166 
172  FWDATA_API virtual size_t getNumberOfDimensions() const;
173 
179  FWDATA_API virtual void setIsBufferOwner(const bool own);
180 
186  FWDATA_API virtual bool getIsBufferOwner() const;
187 
193  FWDATA_API virtual void setType(const std::string& type);
194  FWDATA_API virtual void setType(const ::fwTools::Type& type);
195 
201  FWDATA_API virtual ::fwTools::Type getType() const;
202 
213  FWDATA_API size_t getBufferOffset( const ::fwData::Array::IndexType& id, size_t component,
214  size_t sizeOfType ) const;
215 
225  FWDATA_API static OffsetType computeStrides( SizeType size, size_t nbOfComponents, size_t sizeOfType );
226 
227  ::fwMemory::BufferObject::sptr getBufferObject () const;
228 
229  void setBufferObject (const ::fwMemory::BufferObject::sptr& val);
230 
232  FWDATA_API void swap( Array::sptr _source );
233 
234 protected:
235 
237  Array( const Array& );
238 
239  const Array& operator= ( const Array& );
240 
241  OffsetType m_strides;
242  ::fwTools::Type m_type;
243  ::fwMemory::BufferObject::sptr m_bufferObject;
244  SizeType m_size;
245  size_t m_nbOfComponents;
246  bool m_isBufferOwner;
247 
248 };
249 
250 //-----------------------------------------------------------------------------
251 
252 inline ::fwMemory::BufferObject::sptr Array::getBufferObject () const
253 {
254  return m_bufferObject;
255 }
256 
257 //-----------------------------------------------------------------------------
258 
259 inline void Array::setBufferObject (const ::fwMemory::BufferObject::sptr& val)
260 {
261  m_bufferObject = val;
262 }
263 
264 //-----------------------------------------------------------------------------
265 
266 } // namespace fwData
267 
268 #endif // __FWDATA_ARRAY_HPP__
269 
std::vector< size_t > SizeType
Array size type.
Key class used to restrict access to Object construction. See http://www.drdobbs.com/184402053.
std::vector< size_t > OffsetType
Offset type.
OffsetType IndexType
Index type.
Provides a way to manage a view on a multidimentionnal array.
#define fwCoreClassDefinitionsWithFactoryMacro(_classinfo_, _parameters_, _factory_)
Generate common construction methods for classes with one factory.
Class describing an elementary C++ type aka unsigned char, signed char, .... int, float...
Definition: Type.hpp:32
Base class for each data object.
Contains the representation of the data objects used in the framework.