MemoryAccessor 1
A command-line front-end for exploring virtual memory of a linux process by accessing /proc/PID/mem file.
Loading...
Searching...
No Matches
Console Class Reference

A class to perform CLI. More...

#include <console.h>

Public Member Functions

 Console (MemoryAccessor &memory_accessor, HexViewer &hex_viewer, Tools &tools) noexcept(false)
 Constructor.
 
 Console (const Console &origin)=delete
 Copy constructor (deleted).
 
 Console (Console &&origin)=delete
 Move constructor (deleted).
 
Consoleoperator= (const Console &origin)=delete
 Copy-assignment operator (deleted).
 
Consoleoperator= (Console &&origin)=delete
 Move-assignment operator (deleted).
 
 ~Console () noexcept
 Destructor.
 
void SetBufferSize (const size_t &buffer_size)
 Set buffer size of an instance.
 
void PrintNameVer () const noexcept
 Print project name and version.
 
void Start () noexcept
 Start the console.
 
void ReadStdin () noexcept
 Read and process input from stdin.
 
void HandleCommand (const std::string &line) noexcept
 Handle line with command.
 

Public Attributes

const std::string kProjectName {"MemoryAccessor"}
 Name of the project.
 
const std::string kProjectVersion {"v1.0"}
 Project version.
 
const std::string kProjectDescription
 Project description.
 
const std::string kConsolePrefix
 Prefix shown in console input.
 
MemoryAccessormemory_accessor_
 A reference to a MemoryAccessor class instance.
 
HexViewerhex_viewer_
 A reference to a HexViewer class instance.
 
Toolstools_
 A reference to a Tools class instance.
 
const Command kCommands [kCommandsNumber]
 Definitions of commands.
 

Static Public Attributes

static constexpr int kCommandsNumber
 Number of the commands available.
 

Detailed Description

A class to perform CLI.

The class provides commandline interface to interract with MemoryAccessor effectively. It can handle various commands with arguments. The class can either execute a command as a std::string or read a command from stdin. Moving, copying and creating more than 1 instance of the class is prohibited.

Constructor & Destructor Documentation

◆ Console() [1/3]

Console::Console ( MemoryAccessor & memory_accessor,
HexViewer & hex_viewer,
Tools & tools )
explicit

Constructor.

Parameters
[in,out]memory_accessorA reference to an instance of MemoryAccessor class.
[in,out]hex_viewerA reference to an instance of HexViewer class.
[in,out]toolsA reference to an instance of Tools struct.
Exceptions
std::logic_errorIf an instance of the class have already been created and it is a second instance.

Initializes MemoryAccessor class, HexViewer class and Tools struct references by values got as parameters. Throws an exception if an instance of the class have already been created. Sets one_instance_created_ to true.

◆ Console() [2/3]

Console::Console ( const Console & origin)
delete

Copy constructor (deleted).

Parameters
[in]originConsole instance to copy from.

Create a new object by copying an old one. Prohibited.

◆ Console() [3/3]

Console::Console ( Console && origin)
delete

Move constructor (deleted).

Parameters
[in]originMoved Console object.

Create a new object by moving an old one. Prohibited.

◆ ~Console()

Console::~Console ( )
noexcept

Destructor.

Deletes SIGINT handler attach if it is set to memoryaccessor_console_src::CtrlC, sets variables current_console_p to nullptr, rl_attempted_completion_function to nullptr and one_instance_created_ to false.

Member Function Documentation

◆ HandleCommand()

void Console::HandleCommand ( const std::string & line)
noexcept

Handle line with command.

Parameters
[in]lineLine containing the command.f

Parse and execute the given line containing the command.

◆ operator=() [1/2]

Console & Console::operator= ( Console && origin)
delete

Move-assignment operator (deleted).

Parameters
[in]originMoved Console object.

Assign an object by moving other object. Prohibited.

◆ operator=() [2/2]

Console & Console::operator= ( const Console & origin)
delete

Copy-assignment operator (deleted).

Parameters
[in]originConsole instance to copy from.

Assign an object by copying other object. Prohibited.

◆ PrintNameVer()

void Console::PrintNameVer ( ) const
noexcept

Print project name and version.

Print project name and version to stdout.

◆ ReadStdin()

void Console::ReadStdin ( )
noexcept

Read and process input from stdin.

Print prefix of a console, read input and process it (add line to history and handle command). If Ctrl-D is pressed, print "Quit" and exit the program with the code 0.

◆ SetBufferSize()

void Console::SetBufferSize ( const size_t & buffer_size)
inline

Set buffer size of an instance.

Parameters
[in]buffer_sizeDesired buffer size in bytes.

Set buffer size, a number of bytes that are allocated when needed.

◆ Start()

void Console::Start ( )
noexcept

Start the console.

Try to set handler for SIGINT, set memoryaccessor_console_src::current_console_p, rl_attempted_completion_function and print greeting message to stdout.

Member Data Documentation

◆ kCommandsNumber

int Console::kCommandsNumber
staticconstexpr
Initial value:
{
9}

Number of the commands available.

◆ kConsolePrefix

const std::string Console::kConsolePrefix
Initial value:
{
"(MemAcc)"}

Prefix shown in console input.

◆ kProjectDescription

const std::string Console::kProjectDescription
Initial value:
{
"A command-line front-end for exploring virtual memory of a linux "
"process "
"by accessing /proc/PID/mem file."}

Project description.


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