Skip to content
Snippets Groups Projects
Commit 68a9fca1 authored by Gerhard Raven's avatar Gerhard Raven
Browse files

Modernize StreamLogger

   - use std::unique_ptr with special deleter to deal with the
     'sometimes' ownership
parent 6a3a3e8d
No related branches found
No related tags found
2 merge requests!15[WIP] Code Modernization ,!7C++11 modernization changes
......@@ -13,20 +13,27 @@ public:
StreamLogger(const std::string& file);
StreamLogger(std::ostream &ost);
StreamLogger(IMessageSvc*, MSG::Level);
// StreamLogger();
~StreamLogger();
std::string name() const;
std::string name() const { return m_name; }
void WriteToStream(const std::string& str) { *p_ost << str << std::endl; }
void WriteToMsgSvc(const std::string& str) { *p_msgStr << m_level << str
void WriteToStream(const std::string& str) { *m_ost << str << std::endl; }
void WriteToMsgSvc(const std::string& str) { *m_msgStr << m_level << str
<< endmsg; }
private:
bool m_isMine;
std::ostream *p_ost;
MsgStream *p_msgStr;
struct maybeDelete {
bool m_isMine;
maybeDelete(bool isMine = false) : m_isMine(isMine) {}
maybeDelete& operator=(maybeDelete&& rhs) { m_isMine = rhs.m_isMine; rhs.m_isMine = false; return *this; }
maybeDelete& operator=(maybeDelete& rhs) = delete;
maybeDelete(maybeDelete&& rhs) { *this = std::move(rhs); }
maybeDelete(const maybeDelete& rhs) = delete;
template <typename P>
void operator()(P* p) { if (m_isMine) delete p; }
};
std::unique_ptr<std::ostream,maybeDelete> m_ost;
std::unique_ptr<MsgStream> m_msgStr;
MSG::Level m_level;
std::string m_name;
};
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment