Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Classes | Public Member Functions | List of all members
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 56 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.

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::string & argv0() const
const std::vector< Option > & options() const
const std::vector< std::string > & positional_args() const

◆ ~CommandLine()

fml::CommandLine::~CommandLine ( )
default

Member Function Documentation

◆ argv0()

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

Definition at line 94 of file command_line.h.

94{ return argv0_; }

◆ GetOptionValue()

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

Definition at line 51 of file command_line.cc.

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

◆ GetOptionValues()

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

Definition at line 61 of file command_line.cc.

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}

◆ 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.

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}

◆ has_argv0()

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

Definition at line 93 of file command_line.h.

93{ 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.

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}

◆ operator!=()

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

Definition at line 106 of file command_line.h.

106{ return !operator==(other); }
bool operator==(const CommandLine &other) const

◆ operator=() [1/2]

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

◆ operator=() [2/2]

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

◆ operator==()

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

Definition at line 100 of file command_line.h.

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

◆ options()

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

Definition at line 95 of file command_line.h.

95{ return options_; }

◆ positional_args()

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

Definition at line 96 of file command_line.h.

96 {
97 return positional_args_;
98 }

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