• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright (c) 2021-2024 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 ark::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     // NOLINTNEXTLINE(google-explicit-constructor)
43     EnvOptions(const char *);
44     EnvOptions(const EnvOptions &) = default;
45     EnvOptions(EnvOptions &&) = default;
46     EnvOptions &operator=(const EnvOptions &) = default;
47     EnvOptions &operator=(EnvOptions &&) = default;
48     ~EnvOptions() = default;
49 
50 private:
51     std::unordered_map<std::string, OptionValue> options_;
52 };
53 }  // namespace ark::verifier::test
54 
55 #endif  // !PANDA_VERIFIER_TESTS_ENV_HPP
56