winapi_common
Public Member Functions | Static Public Member Functions | List of all members
winapi::CommandLine Class Reference

Command line for the current process or for launching new processes. More...

Public Member Functions

 CommandLine ()=default
 
 CommandLine (const std::string &argv0, const std::vector< std::string > &args={})
 
 CommandLine (std::string &&argv0, std::vector< std::string > &&args={})
 
 CommandLine (std::vector< std::string > argv)
 
std::string to_string () const
 
std::string args_to_string () const
 
std::string get_argv0 () const
 
bool has_args () const
 
const std::vector< std::string > & get_args () const
 
std::vector< std::string > get_argv () const
 

Static Public Member Functions

static CommandLine query ()
 
static CommandLine parse (const std::string &src)
 
static CommandLine from_main (int argc, wchar_t *argv[])
 
static std::string escape (const std::string &)
 
static std::string escape_cmd (const std::string &)
 

Detailed Description

Command line for the current process or for launching new processes.

This class takes care of proper parsing and stringifying command line arguments so that they are safe to use with CreateProcess, ShellExecute, etc.

Definition at line 21 of file cmd_line.hpp.

Constructor & Destructor Documentation

◆ CommandLine() [1/4]

winapi::CommandLine::CommandLine ( )
default

Build an empty command line. It won't have neither argv[0], nor any other args.

◆ CommandLine() [2/4]

winapi::CommandLine::CommandLine ( const std::string &  argv0,
const std::vector< std::string > &  args = {} 
)
inlineexplicit

Build a command line.

Parameters
argv0UTF-8 string, argv[0].
argsList of UTF-8 strings, other arguments.

Definition at line 50 of file cmd_line.hpp.

◆ CommandLine() [3/4]

winapi::CommandLine::CommandLine ( std::string &&  argv0,
std::vector< std::string > &&  args = {} 
)
inlineexplicit

Build a command line.

Parameters
argv0UTF-8 string, argv[0].
argsList of UTF-8 strings, other arguments.

Definition at line 58 of file cmd_line.hpp.

◆ CommandLine() [4/4]

winapi::CommandLine::CommandLine ( std::vector< std::string >  argv)
explicit

Build a command line.

Parameters
argvList of UTF-8 strings, including argv[0].

Definition at line 89 of file cmd_line.cpp.

Member Function Documentation

◆ query()

CommandLine winapi::CommandLine::query ( )
static

Get the command line used to launch this process.

Definition at line 75 of file cmd_line.cpp.

◆ parse()

CommandLine winapi::CommandLine::parse ( const std::string &  src)
static

Parse a command line from a string.

Parameters
srcUTF-8 encoded string.

Definition at line 79 of file cmd_line.cpp.

◆ from_main()

CommandLine winapi::CommandLine::from_main ( int  argc,
wchar_t *  argv[] 
)
static

Build a command line from main() arguments.

Parameters
argcLength of the argv array.
argvUTF-16 encoded strings.

Definition at line 83 of file cmd_line.cpp.

◆ to_string()

std::string winapi::CommandLine::to_string ( ) const

Build a string that represents this command line.

Returns
UTF-8 string.

Definition at line 138 of file cmd_line.cpp.

◆ args_to_string()

std::string winapi::CommandLine::args_to_string ( ) const

Build a string that represents this command line, but omit argv[0].

Returns
UTF-8 string.

Definition at line 142 of file cmd_line.cpp.

◆ get_argv0()

std::string winapi::CommandLine::get_argv0 ( ) const
inline

Get argv[0] for this command line.

Returns
UTF-8 string.

Definition at line 87 of file cmd_line.hpp.

◆ has_args()

bool winapi::CommandLine::has_args ( ) const
inline

Test if this command line has any additional arguments besides argv[0].

Definition at line 90 of file cmd_line.hpp.

◆ get_args()

const std::vector<std::string>& winapi::CommandLine::get_args ( ) const
inline

Get list of arguments for this command line beyond argv[0].

Returns
List of UTF-8 strings.

Definition at line 96 of file cmd_line.hpp.

◆ get_argv()

std::vector< std::string > winapi::CommandLine::get_argv ( ) const

Get list of arguments for this command line.

Returns
List of UTF-8 strings.

Definition at line 146 of file cmd_line.cpp.


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