fw4spl
fwData::Array Class Reference

Provides a way to manage a view on a multidimentionnal array. More...

#include <Array.hpp>

+ Inheritance diagram for fwData::Array:
+ Collaboration diagram for fwData::Array:

Public Types

typedef std::vector< size_t > SizeType
 Array size type.
 
typedef std::vector< size_t > OffsetType
 Offset type.
 
typedef OffsetType IndexType
 Index type.
 
- Public Types inherited from fwData::Object
typedef ::fwData::factory::Key Key
 
typedef std::string FieldNameType
 
typedef std::vector< FieldNameType > FieldNameVectorType
 
typedef ::std::unordered_map< FieldNameType,::fwData::Object::sptr > FieldMapType
 
typedef ::std::unordered_map< ::fwData::Object::csptr,::fwData::Object::sptr > DeepCopyCacheType
 
typedef ::fwCom::Signal< void() > ModifiedSignalType
 Type of signal m_sigModified.
 
typedef std::map< std::string,::fwData::Object::sptr > FieldsContainerType
 Type of signal m_sigModified.
 
typedef ::fwCom::Signal< void(FieldsContainerType) > AddedFieldsSignalType
 Type of signal when objects are added.
 
typedef ::fwCom::Signal< void(FieldsContainerType, FieldsContainerType) > ChangedFieldsSignalType
 Type of signal when objects are changed (newObjects, oldObjects)
 
typedef ::fwCom::Signal< void(FieldsContainerType) > RemovedFieldsSignalType
 Type of signal when objects are removed.
 
- Public Types inherited from fwCom::HasSignals
typedef std::shared_ptr< HasSignalssptr
 
typedef std::shared_ptr< const HasSignalscsptr
 

Public Member Functions

virtual bool isA (const std::string &type) const override
 
FWDATA_API Array (::fwData::Object::Key key)
 Constructor. More...
 
FWDATA_API void cachedDeepCopy (const Object::csptr &_source, DeepCopyCacheType &cache) override
 Defines deep copy.
 
virtual FWDATA_API size_t resize (const ::fwTools::Type &type, const SizeType &size, size_t nbOfComponents, bool reallocate=false)
 Resizes and allocate (if needed) the array. More...
 
virtual FWDATA_API size_t resize (const std::string &type, const SizeType &size, size_t nbOfComponents, bool reallocate=false)
 Aliases to the resize method.
 
virtual FWDATA_API size_t resize (const SizeType &size, size_t nbOfComponents, bool reallocate=false)
 
virtual FWDATA_API size_t resize (const SizeType &size, bool reallocate=false)
 
virtual FWDATA_API void clear ()
 Clear this array. Size, type, nbOfComponents are reset, buffer is released.
 
virtual FWDATA_API bool empty () const
 Test whether array is empty. More...
 
virtual FWDATA_API size_t getElementSizeInBytes () const
 Get the size of one element of the array, ie. sizeof type * nbOfComponents. More...
 
virtual FWDATA_API size_t getNumberOfElements () const
 Get the number of elements of type <getType()> in the array. More...
 
virtual FWDATA_API size_t getSizeInBytes () const
 Getter for the array view size. More...
 
virtual FWDATA_API const SizeTypegetSize () const
 Getter for the array size. More...
 
virtual FWDATA_API const OffsetTypegetStrides () const
 Getter for the array strides. More...
 
virtual FWDATA_API void setNumberOfComponents (size_t nb)
 Setter for array's number of components If the array has a buffer and owns it, the buffer will be reallocated. More...
 
virtual FWDATA_API size_t getNumberOfComponents () const
 Getter for number of components. More...
 
virtual FWDATA_API size_t getNumberOfDimensions () const
 Getter for number of dimensions, ie. getSize().size() More...
 
virtual FWDATA_API void setIsBufferOwner (const bool own)
 Set array's buffer ownership. More...
 
virtual FWDATA_API bool getIsBufferOwner () const
 Getter for array's buffer ownership. More...
 
virtual FWDATA_API void setType (const std::string &type)
 Setter for array's type. More...
 
virtual FWDATA_API void setType (const ::fwTools::Type &type)
 
virtual FWDATA_API::fwTools::Type getType () const
 Getter for array's type. More...
 
FWDATA_API size_t getBufferOffset (const ::fwData::Array::IndexType &id, size_t component, size_t sizeOfType) const
 Compute offset in buffer for given parameters of type. More...
 
::fwMemory::BufferObject::sptr getBufferObject () const
 
void setBufferObject (const ::fwMemory::BufferObject::sptr &val)
 
