ers::FilterStream Class Reference

filtering stream More...

#include <FilterStream.h>

Inheritance diagram for ers::FilterStream:

ers::Stream List of all members.

Public Member Functions

 FilterStream (Stream *target_ptr, const std::vector< std::string > &include_list, const std::vector< std::string > &exclude_list)
 ~FilterStream ()
 destructor
virtual bool is_accept (const Issue *issue_ptr)
 filter method
virtual void send (const Issue *issue_ptr)
 send method
virtual void print_to (std::ostream &stream) const
 operator std::string () const
virtual Issuereceive ()
 Receives an issue from the stream.

Static Public Member Functions

static FilterStreamfactory (const std::string &include_str, const ::std::string &exclude_str, const std::string &target_str)
 factory method for partially parse information
static FilterStreamfactory (const std::string &parameters)
 factory method for unparsed information

Static Public Attributes

static const char *const FILTER_STREAM_TAG = "filter"
 tag used to identity this stream
static const char *const INCLUDE_TAG = "?"
 tag used to mark the start of the include list
static const char *const EXCLUDE_TAG = "!"
 tag used to mark the start of the exclude list
static const char *const TARGET_TAG = "@"
 tag used to mark the target stream
static const char *const SEPARATORS = ","
 separators between include and exclude qualifiers
static const char *const NULL_STREAM_KEY = "null"

Protected Member Functions

 FilterStream ()
 FilterStream (const FilterStream &other)

Protected Attributes

Streamm_target_stream_ptr
 chained target stream
std::vector< std::stringm_include
 include list
std::vector< std::stringm_exclude
 exclude list

Detailed Description

filtering stream

This stream offers basic filtering capacities It basically hooks up in front of another stream and filters the data output. Filtering is based on two list and include list and and exclude list To be accepted an Issue needs two match two criteria

If the include list is empty, the second condition is not applied. This stream should only be used for severity levels where filtering makes sense, i.e warning, debugs, etc... The syntax to request a filter stream is the following:
filter:filter:?include_qualifier1,include_qualifier2!exclude_qualifier1,exclude_qualifier2@stream_identifier The stream_identifier can be any stream_key used by the ERS system (including a second filter).

For more information on associating a stream to a severity level, see the documentation on the StreamFactory class.

See also:
ers::StreamFactory
Author:
Matthias Wiesmann
Version:
1.0

Definition at line 38 of file FilterStream.h.


Constructor & Destructor Documentation

ers::FilterStream::FilterStream (  )  [protected]

Disabled empty constructor

Definition at line 72 of file FilterStream.cxx.

Referenced by factory().

00072                               : ers::Stream() {
00073 } // FilterStream

ers::FilterStream::FilterStream ( const FilterStream other  )  [protected]

Disabled copy constructor

Definition at line 79 of file FilterStream.cxx.

00079                                                        : ers::Stream(other) {
00080 } // FilterStream

ers::FilterStream::FilterStream ( ers::Stream target_ptr,
const std::vector< std::string > &  include_list,
const std::vector< std::string > &  exclude_list 
)

Constructor

Parameters:
target_ptr pointer to the target stream, the target pointer is assumed to be allocated on the stack and owned by the current object, i.e it will be deleted upon destruction
include_list collection of strings, at least one of these strings need to be present in the qualifiers in order for the Issue to be accepted.
exclude_list collection of strings, no qualifier of the Issue must match those in this collection in order for the Issue to be accepted.

Definition at line 92 of file FilterStream.cxx.

References ERS_CHECK_PTR, m_exclude, m_include, and m_target_stream_ptr.

00093                                                           : ers::Stream() {
00094     ERS_CHECK_PTR(target_ptr); 
00095     m_target_stream_ptr = target_ptr ; 
00096     m_include = include_list ; 
00097     m_exclude = exclude_list ; 
00098 } // FilterStream

ers::FilterStream::~FilterStream (  ) 

destructor

Destructor

Definition at line 105 of file FilterStream.cxx.

References m_target_stream_ptr.

00105                                {
00106     delete(m_target_stream_ptr) ; 
00107 } // FilterStream


Member Function Documentation

ers::FilterStream * ers::FilterStream::factory ( const std::string params  )  [static]

factory method for unparsed information

Builds a stream out of a key string. This method parses the string and calls a more specialised version of the factory method.

Parameters:
params single string describing the requested filter stream
Returns:
pointer to newly heap allocated instance of FilterStream

