fw4spl
Blob.cpp
1 /* ***** BEGIN LICENSE BLOCK *****
2  * FW4SPL - Copyright (C) IRCAD, 2009-2015.
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 "fwAtoms/registry/macros.hpp"
8 #include "fwAtoms/Blob.hpp"
9 
10 fwAtomsRegisterMacro( ::fwAtoms::Blob );
11 
12 namespace fwAtoms
13 {
14 
15 //------------------------------------------------------------------------------
16 
17 Blob::sptr Blob::New(::fwMemory::BufferObject::sptr buffer)
18 {
19  Blob::sptr blob = Blob::New();
20  blob->m_bufferObject = buffer;
21 
22  return blob;
23 }
24 
25 //------------------------------------------------------------------------------
26 
27 Blob::sptr Blob::New(void* buffer, unsigned int size)
28 {
29  ::fwMemory::BufferObject::sptr bufferObject = ::fwMemory::BufferObject::New();
30  bufferObject->setBuffer(buffer, size);
31  Blob::sptr blob = Blob::New(bufferObject);
32  return blob;
33 }
34 
35 //------------------------------------------------------------------------------
36 
37 ::fwMemory::BufferObject::sptr Blob::getBufferObject() const
38 {
39  return m_bufferObject;
40 }
41 
42 //------------------------------------------------------------------------------
43 
44 void Blob::setBufferObject(const ::fwMemory::BufferObject::sptr &bo)
45 {
46  m_bufferObject = bo;
47 }
48 
49 Base::sptr Blob::clone() const
50 {
51  ::fwMemory::BufferObject::sptr bufferObjectDest = ::fwMemory::BufferObject::New();
52  Blob::sptr cloneBlob = Blob::New(bufferObjectDest);
53  if(m_bufferObject)
54  {
55  bufferObjectDest->allocate(m_bufferObject->getSize());
56 
57  ::fwMemory::BufferObject::Lock lockerSource(m_bufferObject);
58  char * buffSrc = static_cast< char * >( lockerSource.getBuffer() );
59 
60  ::fwMemory::BufferObject::Lock lockerDest(bufferObjectDest);
61  char * buffDest = static_cast< char * >( lockerDest.getBuffer() );
62 
63  std::copy(buffSrc, buffSrc + m_bufferObject->getSize(), buffDest );
64  }
65  return cloneBlob;
66 }
67 
68 }
69 
virtual FWATOMS_API Base::sptr clone() const override
Returns a clone object.
Definition: Blob.cpp:49
fwAtoms contains basic objects to represent any other kind of object
base class for BufferObject Lock
FWATOMS_API void setBufferObject(const ::fwMemory::BufferObject::sptr &bo)
buffer accessor.
Definition: Blob.cpp:44
FWATOMS_API::fwMemory::BufferObject::sptr getBufferObject() const
buffer accessor.
Definition: Blob.cpp:37
LockBase< T >::BufferType getBuffer() const
Returns BufferObject&#39;s buffer pointer.
static FWATOMS_API Blob::sptr New(::fwMemory::BufferObject::sptr buffer)
create a new Blob shared ptr.
Definition: Blob.cpp:17
Representation of a buffer.
Definition: Blob.hpp:23