My Project
Public Member Functions | Public Attributes | Private Attributes | Friends | List of all members
uuid::console::CommandLine Class Reference

Representation of a command line, with parameters separated by spaces and an optional trailing space. More...

#include <uuid/console.h>

Collaboration diagram for uuid::console::CommandLine:
Collaboration graph
[legend]

Public Member Functions

 CommandLine ()=default
 Create an empty command line. More...
 
 CommandLine (const std::string &line)
 Parse a command line into separate parameters using built-in escaping rules. More...
 
 CommandLine (std::initializer_list< const std::vector< std::string >> arguments)
 Create a command line from one or more vectors of parameters. More...
 
std::string to_string (size_t reserve=Shell::MAX_COMMAND_LINE_LENGTH) const
 Format a command line from separate parameters using built-in escaping rules. More...
 
size_t total_size () const
 Get the total size of the command line parameters, taking into account the trailing space. More...
 
void reset ()
 Reset this command line's data. More...
 
void escape_all_parameters ()
 Escape all parameters when formatting the command line for output. More...
 
void escape_initial_parameters ()
 Only escape the number of parameters that currently exist when formatting the command line for output. More...
 
void escape_initial_parameters (size_t count)
 Escape the first count parameters when formatting the command line for output. More...
 
std::vector< std::string > & operator* ()
 Obtain the parameters for this command line. More...
 
const std::vector< std::string > & operator* () const
 Obtain the parameters for this command line. More...
 
std::vector< std::string > * operator-> ()
 Obtain the parameters for this command line. More...
 
const std::vector< std::string > * operator-> () const
 Obtain the parameters for this command line. More...
 

Public Attributes

bool trailing_space = false
 

Private Attributes

std::vector< std::string > parameters_
 
size_t escape_parameters_ = std::numeric_limits<size_t>::max()
 

Friends

bool operator== (const CommandLine &lhs, const CommandLine &rhs)
 Compare a command line to another command line for equality. More...
 
bool operator!= (const CommandLine &lhs, const CommandLine &rhs)
 Compare this command line to another command line for inequality. More...
 

Detailed Description

Representation of a command line, with parameters separated by spaces and an optional trailing space.

Since
0.4.0

Definition at line 1642 of file console.h.

Constructor & Destructor Documentation

◆ CommandLine() [1/3]

uuid::console::CommandLine::CommandLine ( )
default

Create an empty command line.

Since
0.4.0

◆ CommandLine() [2/3]

uuid::console::CommandLine::CommandLine ( const std::string &  line)
explicit

Parse a command line into separate parameters using built-in escaping rules.

Parameters
[in]lineCommand line to parse.
Since
0.4.0

Definition at line 28 of file command_line.cpp.

◆ CommandLine() [3/3]

uuid::console::CommandLine::CommandLine ( std::initializer_list< const std::vector< std::string >>  arguments)
explicit

Create a command line from one or more vectors of parameters.

Parameters
[in]argumentsVectors of parameters to add to the command line.
Since
0.4.0

Definition at line 107 of file command_line.cpp.

Member Function Documentation

◆ escape_all_parameters()

void uuid::console::CommandLine::escape_all_parameters ( )
inline

Escape all parameters when formatting the command line for output.

This is the default.

Since
0.5.0

Definition at line 1716 of file console.h.

◆ escape_initial_parameters() [1/2]

void uuid::console::CommandLine::escape_initial_parameters ( )
inline

Only escape the number of parameters that currently exist when formatting the command line for output.

Use this before appending argument help that should not be escaped.

Empty parameters will always be escaped.

Since
0.5.0

Definition at line 1728 of file console.h.

◆ escape_initial_parameters() [2/2]

void uuid::console::CommandLine::escape_initial_parameters ( size_t  count)
inline

Escape the first count parameters when formatting the command line for output.

Use this to prevent argument help from being escaped.

Empty parameters will always be escaped.

Parameters
[in]countNumber of parameters to escape.
Since
0.5.0

Definition at line 1740 of file console.h.

◆ operator*() [1/2]

std::vector<std::string>& uuid::console::CommandLine::operator* ( )
inline

Obtain the parameters for this command line.

Returns
A reference to the parameters.
Since
0.6.0

Definition at line 1748 of file console.h.

◆ operator*() [2/2]

const std::vector<std::string>& uuid::console::CommandLine::operator* ( ) const
inline

Obtain the parameters for this command line.

Returns
A reference to the parameters.
Since
0.6.0

Definition at line 1755 of file console.h.

◆ operator->() [1/2]

std::vector<std::string>* uuid::console::CommandLine::operator-> ( )
inline

Obtain the parameters for this command line.

Returns
A pointer to the parameters.
Since
0.4.0

Definition at line 1762 of file console.h.

◆ operator->() [2/2]

const std::vector<std::string>* uuid::console::CommandLine::operator-> ( ) const
inline

Obtain the parameters for this command line.

Returns
A pointer to the parameters.
Since
0.4.0

Definition at line 1769 of file console.h.

◆ reset()

void uuid::console::CommandLine::reset ( )

Reset this command line's data.

Clears the parameter list and removes any trailing space.

Since
0.4.0

Definition at line 158 of file command_line.cpp.

◆ to_string()

std::string uuid::console::CommandLine::to_string ( size_t  reserve = Shell::MAX_COMMAND_LINE_LENGTH) const

Format a command line from separate parameters using built-in escaping rules.

Parameters
[in]reserveString buffer size to preallocate.
Returns
A command line, with escaping of characters sufficient to reproduce the same command line parameters when parsed.
Since
0.4.0

Definition at line 113 of file command_line.cpp.

◆ total_size()

size_t uuid::console::CommandLine::total_size ( ) const
inline

Get the total size of the command line parameters, taking into account the trailing space.

Returns
The size of the command line parameters, plus 1 for a trailing space.
Since
0.4.0

Definition at line 1698 of file console.h.

Friends And Related Function Documentation

◆ operator!=

bool operator!= ( const CommandLine lhs,
const CommandLine rhs 
)
friend

Compare this command line to another command line for inequality.

Parameters
[in]lhsLeft-hand side command line.
[in]rhsRight-hand side command line.
Returns
True if the command lines are not equal, otherwise false.
Since
0.4.0

Definition at line 1790 of file console.h.

◆ operator==

bool operator== ( const CommandLine lhs,
const CommandLine rhs 
)
friend

Compare a command line to another command line for equality.

Parameters
[in]lhsLeft-hand side command line.
[in]rhsRight-hand side command line.
Returns
True if the command lines are equal, otherwise false.
Since
0.4.0

Definition at line 1779 of file console.h.

Member Data Documentation

◆ escape_parameters_

size_t uuid::console::CommandLine::escape_parameters_ = std::numeric_limits<size_t>::max()
private

Number of initial arguments to escape in output.

Since
0.5.0

Definition at line 1798 of file console.h.

◆ parameters_

std::vector<std::string> uuid::console::CommandLine::parameters_
private

Separate command line parameters.

Since
0.4.0

Definition at line 1797 of file console.h.

◆ trailing_space

bool uuid::console::CommandLine::trailing_space = false

Command line has a trailing space.

Since
0.4.0

Definition at line 1794 of file console.h.


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