FWDATA_API void swap (Array::sptr _source)
 Exchanges the content of the Array with the content of _source.
 
- Public Member Functions inherited from fwData::Object
FWDATA_API::fwData::Object::sptr getField (const FieldNameType &name,::fwData::Object::sptr defaultValue=::fwData::Object::sptr()) const
 Returns a pointer of corresponding field (null if non exist). More...
 
template<typename DATA_TYPE >
std::shared_ptr< DATA_TYPE > getField (const FieldNameType &name) const
 Returns a pointer of corresponding field. More...
 
template<typename DATA_TYPE >
std::shared_ptr< DATA_TYPE > getField (const FieldNameType &name, std::shared_ptr< DATA_TYPE > defaultValue) const
 Returns a pointer of corresponding field. More...
 
template<typename DATA_TYPE >
std::shared_ptr< DATA_TYPE > setDefaultField (const FieldNameType &name, std::shared_ptr< DATA_TYPE > defaultValue)
 Returns a pointer of corresponding field. If field did not exist, it is set to defaultValue if defaultValue is not null. More...
 
FWDATA_API::fwData::Object::csptr getConstField (const FieldNameType &name) const
 Returns a pointer of corresponding field (null if non exist). More...
 
FWDATA_API const FieldMapType & getFields () const
 Returns fields map.
 
FWDATA_API FieldNameVectorType getFieldNames () const
 Returns vector of field names.
 
FWDATA_API void setField (const FieldNameType &name,::fwData::Object::sptr obj)
 Register field with specified name. If the name does already exist, the matching field will be replaced. More...
 
FWDATA_API void setFields (const FieldMapType &fieldMap)
 Replace the field map content.
 
FWDATA_API void removeField (const FieldNameType &name)
 Removes field with specified name. More...
 
virtual FWDATA_API void shallowCopy (const ::fwData::Object::csptr &source)
 A shallow copy of fields (objects in m_children) More...
 
FWDATA_API void deepCopy (const ::fwData::Object::csptr &source)
 Make a deep copy from the source Calling this method may invalidate any DumpLock, RescursiveLock or helper on the object. Prefer using fwData::Object::copy instead.
 
FWDATA_API void fieldShallowCopy (const ::fwData::Object::csptr &source)
 A shallow copy of fields (objects in m_children) More...
 
FWDATA_API void fieldDeepCopy (const ::fwData::Object::csptr &source)
 A deep copy of fields (objects in m_children) More...
 
::fwCore::mt::ReadWriteMutexgetMutex () const
 Returns the object's mutex.
 
- Public Member Functions inherited from fwTools::Object
- Public Member Functions inherited from fwCore::BaseObject
- Public Member Functions inherited from fwCom::HasSignals
std::shared_ptr< SignalBasesignal (const Signals::SignalKeyType &key) const
 
template<typename SignalType >
std::shared_ptr< SignalType > signal (const Signals::SignalKeyType &key) const
 
template<typename SignalType >
std::shared_ptr< SignalType > newSignal (const Signals::SignalKeyType &key)
 

Static Public Member Functions

static bool isTypeOf (const std::string &type)
 
static FWDATA_API OffsetType computeStrides (SizeType size, size_t nbOfComponents, size_t sizeOfType)
 Compute strides for given parameters. More...
 
- Static Public Member Functions inherited from fwData::Object
static bool isTypeOf (const std::string &type)
 
static FWDATA_API::fwData::Object::sptr copy (const ::fwData::Object::csptr &source)
 return a copy of the source. if source is a null pointer, return a null pointer.
 
template<typename DATA_TYPE >
static std::shared_ptr< DATA_TYPE > copy (const std::shared_ptr< const DATA_TYPE > &source)
 return a copy of the source. if source is a null pointer, return a null pointer.
 
template<typename DATA_TYPE >
static std::shared_ptr< DATA_TYPE > copy (const std::shared_ptr< DATA_TYPE > &source)
 return a copy of the source. if source is a null pointer, return a null pointer.
 
static const std::string & classname ()
 return full object's classname with its namespace, i.e. fwCore::BaseObject
 
- Static Public Member Functions inherited from fwTools::Object
static bool isTypeOf (const std::string &type)
 
static const std::string & classname ()
 return full object's classname with its namespace, i.e. fwCore::BaseObject
 
- 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 Member Functions

 Array (const Array &)
 Not implemented.
 
const Arrayoperator= (const Array &)
 
