ADTF
Loading...
Searching...
No Matches
cMemoryPtr

#include <memoryptr.h>

Classes

class  cMemoryPtrPrivate
 

Public Member Functions

 cMemoryPtr ()
 Default constructor.
 
 cMemoryPtr (tVoid *pvData, tSize nSize)
 Constructor for presetting the assigned buffer.
 
 cMemoryPtr (const cMemoryPtr &oMemObject)
 Copy constructor.
 
tBool IsReference ()
 Check whether the object owns its memory or is attached to an external buffer.
 
tResult Attach (tVoid *pvData, tSize nSize)
 Attaches the object to an external buffer.
 
tResult Attach (const cMemoryPtr &oMemObject)
 Attches the object to an external buffer.
 
tResult Detach ()
 Detaches the object from an external buffer.
 
virtual ~cMemoryPtr ()
 Destructor.
 
tVoid Free ()
 Frees all allocated memory and detaches from external buffers.
 
tResult Alloc (tSize nDataSize)
 Allocates memory.
 
tResult Assign (const tVoid *pvData, tSize nDataSize)
 Copies external data to a newly allocated buffer.
 
tResult Assign (const cMemoryPtr &oMemObject)
 Copies external data to a newly allocated buffer.
 
tResult CopyTo (tVoid *pvBuffer, tSize nBufferSize)
 Copies data to an external buffer.
 
const tVoidGetPtr () const
 Get a pointer to the data.
 
tVoidGetWritePtr () const
 Get a pointer to the data.
 
tSize GetSize () const
 Get the size of the memory region.
 
tUInt Ref ()
 Increase reference counter.
 
tUInt Unref ()
 Decrease reference counter.
 
tVoid Destroy ()
 Destroys the object and frees all allocated resources.
 
 operator const tVoid * () const
 Returns a pointer to the data.
 
tVoidoperator= (const cMemoryPtr &oMemObject)
 Copies data.
 
tBool operator== (tVoid *pvData) const
 Checks whether an object handles a memory region.
 

Protected Attributes

tUInt m_nReferenceCounter
 Reference counter.
 
tVoidm_pvData
 Pointer to data.
 
tSize m_nDataSize
 Size of data.
 
tBool m_bReference
 Is reference.
 

Detailed Description

Definition at line 21 of file memoryptr.h.

Constructor & Destructor Documentation

◆ cMemoryPtr() [1/3]

cMemoryPtr ( )
inline

Default constructor.

Definition at line 47 of file memoryptr.h.

References m_bReference, m_nDataSize, m_nReferenceCounter, m_pvData, and tFalse.

Referenced by cMemoryPtr(), Assign(), Attach(), and operator=().

◆ cMemoryPtr() [2/3]

cMemoryPtr ( tVoid * pvData,
tSize nSize )
inline

Constructor for presetting the assigned buffer.

The data is copied to a new buffer.

Parameters
pvData[in] The buffer.
nSize[in] The size of the buffer.

Definition at line 63 of file memoryptr.h.

References Assign(), m_bReference, m_nDataSize, m_nReferenceCounter, m_pvData, and tFalse.

◆ cMemoryPtr() [3/3]

cMemoryPtr ( const cMemoryPtr & oMemObject)
inline

Copy constructor.

Parameters
oMemObject[in] The object to copy from.

Definition at line 79 of file memoryptr.h.

References cMemoryPtr(), Assign(), m_bReference, m_nDataSize, m_nReferenceCounter, m_pvData, and tFalse.

◆ ~cMemoryPtr()

virtual ~cMemoryPtr ( )
inlinevirtual

Destructor.

Definition at line 150 of file memoryptr.h.

References Free().

Member Function Documentation

◆ Alloc()

tResult Alloc ( tSize nDataSize)
inline

Allocates memory.

Parameters
nDataSize[in] The amount of memory in bytes.
Returns
ERR_NOERROR if successfull.
ERR_INVALID_ARG if datasize is less than 1
ERR_MEMORY if buffer could not be allocated

Definition at line 176 of file memoryptr.h.

References Free(), m_nDataSize, m_pvData, A_UTILS_NS::MEMPTR_WRONG_SIZE_PARAM_MASK, RETURN_ERROR, and RETURN_NOERROR.

Referenced by Assign().

◆ Assign() [1/2]

tResult Assign ( const cMemoryPtr & oMemObject)
inline

Copies external data to a newly allocated buffer.

Parameters
oMemObject[in] The data to copy.
Returns
ERR_NOERROR if successfull
ERR_POINTER if data pointer of oMemObject is nullptr.
ERR_INVALID_ARG if datasize of oMemObject is less than 1

Definition at line 226 of file memoryptr.h.

References cMemoryPtr(), Assign(), m_nDataSize, and m_pvData.

◆ Assign() [2/2]

tResult Assign ( const tVoid * pvData,
tSize nDataSize )
inline

Copies external data to a newly allocated buffer.

Parameters
pvData[in] The data to copy.
nDataSize[in] The size of the data.
Returns
ERR_NOERROR if successfull
ERR_POINTER if pvData is nullptr.
ERR_INVALID_ARG if nDataSize is less than 1

Definition at line 209 of file memoryptr.h.

References Alloc(), m_pvData, cMemoryBlock::MemCopy(), RETURN_IF_FAILED, RETURN_IF_POINTER_NULL, and RETURN_NOERROR.

Referenced by cMemoryPtr(), cMemoryPtr(), Assign(), and operator=().

◆ Attach() [1/2]

tResult Attach ( const cMemoryPtr & oMemObject)
inline

Attches the object to an external buffer.

