1 /** 2 * Copyright (c) 2021-2022 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef _PANDA_VERIFIER_TESTS_ENV_HPP 17 #define _PANDA_VERIFIER_TESTS_ENV_HPP 18 19 #include <unordered_map> 20 #include <string> 21 #include <variant> 22 #include <optional> 23 24 namespace panda::verifier::test { 25 using OptionValue = std::variant<std::string, int, bool>; 26 27 class EnvOptions { 28 public: 29 std::optional<OptionValue> operator[](const std::string &name) const; 30 template <typename T> 31 T Get(const std::string &name, T deflt = T {}) const 32 { 33 auto val = (*this)[name]; 34 if (!val) { 35 return deflt; 36 } 37 if (auto pntr = std::get_if<T>(&*val)) { 38 return *pntr; 39 } 40 return deflt; 41 } 42 EnvOptions(const char *); 43 EnvOptions(const EnvOptions &) = default; 44 EnvOptions(EnvOptions &&) = default; 45 EnvOptions &operator=(const EnvOptions &) = default; 46 EnvOptions &operator=(EnvOptions &&) = default; 47 ~EnvOptions() = default; 48 49 private: 50 std::unordered_map<std::string, OptionValue> Options_; 51 }; 52 } // namespace panda::verifier::test 53 54 #endif // !_PANDA_VERIFIER_TESTS_ENV_HPP 55