Line data Source code
1 : /*
2 : * IssueFactory.cxx
3 : * ers
4 : *
5 : * Created by Serguei Kolos on 30.11.04.
6 : * Modified by Serguei Kolos on 10.08.05.
7 : * Copyright 2005 CERN. All rights reserved.
8 : *
9 : */
10 :
11 : #include <ers/ers.hpp>
12 : #include <ers/IssueFactory.hpp>
13 : #include <ers/StreamFactory.hpp>
14 : #include <ers/AnyIssue.hpp>
15 : #include <ers/internal/SingletonCreator.hpp>
16 : #include <ers/internal/macro.hpp>
17 :
18 : /** Returns the singleton instance of the factory.
19 : * \return a reference to the singleton instance
20 : */
21 : ers::IssueFactory &
22 199041 : ers::IssueFactory::instance()
23 : {
24 199041 : static ers::IssueFactory * instance = ers::SingletonCreator<ers::IssueFactory>::create();
25 :
26 199041 : return *instance;
27 : } // instance
28 :
29 : /** Register an issue type with the factory
30 : * \param name the name that will be used to lookup new instances
31 : * \param creator a pointer to the function used to create new instance for that particular type of function
32 : */
33 : void
34 199041 : ers::IssueFactory::register_issue( const std::string & name, IssueCreator creator )
35 : {
36 199041 : FunctionMap::const_iterator it = m_creators.find(name);
37 199041 : if ( it == m_creators.end() )
38 : {
39 9040 : m_creators[name] = creator;
40 : }
41 199041 : }
42 :
43 : /** Builds an issue out of the name it was registered with
44 : * \param name the name used to indentify the class
45 : * \return an newly allocated instance of type \c name or AnyIssue
46 : * \note If the requested type cannot be resolved an instance of type AnyIssue
47 : */
48 : ers::Issue *
49 0 : ers::IssueFactory::create( const std::string & name,
50 : const ers::Context & context ) const
51 : {
52 0 : FunctionMap::const_iterator it = m_creators.find(name);
53 0 : if ( it == m_creators.end() )
54 : {
55 0 : ERS_INTERNAL_DEBUG( 1, "Creator for the \"" << name << "\" issue is not found" );
56 0 : return new ers::AnyIssue( name, context );
57 : }
58 :
59 0 : ERS_INTERNAL_DEBUG( 2, "Creating the \"" << name << "\" issue" );
60 0 : return (it->second)( context );
61 : }
62 :
63 :
64 : ers::Issue *
65 0 : ers::IssueFactory::create( const std::string & name,
66 : const std::list<std::string> & inheritance,
67 : const ers::Context & context,
68 : Severity severity,
69 : const system_clock::time_point & time,
70 : const std::string & message,
71 : const std::vector<std::string> & qualifiers,
72 : const ers::string_map & parameters,
73 : const Issue * cause ) const
74 : {
75 0 : ers::Issue * issue = create( name, context );
76 0 : issue->m_message = message;
77 0 : issue->m_severity = severity;
78 0 : issue->m_qualifiers = qualifiers;
79 0 : issue->m_values = parameters;
80 0 : issue->m_time = time;
81 0 : issue->m_cause.reset( cause );
82 :
83 0 : auto * any = dynamic_cast<ers::AnyIssue *>( issue );
84 0 : if ( any ) {
85 0 : any -> m_inheritance = inheritance;
86 : }
87 0 : return issue;
88 : }
89 :
|