fw4spl
fwMemory::BufferObject Class Reference

Define Base class for FW4SPL buffers. More...

#include <BufferObject.hpp>

+ Inheritance diagram for fwMemory::BufferObject:
+ Collaboration diagram for fwMemory::BufferObject:

Classes

class  LockBase
 base class for BufferObject Lock More...
 

Public Types

typedef std::shared_ptr< void > CounterType
 
typedef std::weak_ptr< void > WeakCounterType
 
typedef size_t SizeType
 
Locks

Locks types

typedef LockBase< BufferObjectLock
 
typedef LockBase< const BufferObjectConstLock
 

Public Member Functions

virtual bool isA (const std::string &type) const override
 
std::string className () const
 return the sub class classname : an alias of this->getClassname
 
virtual ::fwMemory::BufferManager::BufferType getBuffer () const
 
FWMEMORY_API BufferObject ()
 BufferObject constructor. More...
 
virtual FWMEMORY_API ~BufferObject ()
 BufferObject destructor. More...
 
virtual FWMEMORY_API void allocate (SizeType size, const ::fwMemory::BufferAllocationPolicy::sptr &policy=::fwMemory::BufferMallocPolicy::New())
 Buffer allocation. More...
 
virtual FWMEMORY_API void reallocate (SizeType size)
 Buffer reallocation. More...
 
virtual FWMEMORY_API void destroy ()
 Buffer deallocation. More...
 
virtual FWMEMORY_API void setBuffer (::fwMemory::BufferManager::BufferType buffer, SizeType size, const ::fwMemory::BufferAllocationPolicy::sptr &policy=::fwMemory::BufferMallocPolicy::New())
 Buffer setter. More...
 
virtual FWMEMORY_API Lock lock ()
 Return a lock on the BufferObject. More...
 
virtual FWMEMORY_API ConstLock lock () const
 Return a const lock on the BufferObject. More...
 
SizeType getSize () const
 Returns the buffer's size.
 
bool isEmpty () const
 Returns true if the buffer is empty.
 
long lockCount () const
 Returns the number of locks on the BufferObject.
 
long isLocked () const
 Returns true if the buffer has any lock.
 
const ::fwMemory::BufferManager::ConstBufferPtrType getBufferPointer () const
 Returns pointer on BufferObject's buffer.
 
::fwCore::mt::ReadWriteMutexgetMutex ()
 
FWMEMORY_API void swap (const BufferObject::sptr &_source)
 Exchanges the content of the BufferObject with the content of _source.
 
FWMEMORY_API BufferManager::StreamInfo getStreamInfo () const
 
FWMEMORY_API void setIStreamFactory (const std::shared_ptr< ::fwMemory::stream::in::IFactory > &factory, SizeType size, const ::boost::filesystem::path &sourceFile="",::fwMemory::FileFormatType format=::fwMemory::OTHER, const ::fwMemory::BufferAllocationPolicy::sptr &policy=::fwMemory::BufferMallocPolicy::New())
 Set a stream factory for the buffer manager The factory will be used to load data on demand by the buffer manager. More...
 
- Public Member Functions inherited from fwCore::BaseObject

Static Public Member Functions

static bool isTypeOf (const std::string &type)
 
- Static Public Member Functions inherited from fwCore::BaseObject
static bool isTypeOf (const std::string &type)
 
static const std::string & leafClassname ()
 return object's classname without its namespace, i.e. BaseObject
 
static const std::string & classname ()
 return object's classname without its namespace, i.e. BaseObject
 

Protected Attributes

::fwMemory::BufferManager::BufferType m_buffer
 
SizeType m_size
 
WeakCounterType m_count
 
mutable::fwCore::mt::Mutex m_lockDumpMutex
 
::fwCore::mt::ReadWriteMutex m_mutex
 
::fwMemory::BufferManager::sptr m_bufferManager
 
::fwMemory::BufferAllocationPolicy::sptr m_allocPolicy
 

Friends

template<class , class , class >
class ::fwTools::ClassFactory
 
class ::fwTools::Factory
 

Demangling methods

virtual const std::string & getLeafClassname () const override
 return object's classname without its namespace, i.e. BaseObject
 
virtual const std::string & getClassname () const override
 return full object's classname with its namespace, i.e. fwCore::BaseObject
 
