BDE 4.39.x Production Release
Loading...
Searching...
No Matches
balb_filecleanerconfiguration.h
Go to the documentation of this file.
1/// @file balb_filecleanerconfiguration.h
2///
3/// The content of this file has been pre-processed for Doxygen.
4///
5
6
7// balb_filecleanerconfiguration.h -*-C++-*-
8#ifndef INCLUDED_BALB_FILECLEANERCONFIGURATION
9#define INCLUDED_BALB_FILECLEANERCONFIGURATION
10
11#include <bsls_ident.h>
12BSLS_IDENT("$Id: $")
13
14/// @defgroup balb_filecleanerconfiguration balb_filecleanerconfiguration
15/// @brief Provide an attribute class for file cleaner configuration.
16/// @addtogroup bal
17/// @{
18/// @addtogroup balb
19/// @{
20/// @addtogroup balb_filecleanerconfiguration
21/// @{
22///
23/// <h1> Outline </h1>
24/// * <a href="#balb_filecleanerconfiguration-purpose"> Purpose</a>
25/// * <a href="#balb_filecleanerconfiguration-classes"> Classes </a>
26/// * <a href="#balb_filecleanerconfiguration-description"> Description </a>
27/// * <a href="#balb_filecleanerconfiguration-attributes"> Attributes </a>
28/// * <a href="#balb_filecleanerconfiguration-thread-safety"> Thread Safety </a>
29/// * <a href="#balb_filecleanerconfiguration-usage"> Usage </a>
30/// * <a href="#balb_filecleanerconfiguration-example-1-basic-usage"> Example 1: Basic Usage </a>
31///
32/// # Purpose {#balb_filecleanerconfiguration-purpose}
33/// Provide an attribute class for file cleaner configuration.
34///
35/// # Classes {#balb_filecleanerconfiguration-classes}
36///
37/// - balb::FileCleanerConfiguration: configuration spec for a file cleaner
38///
39/// @see balb_filecleanerutil
40///
41/// # Description {#balb_filecleanerconfiguration-description}
42/// This component provides a single, simply constrained
43/// (value-semantic) attribute class, `balb::FileCleanerConfiguration`, that
44/// contains a set of attributes (objects and parameters) of a file cleaner.
45///
46/// ## Attributes {#balb_filecleanerconfiguration-attributes}
47///
48///
49/// @code
50/// Name Type Default Simple Constraints
51/// -------------- ------------------ -------------- ------------------
52/// filePattern bsl::string "" none
53/// maxFileAge bsls::TimeInterval TimeInterval() none
54/// minNumFiles int 0 [0 .. maxNumFiles]
55/// maxNumFiles int INT_MAX [minNumFiles .. INT_MAX]
56/// @endcode
57/// * `filePattern` : filesystem pattern used for file matching.
58/// * `maxFileAge` : maximum file age (since last modification).
59/// * `minNumFiles` : minumum number of (newest) files, matching the pattern,
60/// that must be kept by the file cleaner.
61/// * `maxNumFiles` : maxumum number of (newest) files, matching the pattern,
62/// that are to be kept by the file cleaner.
63///
64/// ## Thread Safety {#balb_filecleanerconfiguration-thread-safety}
65///
66///
67/// `balb::FileCleanerConfiguration` is *const* *thread-safe*, meaning that
68/// accessors may be invoked concurrently from different threads, but it is not
69/// safe to access or modify a `balb::FileCleanerConfiguration` in one thread
70/// while another thread modifies the same object.
71///
72/// ## Usage {#balb_filecleanerconfiguration-usage}
73///
74///
75/// This section illustrates intended use of this component.
76///
77/// ### Example 1: Basic Usage {#balb_filecleanerconfiguration-example-1-basic-usage}
78///
79///
80/// The following code illustrates how to create a configuration that can be
81/// later supplied to a file cleanup utility (see @ref balb_filecleanerutil for
82/// an example of how to use the created configuration to perform file
83/// cleaning).
84///
85/// First, we create a `balb::FileCleanerConfiguration` object having the
86/// default value:
87/// @code
88/// balb::FileCleanerConfiguration config;
89/// @endcode
90/// Next, we populate the attributes of our configuration object:
91/// @code
92/// config.setFilePattern("/var/log/myApp/log*");
93/// config.setMaxFileAge(bsls::TimeInterval(60*60*24));
94/// config.setMinFilesNumber(4);
95/// @endcode
96/// Now, we verify the options are configured correctly:
97/// @code
98/// assert("/var/log/myApp/log*" == config.filePattern());
99/// assert(bsls::TimeInterval(60*60*24) == config.maxFileAge());
100/// assert(4 == config.minNumFiles());
101/// assert(INT_MAX == config.maxNumFiles());
102/// @endcode
103/// Finally, we print the configuration value to `cout` and return:
104/// @code
105/// bsl::cout << config << bsl::endl;
106/// @endcode
107/// This produces the following (multi-line) output:
108/// @code
109/// [
110/// FilePattern = /var/log/myApp/log*
111/// MaxFileAge = (86400, 0)
112/// MinNumFiles = 4
113/// ]
114/// @endcode
115/// @}
116/** @} */
117/** @} */
118
119/** @addtogroup bal
120 * @{
121 */
122/** @addtogroup balb
123 * @{
124 */
125/** @addtogroup balb_filecleanerconfiguration
126 * @{
127 */
128
129#include <balscm_version.h>
130
131#include <bslma_allocator.h>
133
135
136#include <bsls_assert.h>
137#include <bsls_review.h>
138#include <bsls_timeinterval.h>
139
140#include <bsl_climits.h>
141#include <bsl_iosfwd.h>
142#include <bsl_string.h>
143
144
145namespace balb {
146
147 // ==============================
148 // class FileCleanerConfiguration
149 // ==============================
150
151/// This simply constrained (value-semantic) attribute class characterizes
152/// configuration parameters for a file cleaner. See the @ref balb_filecleanerconfiguration-attributes for information on the class attributes.
153///
154/// \note Note that the class invariants are
155/// identically the constraints on the individual attributes.
156///
157/// This class:
158/// * supports a complete set of *value-semantic* operations
159/// - except for `bdex` serialization
160/// * is *exception-neutral* (agnostic)
161/// * is *alias-safe*
162/// * is `const` *thread-safe*
163/// For terminology see @ref bsldoc_glossary .
164///
165/// See @ref balb_filecleanerconfiguration
167
168 private:
169 // DATA
170 bsl::string d_filePattern; // file pattern
171
172 bsls::TimeInterval d_maxFileAge; // maximum age of the files to keep
173 // (since last modification)
174
175 int d_minNumFiles; // minimum number of files to keep
176
177 int d_maxNumFiles; // maximum number of files to keep
178
179 // FRIENDS
182
183 public:
184 // TRAITS
187
188 // CREATORS
189
190 /// Create a file cleaner configuration object having default values for
191 /// all attributes. Optionally specify a `basicAllocator` used to supply
192 /// memory. If `basicAllocator` is 0, the currently installed default
193 /// allocator is used.
194 explicit FileCleanerConfiguration(bslma::Allocator *basicAllocator = 0);
195
196 /// Create a file cleaner configuration object having the specified
197 /// `filePattern`, `maxAge`, `minNumFiles`, `maxNumFiles` attribute values.
198 /// Optionally specify a `basicAllocator` used to supply memory. If
199 /// `basicAllocator` is 0, the currently installed default allocator is used.
200 ///
201 /// \pre The behavior is undefined unless `0 <= minNumFiles`, and
202 /// `minNumFiles <= maxNumFiles`.
204 const bsls::TimeInterval& maxAge,
205 int minNumFiles,
206 bslma::Allocator *basicAllocator = 0);
208 const bsls::TimeInterval& maxAge,
209 int minNumFiles,
210 int maxNumFiles,
211 bslma::Allocator *basicAllocator = 0);
212
213 /// Create a file cleaner configuration object having the in-core value of
214 /// the specified `original` object. Optionally specify a `basicAllocator`
215 /// used to supply memory. If `basicAllocator` is 0, the currently
216 /// installed default allocator is used.
218 const FileCleanerConfiguration& original,
219 bslma::Allocator *basicAllocator = 0);
220
221 /// Destroy this object.
223
224 // MANIPULATORS
225
226 /// Assign to this file cleaner configuration object the in-core value of
227 /// the specified `rhs` object, and return a reference providing modifiable
228 /// access to this object.
230
231 /// Set the file pattern attribute of this object to the specified
232 /// `filePattern`.
234
235 /// Set the maximum file age attribute of this object to the specified
236 /// `maxAge`.
237 void setMaxFileAge(const bsls::TimeInterval& maxAge);
238
239 /// Set the minimum number of files to keep attribute of this object to the specified `minNumFiles`.
240 ///
241 /// \pre The behavior is undefined if
242 /// `minNumFiles < 0` or `maxNumFiles() < minNumFiles`.
243 void setMinNumFiles(int minNumFiles);
244
245 /// Set the maximum number of files to keep attribute of this object to the specified `maxNumFiles`.
246 ///
247 /// \pre The behavior is undefined if
248 /// `maxNumFiles < 0` or `maxNumFiles < minNumFiles()`.
249 void setMaxNumFiles(int maxNumFiles);
250
251 // ACCESSORS
252
253 /// Return a `const` reference to the file pattern attribute of this
254 /// object.
255 const bsl::string& filePattern() const;
256
257 /// Return the maximum file age attribute of this object.
259
260 /// Return the minimum number of files to keep attribute of this object.
261 int minNumFiles() const;
262
263 /// Return the maximum number of files to keep attribute of this object.
264 int maxNumFiles() const;
265
266 /// Format a reasonable representation of this object to the specified
267 /// output `stream` at the (absolute value of) the optionally specified
268 /// indentation `level` and return a reference to `stream`. If `level`
269 /// is specified, optionally specify `spacesPerLevel`, the number of
270 /// spaces per indentation level for this and all of its nested objects.
271 /// If `level` is negative, suppress indentation of the first line. If
272 /// `spacesPerLevel` is negative, suppress all indentation AND format
273 /// the entire output on one line. If `stream` is not valid on entry,
274 /// this operation has no effect.
275 bsl::ostream& print(bsl::ostream& stream,
276 int level = 0,
277 int spacesPerLevel = 4) const;
278};
279
280// FREE OPERATORS
281
282/// Return `true` if the specified `lhs` and `rhs` attribute objects have the
283/// same (in-core) value, and `false` otherwise. Two attribute objects have
284/// the same in-core value if each respective attribute has the same in-core
285/// value.
287 const FileCleanerConfiguration& rhs);
288
289/// Return `true` if the specified `lhs` and `rhs` attribute objects do not
290/// have the same (in-core) value, and `false` otherwise. Two attribute
291/// objects do not have the same in-core value if one or more respective
292/// attributes differ in in-core values.
294 const FileCleanerConfiguration& rhs);
295
296/// Write a reasonable representation of the specified `configuration` object
297/// to the specified output `stream`, and return a reference to `stream`.
298bsl::ostream& operator<<(bsl::ostream& stream,
299 const FileCleanerConfiguration& configuration);
300
301// ============================================================================
302// INLINE DEFINITIONS
303// ============================================================================
304
305 // ------------------------------
306 // class FileCleanerConfiguration
307 // ------------------------------
308
309// CREATORS
310inline
312 bslma::Allocator *basicAllocator)
313: d_filePattern(basicAllocator)
314, d_maxFileAge(0, 0)
315, d_minNumFiles(0)
316, d_maxNumFiles(INT_MAX)
317{
318}
319
320inline
322 const bsl::string_view& filePattern,
323 const bsls::TimeInterval& maxAge,
324 int minNumFiles,
325 bslma::Allocator *basicAllocator)
326: d_filePattern(filePattern, basicAllocator)
327, d_maxFileAge(maxAge)
328, d_minNumFiles(minNumFiles)
329, d_maxNumFiles(INT_MAX)
330{
332}
333
334inline
336 const bsl::string_view& filePattern,
337 const bsls::TimeInterval& maxAge,
338 int minNumFiles,
339 int maxNumFiles,
340 bslma::Allocator *basicAllocator)
341: d_filePattern(filePattern, basicAllocator)
342, d_maxFileAge(maxAge)
343, d_minNumFiles(minNumFiles)
344, d_maxNumFiles(maxNumFiles)
345{
348}
349
350inline
352 const FileCleanerConfiguration& original,
353 bslma::Allocator *basicAllocator)
354: d_filePattern(original.d_filePattern, basicAllocator)
355, d_maxFileAge(original.d_maxFileAge)
356, d_minNumFiles(original.d_minNumFiles)
357, d_maxNumFiles(original.d_maxNumFiles)
358{
359}
360
361// MANIPULATORS
362inline
365{
366 d_filePattern = rhs.d_filePattern;
367 d_maxFileAge = rhs.d_maxFileAge;
368 d_minNumFiles = rhs.d_minNumFiles;
369 d_maxNumFiles = rhs.d_maxNumFiles;
370
371 return *this;
372}
373
374inline
376 const bsl::string_view& filePattern)
377{
378 d_filePattern = filePattern;
379}
380
381inline
383{
384 d_maxFileAge = maxAge;
385}
386
387inline
389{
391 BSLS_ASSERT_OPT(minNumFiles <= d_maxNumFiles);
392
393 d_minNumFiles = minNumFiles;
394}
395
396inline
398{
399 BSLS_ASSERT_OPT(d_minNumFiles <= maxNumFiles);
400
401 d_maxNumFiles = maxNumFiles;
402}
403
404// ACCESSORS
405inline
407{
408 return d_filePattern;
409}
410
411inline
413{
414 return d_maxFileAge;
415}
416
417inline
419{
420 return d_minNumFiles;
421}
422
423inline
425{
426 return d_maxNumFiles;
427}
428
429} // close package namespace
430
431// FREE OPERATORS
432inline
435{
436 return lhs.d_filePattern == rhs.d_filePattern
437 && lhs.d_maxFileAge == rhs.d_maxFileAge
438 && lhs.d_minNumFiles == rhs.d_minNumFiles
439 && lhs.d_maxNumFiles == rhs.d_maxNumFiles;
440}
441
442inline
445{
446 return !(lhs == rhs);
447}
448
449inline
450bsl::ostream& balb::operator<<(
451 bsl::ostream& stream,
452 const balb::FileCleanerConfiguration& configuration)
453{
454 return configuration.print(stream);
455}
456
457
458
459#endif
460
461// ----------------------------------------------------------------------------
462// Copyright 2017 Bloomberg Finance L.P.
463//
464// Licensed under the Apache License, Version 2.0 (the "License");
465// you may not use this file except in compliance with the License.
466// You may obtain a copy of the License at
467//
468// http://www.apache.org/licenses/LICENSE-2.0
469//
470// Unless required by applicable law or agreed to in writing, software
471// distributed under the License is distributed on an "AS IS" BASIS,
472// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
473// See the License for the specific language governing permissions and
474// limitations under the License.
475// ----------------------------- END-OF-FILE ----------------------------------
476
477
478/** @} */
479/** @} */
480/** @} */
Definition balb_filecleanerconfiguration.h:166
int maxNumFiles() const
Return the maximum number of files to keep attribute of this object.
Definition balb_filecleanerconfiguration.h:424
void setFilePattern(const bsl::string_view &filePattern)
Definition balb_filecleanerconfiguration.h:375
FileCleanerConfiguration & operator=(const FileCleanerConfiguration &rhs)
Definition balb_filecleanerconfiguration.h:364
void setMaxNumFiles(int maxNumFiles)
Definition balb_filecleanerconfiguration.h:397
const bsl::string & filePattern() const
Definition balb_filecleanerconfiguration.h:406
BSLMF_NESTED_TRAIT_DECLARATION(FileCleanerConfiguration, bslma::UsesBslmaAllocator)
int minNumFiles() const
Return the minimum number of files to keep attribute of this object.
Definition balb_filecleanerconfiguration.h:418
friend bool operator==(const FileCleanerConfiguration &, const FileCleanerConfiguration &)
FileCleanerConfiguration(bslma::Allocator *basicAllocator=0)
Definition balb_filecleanerconfiguration.h:311
bsls::TimeInterval maxFileAge() const
Return the maximum file age attribute of this object.
Definition balb_filecleanerconfiguration.h:412
bsl::ostream & print(bsl::ostream &stream, int level=0, int spacesPerLevel=4) const
~FileCleanerConfiguration()=default
Destroy this object.
void setMaxFileAge(const bsls::TimeInterval &maxAge)
Definition balb_filecleanerconfiguration.h:382
void setMinNumFiles(int minNumFiles)
Definition balb_filecleanerconfiguration.h:388
Definition bslstl_stringview.h:471
Definition bslstl_string.h:1252
Definition bslma_allocator.h:545
Definition bsls_timeinterval.h:307
#define BSLS_ASSERT_OPT(X)
Definition bsls_assert.h:2045
#define BSLS_IDENT(str)
BSLS_IDENT() - insert string into .comment binary segment (if supported)
Definition bsls_ident.h:238
Definition balb_controlmanager.h:144
bsl::ostream & operator<<(bsl::ostream &stream, const FileCleanerConfiguration &configuration)
bool operator!=(const FileCleanerConfiguration &lhs, const FileCleanerConfiguration &rhs)
bool operator==(const FileCleanerConfiguration &lhs, const FileCleanerConfiguration &rhs)
ALLOCATOR const STRING_VIEW_LIKE_TYPE & rhs
Definition bslstl_string.h:3918
ALLOCATOR & lhs
Definition bslstl_string.h:3917
Definition bslma_usesbslmaallocator.h:344