Replace Maybe with std::optional
With c++17, std::optional provides the functionality that Maybe
provided.
Bug: 183215655
Test: aapt2_tests
Change-Id: I62bb9c2fa4985dc5217a6ed153df92b85ad9a034
diff --git a/tools/aapt2/test/Builders.cpp b/tools/aapt2/test/Builders.cpp
index 4816596..23331de 100644
--- a/tools/aapt2/test/Builders.cpp
+++ b/tools/aapt2/test/Builders.cpp
@@ -159,7 +159,8 @@
return std::move(table_);
}
-std::unique_ptr<Reference> BuildReference(const StringPiece& ref, const Maybe<ResourceId>& id) {
+std::unique_ptr<Reference> BuildReference(const StringPiece& ref,
+ const std::optional<ResourceId>& id) {
std::unique_ptr<Reference> reference = util::make_unique<Reference>(ParseNameOrDie(ref));
reference->id = id;
return reference;
@@ -218,7 +219,8 @@
return std::move(style_);
}
-StyleableBuilder& StyleableBuilder::AddItem(const StringPiece& str, const Maybe<ResourceId>& id) {
+StyleableBuilder& StyleableBuilder::AddItem(const StringPiece& str,
+ const std::optional<ResourceId>& id) {
styleable_->entries.push_back(Reference(ParseNameOrDie(str)));
styleable_->entries.back().id = id;
return *this;
diff --git a/tools/aapt2/test/Builders.h b/tools/aapt2/test/Builders.h
index 3ff955d..55778ae 100644
--- a/tools/aapt2/test/Builders.h
+++ b/tools/aapt2/test/Builders.h
@@ -29,7 +29,6 @@
#include "configuration/ConfigurationParser.internal.h"
#include "process/IResourceTableConsumer.h"
#include "test/Common.h"
-#include "util/Maybe.h"
#include "xml/XmlDom.h"
namespace aapt {
@@ -86,7 +85,7 @@
};
std::unique_ptr<Reference> BuildReference(const android::StringPiece& ref,
- const Maybe<ResourceId>& id = {});
+ const std::optional<ResourceId>& id = {});
std::unique_ptr<BinaryPrimitive> BuildPrimitive(uint8_t type, uint32_t data);
template <typename T>
@@ -149,7 +148,8 @@
class StyleableBuilder {
public:
StyleableBuilder() = default;
- StyleableBuilder& AddItem(const android::StringPiece& str, const Maybe<ResourceId>& id = {});
+ StyleableBuilder& AddItem(const android::StringPiece& str,
+ const std::optional<ResourceId>& id = {});
std::unique_ptr<Styleable> Build();
private:
diff --git a/tools/aapt2/test/Common.cpp b/tools/aapt2/test/Common.cpp
index 23c2218..e029d02 100644
--- a/tools/aapt2/test/Common.cpp
+++ b/tools/aapt2/test/Common.cpp
@@ -48,7 +48,7 @@
const android::StringPiece& res_name,
const ConfigDescription& config,
const android::StringPiece& product) {
- Maybe<ResourceTable::SearchResult> result = table->FindResource(ParseNameOrDie(res_name));
+ std::optional<ResourceTable::SearchResult> result = table->FindResource(ParseNameOrDie(res_name));
if (result) {
ResourceConfigValue* config_value = result.value().entry->FindValue(config, product);
if (config_value) {
diff --git a/tools/aapt2/test/Common.h b/tools/aapt2/test/Common.h
index 777ca5c..7006964 100644
--- a/tools/aapt2/test/Common.h
+++ b/tools/aapt2/test/Common.h
@@ -55,7 +55,7 @@
T* GetValueForConfigAndProduct(ResourceTable* table, const android::StringPiece& res_name,
const android::ConfigDescription& config,
const android::StringPiece& product) {
- Maybe<ResourceTable::SearchResult> result = table->FindResource(ParseNameOrDie(res_name));
+ std::optional<ResourceTable::SearchResult> result = table->FindResource(ParseNameOrDie(res_name));
if (result) {
ResourceConfigValue* config_value = result.value().entry->FindValue(config, product);
if (config_value) {
@@ -130,7 +130,7 @@
// Add a print method to Maybe.
template <typename T>
-void PrintTo(const Maybe<T>& value, std::ostream* out) {
+void PrintTo(const std::optional<T>& value, std::ostream* out) {
if (value) {
*out << ::testing::PrintToString(value.value());
} else {
diff --git a/tools/aapt2/test/Context.h b/tools/aapt2/test/Context.h
index 5d8ded3..e1b8dd5 100644
--- a/tools/aapt2/test/Context.h
+++ b/tools/aapt2/test/Context.h
@@ -95,8 +95,8 @@
friend class ContextBuilder;
PackageType package_type_ = PackageType::kApp;
- Maybe<std::string> compilation_package_;
- Maybe<uint8_t> package_id_;
+ std::optional<std::string> compilation_package_;
+ std::optional<uint8_t> package_id_;
StdErrDiagnostics diagnostics_;
NameMangler name_mangler_;
SymbolTable symbols_;
diff --git a/tools/aapt2/test/Fixture.cpp b/tools/aapt2/test/Fixture.cpp
index 285e5a1..e2f71dc 100644
--- a/tools/aapt2/test/Fixture.cpp
+++ b/tools/aapt2/test/Fixture.cpp
@@ -126,7 +126,7 @@
link_args.insert(link_args.end(), {"-I", android_sdk});
// Add the files from the compiled resources directory to the link file arguments
- Maybe<std::vector<std::string>> compiled_files = file::FindFiles(flat_dir, diag);
+ std::optional<std::vector<std::string>> compiled_files = file::FindFiles(flat_dir, diag);
if (compiled_files) {
for (std::string& compile_file : compiled_files.value()) {
compile_file = file::BuildPath({flat_dir, compile_file});