25 std::cout << std::endl;
26 std::cout <<
"Adapter Exercise" << std::endl;
33 std::vector<uint8_t> readData = dataReaderWriter.
Read(0, memoryBlockSize);
34 std::string dataDump =
36 std::cout <<
" Initial memory block contents:" << std::endl;
37 std::cout << dataDump << std::endl;
40 uint32_t dataSize = 16;
42 std::vector<uint8_t> writeData(dataSize);
43 for (uint32_t index = 0; index < dataSize; ++index)
45 writeData[index] =
static_cast<uint8_t
>(index+1);
49 dataDump = dataReaderWriter.
BufferToString(writeData, dataSize, 2);
50 std::cout <<
" Data to be written to memory block:" << std::endl;
51 std::cout << dataDump << std::endl;
53 std::cout <<
" Writing data to byte offset " << byteOffset <<
"..." << std::endl;
55 dataReaderWriter.
Write(byteOffset, writeData, dataSize);
57 std::cout <<
" Reading back the memory block..." << std::endl;
59 readData = dataReaderWriter.
Read(0, memoryBlockSize);
60 std::cout << std::endl;
63 dataDump = dataReaderWriter.
BufferToString(readData, memoryBlockSize, 2);
64 std::cout <<
" Current memory block contents:" << std::endl;
65 std::cout << dataDump << std::endl;
69 std::cout <<
"Error with startup or shutdown! " << e.
what()
74 std::cout <<
"Error with reading or writing! " << e.
what()
78 std::cout <<
" Done." << std::endl;
Declaration of the DataReaderWriter class used in the Adapter Pattern.
Represents an error that occurred when reading or writing data in the Data reader/writer.
Represents a data reader/writer to a caller.
uint32_t GetMemoryBlockByteSize()
Retrieve the size of the currently opened memory block in 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 dum...
void Write(int byteOffset, const ByteArray &data, uint32_t maxBytes)
Write a specified number of bytes.
ByteArray Read(int byteOffset, uint32_t maxBytes)
Read a specified number of bytes.
@ Memory_Block_0
First block.
Represents an error that occurred during initialization or shut down of the Data reader/writer.
const char * what()
Override exception::what() to return the message we are tracking.
Declaration of the Adapter_Exercise() function as used in the Adapter Pattern.
The namespace containing all Design Pattern Examples implemented in C++.
void Adapter_Exercise()
Example of using the Adapter Pattern.