Flutter Engine
fml::CommandLine Class Referencefinal

#include <command_line.h>

Classes

struct  Option
 

Public Member Functions

 CommandLine ()
 
 CommandLine (const CommandLine &from)
 
 CommandLine (CommandLine &&from)
 
 CommandLine (const std::string &argv0, const std::vector< Option > &options, const std::vector< std::string > &positional_args)
 
 ~CommandLine ()
 
CommandLineoperator= (const CommandLine &from)
 
CommandLineoperator= (CommandLine &&from)
 
bool has_argv0 () const
 
const std::string & argv0 () const
 
const std::vector< Option > & options () const
 
const std::vector< std::string > & positional_args () const
 
bool operator== (const CommandLine &other) const
 
bool operator!= (const CommandLine &other) const
 
bool HasOption (std::string_view name, size_t *index=nullptr) const
 
bool GetOptionValue (std::string_view name, std::string *value) const
 
std::vector< std::string_view > GetOptionValues (std::string_view name) const
 
std::string GetOptionValueWithDefault (std::string_view name, std::string_view default_value) const
 

Detailed Description

Definition at line 55 of file command_line.h.

Constructor & Destructor Documentation

◆ CommandLine() [1/4]

fml::CommandLine::CommandLine ( )
default

◆ CommandLine() [2/4]

fml::CommandLine::CommandLine ( const CommandLine from)
default

◆ CommandLine() [3/4]

fml::CommandLine::CommandLine ( CommandLine &&  from)
default

◆ CommandLine() [4/4]

fml::CommandLine::CommandLine ( const std::string &  argv0,
const std::vector< Option > &  options,
const std::vector< std::string > &  positional_args 
)
explicit

Definition at line 22 of file command_line.cc.

References operator=(), and ~CommandLine().

25  : has_argv0_(true),
26  argv0_(argv0),
27  options_(options),
28  positional_args_(positional_args) {
29  for (size_t i = 0; i < options_.size(); i++) {
30  option_index_[options_[i].name] = i;
31  }
32 }
const std::vector< Option > & options() const
Definition: command_line.h:94
const std::string & argv0() const
Definition: command_line.h:93
const std::vector< std::string > & positional_args() const
Definition: command_line.h:95

◆ ~CommandLine()

fml::CommandLine::~CommandLine ( )
default

Referenced by CommandLine().

Member Function Documentation

◆ argv0()

const std::string& fml::CommandLine::argv0 ( ) const
inline

Definition at line 93 of file command_line.h.

Referenced by fml::CommandLineToArgv().

93 { return argv0_; }

◆ GetOptionValue()

bool fml::CommandLine::GetOptionValue ( std::string_view  name,
std::string *  value 
) const

Definition at line 51 of file command_line.cc.

References HasOption().

Referenced by flutter::GetSwitchValue(), operator!=(), and flutter::SettingsFromCommandLine().

52  {
53  size_t index;
54  if (!HasOption(name, &index)) {
55  return false;
56  }
57  *value = options_[index].value;
58  return true;
59 }
uint8_t value
const char * name
Definition: fuchsia.cc:50
bool HasOption(std::string_view name, size_t *index=nullptr) const
Definition: command_line.cc:40

◆ GetOptionValues()

std::vector< std::string_view > fml::CommandLine::GetOptionValues ( std::string_view  name) const

Definition at line 61 of file command_line.cc.

Referenced by operator!=(), and flutter::SettingsFromCommandLine().

62  {
63  std::vector<std::string_view> ret;
64  for (const auto& option : options_) {
65  if (option.name == name) {
66  ret.push_back(option.value);
67  }
68  }
69  return ret;
70 }
const char * name
Definition: fuchsia.cc:50

◆ GetOptionValueWithDefault()

std::string fml::CommandLine::GetOptionValueWithDefault ( std::string_view  name,
std::string_view  default_value 
) const

Definition at line 72 of file command_line.cc.

References HasOption().

Referenced by main(), and operator!=().

74  {
75  size_t index;
76  if (!HasOption(name, &index)) {
77  return {default_value.data(), default_value.size()};
78  }
79  return options_[index].value;
80 }
const char * name
Definition: fuchsia.cc:50
bool HasOption(std::string_view name, size_t *index=nullptr) const
Definition: command_line.cc:40

◆ has_argv0()

bool fml::CommandLine::has_argv0 ( ) const
inline

Definition at line 92 of file command_line.h.

Referenced by fml::CommandLineToArgv().

92 { return has_argv0_; }

◆ HasOption()

bool fml::CommandLine::HasOption ( std::string_view  name,
size_t *  index = nullptr 
) const

Definition at line 40 of file command_line.cc.

Referenced by GetOptionValue(), GetOptionValueWithDefault(), operator!=(), and flutter::SettingsFromCommandLine().

40  {
41  auto it = option_index_.find(name.data());
42  if (it == option_index_.end()) {
43  return false;
44  }
45  if (index) {
46  *index = it->second;
47  }
48  return true;
49 }
const char * name
Definition: fuchsia.cc:50

◆ operator!=()

bool fml::CommandLine::operator!= ( const CommandLine other) const
inline

◆ operator=() [1/2]

CommandLine & fml::CommandLine::operator= ( const CommandLine from)
default

Referenced by CommandLine().

◆ operator=() [2/2]

CommandLine & fml::CommandLine::operator= ( CommandLine &&  from)
default

◆ operator==()

bool fml::CommandLine::operator== ( const CommandLine other) const
inline

Definition at line 99 of file command_line.h.

99  {
100  // No need to compare |option_index_|.
101  return has_argv0_ == other.has_argv0_ && argv0_ == other.argv0_ &&
102  options_ == other.options_ &&
103  positional_args_ == other.positional_args_;
104  }

◆ options()

const std::vector<Option>& fml::CommandLine::options ( ) const
inline

Definition at line 94 of file command_line.h.

Referenced by fml::CommandLineToArgv().

94 { return options_; }

◆ positional_args()

const std::vector<std::string>& fml::CommandLine::positional_args ( ) const
inline

Definition at line 95 of file command_line.h.

Referenced by fml::CommandLineToArgv().

95  {
96  return positional_args_;
97  }

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