Definition at line 57 of file FilterStream.cxx.

References EXCLUDE_TAG, factory(), INCLUDE_TAG, deljobs::string, and TARGET_TAG.

00057                                                                   {
00058     std::string::size_type include_start = params.find(INCLUDE_TAG); 
00059     std::string::size_type exclude_start = params.find(EXCLUDE_TAG);
00060     std::string::size_type target_start =  params.find(TARGET_TAG);
00061     std::string include_str = params.substr(include_start+1,exclude_start-1);
00062     std::string exclude_str = params.substr(exclude_start+1,target_start-exclude_start-1);
00063     std::string target_str = params.substr(target_start+1); 
00064     // ERS_DEBUG_0("include: '%s' exclude: '%s' target '%s'",include_str.c_str(),exclude_str.c_str(), target_str.c_str()); 
00065     return factory(include_str,exclude_str,target_str); 
00066 } // factory

ers::FilterStream * ers::FilterStream::factory ( const std::string include_str,
const ::std::string exclude_str,
const std::string target_str 
) [static]

factory method for partially parse information

Builds a stream out of a set of parameters

Parameters:
include_str string containing all the coma separated include qualifiers
exclude_str string containing all the coma separated exclude qualifiers
target_str string containing the key for the target stream, i.e the stream where accepted Issues are sent.

Definition at line 43 of file FilterStream.cxx.

References ers::StreamFactory::create_stream(), FilterStream(), ers::StreamFactory::instance(), SEPARATORS, and ers::Core::tokenize().

Referenced by create_stream(), and factory().

00043                                                                                                                                  {
00044     ers::Stream *target_stream = ers::StreamFactory::instance()->create_stream(target_str); 
00045     std::vector<std::string> include_list = ers::Core::tokenize(include_str,SEPARATORS);
00046     std::vector<std::string> exclude_list = ers::Core::tokenize(exclude_str,SEPARATORS); 
00047     return new FilterStream(target_stream,include_list,exclude_list); 
00048 } // factory

bool ers::FilterStream::is_accept ( const Issue issue_ptr  )  [virtual]

filter method

Filtering method This method checks if an Issue is to be accepted or not.

Parameters:
issue_ptr the issue to check
Returns:
true if the Issue passes filtering, false otherwise.

Definition at line 115 of file FilterStream.cxx.

References ERS_CHECK_PTR, false, ers::Issue::get_value(), m_exclude, m_include, RealDBUtil::npos, ers::Issue::QUALIFIER_LIST_KEY, deljobs::string, and true.

Referenced by send().

00115                                                          {
00116     ERS_CHECK_PTR(issue_ptr);
00117     std::string qualifiers = issue_ptr->get_value(ers::Issue::QUALIFIER_LIST_KEY) ;
00118     if (! qualifiers.empty()) { // we check if qualifiers are in exclude list
00119         std::vector<std::string>::const_iterator e_pos ; 
00120         for(e_pos = m_exclude.begin();e_pos!=m_exclude.end();e_pos++) {
00121             std::string::size_type conflict = qualifiers.find(*e_pos) ; 
00122             if (conflict!=std::string::npos) {
00123                 return false ;   
00124             } // found conflict 
00125         } // for 
00126     } // there are some qualifiers 
00127     if (! m_include.empty()) {
00128         std::vector<std::string>::const_iterator i_pos ; 
00129         for(i_pos = m_include.begin();i_pos!=m_include.end();i_pos++) {
00130             std::string::size_type match = qualifiers.find(*i_pos) ; 
00131             if (match!=std::string::npos) {
00132                 return true ; 
00133             } // found match 
00134         } // for
00135         return false ; 
00136     } // include list contains items 
00137     return true ; 
00138 } // is_accept

ers::Stream::operator std::string (  )  const [inherited]

Definition at line 35 of file Stream.cxx.

References ers::Stream::print_to().

00035                                     {
00036     std::ostringstream stream ; 
00037     print_to(stream); 
00038     return stream.str(); 
00039 } // to string 

void ers::FilterStream::print_to ( std::ostream stream  )  const [virtual]

Prints stream description to stream

Parameters:
stream STL target stream

Reimplemented from ers::Stream.

Definition at line 162 of file FilterStream.cxx.