Parameters
oMemObject[in] The external buffer.
Returns
ERR_NOERROR if arguments are ok.
ERR_INVALID_ARG if data of oMemObject is nullptr and datasize of oMemObject is not zero or if data of oMemObject is not nullptr but datasize of oMemObject is zero or less

Definition at line 129 of file memoryptr.h.

References cMemoryPtr(), Attach(), m_nDataSize, and m_pvData.

◆ Attach() [2/2]

tResult Attach ( tVoid * pvData,
tSize nSize )
inline

Attaches the object to an external buffer.

Parameters
pvData[in] The buffer.
nSize[in] The size of the buffer.
Returns
ERR_NOERROR if arguments are ok.
ERR_INVALID_ARG if pvData is nullptr or nSize zero or less

Definition at line 108 of file memoryptr.h.

References Free(), m_bReference, m_nDataSize, m_pvData, A_UTILS_NS::MEMPTR_WRONG_SIZE_PARAM_MASK, RETURN_ERROR, RETURN_NOERROR, and tTrue.

Referenced by Attach().

◆ CopyTo()

tResult CopyTo ( tVoid * pvBuffer,
tSize nBufferSize )
inline

Copies data to an external buffer.

Parameters
pvBuffer[in] The destintion buffer.
nBufferSize[in] The amount of bytes to copy.
Returns
ERR_NOERROR if successfull.
ERR_POINTER if pvBuffer is nullptr
ERR_NOT_INITIALIZED if
This method is real-time safe.\nSee @ref page_real_time_safe.\n

Definition at line 240 of file memoryptr.h.

References m_nDataSize, m_pvData, cMemoryBlock::MemCopy(), A_UTILS_NS::MEMPTR_WRONG_SIZE_PARAM_MASK, RETURN_ERROR, RETURN_IF_POINTER_NULL, and RETURN_NOERROR.

◆ Destroy()

tVoid Destroy ( )
inline

Destroys the object and frees all allocated resources.

Definition at line 322 of file memoryptr.h.

References Free().

Referenced by Unref().

◆ Detach()

tResult Detach ( )
inline

Detaches the object from an external buffer.

Returns
Standard Result Code.

Definition at line 138 of file memoryptr.h.

References Free(), and RETURN_NOERROR.

◆ Free()

tVoid Free ( )
inline

Frees all allocated memory and detaches from external buffers.

Definition at line 158 of file memoryptr.h.

References m_bReference, m_nDataSize, m_pvData, and tFalse.

Referenced by ~cMemoryPtr(), Alloc(), Attach(), Destroy(), and Detach().

◆ GetPtr()

const tVoid * GetPtr ( ) const
inline

Get a pointer to the data.

Returns
A pointer to the data.
This method is real-time safe.\nSee @ref page_real_time_safe.\n

Definition at line 263 of file memoryptr.h.

References m_pvData.

◆ GetSize()

tSize GetSize ( ) const
inline

Get the size of the memory region.

Returns
The size of the memory region.
This method is real-time safe.\nSee @ref page_real_time_safe.\n

Definition at line 283 of file memoryptr.h.

References m_nDataSize.

◆ GetWritePtr()

tVoid * GetWritePtr ( ) const
inline

Get a pointer to the data.

Returns
A pointer to the data.
This method is real-time safe.\nSee @ref page_real_time_safe.\n

Definition at line 273 of file memoryptr.h.

References m_pvData.

◆ IsReference()

tBool IsReference ( )
inline

Check whether the object owns its memory or is attached to an external buffer.

Returns
tTrue if it is attached to an external buffer, otherwise tFalse.
This method is real-time safe.\nSee @ref page_real_time_safe.\n

Definition at line 96 of file memoryptr.h.

References m_bReference.

◆ operator const tVoid *()

operator const tVoid * ( ) const
inline

Returns a pointer to the data.

This method is real-time safe.\nSee @ref page_real_time_safe.\n

Definition at line 334 of file memoryptr.h.

References m_pvData.

◆ operator=()

tVoid * operator= ( const cMemoryPtr & oMemObject)
inline

Copies data.

Definition at line 342 of file memoryptr.h.

References cMemoryPtr(), Assign(), m_nDataSize, and m_pvData.

◆ operator==()

tBool operator== ( tVoid * pvData) const
inline

Checks whether an object handles a memory region.

Parameters
pvDataThe memory region.
Returns
tTrue if it handles the region, tFalse otherwise.
This method is real-time safe.\nSee @ref page_real_time_safe.\n

Definition at line 355 of file memoryptr.h.

References m_pvData.

◆ Ref()

tUInt Ref ( )
inline

Increase reference counter.

Returns
The new reference count.

Definition at line 293 of file memoryptr.h.

References m_nReferenceCounter.

◆ Unref()

tUInt Unref ( )
inline

Decrease reference counter.

Returns
The new reference count.

Definition at line 302 of file memoryptr.h.

References Destroy(), and m_nReferenceCounter.

Member Data Documentation

◆ m_bReference

tBool m_bReference
protected

Is reference.

Definition at line 41 of file memoryptr.h.

Referenced by cMemoryPtr(), cMemoryPtr(), cMemoryPtr(), Attach(), Free(), and IsReference().

◆ m_nDataSize

tSize m_nDataSize
protected

Size of data.

Definition at line 40 of file memoryptr.h.

Referenced by cMemoryPtr(), cMemoryPtr(), cMemoryPtr(), Alloc(), Assign(), Attach(), Attach(), CopyTo(), Free(), GetSize(), and operator=().

◆ m_nReferenceCounter

tUInt m_nReferenceCounter
protected

Reference counter.

Definition at line 38 of file memoryptr.h.

Referenced by cMemoryPtr(), cMemoryPtr(), cMemoryPtr(), Ref(), and Unref().

◆ m_pvData

tVoid* m_pvData
protected