Design Pattern Examples
Overview of object-oriented design patterns
DataReaderWriter Class Reference

Represents a data reader/writer to a caller. More...

#include <Adapter_FrontEndClass.h>

Collaboration diagram for DataReaderWriter:
Collaboration graph

Public Types

enum  MemoryBlockNumber { Memory_Block_0 = 0 , Memory_Block_1 = 1 , Memory_Block_2 = 2 }
 Represents the memory blocks that can be accessed. Hides how memory blocks are actually identified. More...
 

Public Member Functions

 DataReaderWriter (MemoryBlockNumber blockNumber)
 Constructor.
 
 ~DataReaderWriter ()
 Destructor.
 
uint32_t GetMemoryBlockByteSize ()
 Retrieve the size of the currently opened memory block in bytes.
 
ByteArray Read (int byteOffset, uint32_t maxBytes)
 Read a specified number of bytes.
 
void Write (int byteOffset, const ByteArray &data, uint32_t maxBytes)
 Write a specified number of bytes.
 
std::string BufferToString (const ByteArray &data, uint32_t maxBytes, int indent)
 Convert the specified data up to the specified number of bytes into a string by performing a "hex dump" on the data.
 

Private Member Functions

const char * _GetBlockNameForBlockNumber (DataReaderWriter::MemoryBlockNumber blockNumber)
 Given a block number, retrieve the corresponding block name.
 

Private Attributes

bool _initialized
 
int _dataHandle
 
uint32_t _memoryBlockByteSize
 

Detailed Description

Represents a data reader/writer to a caller.

Wraps the Adapter_BackEnd dynamic library.

Definition at line 73 of file Adapter_FrontEndClass.h.

Member Enumeration Documentation

◆ MemoryBlockNumber

Represents the memory blocks that can be accessed. Hides how memory blocks are actually identified.

Enumerator
Memory_Block_0 

First block.

Memory_Block_1 

Second block.

Memory_Block_2 

Third block.

Definition at line 80 of file Adapter_FrontEndClass.h.

Constructor & Destructor Documentation

◆ DataReaderWriter()

Constructor.

Parameters
blockNumberA value from the MemoryBlockNumber enumeration indicating which memory block to access.

Definition at line 118 of file Adapter_FrontEndClass.cpp.

References DataReaderWriter::_dataHandle, DataReaderWriter::_GetBlockNameForBlockNumber(), DataReaderWriter::_initialized, DataReaderWriter::_memoryBlockByteSize, DDR_ErrorCode_Success, DDR_GetMemorySize(), and DDR_OpenMemoryBlock().

◆ ~DataReaderWriter()

Member Function Documentation

◆ _GetBlockNameForBlockNumber()

const char * _GetBlockNameForBlockNumber ( DataReaderWriter::MemoryBlockNumber  blockNumber)
private

Given a block number, retrieve the corresponding block name.

Parameters
blockNumberA value from the MemoryBlockNumber enumeration indicating the block of memory to open.
Returns
Returns a pointer to the block name if the block number is recognized; otherwise returns NULL.

Definition at line 89 of file Adapter_FrontEndClass.cpp.

References BLOCK_NAME_0, BLOCK_NAME_1, BLOCK_NAME_2, DataReaderWriter::Memory_Block_0, DataReaderWriter::Memory_Block_1, and DataReaderWriter::Memory_Block_2.

Referenced by DataReaderWriter::__enter__(), and DataReaderWriter::DataReaderWriter().

◆ BufferToString()

std::string BufferToString ( const ByteArray data,
uint32_t  maxBytes,
int  indent 
)

Convert the specified data up to the specified number of bytes into a string by performing a "hex dump" on the data.

Parameters
dataThe data to process.
maxBytesThe number of bytes from the data to process.
indentNumber of spaces to indent each line.
Returns
A string containing the data in the form of a hex dump, possibly multiple lines.

Definition at line 313 of file Adapter_FrontEndClass.cpp.

References Helpers::formatstring().

Referenced by DesignPatternExamples_cpp::Adapter_Exercise().

◆ GetMemoryBlockByteSize()

uint32_t GetMemoryBlockByteSize ( )

Retrieve the size of the currently opened memory block in bytes.

Returns
The size of memory block in bytes.

Definition at line 164 of file Adapter_FrontEndClass.cpp.

References DataReaderWriter::_initialized, and DataReaderWriter::_memoryBlockByteSize.

Referenced by DesignPatternExamples_cpp::Adapter_Exercise().

◆ Read()

ByteArray Read ( int  byteOffset,
uint32_t  maxBytes 
)

Read a specified number of bytes.

Parameters
byteOffsetByte offset into the memory block from which to start reading.
maxBytesNumber of bytes to read
Returns
An array of bytes that were read.
Exceptions
DataReaderWriterInitExceptionData reader/writer not initialized.
DataReaderWriterExceptionFailed to read data.

Definition at line 172 of file Adapter_FrontEndClass.cpp.

References DataReaderWriter::_dataHandle, DataReaderWriter::_initialized, DDR_ErrorCode_Success, DDR_GetDataChunk(), and DDR_MAX_OFFSET.

Referenced by DesignPatternExamples_cpp::Adapter_Exercise().

◆ Write()

void Write ( int  byteOffset,
const ByteArray data,
uint32_t  maxBytes 
)

Write a specified number of bytes.

Parameters
byteOffsetByte offset into the memory block to which to start writing.
dataArray of bytes to write. Must be at least 'maxBytes' in length.
maxBytesNumber of bytes to write
Exceptions
DataReaderWriterInitExceptionData reader/writer not initialized.
DataReaderWriterExceptionFailed to write data.

Definition at line 236 of file Adapter_FrontEndClass.cpp.

References DataReaderWriter::_dataHandle, DataReaderWriter::_initialized, DDR_ErrorCode_Success, DDR_GetDataChunk(), DDR_MAX_OFFSET, and DDR_SetDataChunk().

Referenced by DesignPatternExamples_cpp::Adapter_Exercise().

Member Data Documentation

◆ _dataHandle

◆ _initialized

◆ _memoryBlockByteSize


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