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_DEBUG_OPTIONS_METHOD_OPTIONS_CONFIG_H_ 17 #define PANDA_VERIFIER_DEBUG_OPTIONS_METHOD_OPTIONS_CONFIG_H_ 18 19 #include "method_options.h" 20 21 #include <regex> 22 23 namespace ark::verifier { 24 25 class MethodOptionsConfig { 26 public: NewOptions(const PandaString & name)27 MethodOptions &NewOptions(const PandaString &name) 28 { 29 return config_.emplace(name, name).first->second; 30 } GetOptions(const PandaString & name)31 const MethodOptions &GetOptions(const PandaString &name) const 32 { 33 ASSERT(IsOptionsPresent(name)); 34 return config_.at(name); 35 } IsOptionsPresent(const PandaString & name)36 bool IsOptionsPresent(const PandaString &name) const 37 { 38 return config_.count(name) > 0; 39 } 40 const MethodOptions &operator[](const PandaString &methodName) const 41 { 42 for (const auto &g : methodGroups_) { 43 const auto ®ex = g.first; 44 if (std::regex_match(methodName, regex)) { 45 return g.second; 46 } 47 } 48 return GetOptions("default"); 49 } AddOptionsForGroup(const PandaString & groupRegex,const PandaString & optionsName)50 bool AddOptionsForGroup(const PandaString &groupRegex, const PandaString &optionsName) 51 { 52 if (!IsOptionsPresent(optionsName)) { 53 return false; 54 } 55 methodGroups_.emplace_back( 56 std::regex {groupRegex, std::regex_constants::basic | std::regex_constants::optimize | 57 std::regex_constants::nosubs | std::regex_constants::icase}, 58 GetOptions(optionsName)); 59 return true; 60 } 61 62 private: 63 PandaUnorderedMap<PandaString, MethodOptions> config_; 64 PandaVector<std::pair<std::regex, const MethodOptions &>> methodGroups_; 65 }; 66 67 } // namespace ark::verifier 68 69 #endif // PANDA_VERIFIER_DEBUG_OPTIONS_METHOD_OPTIONS_CONFIG_H_ 70