1 //===-- LogFilterChain.cpp --------------------------------------*- C++ -*-===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 9 #include "LogFilterChain.h" 10 11 #include "LogFilter.h" 12 LogFilterChain(bool default_accept)13LogFilterChain::LogFilterChain(bool default_accept) 14 : m_filters(), m_default_accept(default_accept) {} 15 AppendFilter(const LogFilterSP & filter_sp)16void LogFilterChain::AppendFilter(const LogFilterSP &filter_sp) { 17 if (filter_sp) 18 m_filters.push_back(filter_sp); 19 } 20 ClearFilterChain()21void LogFilterChain::ClearFilterChain() { m_filters.clear(); } 22 GetDefaultAccepts() const23bool LogFilterChain::GetDefaultAccepts() const { return m_default_accept; } 24 SetDefaultAccepts(bool default_accept)25void LogFilterChain::SetDefaultAccepts(bool default_accept) { 26 m_default_accept = default_accept; 27 } 28 GetAcceptMessage(const LogMessage & message) const29bool LogFilterChain::GetAcceptMessage(const LogMessage &message) const { 30 for (auto filter_sp : m_filters) { 31 if (filter_sp->DoesMatch(message)) { 32 // This message matches this filter. If the filter accepts matches, 33 // this message matches; otherwise, it rejects matches. 34 return filter_sp->MatchesAreAccepted(); 35 } 36 } 37 38 // None of the filters matched. Therefore, we do whatever the 39 // default fall-through rule says. 40 return m_default_accept; 41 } 42