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/process/SymbolTable.cpp b/tools/aapt2/process/SymbolTable.cpp
index d385267..2d58cbf 100644
--- a/tools/aapt2/process/SymbolTable.cpp
+++ b/tools/aapt2/process/SymbolTable.cpp
@@ -75,8 +75,8 @@
// Fill in the package name if necessary.
// If there is no package in `name`, we will need to copy the ResourceName
- // and store it somewhere; we use the Maybe<> class to reserve storage.
- Maybe<ResourceName> name_with_package_impl;
+ // and store it somewhere; we use the std::optional<> class to reserve storage.
+ std::optional<ResourceName> name_with_package_impl;
if (name.package.empty()) {
name_with_package_impl = ResourceName(mangler_->GetTargetPackageName(), name.type, name.entry);
name_with_package = &name_with_package_impl.value();
@@ -88,9 +88,9 @@
}
// The name was not found in the cache. Mangle it (if necessary) and find it in our sources.
- // Again, here we use a Maybe<> object to reserve storage if we need to mangle.
+ // Again, here we use a std::optional<> object to reserve storage if we need to mangle.
const ResourceName* mangled_name = name_with_package;
- Maybe<ResourceName> mangled_name_impl;
+ std::optional<ResourceName> mangled_name_impl;
if (mangler_->ShouldMangle(name_with_package->package)) {
mangled_name_impl = mangler_->MangleName(*name_with_package);
mangled_name = &mangled_name_impl.value();
@@ -183,7 +183,7 @@
std::unique_ptr<SymbolTable::Symbol> ResourceTableSymbolSource::FindByName(
const ResourceName& name) {
- Maybe<ResourceTable::SearchResult> result = table_->FindResource(name);
+ std::optional<ResourceTable::SearchResult> result = table_->FindResource(name);
if (!result) {
if (name.type == ResourceType::kAttr) {
// Recurse and try looking up a private attribute.
@@ -306,7 +306,7 @@
return nullptr;
}
- Maybe<ResourceName> parsed_name = ResourceUtils::ToResourceName(*name);
+ std::optional<ResourceName> parsed_name = ResourceUtils::ToResourceName(*name);
if (!parsed_name) {
return nullptr;
}
@@ -382,8 +382,7 @@
return {};
}
-static Maybe<ResourceName> GetResourceName(android::AssetManager2& am,
- ResourceId id) {
+static std::optional<ResourceName> GetResourceName(android::AssetManager2& am, ResourceId id) {
auto name = am.GetResourceName(id.id);
if (!name.has_value()) {
return {};
@@ -402,7 +401,7 @@
return {};
}
- Maybe<ResourceName> maybe_name = GetResourceName(asset_manager_, id);
+ std::optional<ResourceName> maybe_name = GetResourceName(asset_manager_, id);
if (!maybe_name) {
return {};
}
diff --git a/tools/aapt2/process/SymbolTable.h b/tools/aapt2/process/SymbolTable.h
index 06eaf63..65ae7be 100644
--- a/tools/aapt2/process/SymbolTable.h
+++ b/tools/aapt2/process/SymbolTable.h
@@ -56,7 +56,7 @@
struct Symbol {
Symbol() = default;
- explicit Symbol(const Maybe<ResourceId>& i, const std::shared_ptr<Attribute>& attr = {},
+ explicit Symbol(const std::optional<ResourceId>& i, const std::shared_ptr<Attribute>& attr = {},
bool pub = false)
: id(i), attribute(attr), is_public(pub) {
}
@@ -66,7 +66,7 @@
Symbol& operator=(const Symbol&) = default;
Symbol& operator=(Symbol&&) = default;
- Maybe<ResourceId> id;
+ std::optional<ResourceId> id;
std::shared_ptr<Attribute> attribute;
bool is_public = false;
bool is_dynamic = false;