BOSS 8.0.0
BESIII Offline Software System
Loading...
Searching...
No Matches
FilterStream.cxx
Go to the documentation of this file.
1/*
2 * FilterStream.cxx
3 * ers
4 *
5 * Created by Matthias Wiesmann on 31.03.05.
6 * Copyright 2005 CERN. All rights reserved.
7 *
8 */
9
10#include "ers/FilterStream.h"
11#include "ers/InvalidReferenceIssue.h"
12#include "ers/NotImplemented.h"
13#include "ers/StreamFactory.h"
14
15/** Tag used to identify the stream
16 */
17
18const char* const ers::FilterStream::FILTER_STREAM_TAG = "filter";
19const char* const ers::FilterStream::INCLUDE_TAG = "?";
20const char* const ers::FilterStream::EXCLUDE_TAG = "!";
21const char* const ers::FilterStream::TARGET_TAG = "@";
22const char* const ers::FilterStream::SEPARATORS = ",";
23
24namespace {
25 ers::Stream* create_stream( const std::string& protocol, const std::string& uri ) {
27 {
29 // ERS_DEBUG_0("build stream %x",stream);
30 return stream;
31 } // if
32 return 0;
33 } // create_stream
36} // anonymous namespace
37
38/** Builds a stream out of a set of parameters
39 * \param include_str string containing all the coma separated include qualifiers
40 * \param exclude_str string containing all the coma separated exclude qualifiers
41 * \param target_str string containing the key for the target stream, i.e the stream where
42 * accepted Issues are sent. \brief factory method for partially parse information
43 */
44
45ers::FilterStream* ers::FilterStream::factory( const std::string& include_str,
46 const ::std::string& exclude_str,
47 const std::string& target_str ) {
48 ers::Stream* target_stream = ers::StreamFactory::instance()->create_stream( target_str );
49 std::vector<std::string> include_list = ers::Core::tokenize( include_str, SEPARATORS );
50 std::vector<std::string> exclude_list = ers::Core::tokenize( exclude_str, SEPARATORS );
51 return new FilterStream( target_stream, include_list, exclude_list );
52} // factory
53
54/** Builds a stream out of a key string.
55 * This method parses the string and calls a more specialised version of the \c factory method.
56 * \param params single string describing the requested filter stream
57 * \return pointer to newly heap allocated instance of FilterStream
58 * \brief factory method for unparsed information
59 */
60
61ers::FilterStream* ers::FilterStream::factory( const std::string& params ) {
62 std::string::size_type include_start = params.find( INCLUDE_TAG );
63 std::string::size_type exclude_start = params.find( EXCLUDE_TAG );
64 std::string::size_type target_start = params.find( TARGET_TAG );
65 std::string include_str = params.substr( include_start + 1, exclude_start - 1 );
66 std::string exclude_str =
67 params.substr( exclude_start + 1, target_start - exclude_start - 1 );
68 std::string target_str = params.substr( target_start + 1 );
69 // ERS_DEBUG_0("include: '%s' exclude: '%s' target
70 // '%s'",include_str.c_str(),exclude_str.c_str(), target_str.c_str());
71 return factory( include_str, exclude_str, target_str );
72} // factory
73
74/** Disabled empty constructor
75 */
76
78
79/** Disabled copy constructor
80 */
81
83 : ers::Stream( other ) {} // FilterStream
84
85/** Constructor
86 * \param target_ptr pointer to the target stream, the target pointer is assumed to be
87 * allocated on the stack and owned by the current object, i.e it will be deleted upon
88 * destruction \param include_list collection of strings, at least one of these strings need to
89 * be present in the qualifiers in order for the Issue to be accepted. \param exclude_list
90 * collection of strings, no qualifier of the Issue must match those in this collection in
91 * order for the Issue to be accepted.
92 */
93
95 const std::vector<std::string>& include_list,
96 const std::vector<std::string>& exclude_list )
97 : ers::Stream() {
98 ERS_CHECK_PTR( target_ptr );
99 m_target_stream_ptr = target_ptr;
100 m_include = include_list;
101 m_exclude = exclude_list;
102} // FilterStream
103
104/** Destructor
105 */
106
108
109/** Filtering method
110 * This method checks if an Issue is to be accepted or not.
111 * \param issue_ptr the issue to check
112 * \return \c true if the Issue passes filtering, \c false otherwise.
113 */
114
115bool ers::FilterStream::is_accept( const ers::Issue* issue_ptr ) {
116 ERS_CHECK_PTR( issue_ptr );
117 std::string qualifiers = issue_ptr->get_value( ers::Issue::QUALIFIER_LIST_KEY );
118 if ( !qualifiers.empty() )
119 { // we check if qualifiers are in exclude list
120 std::vector<std::string>::const_iterator e_pos;
121 for ( e_pos = m_exclude.begin(); e_pos != m_exclude.end(); e_pos++ )
122 {
123 std::string::size_type conflict = qualifiers.find( *e_pos );
124 if ( conflict != std::string::npos ) { return false; } // found conflict
125 } // for
126 } // there are some qualifiers
127 if ( !m_include.empty() )
128 {
129 std::vector<std::string>::const_iterator i_pos;
130 for ( i_pos = m_include.begin(); i_pos != m_include.end(); i_pos++ )
131 {
132 std::string::size_type match = qualifiers.find( *i_pos );
133 if ( match != std::string::npos ) { return true; } // found match
134 } // for
135 return false;
136 } // include list contains items
137 return true;
138} // is_accept
139
140/** Send method
141 * basically calls \c is_accept to check if the issue is accepted.
142 * If this is the case, the \c send method on the target is called with
143 * \c issue_ptr.
144 * \param issue_ptr pointer to the issue to send.
145 */
146
147void ers::FilterStream::send( const ers::Issue* issue_ptr ) {
148 ERS_CHECK_PTR( issue_ptr );
150 if ( is_accept( issue_ptr ) )
151 {
152 // ERS_DEBUG_3("accepted %s:",issue_ptr->what());
153 m_target_stream_ptr->send( issue_ptr );
154 }
155 else
156 {
157 // ERS_DEBUG_3("rejected %s:",issue_ptr->what());
158 }
159} // send
160
161/** Prints stream description to stream
162 * \param stream STL target stream
163 */
164
165void ers::FilterStream::print_to( std::ostream& stream ) const {
166 stream << FILTER_STREAM_TAG << ':';
167 std::vector<std::string>::const_iterator i_pos;
168 stream << INCLUDE_TAG;
169 for ( i_pos = m_include.begin(); i_pos != m_include.end(); i_pos++ )
170 {
171 if ( i_pos != m_include.begin() ) { stream << SEPARATORS; } // if not first
172 stream << *i_pos;
173 } // for include
174 stream << EXCLUDE_TAG;
175 std::vector<std::string>::const_iterator e_pos;
176 for ( e_pos = m_exclude.begin(); e_pos != m_exclude.end(); e_pos++ )
177 {
178 if ( e_pos != m_exclude.begin() ) { stream << SEPARATORS; } // if not first
179 stream << *e_pos;
180 } // for exclude
181 stream << TARGET_TAG;
182 stream << *m_target_stream_ptr;
183} // print_to
static std::vector< std::string > tokenize(const std::string &text, const std::string &separators)
Definition Core.cxx:157
static FilterStream * factory(const std::string &include_str, const ::std::string &exclude_str, const std::string &target_str)
factory method for partially parse information
std::vector< std::string > m_include
include list
static const char *const TARGET_TAG
tag used to mark the target stream
virtual void print_to(std::ostream &stream) const
static const char *const FILTER_STREAM_TAG
tag used to identity this stream
static const char *const EXCLUDE_TAG
tag used to mark the start of the exclude list
static const char *const SEPARATORS
separators between include and exclude qualifiers
Stream * m_target_stream_ptr
chained target stream
virtual void send(const Issue *issue_ptr)
send method
std::vector< std::string > m_exclude
exclude list
~FilterStream()
destructor
static const char *const INCLUDE_TAG
tag used to mark the start of the include list
virtual bool is_accept(const Issue *issue_ptr)
filter method
Root Issue class.
const std::string & get_value(const std::string &key, const std::string &def) const
Reads the property list.
static const char *const QUALIFIER_LIST_KEY
key used to store the qualifier list
Stream * create_stream(severity_t s)
create a stream for severity_t
bool register_factory(const std::string &name, create_stream_callback callback)
register a factory method
static StreamFactory * instance()
return the singleton
Root/Null issue stream.
efhlt::Interface * factory(void)
Definition factory.cxx:15