- Protected Member Functions inherited from fwData::Object
FWDATA_API void fieldDeepCopy (const ::fwData::Object::csptr &source, DeepCopyCacheType &cache)
 Internal-use methods to implement Object's deepCopy.
 
virtual FWDATA_API void cachedDeepCopy (const ::fwData::Object::csptr &source, DeepCopyCacheType &cache)=0
 Internal-use methods to implement Object's deepCopy.
 
- Protected Member Functions inherited from fwTools::fwID
FWTOOLS_API bool hasID () const
 Return true if the object has an id set. More...
 
FWTOOLS_API IDType getID (Policy policy=GENERATE) const
 Returns the id of the object. If it is not set and the policy value is. More...
 
virtual FWTOOLS_API void setID (IDType newID)
 Set a newID for the object, (newID must not exist in fwID), the oldest one is released. More...
 
FWTOOLS_API void resetID ()
 Release the id for the object. More...
 
 fwID ()
 Constructor : does nothing.
 
- Protected Member Functions inherited from fwCom::HasSignals
 HasSignals (const HasSignals &)
 Copy constructor forbidden.
 
HasSignalsoperator= (const HasSignals &)
 Copy operator forbidden.
 

Protected Attributes

OffsetType m_strides
 
::fwTools::Type m_type
 
::fwMemory::BufferObject::sptr m_bufferObject
 
SizeType m_size
 
size_t m_nbOfComponents
 
bool m_isBufferOwner
 
- Protected Attributes inherited from fwData::Object
FieldMapType m_fields
 Fields.
 
mutable::fwCore::mt::ReadWriteMutex m_mutex
 Mutex to protect object access.
 
- Protected Attributes inherited from fwTools::Object
std::shared_ptr< ::fwTools::UUIDm_uuid
 UUID used to identify the object, notably for serialization.
 
- Protected Attributes inherited from fwCom::HasSignals
Signals m_signals
 

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
 

Additional Inherited Members

- Static Public Attributes inherited from fwData::Object
static FWDATA_APIconst::fwCom::Signals::SignalKeyType s_MODIFIED_SIG = "modified"
 Key in m_signals map of signal m_sigModified.
 
static FWDATA_APIconst::fwCom::Signals::SignalKeyType s_ADDED_FIELDS_SIG = "addedFields"
 Type of signal m_sigModified.
 
static FWDATA_APIconst::fwCom::Signals::SignalKeyType s_CHANGED_FIELDS_SIG = "changedFields"
 Type of signal m_sigModified.
 
static FWDATA_APIconst::fwCom::Signals::SignalKeyType s_REMOVED_FIELDS_SIG = "removedFields"
 Type of signal m_sigModified.
 
- Protected Types inherited from fwTools::fwID
enum  Policy { EMPTY = 1, GENERATE, MUST_EXIST }
 
typedef std::string IDType
 
- Static Protected Member Functions inherited from fwData::Object
static FWDATA_API::fwData::Object::sptr copy (const ::fwData::Object::csptr &source, DeepCopyCacheType &cache)
 Internal-use methods to implement Object's deepCopy.
 
template<typename DATA_TYPE >
static std::shared_ptr< DATA_TYPE > copy (const std::shared_ptr< const DATA_TYPE > &source, DeepCopyCacheType &cache)
 Internal-use methods to implement Object's deepCopy.
 
template<typename DATA_TYPE >
static std::shared_ptr< DATA_TYPE > copy (const std::shared_ptr< DATA_TYPE > &source, DeepCopyCacheType &cache)
 Internal-use methods to implement Object's deepCopy.
 
- Static Protected Member Functions inherited from fwTools::fwID
static bool isTypeOf (const std::string &type)
 
static FWTOOLS_API bool exist (IDType _id)
 
static FWTOOLS_API std::shared_ptr< ::fwTools::ObjectgetObject (IDType requestID)
 Retrieve the object attached to the given id. Return a null sptr if no correspondence exist. More...
 
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

Provides a way to manage a view on a multidimentionnal array.

If the array own his buffer, it will perform the allocation, reallocation, destruction of the buffer. Else, this class will provide an array "view" of the buffer

Definition at line 32 of file include/fwData/Array.hpp.

Constructor & Destructor Documentation

fwData::Array::Array ( ::fwData::Object::Key  key)

Constructor.

Parameters
keyPrivate construction key

Definition at line 54 of file src/fwData/Array.cpp.

References clear().

+ Here is the call graph for this function:

Member Function Documentation

fwData::Array::OffsetType fwData::Array::computeStrides ( SizeType  size,
size_t  nbOfComponents,
size_t  sizeOfType 
)
static

Compute strides for given parameters.

