// A util class that builds cmdline arguments. class CmdlineBuilder { public: // Returns all arguments. const std::vector<std::string>& Get() const { return elements_; }
// Same as above but adds a runtime argument.
CmdlineBuilder& AddRuntime(std::string_view arg) { return Add("--runtime-arg").Add(arg); }
// Adds a string value formatted by the format string. // // Usage: Add("--flag=%s", "value")
CmdlineBuilder& Add(constchar* arg_format, const std::string& value)
__attribute__((enable_if(internal::ContainsOneFormatSpecifier(arg_format, 's'), "'arg' must be a string literal that contains '%s'"))) { return Add(android::base::StringPrintf(arg_format, value.c_str()));
}
// Same as above but adds a runtime argument.
CmdlineBuilder& AddRuntime(constchar* arg_format, const std::string& value)
__attribute__((enable_if(internal::ContainsOneFormatSpecifier(arg_format, 's'), "'arg' must be a string literal that contains '%s'"))) { return AddRuntime(android::base::StringPrintf(arg_format, value.c_str()));
}
// Adds an integer value formatted by the format string. // // Usage: Add("--flag=%d", 123)
CmdlineBuilder& Add(constchar* arg_format, int value)
__attribute__((enable_if(internal::ContainsOneFormatSpecifier(arg_format, 'd'), "'arg' must be a string literal that contains '%d'"))) { return Add(android::base::StringPrintf(arg_format, value));
}
// Same as above but adds a runtime argument.
CmdlineBuilder& AddRuntime(constchar* arg_format, int value)
__attribute__((enable_if(internal::ContainsOneFormatSpecifier(arg_format, 'd'), "'arg' must be a string literal that contains '%d'"))) { return AddRuntime(android::base::StringPrintf(arg_format, value));
}
// Adds a string value formatted by the format string if the value is non-empty. Does nothing // otherwise. // // Usage: AddIfNonEmpty("--flag=%s", "value")
CmdlineBuilder& AddIfNonEmpty(constchar* arg_format, const std::string& value)
__attribute__((enable_if(internal::ContainsOneFormatSpecifier(arg_format, 's'), "'arg' must be a string literal that contains '%s'"))) { if (!value.empty()) {
Add(android::base::StringPrintf(arg_format, value.c_str()));
} return *this;
}
// Same as above but adds a runtime argument.
CmdlineBuilder& AddRuntimeIfNonEmpty(constchar* arg_format, const std::string& value)
__attribute__((enable_if(internal::ContainsOneFormatSpecifier(arg_format, 's'), "'arg' must be a string literal that contains '%s'"))) { if (!value.empty()) {
AddRuntime(android::base::StringPrintf(arg_format, value.c_str()));
} return *this;
}
// Adds an argument as-is if the boolean value is true. Does nothing otherwise.
CmdlineBuilder& AddIf(bool value, std::string_view arg) { if (value) {
Add(arg);
} return *this;
}
// Same as above but adds a runtime argument.
CmdlineBuilder& AddRuntimeIf(bool value, std::string_view arg) { if (value) {
AddRuntime(arg);
} return *this;
}
// Concatenates this builder with another. Returns the concatenated result and nullifies the input // builder.
CmdlineBuilder& Concat(CmdlineBuilder&& other) {
elements_.reserve(elements_.size() + other.elements_.size());
std::move(other.elements_.begin(), other.elements_.end(), std::back_inserter(elements_));
other.elements_.clear(); return *this;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.