BDE 4.14.0 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 .. INT_MAX]
55/// @endcode
56/// * `filePattern`: filesystem pattern used for file matching.
57/// * `maxFileAge` : maximum file age (since last modification).
58/// * `minNumFiles`: minumum number of (newest) files, matching the pattern,
59/// that must be kept by the file cleaner.
60///
61/// ## Thread Safety {#balb_filecleanerconfiguration-thread-safety}
62///
63///
64/// `balb::FileCleanerConfiguration` is *const* *thread-safe*, meaning that
65/// accessors may be invoked concurrently from different threads, but it is not
66/// safe to access or modify a `balb::FileCleanerConfiguration` in one thread
67/// while another thread modifies the same object.
68///
69/// ## Usage {#balb_filecleanerconfiguration-usage}
70///
71///
72/// This section illustrates intended use of this component.
73///
74/// ### Example 1: Basic Usage {#balb_filecleanerconfiguration-example-1-basic-usage}
75///
76///
77/// The following code illustrates how to create a configuration that can be
78/// later supplied to a file cleanup utility (see @ref balb_filecleanerutil for
79/// an example of how to use the created configuration to perform file
80/// cleaning).
81///
82/// First, we create a `balb::FileCleanerConfiguration` object having the
83/// default value:
84/// @code
85/// balb::FileCleanerConfiguration config;
86/// @endcode
87/// Next, we populate the attributes of our configuration object:
88/// @code
89/// config.setFilePattern("/var/log/myApp/log*");
90/// config.setMaxFileAge(bsls::TimeInterval(60*60*24));
91/// config.setMinFilesNumber(4);
92/// @endcode
93/// Now, we verify the options are configured correctly:
94/// @code
95/// assert("/var/log/myApp/log*" == config.filePattern());
96/// assert(bsls::TimeInterval(60*60*24) == config.maxFileAge());
97/// assert(4 == config.minNumFiles());
98/// @endcode
99/// Finally, we print the configuration value to `cout` and return:
100/// @code
101/// bsl::cout << config << bsl::endl;
102/// @endcode
103/// This produces the following (multi-line) output:
104/// @code
105/// [
106/// FilePattern = /var/log/myApp/log*
107/// MaxFileAge = (86400, 0)
108/// MinNumFiles = 4
109/// ]
110/// @endcode
111/// @}
112/** @} */
113/** @} */
114
115/** @addtogroup bal
116 * @{
117 */
118/** @addtogroup balb
119 * @{
120 */
121/** @addtogroup balb_filecleanerconfiguration
122 * @{
123 */
124
125#include <balscm_version.h>
126
127#include <bslma_allocator.h>
129
131
132#include <bsls_assert.h>
133#include <bsls_review.h>
134#include <bsls_timeinterval.h>
135
136#include <bsl_iosfwd.h>
137#include <bsl_string.h>
138
139
140namespace balb {
141
142 // ==============================
143 // class FileCleanerConfiguration
144 // ==============================
145
146/// This simply constrained (value-semantic) attribute class characterizes
147/// configuration parameters for a file cleaner. See the {Attributes}
148/// section under @DESCRIPTION in the component-level documentation for
149/// information on the class attributes. Note that the class invariants are
150/// identically the constraints on the individual attributes.
151///
152/// This class:
153/// * supports a complete set of *value-semantic* operations
154/// - except for `bdex` serialization
155/// * is *exception-neutral* (agnostic)
156/// * is *alias-safe*
157/// * is `const` *thread-safe*
158/// For terminology see @ref bsldoc_glossary .
159///
160/// See @ref balb_filecleanerconfiguration
162
163 private:
164 // DATA
165 bsl::string d_filePattern; // file pattern
166
167 bsls::TimeInterval d_maxFileAge; // maximum age of the files to keep
168 // (since last modification)
169
170 int d_minNumFiles; // minimum number of files to keep
171
172 // FRIENDS
175
176 public:
177 // TRAITS
180
181 // CREATORS
182
183 /// Create a file cleaner configuration object having default values for
184 /// all attributes. Optionally specify a `basicAllocator` used to
185 /// supply memory. If `basicAllocator` is 0, the currently installed
186 /// default allocator is used.
187 explicit FileCleanerConfiguration(bslma::Allocator *basicAllocator = 0);
188
189 /// Create a file cleaner configuration object having the specified
190 /// `filePattern`, `maxAge`, and `minNumber` attribute values.
191 /// Optionally specify a `basicAllocator` used to supply memory. If
192 /// `basicAllocator` is 0, the currently installed default allocator is
193 /// used.
195 const bsls::TimeInterval& maxAge,
196 int minNumber,
197 bslma::Allocator *basicAllocator = 0);
198
199 /// Create a file cleaner configuration object having the in-core value
200 /// of the specified `original` object. Optionally specify a
201 /// `basicAllocator` used to supply memory. If `basicAllocator` is 0,
202 /// the currently installed default allocator is used.
204 const FileCleanerConfiguration& original,
205 bslma::Allocator *basicAllocator = 0);
206
208 // Destroy this object.
209
210 // MANIPULATORS
211
212 /// Assign to this file cleaner configuration object the in-core value
213 /// of the specified `rhs` object, and return a reference providing
214 /// modifiable access to this object.
216
217 /// Set the file pattern attribute of this object to the specified
218 /// `filePattern`.
220
221 /// Set the maximum file age attribute of this object to the specified
222 /// `maxAge`.
223 void setMaxFileAge(const bsls::TimeInterval& maxAge);
224
225 /// Set the minimum number of files to keep attribute of this object to
226 /// the specified `minNumber`.
227 void setMinNumFiles(int minNumber);
228
229 // ACCESSORS
230
231 /// Return a `const` reference to the file pattern attribute of this
232 /// object.
233 const bsl::string& filePattern() const;
234
235 /// Return the maximum file age attribute of this object.
237
238 /// Return the minimum number of files to keep attribute of this object.
239 int minNumFiles() const;
240
241 /// Format a reasonable representation of this object to the specified
242 /// output `stream` at the (absolute value of) the optionally specified
243 /// indentation `level` and return a reference to `stream`. If `level`
244 /// is specified, optionally specify `spacesPerLevel`, the number of
245 /// spaces per indentation level for this and all of its nested objects.
246 /// If `level` is negative, suppress indentation of the first line. If
247 /// `spacesPerLevel` is negative, suppress all indentation AND format
248 /// the entire output on one line. If `stream` is not valid on entry,
249 /// this operation has no effect.
250 bsl::ostream& print(bsl::ostream& stream,
251 int level = 0,
252 int spacesPerLevel = 4) const;
253};
254
255// FREE OPERATORS
256
257/// Return `true` if the specified `lhs` and `rhs` attribute objects have
258/// the same (in-core) value, and `false` otherwise. Two attribute objects
259/// have the same in-core value if each respective attribute has the same
260/// in-core value.
262 const FileCleanerConfiguration& rhs);
263
264/// Return `true` if the specified `lhs` and `rhs` attribute objects do not
265/// have the same (in-core) value, and `false` otherwise. Two attribute
266/// objects do not have the same in-core value if one or more respective
267/// attributes differ in in-core values.
269 const FileCleanerConfiguration& rhs);
270
271/// Write a reasonable representation of the specified `configuration`
272/// object to the specified output `stream`, and return a reference to
273/// `stream`.
274bsl::ostream& operator<<(bsl::ostream& stream,
275 const FileCleanerConfiguration& configuration);
276
277// ============================================================================
278// INLINE DEFINITIONS
279// ============================================================================
280
281 // ------------------------------
282 // class FileCleanerConfiguration
283 // ------------------------------
284
285// CREATORS
286inline
288 bslma::Allocator *basicAllocator)
289: d_filePattern(basicAllocator)
290, d_maxFileAge(0, 0)
291, d_minNumFiles(0)
292{
293}
294
295inline
297 const bsl::string_view& filePattern,
298 const bsls::TimeInterval& maxAge,
299 int minNumber,
300 bslma::Allocator *basicAllocator)
301: d_filePattern(filePattern, basicAllocator)
302, d_maxFileAge(maxAge)
303, d_minNumFiles(minNumber)
304{
305}
306
307inline
309 const FileCleanerConfiguration& original,
310 bslma::Allocator *basicAllocator)
311: d_filePattern(original.d_filePattern, basicAllocator)
312, d_maxFileAge(original.d_maxFileAge)
313, d_minNumFiles(original.d_minNumFiles)
314{
315}
316
317// MANIPULATORS
318inline
321{
322 d_filePattern = rhs.d_filePattern;
323 d_maxFileAge = rhs.d_maxFileAge;
324 d_minNumFiles = rhs.d_minNumFiles;
325
326 return *this;
327}
328
329inline
331 const bsl::string_view& filePattern)
332{
333 d_filePattern = filePattern;
334}
335
336inline
338{
339 d_maxFileAge = maxAge;
340}
341
342inline
344{
345 BSLS_ASSERT(0 <= minNumber);
346 d_minNumFiles = minNumber;
347}
348
349// ACCESSORS
350inline
352{
353 return d_filePattern;
354}
355
356inline
358{
359 return d_maxFileAge;
360}
361
362inline
364{
365 return d_minNumFiles;
366}
367
368} // close package namespace
369
370// FREE OPERATORS
371inline
374{
375 return lhs.d_filePattern == rhs.d_filePattern
376 && lhs.d_maxFileAge == rhs.d_maxFileAge
377 && lhs.d_minNumFiles == rhs.d_minNumFiles;
378}
379
380inline
383{
384 return !(lhs == rhs);
385}
386
387inline
388bsl::ostream& balb::operator<<(
389 bsl::ostream& stream,
390 const balb::FileCleanerConfiguration& configuration)
391{
392 return configuration.print(stream);
393}
394
395
396
397#endif
398
399// ----------------------------------------------------------------------------
400// Copyright 2017 Bloomberg Finance L.P.
401//
402// Licensed under the Apache License, Version 2.0 (the "License");
403// you may not use this file except in compliance with the License.
404// You may obtain a copy of the License at
405//
406// http://www.apache.org/licenses/LICENSE-2.0
407//
408// Unless required by applicable law or agreed to in writing, software
409// distributed under the License is distributed on an "AS IS" BASIS,
410// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
411// See the License for the specific language governing permissions and
412// limitations under the License.
413// ----------------------------- END-OF-FILE ----------------------------------
414
415/** @} */
416/** @} */
417/** @} */
Definition balb_filecleanerconfiguration.h:161
void setFilePattern(const bsl::string_view &filePattern)
Definition balb_filecleanerconfiguration.h:330
FileCleanerConfiguration & operator=(const FileCleanerConfiguration &rhs)
Definition balb_filecleanerconfiguration.h:320
const bsl::string & filePattern() const
Definition balb_filecleanerconfiguration.h:351
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:363
void setMinNumFiles(int minNumber)
Definition balb_filecleanerconfiguration.h:343
friend bool operator==(const FileCleanerConfiguration &, const FileCleanerConfiguration &)
FileCleanerConfiguration(bslma::Allocator *basicAllocator=0)
Definition balb_filecleanerconfiguration.h:287
bsls::TimeInterval maxFileAge() const
Return the maximum file age attribute of this object.
Definition balb_filecleanerconfiguration.h:357
bsl::ostream & print(bsl::ostream &stream, int level=0, int spacesPerLevel=4) const
void setMaxFileAge(const bsls::TimeInterval &maxAge)
Definition balb_filecleanerconfiguration.h:337
Definition bslstl_stringview.h:441
Definition bslstl_string.h:1281
Definition bslma_allocator.h:457
Definition bsls_timeinterval.h:301
#define BSLS_ASSERT(X)
Definition bsls_assert.h:1804
#define BSLS_IDENT(str)
Definition bsls_ident.h:195
Definition balb_controlmanager.h:133
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)
Definition bslma_usesbslmaallocator.h:343