w11 - cpp 0.794
Backend server for Rlink and w11
Loading...
Searching...
No Matches
RlogFile.hpp
Go to the documentation of this file.
1// $Id: RlogFile.hpp 1186 2019-07-12 17:49:59Z mueller $
2// SPDX-License-Identifier: GPL-3.0-or-later
3// Copyright 2011-2018 by Walter F.J. Mueller <W.F.J.Mueller@gsi.de>
4//
5// Revision History:
6// Date Rev Version Comment
7// 2018-12-17 1085 1.2.2 use std::mutex instead of boost
8// 2018-12-16 1084 2.2.1 use =delete for noncopyable instead of boost
9// 2015-01-08 631 2.2 Open(): now with RerrMsg and cout/cerr support
10// 2013-02-23 492 2.1 add Name(), keep log file name; add Dump()
11// 2013-02-22 491 2.0 add Write(),IsNew(), RlogMsg iface; use lockable
12// 2011-04-24 380 1.0.1 use boost::noncopyable (instead of private dcl's)
13// 2011-01-30 357 1.0 Initial version
14// ---------------------------------------------------------------------------
15
20#ifndef included_Retro_RlogFile
21#define included_Retro_RlogFile 1
22
23#include <string>
24#include <ostream>
25#include <fstream>
26#include <mutex>
27
28#include "RerrMsg.hpp"
29
30namespace Retro {
31
32 class RlogMsg; // forw decl to avoid circular incl
33
34 class RlogFile {
35 public:
36 RlogFile();
37 explicit RlogFile(std::ostream* os, const std::string& name = "");
38 ~RlogFile();
39
40 RlogFile(const RlogFile&) = delete; // noncopyable
41 RlogFile& operator=(const RlogFile&) = delete; // noncopyable
42
43 bool IsNew() const;
44 bool Open(std::string name, RerrMsg& emsg);
45 void Close();
46 void UseStream(std::ostream* os, const std::string& name = "");
47 const std::string& Name() const;
48
49 void Write(const std::string& str, char tag = 0);
50
51 void Dump(std::ostream& os, int ind=0, const char* text=0) const;
52
53 // provide Lockable interface
54 void lock();
55 void unlock();
56
57 RlogFile& operator<<(const RlogMsg& lmsg);
58
59 protected:
60 std::ostream& Stream();
61 void ClearTime();
62 std::string BuildinStreamName(std::ostream* os, const std::string& str);
63
64 protected:
65 std::ostream* fpExtStream;
66 std::ofstream fIntStream;
67 bool fNew;
68 std::string fName;
71 int fTagDay;
72 std::mutex fMutex;
73 };
74
75} // end namespace Retro
76
77#include "RlogFile.ipp"
78
79#endif
FIXME_docs.
Definition: RerrMsg.hpp:25
FIXME_docs.
Definition: RlogFile.hpp:34
std::ostream * fpExtStream
pointer to external stream
Definition: RlogFile.hpp:65
void Close()
FIXME_docs.
Definition: RlogFile.cpp:104
void unlock()
FIXME_docs.
Definition: RlogFile.cpp:193
int fTagYear
year of last time tag
Definition: RlogFile.hpp:69
RlogFile & operator<<(const RlogMsg &lmsg)
FIXME_docs.
Definition: RlogFile.cpp:202
int fTagMonth
month of last time tag
Definition: RlogFile.hpp:70
bool IsNew() const
FIXME_docs.
Definition: RlogFile.ipp:22
std::ofstream fIntStream
internal stream
Definition: RlogFile.hpp:66
void UseStream(std::ostream *os, const std::string &name="")
FIXME_docs.
Definition: RlogFile.cpp:113
~RlogFile()
Destructor.
Definition: RlogFile.cpp:73
int fTagDay
day of last time tag
Definition: RlogFile.hpp:71
std::string fName
log file name
Definition: RlogFile.hpp:68
void lock()
FIXME_docs.
Definition: RlogFile.cpp:184
bool Open(std::string name, RerrMsg &emsg)
FIXME_docs.
Definition: RlogFile.cpp:79
RlogFile(const RlogFile &)=delete
void ClearTime()
FIXME_docs.
Definition: RlogFile.cpp:212
bool fNew
true if never opened or used
Definition: RlogFile.hpp:67
const std::string & Name() const
FIXME_docs.
Definition: RlogFile.ipp:30
std::ostream & Stream()
FIXME_docs.
Definition: RlogFile.ipp:38
std::mutex fMutex
mutex to lock file
Definition: RlogFile.hpp:72
RlogFile()
Default constructor.
Definition: RlogFile.cpp:47
void Dump(std::ostream &os, int ind=0, const char *text=0) const
FIXME_docs.
Definition: RlogFile.cpp:168
std::string BuildinStreamName(std::ostream *os, const std::string &str)
FIXME_docs.
Definition: RlogFile.cpp:223
void Write(const std::string &str, char tag=0)
FIXME_docs.
Definition: RlogFile.cpp:125
RlogFile & operator=(const RlogFile &)=delete
FIXME_docs.
Definition: RlogMsg.hpp:24
Declaration of class ReventLoop.
Definition: ReventLoop.cpp:47