LCOV - code coverage report
Current view: top level - ers/plugins - RFilterStream.cpp (source / functions) Coverage Total Hit
Test: code.result Lines: 3.2 % 31 1
Test Date: 2026-02-16 10:18:04 Functions: 20.0 % 5 1

            Line data    Source code
       1              : /*
       2              :  *  RFilterStream.cxx
       3              :  *  ers
       4              :  *
       5              :  *  Created by Andrea Negri on 13.11.06 (from FilterStream.cxx)
       6              :  *  Copyright 2005 CERN. All rights reserved.
       7              :  *
       8              :  */
       9              : 
      10              : #include <ers/internal/RFilterStream.hpp>
      11              : #include <ers/internal/Util.hpp>
      12              : #include <ers/StreamFactory.hpp>
      13              : 
      14           41 : ERS_REGISTER_OUTPUT_STREAM( ers::RFilterStream, "rfilter", format )
      15              : 
      16              : namespace
      17              : {
      18              :     const char NOT = '!';
      19              :     const char * const SEPARATORS = ",";
      20              : } // anonymous namespace
      21              : 
      22              : 
      23              : 
      24              : /** Constructor 
      25              :   * \param chained the chained stream, which will be filtered. Only messages, which pass the filter
      26              :   * will go to the chained stream
      27              :   * on the stack and owned by the current object, i.e it will be deleted upon destruction
      28              :   * \param format describes filter expression.
      29              :   */
      30            0 : ers::RFilterStream::RFilterStream( const std::string & format )
      31              : {
      32            0 :     std::vector<std::string> tokens;
      33            0 :     ers::tokenize( format, SEPARATORS, tokens );
      34            0 :     for( size_t i = 0; i < tokens.size(); i++ )
      35              :     {
      36            0 :         if ( !tokens[i].empty() && tokens[i][0] == NOT ) 
      37            0 :             m_regExclude.push_back( boost::regex(tokens[i].substr( 1 )) );
      38              :         else
      39            0 :             m_regInclude.push_back( boost::regex(tokens[i]) );
      40              :     }
      41            0 : }
      42              : 
      43              : 
      44              : /** Filtering method 
      45              :   * This method checks if an Issue is to be accepted or not. 
      46              :   * \param issue_ptr the issue to check 
      47              :   * \return \c true if the Issue passes filtering, \c false otherwise.
      48              :   */
      49              : bool
      50            0 : ers::RFilterStream::is_accepted( const ers::Issue & issue )
      51              : {
      52              :   // Get the function name that will be the input of the pattern search
      53            0 :   std::string s = issue.context().function_name();
      54              :   // Remove the function arguments, which could lead to fake matches
      55            0 :   s = s.substr(0,s.find_first_of('('));   
      56              :   
      57            0 :   const std::vector<std::string> & qualifiers = issue.qualifiers( );
      58            0 :   std::vector<boost::regex>::const_iterator it;
      59              : 
      60              :   // Check excluded matches 
      61            0 :   for( it = m_regExclude.begin(); it != m_regExclude.end(); ++it )
      62              :   {
      63              :     // 1. Check against function name
      64            0 :     if (boost::regex_search(s, *it))
      65            0 :       return false;
      66              :     
      67              :     // 2. Check against qualifiers
      68            0 :     std::vector<std::string>::const_iterator ko;
      69            0 :     for ( ko=qualifiers.begin(); ko<qualifiers.end(); ko++)
      70            0 :       if ( boost::regex_search(*ko,*it) ) 
      71              :         return false;
      72              :   }
      73              : 
      74              :   // Check included matches (function name, then qualifiers)
      75            0 :   for( it = m_regInclude.begin(); it != m_regInclude.end(); ++it )
      76              :   {
      77              :     // 1. Check against function name
      78            0 :     if (boost::regex_search(s, *it))
      79            0 :       return true;
      80              :    
      81              :     // 2. Check against qualifiers
      82            0 :     std::vector<std::string>::const_iterator ok;
      83            0 :     for (ok=qualifiers.begin(); ok<qualifiers.end(); ok++)
      84            0 :       if ( boost::regex_search(*ok,*it) )
      85              :         return true;
      86              :   }
      87              : 
      88              :   return false; //m_regInclude.empty();
      89            0 : }
      90              : 
      91              : /** Write method 
      92              :   * basically calls \c is_accept to check if the issue is accepted. 
      93              :   * If this is the case, the \c write method on the chained stream is called with 
      94              :   * \c issue. 
      95              :   * \param issue issue to be sent.
      96              :   */
      97              : void
      98            0 : ers::RFilterStream::write( const ers::Issue & issue )
      99              : {
     100            0 :     if ( is_accepted( issue ) )
     101              :     {
     102            0 :         chained().write( issue ); 
     103              :     }
     104            0 : } // send
     105              : 
        

Generated by: LCOV version 2.0-1