BOSS 7.0.3
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/StreamFactory.h"
13#include "ers/NotImplemented.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) {
28 // ERS_DEBUG_0("build stream %x",stream);
29 return stream ;
30 } // if
31 return 0 ;
32 } // create_stream
34} // anonymous namespace
35
36/** Builds a stream out of a set of parameters
37 * \param include_str string containing all the coma separated include qualifiers
38 * \param exclude_str string containing all the coma separated exclude qualifiers
39 * \param target_str string containing the key for the target stream, i.e the stream where accepted Issues are sent.
40 * \brief factory method for partially parse information
41 */
42
43ers::FilterStream * ers::FilterStream::factory(const std::string &include_str, const::std::string &exclude_str, const std::string &target_str) {
44 ers::Stream *target_stream = ers::StreamFactory::instance()->create_stream(target_str);
45 std::vector<std::string> include_list = ers::Core::tokenize(include_str,SEPARATORS);
46 std::vector<std::string> exclude_list = ers::Core::tokenize(exclude_str,SEPARATORS);
47 return new FilterStream(target_stream,include_list,exclude_list);
48} // factory
49
50/** Builds a stream out of a key string.
51 * This method parses the string and calls a more specialised version of the \c factory method.
52 * \param params single string describing the requested filter stream
53 * \return pointer to newly heap allocated instance of FilterStream
54 * \brief factory method for unparsed information
55 */
56
57ers::FilterStream * ers::FilterStream::factory(const std::string &params) {
58 std::string::size_type include_start = params.find(INCLUDE_TAG);
59 std::string::size_type exclude_start = params.find(EXCLUDE_TAG);
60 std::string::size_type target_start = params.find(TARGET_TAG);
61 std::string include_str = params.substr(include_start+1,exclude_start-1);
62 std::string exclude_str = params.substr(exclude_start+1,target_start-exclude_start-1);
63 std::string target_str = params.substr(target_start+1);
64 // ERS_DEBUG_0("include: '%s' exclude: '%s' target '%s'",include_str.c_str(),exclude_str.c_str(), target_str.c_str());
65 return factory(include_str,exclude_str,target_str);
66} // factory
67
68
69/** Disabled empty constructor
70*/
71
73} // FilterStream
74
75
76/** Disabled copy constructor
77*/
78
80} // FilterStream
81
82
83/** Constructor
84 * \param target_ptr pointer to the target stream, the target pointer is assumed to be allocated
85 * on the stack and owned by the current object, i.e it will be deleted upon destruction
86 * \param include_list collection of strings, at least one of these strings need to be present
87 * in the qualifiers in order for the Issue to be accepted.
88 * \param exclude_list collection of strings, no qualifier of the Issue must match those in this
89 * collection in order for the Issue to be accepted.
90 */
91
92ers::FilterStream::FilterStream(ers::Stream *target_ptr, const std::vector<std::string> &
93include_list, const std::vector<std::string> & exclude_list) : ers::Stream() {
94 ERS_CHECK_PTR(target_ptr);
95 m_target_stream_ptr = target_ptr ;
96 m_include = include_list ;
97 m_exclude = exclude_list ;
98} // FilterStream
99
100
101
102/** Destructor
103 */
104
106 delete(m_target_stream_ptr) ;
107} // FilterStream
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
116 ERS_CHECK_PTR(issue_ptr);
117 std::string qualifiers = issue_ptr->get_value(ers::Issue::QUALIFIER_LIST_KEY) ;
118 if (! qualifiers.empty()) { // we check if qualifiers are in exclude list
119 std::vector<std::string>::const_iterator e_pos ;
120 for(e_pos = m_exclude.begin();e_pos!=m_exclude.end();e_pos++) {
121 std::string::size_type conflict = qualifiers.find(*e_pos) ;
122 if (conflict!=std::string::npos) {
123 return false ;
124 } // found conflict
125 } // for
126 } // there are some qualifiers
127 if (! m_include.empty()) {
128 std::vector<std::string>::const_iterator i_pos ;
129 for(i_pos = m_include.begin();i_pos!=m_include.end();i_pos++) {
130 std::string::size_type match = qualifiers.find(*i_pos) ;
131 if (match!=std::string::npos) {
132 return true ;
133 } // 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);
149 ERS_CHECK_PTR(m_target_stream_ptr);
150 if (is_accept(issue_ptr)) {
151 // ERS_DEBUG_3("accepted %s:",issue_ptr->what());
152 m_target_stream_ptr->send(issue_ptr);
153 } else {
154 // ERS_DEBUG_3("rejected %s:",issue_ptr->what());
155 }
156} // send
157
158/** Prints stream description to stream
159 * \param stream STL target stream
160 */
161
162void ers::FilterStream::print_to(std::ostream& stream) const {
163 stream << FILTER_STREAM_TAG << ':' ;
164 std::vector<std::string>::const_iterator i_pos ;
165 stream << INCLUDE_TAG ;
166 for(i_pos = m_include.begin();i_pos!=m_include.end();i_pos++) {
167 if (i_pos!=m_include.begin()) {
168 stream << SEPARATORS ;
169 } // if not first
170 stream << *i_pos ;
171 } // for include
172 stream << EXCLUDE_TAG ;
173 std::vector<std::string>::const_iterator e_pos ;
174 for(e_pos = m_exclude.begin();e_pos!=m_exclude.end();e_pos++) {
175 if (e_pos!=m_exclude.begin()) {
176 stream << SEPARATORS ;
177 } // if not first
178 stream << *e_pos ;
179 } // for exclude
180 stream << TARGET_TAG ;
181 stream << *m_target_stream_ptr ;
182} // print_to
183
184
185
efhlt::Interface * factory(void)
Definition: factory.cxx:17
static std::vector< std::string > tokenize(const std::string &text, const std::string &separators)
Definition: Core.cxx:151
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
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.