Parameters
sizeArray size
nbOfComponentsnumber of components
sizeOfTypesize of a component
Returns

Definition at line 38 of file src/fwData/Array.cpp.

Referenced by resize().

+ Here is the caller graph for this function:

bool fwData::Array::empty ( ) const
virtual

Test whether array is empty.

Returns
Returns whether array is empty, ie. this->getSize() is an empty vector.

Definition at line 194 of file src/fwData/Array.cpp.

size_t fwData::Array::getBufferOffset ( const ::fwData::Array::IndexType id,
size_t  component,
size_t  sizeOfType 
) const

Compute offset in buffer for given parameters of type.

Parameters
idItem id
componentItem component id
sizeOfTypesize of a component
Returns
buffer offset

Definition at line 305 of file src/fwData/Array.cpp.

References OSLM_ASSERT.

size_t fwData::Array::getElementSizeInBytes ( ) const
virtual

Get the size of one element of the array, ie. sizeof type * nbOfComponents.

Returns
One array elemet size in bytes.

Definition at line 201 of file src/fwData/Array.cpp.

References fwTools::Type::sizeOf().

+ Here is the call graph for this function:

bool fwData::Array::getIsBufferOwner ( ) const
virtual

Getter for array's buffer ownership.

Returns
Current array buffer ownership

Definition at line 271 of file src/fwData/Array.cpp.

size_t fwData::Array::getNumberOfComponents ( ) const
virtual

Getter for number of components.

Returns
Array's number of components

Definition at line 250 of file src/fwData/Array.cpp.

size_t fwData::Array::getNumberOfDimensions ( ) const
virtual

Getter for number of dimensions, ie. getSize().size()

Returns
Array's number of dimensions

Definition at line 257 of file src/fwData/Array.cpp.

size_t fwData::Array::getNumberOfElements ( ) const
virtual

Get the number of elements of type <getType()> in the array.

Returns
number of array elements

Definition at line 208 of file src/fwData/Array.cpp.

const ::fwData::Array::SizeType & fwData::Array::getSize ( ) const
virtual

Getter for the array size.

Returns
vector of size lengths in each dimension

Definition at line 223 of file src/fwData/Array.cpp.

size_t fwData::Array::getSizeInBytes ( ) const
virtual

Getter for the array view size.

Returns
Array view size in bytes.

Definition at line 215 of file src/fwData/Array.cpp.

References fwTools::Type::sizeOf().

+ Here is the call graph for this function:

const ::fwData::Array::OffsetType & fwData::Array::getStrides ( ) const
virtual

Getter for the array strides.

Returns
vector of steps in each dimension for array walking

Definition at line 230 of file src/fwData/Array.cpp.

fwTools::Type fwData::Array::getType ( ) const
virtual

Getter for array's type.

Returns
Type of array

Definition at line 298 of file src/fwData/Array.cpp.

size_t fwData::Array::resize ( const ::fwTools::Type type,
const SizeType size,
size_t  nbOfComponents,
bool  reallocate = false 
)
virtual

Resizes and allocate (if needed) the array.

If no buffer is allocated and reallocate is true, this method will allocate a buffer and take it ownership.

If the combination of type, size and components parameters do not match anymore the size of the previously allocated buffer, a reallocation is needed. In this case :

  • if reallocate is true and if the Array do not own the buffer, an exception is thrown
  • else if reallocate is false, the array will update the view informations
  • else, the reallocation is performed.
Parameters
typeType of the array view
sizeSize of the array view
nbOfComponentsNumber of components of the array view, Min value : 1
reallocateIf true, allow buffer reallocation
Returns
return the size of the array view
Exceptions
fwData::Exception

Definition at line 117 of file src/fwData/Array.cpp.

References computeStrides().

Referenced by cachedDeepCopy(), resize(), setNumberOfComponents(), and setType().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void fwData::Array::setIsBufferOwner ( const bool  own)
virtual

Set array's buffer ownership.

Parameters
ownNew ownership value

Definition at line 264 of file src/fwData/Array.cpp.

void fwData::Array::setNumberOfComponents ( size_t  nb)
virtual

Setter for array's number of components If the array has a buffer and owns it, the buffer will be reallocated.

Parameters
nbnumber of components

Definition at line 237 of file src/fwData/Array.cpp.

References resize().

+ Here is the call graph for this function:

void fwData::Array::setType ( const std::string &  type)
virtual

Setter for array's type.

Parameters
typenew array type

Definition at line 278 of file src/fwData/Array.cpp.

References resize().

+ Here is the call graph for this function:


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