Changeset 107:c6c676b6714d in rrlib_logging


Ignore:
Timestamp:
11.09.2013 11:45:10 (7 years ago)
Author:
Tobias Föhst <foehst@…>
Branch:
default
Phase:
public
Message:

Added ctors to create sinks directly without factory

Files:
7 edited

Legend:

Unmodified
Added
Removed
  • configuration/tConfiguration.cpp

    r106 r107  
    4242//---------------------------------------------------------------------- 
    4343#include "rrlib/logging/configuration/tDomainRegistry.h" 
     44#include "rrlib/logging/sinks/tFile.h" 
    4445 
    4546//---------------------------------------------------------------------- 
     
    168169  if (sink_mask | eLOG_SINK_STDOUT) 
    169170  { 
    170     xml::tNode node; 
    171     node.SetAttribute("id", "stdout"); 
    172     this->AddSink(std::shared_ptr<sinks::tSink>(sinks::tSinkFactory::Instance().Create("stream", node, *this))); 
     171    this->AddSink(std::shared_ptr<sinks::tSink>(new sinks::tStream("stdout"))); 
    173172  } 
    174173  if (sink_mask | eLOG_SINK_STDERR) 
    175174  { 
    176     xml::tNode node; 
    177     node.SetAttribute("id", "stderr"); 
    178     this->AddSink(std::shared_ptr<sinks::tSink>(sinks::tSinkFactory::Instance().Create("stream", node, *this))); 
     175    this->AddSink(std::shared_ptr<sinks::tSink>(new sinks::tStream("stderr"))); 
    179176  } 
    180177  if (sink_mask | eLOG_SINK_FILE) 
    181178  { 
    182179    std::cerr << "INFO: The meaning of this sink changed to be the same as combined file. There will be one file for the whole subtree starting at " << this->GetFullQualifiedName() << std::endl; 
    183     xml::tNode node; 
    184     this->AddSink(std::shared_ptr<sinks::tSink>(sinks::tSinkFactory::Instance().Create("file", node, *this))); 
     180    this->AddSink(std::shared_ptr<sinks::tSink>(new sinks::tFile(*this))); 
    185181  } 
    186182  if (sink_mask | eLOG_SINK_COMBINED_FILE) 
    187183  { 
    188     xml::tNode node; 
    189     this->AddSink(std::shared_ptr<sinks::tSink>(sinks::tSinkFactory::Instance().Create("file", node, *this))); 
     184    this->AddSink(std::shared_ptr<sinks::tSink>(new sinks::tFile(*this))); 
    190185  } 
    191186} 
  • sinks/tFile.cpp

    r106 r107  
    7676// tFile constructors 
    7777//---------------------------------------------------------------------- 
     78tFile::tFile(const tConfiguration &configuration) : 
     79  configuration(configuration) 
     80{} 
     81 
    7882tFile::tFile(const xml::tNode &node, const tConfiguration &configuration) : 
    7983  configuration(configuration) 
  • sinks/tFile.h

    r106 r107  
    8080public: 
    8181 
     82  tFile(const tConfiguration &configuration); 
    8283  tFile(const xml::tNode &node, const tConfiguration &configuration); 
     84 
    8385  virtual ~tFile(); 
    8486 
  • sinks/tSpeechSynthesis.cpp

    r106 r107  
    7171//---------------------------------------------------------------------- 
    7272 
     73namespace 
     74{ 
     75speech_synthesis::tStreamBuffer *SpeechStreamBufferFromVoiceString(const std::string &voice_string) 
     76{ 
     77  size_t separator_position = voice_string.find(cSEPARATOR); 
     78  if (separator_position != std::string::npos) 
     79  { 
     80    std::string synthesis = voice_string.substr(0, separator_position); 
     81    std::string voice = voice_string.substr(separator_position + cSEPARATOR.length()); 
     82    return new speech_synthesis::tStreamBuffer(*speech_synthesis::tVoiceFactory::Instance().Create(synthesis, voice)); 
     83  } 
     84  return NULL; 
     85} 
     86} 
     87 
    7388//---------------------------------------------------------------------- 
    7489// tSpeechSynthesis constructors 
    7590//---------------------------------------------------------------------- 
     91tSpeechSynthesis::tSpeechSynthesis(const std::string &voice) : 
     92  stream_buffer(SpeechStreamBufferFromVoiceString(voice)) 
     93{} 
     94 
    7695tSpeechSynthesis::tSpeechSynthesis(const xml::tNode &node, const tConfiguration &configuration) : 
    7796  stream_buffer(NULL) 
     
    82101  } 
    83102 
    84   std::string voice_string = node.GetStringAttribute("voice"); 
    85   size_t separator_position = voice_string.find(cSEPARATOR); 
    86   if (separator_position != std::string::npos) 
    87   { 
    88     std::string synthesis = voice_string.substr(0, separator_position); 
    89     std::string voice = voice_string.substr(separator_position + cSEPARATOR.length()); 
    90     this->stream_buffer = new speech_synthesis::tStreamBuffer(*speech_synthesis::tVoiceFactory::Instance().Create(synthesis, voice)); 
    91   } 
     103  this->stream_buffer = SpeechStreamBufferFromVoiceString(node.GetStringAttribute("voice")); 
    92104} 
    93105 
  • sinks/tSpeechSynthesis.h

    r106 r107  
    7474public: 
    7575 
     76  tSpeechSynthesis(const std::string &voice); 
    7677  tSpeechSynthesis(const xml::tNode &node, const tConfiguration &configuration); 
    7778 
  • sinks/tStream.cpp

    r106 r107  
    7171//---------------------------------------------------------------------- 
    7272 
     73namespace 
     74{ 
     75tFormattingBuffer IdToStreamBuffer(const std::string &id) 
     76{ 
     77  if (id == "stdout") 
     78  { 
     79    return tFormattingBuffer(std::cout.rdbuf()); 
     80  } 
     81  if (id == "stderr") 
     82  { 
     83    return tFormattingBuffer(std::cerr.rdbuf()); 
     84  } 
     85  throw std::runtime_error("Could not identify and use stream for logging"); 
     86} 
     87} 
     88 
    7389//---------------------------------------------------------------------- 
    7490// tStream constructors 
    7591//---------------------------------------------------------------------- 
     92tStream::tStream(const std::string &id) : 
     93  stream_buffer(IdToStreamBuffer(id)) 
     94{} 
     95 
    7696tStream::tStream(const xml::tNode &node, const tConfiguration &configuration) : 
    7797  stream_buffer(NULL) 
     
    82102  } 
    83103 
    84   std::string id = node.GetStringAttribute("id"); 
    85   if (id == "stdout") 
    86   { 
    87     this->stream_buffer = tFormattingBuffer(std::cout.rdbuf()); 
    88     return; 
    89   } 
    90   if (id == "stderr") 
    91   { 
    92     this->stream_buffer = tFormattingBuffer(std::cerr.rdbuf()); 
    93     return; 
    94   } 
    95  
    96   throw std::runtime_error("Could not identify and use stream for logging"); 
     104  this->stream_buffer = IdToStreamBuffer(node.GetStringAttribute("id")); 
    97105} 
    98106 
  • sinks/tStream.h

    r106 r107  
    7979public: 
    8080 
     81  tStream(const std::string &id); 
    8182  tStream(const xml::tNode &node, const tConfiguration &configuration); 
    8283 
Note: See TracChangeset for help on using the changeset viewer.