Flutter Engine
The Flutter Engine
Public Member Functions | List of all members
dart::bin::CommandLineOptions Class Reference

#include <dartutils.h>

Public Member Functions

 CommandLineOptions (int max_count)
 
 ~CommandLineOptions ()
 
void Reset ()
 
int count () const
 
int max_count () const
 
const char ** arguments () const
 
const char * GetArgument (int index) const
 
void AddArgument (const char *argument)
 
void AddArguments (const char **argv, int argc)
 
Dart_Handle CreateRuntimeOptions ()
 
void operator delete (void *pointer)
 

Detailed Description

Definition at line 42 of file dartutils.h.

Constructor & Destructor Documentation

◆ CommandLineOptions()

dart::bin::CommandLineOptions::CommandLineOptions ( int  max_count)
inlineexplicit

Definition at line 44 of file dartutils.h.

45 : count_(0), max_count_(max_count), arguments_(nullptr) {
46 const int kWordSize = sizeof(intptr_t);
47 arguments_ = reinterpret_cast<const char**>(malloc(max_count * kWordSize));
48 if (arguments_ == nullptr) {
49 max_count_ = 0;
50 }
51 }
void * malloc(size_t size)
Definition: allocation.cc:19
constexpr intptr_t kWordSize
Definition: globals.h:509

◆ ~CommandLineOptions()

dart::bin::CommandLineOptions::~CommandLineOptions ( )
inline

Definition at line 52 of file dartutils.h.

52 {
53 free(arguments_);
54 count_ = 0;
55 max_count_ = 0;
56 arguments_ = nullptr;
57 }

Member Function Documentation

◆ AddArgument()

void dart::bin::CommandLineOptions::AddArgument ( const char *  argument)
inline

Definition at line 68 of file dartutils.h.

68 {
69 if (count_ < max_count_) {
70 arguments_[count_] = argument;
71 count_ += 1;
72 } else {
73 abort(); // We should never get into this situation.
74 }
75 }

◆ AddArguments()

void dart::bin::CommandLineOptions::AddArguments ( const char **  argv,
int  argc 
)
inline

Definition at line 77 of file dartutils.h.

77 {
78 if (count_ + argc >= max_count_) {
79 abort(); // We should never get into this situation.
80 }
81 for (int i = 0; i < argc; ++i) {
82 arguments_[count_++] = argv[i];
83 }
84 }
char ** argv
Definition: library.h:9

◆ arguments()

const char ** dart::bin::CommandLineOptions::arguments ( ) const
inline

Definition at line 63 of file dartutils.h.

63{ return arguments_; }

◆ count()

int dart::bin::CommandLineOptions::count ( ) const
inline

Definition at line 61 of file dartutils.h.

61{ return count_; }

◆ CreateRuntimeOptions()

Dart_Handle dart::bin::CommandLineOptions::CreateRuntimeOptions ( )

Definition at line 58 of file dartutils.cc.

58 {
59 Dart_Handle string_type = DartUtils::GetDartType("dart:core", "String");
60 if (Dart_IsError(string_type)) {
61 return string_type;
62 }
63 Dart_Handle dart_arguments =
64 Dart_NewListOfTypeFilled(string_type, Dart_EmptyString(), count_);
65 if (Dart_IsError(dart_arguments)) {
66 return dart_arguments;
67 }
68 for (int i = 0; i < count_; i++) {
70 if (Dart_IsError(argument_value)) {
71 return argument_value;
72 }
73 Dart_Handle result = Dart_ListSetAt(dart_arguments, i, argument_value);
74 if (Dart_IsError(result)) {
75 return result;
76 }
77 }
78 return dart_arguments;
79}
const char * GetArgument(int index) const
Definition: dartutils.h:65
static Dart_Handle NewString(const char *str)
Definition: dartutils.h:214
static Dart_Handle GetDartType(const char *library_url, const char *class_name)
Definition: dartutils.cc:696
struct _Dart_Handle * Dart_Handle
Definition: dart_api.h:258
GAsyncResult * result
DART_EXPORT Dart_Handle Dart_NewListOfTypeFilled(Dart_Handle element_type, Dart_Handle fill_object, intptr_t length)
DART_EXPORT Dart_Handle Dart_ListSetAt(Dart_Handle list, intptr_t index, Dart_Handle value)
DART_EXPORT bool Dart_IsError(Dart_Handle handle)
DART_EXPORT Dart_Handle Dart_EmptyString()

◆ GetArgument()

const char * dart::bin::CommandLineOptions::GetArgument ( int  index) const
inline

Definition at line 65 of file dartutils.h.

65 {
66 return (index >= 0 && index < count_) ? arguments_[index] : nullptr;
67 }

◆ max_count()

int dart::bin::CommandLineOptions::max_count ( ) const
inline

Definition at line 62 of file dartutils.h.

62{ return max_count_; }

◆ operator delete()

void dart::bin::CommandLineOptions::operator delete ( void *  pointer)
inline

Definition at line 96 of file dartutils.h.

96{ abort(); }

◆ Reset()

void dart::bin::CommandLineOptions::Reset ( )
inline

Definition at line 59 of file dartutils.h.

59{ count_ = 0; }

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