1 /* 2 * Copyright (c) 2021 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_VERIFICATION_DEBUG_OPTIONS_METHOD_OPTIONS_CONFIG_H_ 17 #define PANDA_VERIFICATION_DEBUG_OPTIONS_METHOD_OPTIONS_CONFIG_H_ 18 19 #include "method_options.h" 20 #include "method_selector.h" 21 22 #include <regex> 23 24 namespace panda::verifier { 25 26 template <typename String, typename VerifierMessagesEnum, template <typename...> class UnorderedMap, 27 template <typename...> class Vector> 28 class VerifierMethodOptionsConfig { 29 public: 30 using MethodOptions = VerifierMethodOptions<String, VerifierMessagesEnum, UnorderedMap, Vector>; 31 using MethodSelector = VerifierMethodSelector<MethodOptions, Vector, std::regex, String>; NewOptions(const String & name)32 MethodOptions &NewOptions(const String &name) 33 { 34 return Config.emplace(name, name).first->second; 35 } GetOptions(const String & name)36 const MethodOptions &GetOptions(const String &name) const 37 { 38 return Config.at(name); 39 } IsOptionsPresent(const String & name)40 bool IsOptionsPresent(const String &name) const 41 { 42 return Config.count(name) > 0; 43 } 44 auto operator[](const String &method_name) const 45 { 46 return MethodGroups[method_name]; 47 } AddOptionsForGroup(const String & group_regex,const String & options_name)48 bool AddOptionsForGroup(const String &group_regex, const String &options_name) 49 { 50 if (!IsOptionsPresent(options_name)) { 51 return false; 52 } 53 MethodGroups.Add(group_regex, GetOptions(options_name)); 54 return true; 55 } 56 57 private: 58 UnorderedMap<String, MethodOptions> Config; 59 MethodSelector MethodGroups; 60 }; 61 62 } // namespace panda::verifier 63 64 #endif // PANDA_VERIFICATION_DEBUG_OPTIONS_METHOD_OPTIONS_CONFIG_H_ 65