9 #include "fwMemory/BufferAllocationPolicy.hpp" 10 #include "fwMemory/BufferManager.hpp" 11 #include "fwMemory/config.hpp" 13 #include <fwCamp/macros.hpp> 15 #include <boost/filesystem/path.hpp> 18 #include <type_traits> 20 fwCampAutoDeclareMacro((
fwMemory)(BufferObject), FWMEMORY_API);
56 typedef std::shared_ptr< void > CounterType;
57 typedef std::weak_ptr< void > WeakCounterType;
59 typedef size_t SizeType;
67 return this->getClassname();
72 virtual ::fwMemory::BufferManager::BufferType getBuffer()
const 92 typedef typename ::boost::conditional< std::is_const< T >::value,
const void*,
void* >::type BufferType;
113 ::fwCore::mt::ScopedLock lock(bo->m_lockDumpMutex);
114 m_count = bo->m_count.lock();
117 m_count = bo->m_bufferManager->lockBuffer(&(bo->m_buffer)).get();
118 bo->m_count = m_count;
128 SPTR(T) bufferObject = m_bufferObject.lock();
129 BufferType buffer = bufferObject->m_buffer;
139 m_bufferObject.reset();
144 BufferObject::CounterType m_count;
145 WPTR(T) m_bufferObject;
169 FWMEMORY_API
virtual ~BufferObject();
181 FWMEMORY_API
virtual void allocate(SizeType size,
182 const ::fwMemory::BufferAllocationPolicy::sptr& policy =
183 ::fwMemory::BufferMallocPolicy::New());
195 FWMEMORY_API
virtual void reallocate(SizeType size);
204 FWMEMORY_API
virtual void destroy();
216 FWMEMORY_API
virtual void setBuffer(::fwMemory::BufferManager::BufferType buffer, SizeType size,
217 const ::fwMemory::BufferAllocationPolicy::sptr& policy =
218 ::fwMemory::BufferMallocPolicy::New());
225 FWMEMORY_API
virtual Lock lock();
232 FWMEMORY_API
virtual ConstLock lock()
const;
255 return m_count.use_count();
263 return lockCount() != 0;
282 FWMEMORY_API
void swap(
const BufferObject::sptr& _source );
298 const ::boost::filesystem::path& sourceFile =
"",
299 ::fwMemory::FileFormatType format = ::fwMemory::OTHER,
300 const ::fwMemory::BufferAllocationPolicy::sptr& policy = ::fwMemory::BufferMallocPolicy::New()
305 ::fwMemory::BufferManager::BufferType m_buffer;
309 mutable WeakCounterType m_count;
310 mutable ::fwCore::mt::Mutex m_lockDumpMutex;
313 ::fwMemory::BufferManager::sptr m_bufferManager;
315 ::fwMemory::BufferAllocationPolicy::sptr m_allocPolicy;
bool isEmpty() const
Returns true if the buffer is empty.
SizeType getSize() const
Returns the buffer's size.
Base class for all FW4SPL's classes.
::boost::shared_mutex ReadWriteMutex
Defines a single writer, multiple readers mutex.
The namespace fwMemory contains tools to manage memory. Use for dump.
std::string className() const
return the sub class classname : an alias of this->getClassname
base class for BufferObject Lock
Contains fwAtomsFilter::factory utilities.
LockBase< T >::BufferType getBuffer() const
Returns BufferObject's buffer pointer.
#define fwCoreClassDefinitionsWithFactoryMacro(_classinfo_, _parameters_, _factory_)
Generate common construction methods for classes with one factory.
LockBase()
Build an empty lock.
#define SLM_ASSERT(message, cond)
work like 'assert' from 'cassert', with in addition a message logged by spylog (with FATAL loglevel) ...
void reset()
Release any count on any Buffer the lock may have.
#define fwCoreAllowSharedFromThis()
Generate getSptr and getConstSptr methods.
const ::fwMemory::BufferManager::ConstBufferPtrType getBufferPointer() const
Returns pointer on BufferObject's buffer.
Define Base class for FW4SPL buffers.
long lockCount() const
Returns the number of locks on the BufferObject.
LockBase(const std::shared_ptr< T > &bo)
Build a lock on object 'bo'.
long isLocked() const
Returns true if the buffer has any lock.