summaryrefslogtreecommitdiff
path: root/init/service_parser.cpp
diff options
context:
space:
mode:
authorTom Cherry <tomcherry@google.com>2019-07-22 16:05:36 -0700
committerTom Cherry <tomcherry@google.com>2019-07-23 14:39:38 -0700
commitd52a5b3c10ad341e38f61466e81b7a963e6eb92e (patch)
tree4a39211c457d181b091a854d8faeedb1be7170c5 /init/service_parser.cpp
parentb3fc1b7441b8cc4d11384cf8867682308daffb15 (diff)
init: simplify keyword_map
I've heard that keyword_map is too complex, in particular the tuple and the pair in BuiltinFunctionMap, so this change removes a lot of that complexity and, more importantly, better documents how all of this works. Test: boot, init unit tests Change-Id: I74e5f9de7f2ec524cb6127bb9da2956b5f307f56
Diffstat (limited to 'init/service_parser.cpp')
-rw-r--r--init/service_parser.cpp17
1 files changed, 4 insertions, 13 deletions
diff --git a/init/service_parser.cpp b/init/service_parser.cpp
index 0fbbeb828..65d96c665 100644
--- a/init/service_parser.cpp
+++ b/init/service_parser.cpp
@@ -461,18 +461,10 @@ Result<void> ServiceParser::ParseUpdatable(std::vector<std::string>&& args) {
return {};
}
-class ServiceParser::OptionParserMap : public KeywordMap<OptionParser> {
- public:
- OptionParserMap() {}
-
- private:
- const Map& map() const override;
-};
-
-const ServiceParser::OptionParserMap::Map& ServiceParser::OptionParserMap::map() const {
+const KeywordMap<ServiceParser::OptionParser>& ServiceParser::GetParserMap() const {
constexpr std::size_t kMax = std::numeric_limits<std::size_t>::max();
// clang-format off
- static const Map option_parsers = {
+ static const KeywordMap<ServiceParser::OptionParser> parser_map = {
{"capabilities",
{0, kMax, &ServiceParser::ParseCapabilities}},
{"class", {1, kMax, &ServiceParser::ParseClass}},
@@ -518,7 +510,7 @@ const ServiceParser::OptionParserMap::Map& ServiceParser::OptionParserMap::map()
{"writepid", {1, kMax, &ServiceParser::ParseWritepid}},
};
// clang-format on
- return option_parsers;
+ return parser_map;
}
Result<void> ServiceParser::ParseSection(std::vector<std::string>&& args,
@@ -561,8 +553,7 @@ Result<void> ServiceParser::ParseLineSection(std::vector<std::string>&& args, in
return {};
}
- static const OptionParserMap parser_map;
- auto parser = parser_map.FindFunction(args);
+ auto parser = GetParserMap().Find(args);
if (!parser) return parser.error();