1 /* 2 * Copyright (C) 2023 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #pragma once 18 19 #include <memory> 20 #include <optional> 21 #include <string> 22 #include <unordered_map> 23 #include <vector> 24 25 namespace cuttlefish { 26 27 class FlagInfo { 28 public: 29 using FlagInfoFieldMap = std::unordered_map<std::string, std::string>; 30 static std::unique_ptr<FlagInfo> Create( 31 const FlagInfoFieldMap& field_value_map); Name()32 const std::string& Name() const { return name_; } Type()33 const std::string& Type() const { return type_; } 34 35 private: 36 // field_value_map must have needed fields; guaranteed by the factory 37 // function, static Create(). FlagInfo(const FlagInfoFieldMap & field_value_map)38 FlagInfo(const FlagInfoFieldMap& field_value_map) 39 : name_(field_value_map.at("name")), type_(field_value_map.at("type")) {} 40 41 // TODO(kwstephenkim): add more fields 42 std::string name_; 43 std::string type_; 44 }; 45 46 using FlagInfoPtr = std::unique_ptr<FlagInfo>; 47 48 std::optional<std::vector<FlagInfoPtr>> CollectFlagsFromHelpxml( 49 const std::string& xml_str); 50 51 } // namespace cuttlefish 52