DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
StreamFactory.cpp
Go to the documentation of this file.
1/*
2 * StreamFactory.cxx
3 * ERS
4 *
5 * Created by Serguei Kolos on 21.01.05.
6 * Modified by Serguei Kolos on 21.11.05.
7 * Copyright 2005 CERN. All rights reserved.
8 *
9 */
10
11#include <iostream>
12
13#include <ers/Issue.hpp>
14#include <ers/OutputStream.hpp>
15#include <ers/StreamFactory.hpp>
16#include <ers/Severity.hpp>
17#include <ers/ers.hpp>
18#include <ers/internal/Util.hpp>
23
28ers::StreamFactory &
29ers::StreamFactory::instance()
30{
33 static ers::StreamFactory * instance = ers::SingletonCreator<ers::StreamFactory>::create();
34
35 return *instance;
36} // instance
37
47ers::StreamFactory::create_out_stream( const std::string & format ) const
48{
49 std::string key = format;
50 std::string param;
51 std::string::size_type start = format.find( '(' );
52 if ( start != std::string::npos )
53 {
54 key = format.substr( 0, start );
55 std::string::size_type end = format.find( ')', start );
56 if ( end != std::string::npos )
57 param = format.substr( start + 1, end - start - 1 );
58 }
59
60 OutFunctionMap::const_iterator it = m_out_factories.find( key );
61
62 if( it != m_out_factories.end() )
63 {
64 try
65 {
66 return it->second( param );
67 }
68 catch( ers::Issue & issue )
69 {
70 ERS_INTERNAL_ERROR( issue )
71 }
72 }
73 else
74 {
75 ERS_INTERNAL_ERROR( "Creator for the \"" << key << "\" stream is not found" )
76 }
77
78 return 0;
79}
80
90ers::StreamFactory::create_in_stream( const std::string & stream,
91 const std::string & param ) const
92{
93 return create_in_stream( stream, { param } );
94}
95
105ers::StreamFactory::create_in_stream(
106 const std::string & stream,
107 const std::initializer_list<std::string> & params ) const
108{
109 InFunctionMap::const_iterator it = m_in_factories.find( stream );
110
111 if( it != m_in_factories.end() )
112 {
113 try
114 {
115 return it->second( params );
116 }
117 catch( ers::Issue & issue )
118 {
119 throw ers::InvalidFormat( ERS_HERE, stream, issue );
120 }
121 }
122
123 throw ers::InvalidFormat( ERS_HERE, stream );
124}
125
136void
137ers::StreamFactory::register_in_stream( const std::string & name, InputStreamCreator callback )
138{
139 m_in_factories[name] = callback;
140}
141
152void
153ers::StreamFactory::register_out_stream( const std::string & name, OutputStreamCreator callback )
154{
155 m_out_factories[name] = callback;
156}
157
158std::ostream &
159ers::operator<<( std::ostream & out, const ers::StreamFactory & sf )
160{
161 StreamFactory::OutFunctionMap::const_iterator oit = sf.m_out_factories.begin();
162 for( ; oit != sf.m_out_factories.end(); ++oit )
163 {
164 out << oit->first << "\t\"" << oit->second << "\"" << std::endl;
165 }
166
167 StreamFactory::InFunctionMap::const_iterator iit = sf.m_in_factories.begin();
168 for( ; iit != sf.m_in_factories.end(); ++iit )
169 {
170 out << iit->first << "\t\"" << iit->second << "\"" << std::endl;
171 }
172 return out;
173}
#define ERS_HERE
ERS Issue input stream interface.
Base class for any user define issue.
Definition Issue.hpp:69
ERS abstract output stream interface.
#define ERS_INTERNAL_ERROR(message)
Definition macro.hpp:52
FELIX Initialization std::string initerror FELIX queue timed out
std::ostream & operator<<(std::ostream &, const ers::Configuration &)