libDwm-0.9.45
DwmFileRoller.hh
Go to the documentation of this file.
1//===========================================================================
2// @(#) $DwmPath$
3//===========================================================================
4// Copyright (c) Daniel W. McRobb 2006, 2016
5// All rights reserved.
6//
7// Redistribution and use in source and binary forms, with or without
8// modification, are permitted provided that the following conditions
9// are met:
10//
11// 1. Redistributions of source code must retain the above copyright
12// notice, this list of conditions and the following disclaimer.
13// 2. Redistributions in binary form must reproduce the above copyright
14// notice, this list of conditions and the following disclaimer in the
15// documentation and/or other materials provided with the distribution.
16// 3. The names of the authors and copyright holders may not be used to
17// endorse or promote products derived from this software without
18// specific prior written permission.
19//
20// IN NO EVENT SHALL DANIEL W. MCROBB BE LIABLE TO ANY PARTY FOR
21// DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES,
22// INCLUDING LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE,
23// EVEN IF DANIEL W. MCROBB HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
24// DAMAGE.
25//
26// THE SOFTWARE PROVIDED HEREIN IS ON AN "AS IS" BASIS, AND
27// DANIEL W. MCROBB HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT,
28// UPDATES, ENHANCEMENTS, OR MODIFICATIONS. DANIEL W. MCROBB MAKES NO
29// REPRESENTATIONS AND EXTENDS NO WARRANTIES OF ANY KIND, EITHER
30// IMPLIED OR EXPRESS, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
31// WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE,
32// OR THAT THE USE OF THIS SOFTWARE WILL NOT INFRINGE ANY PATENT,
33// TRADEMARK OR OTHER RIGHTS.
34//===========================================================================
35
36//---------------------------------------------------------------------------
39//---------------------------------------------------------------------------
40
41#ifndef _DWMFILEROLLER_HH_
42#define _DWMFILEROLLER_HH_
43
44#include <cstdio>
45#include <cstdlib>
46#include <iostream>
47#include <set>
48#include <string>
49
50namespace Dwm {
51
52 //--------------------------------------------------------------------------
57 //--------------------------------------------------------------------------
59 {
60 public:
61 //------------------------------------------------------------------------
63 //------------------------------------------------------------------------
64 typedef enum {
65 e_compressionNone,
66 e_compressionGzip,
67 e_compressionBzip2
69
70 //------------------------------------------------------------------------
78 //------------------------------------------------------------------------
79 FileRoller(const std::string & dir,
80 const std::string & prefix,
81 size_t maxSize, size_t numFiles,
82 CompressionEnum compression = e_compressionNone);
83
84 //------------------------------------------------------------------------
88 //------------------------------------------------------------------------
89 bool FilesNeedRolling() const;
90
91 //------------------------------------------------------------------------
99 //------------------------------------------------------------------------
100 bool FilesNeedRolling(int fd) const;
101
102 //------------------------------------------------------------------------
110 //------------------------------------------------------------------------
111 bool FilesNeedRolling(std::ostream & os) const;
112
113 //------------------------------------------------------------------------
121 //------------------------------------------------------------------------
122 bool FilesNeedRolling(FILE *f) const;
123
124 //------------------------------------------------------------------------
127 //------------------------------------------------------------------------
128 bool RollFiles();
129
130 //------------------------------------------------------------------------
132 //------------------------------------------------------------------------
133 size_t MaxSize() const;
134
135 //------------------------------------------------------------------------
137 //------------------------------------------------------------------------
138 size_t MaxSize(size_t maxSize);
139
140 //------------------------------------------------------------------------
142 //------------------------------------------------------------------------
143 size_t NumFiles() const;
144
145 //------------------------------------------------------------------------
147 //------------------------------------------------------------------------
148 size_t NumFiles(size_t numFiles);
149
150 private:
151 std::string _dir;
152 std::string _prefix;
153 off_t _maxSize;
154 size_t _numFiles;
155 CompressionEnum _compression;
156
157 bool GzipFile(const std::string & src, const std::string & dst) const;
158 bool BzipFile(const std::string & src, const std::string & dst) const;
159 bool GetFilename(size_t fileNum, std::string & filename) const;
160
161 };
162
163} // namespace Dwm
164
165#endif // _DWMFILEROLLER_HH_
166
167//---------------------------- emacs settings -----------------------------
168// Local Variables:
169// mode: C++
170// tab-width: 2
171// indent-tabs-mode: nil
172// c-basic-offset: 2
173// End:
174//-------------------------------------------------------------------------
This class can be used to roll over files such as log files.
Definition DwmFileRoller.hh:59
CompressionEnum
Available compression types.
Definition DwmFileRoller.hh:64
bool FilesNeedRolling(FILE *f) const
Returns true if the current write position of f is larger than our maximum file size (set with maxSiz...
FileRoller(const std::string &dir, const std::string &prefix, size_t maxSize, size_t numFiles, CompressionEnum compression=e_compressionNone)
Constructor.
bool FilesNeedRolling(int fd) const
Returns true if the current write position of fd is larger than our maximum file size (set with maxSi...
size_t MaxSize() const
Returns the max file size.
size_t NumFiles(size_t numFiles)
Sets and returns the max file size.
size_t NumFiles() const
Returns the max file size.
size_t MaxSize(size_t maxSize)
Sets and returns the max file size.
bool FilesNeedRolling(std::ostream &os) const
Returns true if the current write position of os is larger than our maximum file size (set with maxSi...
bool FilesNeedRolling() const
Returns true if the active file (identified by the dir and prefix in the call to our constructor) is ...
bool RollFiles()
Rolls the files.