static const std::string & leafClassname ()
 return object's classname without its namespace, i.e. BaseObject
 
static const std::string & classname ()
 return object's classname without its namespace, i.e. BaseObject
 

Detailed Description

Define Base class for FW4SPL buffers.

Keep a pointer to a buffer and it's allocation policy (new malloc) without any cleverness about allocating/destroying the buffer. Users of this class needs to take care about allocation and destruction by themselves.

BufferObject class has a BufferManager and Locks mechanism, Allowing to trigger special treatments on various events on BufferObjects (allocation, reallocation, destruction, swapping, locking, unlocking) and allowing to give some guarantees.

Users of buffer have to keep a lock on a BufferObject when dealing with the buffers content. Keeping a lock on a BufferObject guarantees that the buffer will not be changed or modified by the BufferManager mechanism. A lock DO NOT GARANTEE that an other user of this buffer object are not changing/modifying the buffer.

Definition at line 51 of file BufferObject.hpp.

Constructor & Destructor Documentation

fwMemory::BufferObject::BufferObject ( )

BufferObject constructor.

Register the buffer to an existing buffer manager.

Definition at line 21 of file BufferObject.cpp.

fwMemory::BufferObject::~BufferObject ( )
virtual

BufferObject destructor.

unregister the buffer from the buffer manager.

Definition at line 32 of file BufferObject.cpp.

Member Function Documentation

void fwMemory::BufferObject::allocate ( SizeType  size,
const ::fwMemory::BufferAllocationPolicy::sptr &  policy = ::fwMemory::BufferMallocPolicy::New() 
)
virtual

Buffer allocation.

Allocate a buffer using given policy. The allocation may have been hooked by the buffer manager.

Parameters
sizenumber of bytes to allocate
policyBuffer allocation policy, default is Malloc policy

Definition at line 41 of file BufferObject.cpp.

void fwMemory::BufferObject::destroy ( )
virtual

Buffer deallocation.

Destroy the buffer using the associated policy. The destruction may have been hooked by the buffer manager.

Definition at line 58 of file BufferObject.cpp.

BufferObject::Lock fwMemory::BufferObject::lock ( )
virtual

Return a lock on the BufferObject.

Returns
Lock on the BufferObject

Definition at line 77 of file BufferObject.cpp.

BufferObject::ConstLock fwMemory::BufferObject::lock ( ) const
virtual

Return a const lock on the BufferObject.

Returns
ConstLock on the BufferObject

Definition at line 84 of file BufferObject.cpp.

void fwMemory::BufferObject::reallocate ( SizeType  size)
virtual

Buffer reallocation.

Reallocate the buffer using the associated policy. A policy may not handle reallocation. The reallocation may have been hooked by the buffer manager.

Parameters
sizeNew buffer size

Definition at line 50 of file BufferObject.cpp.

void fwMemory::BufferObject::setBuffer ( ::fwMemory::BufferManager::BufferType  buffer,
SizeType  size,
const ::fwMemory::BufferAllocationPolicy::sptr &  policy = ::fwMemory::BufferMallocPolicy::New() 
)
virtual

Buffer setter.

Set the buffer from an existing one.

Parameters
bufferExternal Buffer
sizeBuffer's size
policyExternal buffer allocation policy, default is Malloc policy

Definition at line 67 of file BufferObject.cpp.

void fwMemory::BufferObject::setIStreamFactory ( const std::shared_ptr< ::fwMemory::stream::in::IFactory > &  factory,
SizeType  size,
const ::boost::filesystem::path &  sourceFile = "",
::fwMemory::FileFormatType  format = ::fwMemory::OTHER,
const ::fwMemory::BufferAllocationPolicy::sptr &  policy = ::fwMemory::BufferMallocPolicy::New() 
)

Set a stream factory for the buffer manager The factory will be used to load data on demand by the buffer manager.

Parameters
factoryfwMemory::stream::in::IFactory stream factory
sizesize of data provided by the stream
sourceFileFilesystem path of the source file, if applicable
formatfile format (RAW,RAWZ,OTHER), if sourceFile is provided
policyBuffer allocation policy

Definition at line 109 of file BufferObject.cpp.


The documentation for this class was generated from the following files: