use non-throwing test for presence of Target
[platform/upstream/libzypp.git] / zypp / target / CommitLog.h
1  /*---------------------------------------------------------------------\
2 |                          ____ _   __ __ ___                          |
3 |                         |__  / \ / / . \ . \                         |
4 |                           / / \ V /|  _/  _/                         |
5 |                          / /__ | | | | | |                           |
6 |                         /_____||_| |_| |_|                           |
7 |                                                                      |
8 \---------------------------------------------------------------------*/
9 /** \file zypp/target/CommitLog.h
10  *
11 */
12 #ifndef ZYPP_TARGET_COMMITLOG_H
13 #define ZYPP_TARGET_COMMITLOG_H
14
15 #include <iosfwd>
16
17 #include "zypp/Pathname.h"
18
19 namespace zypp {
20   namespace target {
21
22     ///////////////////////////////////////////////////////////////////
23     //
24     //  CLASS NAME : CommitLog
25     /**
26      * Simple wrapper for progress log. Refcnt, filename and corresponding
27      * ofstream are static members. Logfile constructor raises, destructor
28      * lowers refcounter. On refcounter changing from 0->1, file is opened.
29      * Changing from 1->0 the file is closed. Thus Logfile objects should be
30      * local to those functions, writing the log, and must not be stored
31      * permanently;
32      *
33      * Usage:
34      *  some methothd ()
35      *  {
36      *    CommitLog progresslog;
37      *    ...
38      *    progresslog() << "some message" << endl;
39      *    ...
40      *  }
41      **/
42     class CommitLog {
43       CommitLog( const CommitLog & );
44       CommitLog & operator=( const CommitLog & );
45     private:
46       static std::ofstream _log;
47       static unsigned _refcnt;
48       static Pathname _fname;
49
50       static void openLog();
51       static void closeLog();
52       static void refUp();
53       static void refDown();
54     public:
55       CommitLog() { refUp(); }
56       ~CommitLog() { refDown(); }
57       std::ostream & operator()( bool timestamp = false );
58       static void setFname( const Pathname & fname_r );
59       static const Pathname & fname();
60     };
61     ///////////////////////////////////////////////////////////////////
62
63   } // namespace target
64 } // namespace zypp
65
66
67 #endif // ZYPP_TARGET_COMMITLOG_H