References EXCLUDE_TAG, FILTER_STREAM_TAG, INCLUDE_TAG, m_exclude, m_include, m_target_stream_ptr, SEPARATORS, and TARGET_TAG.

00162                                                        {
00163     stream << FILTER_STREAM_TAG << ':' ; 
00164     std::vector<std::string>::const_iterator i_pos ; 
00165     stream << INCLUDE_TAG ; 
00166     for(i_pos = m_include.begin();i_pos!=m_include.end();i_pos++) {
00167         if (i_pos!=m_include.begin()) {
00168             stream << SEPARATORS ; 
00169         } // if not first 
00170         stream << *i_pos ; 
00171     } // for include 
00172     stream << EXCLUDE_TAG ; 
00173     std::vector<std::string>::const_iterator e_pos ; 
00174     for(e_pos = m_exclude.begin();e_pos!=m_exclude.end();e_pos++) {
00175         if (e_pos!=m_exclude.begin()) {
00176             stream << SEPARATORS ; 
00177         } // if not first 
00178         stream << *e_pos ; 
00179     } // for exclude 
00180     stream << TARGET_TAG ; 
00181     stream << *m_target_stream_ptr ; 
00182 } // print_to

ers::Issue * ers::Stream::receive (  )  [virtual, inherited]

Receives an issue from the stream.

Reads an isssue on the stream

Returns:
the issue that has been read
Note:
This implementation always returns a null pointer

Reimplemented in ers::FIFOStream.

Definition at line 55 of file Stream.cxx.

00055                              {
00056     return 0 ; 
00057 } // receive

void ers::FilterStream::send ( const Issue issue_ptr  )  [virtual]

send method

Send method basically calls is_accept to check if the issue is accepted. If this is the case, the send method on the target is called with issue_ptr.

Parameters:
issue_ptr pointer to the issue to send.

Reimplemented from ers::Stream.

Definition at line 147 of file FilterStream.cxx.

References ERS_CHECK_PTR, is_accept(), m_target_stream_ptr, and ers::Stream::send().

00147                                                     {
00148     ERS_CHECK_PTR(issue_ptr);
00149     ERS_CHECK_PTR(m_target_stream_ptr); 
00150     if (is_accept(issue_ptr)) {
00151         // ERS_DEBUG_3("accepted %s:",issue_ptr->what()); 
00152         m_target_stream_ptr->send(issue_ptr); 
00153     } else {
00154         // ERS_DEBUG_3("rejected %s:",issue_ptr->what()); 
00155     } 
00156 } // send


Member Data Documentation

const char *const ers::FilterStream::EXCLUDE_TAG = "!" [static]

tag used to mark the start of the exclude list

Definition at line 48 of file FilterStream.h.

Referenced by factory(), and print_to().

const char *const ers::FilterStream::FILTER_STREAM_TAG = "filter" [static]

tag used to identity this stream

Tag used to identify the stream

Definition at line 46 of file FilterStream.h.

Referenced by create_stream(), and print_to().

const char *const ers::FilterStream::INCLUDE_TAG = "?" [static]

tag used to mark the start of the include list

Definition at line 47 of file FilterStream.h.

Referenced by factory(), and print_to().

std::vector<std::string> ers::FilterStream::m_exclude [protected]

exclude list

Definition at line 42 of file FilterStream.h.

Referenced by FilterStream(), is_accept(), and print_to().

std::vector<std::string> ers::FilterStream::m_include [protected]

include list

Definition at line 41 of file FilterStream.h.

Referenced by FilterStream(), is_accept(), and print_to().

Stream* ers::FilterStream::m_target_stream_ptr [protected]

chained target stream

Definition at line 40 of file FilterStream.h.

Referenced by FilterStream(), print_to(), send(), and ~FilterStream().

const char *const ers::Stream::NULL_STREAM_KEY = "null" [static, inherited]

Key for discard stream

Definition at line 39 of file Stream.h.

Referenced by create_stream(), and ers::Stream::print_to().

const char *const ers::FilterStream::SEPARATORS = "," [static]

separators between include and exclude qualifiers

Definition at line 50 of file FilterStream.h.

Referenced by factory(), and print_to().

const char *const ers::FilterStream::TARGET_TAG = "@" [static]

tag used to mark the target stream

Definition at line 49 of file FilterStream.h.

Referenced by factory(), and print_to().


Generated on Tue Nov 29 23:36:31 2016 for BOSS_7.0.2 by  doxygen 1.4.7