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_SELECTOR_H_ 17 #define PANDA_VERIFICATION_DEBUG_OPTIONS_METHOD_SELECTOR_H_ 18 19 #include <regex> 20 21 template <typename Info, template <typename...> class Vector, typename Regex, typename String> 22 class VerifierMethodSelector { 23 public: 24 using InfoRef = std::reference_wrapper<const Info>; 25 Add(const String & regex_str,const Info & info)26 void Add(const String ®ex_str, const Info &info) 27 { 28 groups.emplace_back(Regex {regex_str, std::regex_constants::basic | std::regex_constants::optimize | 29 std::regex_constants::nosubs | std::regex_constants::icase}, 30 std::cref(info)); 31 } 32 33 std::optional<InfoRef> operator[](const String &name) const 34 { 35 for (const auto &g : groups) { 36 const auto ®ex = g.first; 37 const auto &info_ref = g.second; 38 if (std::regex_match(name, regex)) { 39 return info_ref; 40 } 41 } 42 return std::nullopt; 43 } 44 45 private: 46 Vector<std::pair<Regex, InfoRef>> groups; 47 }; 48 49 #endif // PANDA_VERIFICATION_DEBUG_OPTIONS_METHOD_SELECTOR_H_ 50