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