📄 logfile.hpp
字号:
/*** *** See the file "L2_RTI_EO1/disclaimers-and-notices-L2.txt" for *** information on usage and redistribution of this file, *** and for a DISCLAIMER OF ALL WARRANTIES. ***/#ifndef LOGFILE_H#define LOGFILE_H#include <stdio.h> // for FILEclass LOG_MSG;/** * Encapsulates information about a log stream, allowing files to be of * bounded size, with round-robin alternation among versions. * \ingroup RTI */class LogFile {public: /** * The only constructor. * \param pathname the pathname of the log file * \param linesPerVersion the number of lines to be written to a log file * before it is closed and a different version is opened; must be positive * \param numberOfVersions the number of different versions of a log file to * be created; must be positive. */ LogFile(const char* pathname, unsigned bytesPerVersion, unsigned numberOfVersions); /** Non-default destructor. */ ~LogFile(); /** Return the pathname of the log file. */ const char* getPathname() const { return d_pathname; } /** * Open the file if needed. Write the message to the log file. If the log * file is full, switch to a different file version. * \param logMsg a LOG_MSG object */ void writeToDisk(const LOG_MSG& logMsg); /** Is the log file stream open? */ bool isOpen() const { return (d_file != 0); } /** * Close the log file stream and set it to 0. The log files must be closed * explicitly, taking care of order. This can not be left to the destructor. */ void closeFile();private: /** Insert the version number before the final period. */ void makeVersionPathname(char versionPathname[]); /** If d_file is not open, try to open it. */ void assureOpen();private: /** The pathname of the log file. */ const char* const d_pathname; /** * The number of lines to be written to a log file before it is closed and a * different version is opened. Must be positive. */ const unsigned d_bytesPerVersion; /** * The number of different versions of a log file to be created. Must be * positive. */ const unsigned d_numberOfVersions; /** The current version that is being written (if any).*/ unsigned d_currentVersion; /** The number of bytes that have been written to the current file version.*/ unsigned d_byteCount; /** The log file descriptor. */ int d_file;};#endif // LOGFILE_H
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -