Sierra Toolkit  Version of the Day
WriterRegistry.cpp
1 #include <stk_util/diag/WriterRegistry.hpp>
2 #include <stk_util/diag/Option.hpp>
3 
4 namespace sierra {
5 namespace Diag {
6 
7 WriterThrowSafe::WriterThrowSafe()
8 {
9  for (Diag::WriterRegistry::iterator it = Diag::getWriterRegistry().begin(); it != Diag::getWriterRegistry().end(); ++it)
10  m_writerVector.push_back(new stk_classic::diag::WriterThrowSafe(*(*it).second.first));
11 }
12 
13 
14 WriterThrowSafe::~WriterThrowSafe()
15 {
16  for (std::vector<stk_classic::diag::WriterThrowSafe *>::iterator it = m_writerVector.begin(); it != m_writerVector.end(); ++it)
17  delete (*it);
18 }
19 
20 
21 WriterRegistry::WriterRegistry()
22 {}
23 
24 
25 WriterRegistry::~WriterRegistry()
26 {}
27 
28 
29 WriterRegistry &
31 {
32  static WriterRegistry s_writerRegistry;
33 
34  return s_writerRegistry;
35 }
36 
37 
38 void
40  const std::string & name,
41  Writer & diag_writer,
42  OptionMaskParser & option_parser)
43 {
44  getWriterRegistry().insert(std::make_pair(name, std::make_pair(&diag_writer, &option_parser)));
45 }
46 
47 
48 void
50  const std::string & name,
51  Writer & writer)
52 {
53  WriterRegistry::iterator it = getWriterRegistry().find(name);
54  if (it != getWriterRegistry().end() && (*it).second.first == &writer)
55  getWriterRegistry().erase(it);
56 }
57 
58 } // namespace Diag
59 } // namespace sierra
Definition: Env.cpp:53
void registerWriter(const std::string &name, Writer &diag_writer, OptionMaskParser &option_parser)
Function registerWriter registers a diagnostic writer with the diagnostic writer registry.
Typedef WriterRegistry is a mapping from name to diagnostic writer.
Class Writer implements a runtime selectable diagnostic output writer to aid in the development and d...
Definition: Writer.hpp:49
WriterRegistry & getWriterRegistry()
Function getWriterRegistry returns a reference to the diagnostic writer registry. ...
void unregisterWriter(const std::string &name, Writer &writer)
Member function unregisterWriter unregisters a diagnostic writer from the diagnostic writer registry...