]> cygwin.com Git - cygwin-apps/setup.git/blob - LogSingleton.cc
2002-05-04 Robert Collins <rbtcollins@hotmail.com>
[cygwin-apps/setup.git] / LogSingleton.cc
1 /*
2 * Copyright (c) 2002, Robert Collins..
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * A copy of the GNU General Public License can be found at
10 * http://www.gnu.org/
11 *
12 * Written by Robert Collins <rbtcollins@hotmail.com>
13 *
14 */
15
16 #include "LogSingleton.h"
17 #include <stdexcept>
18
19 /* Helper functions */
20
21 /* End of a Log comment */
22 ostream& endLog(ostream& outs)
23 {
24 /* Doesn't seem to be any way around this */
25 dynamic_cast<LogSingleton &>(outs).endEntry();
26 return outs;
27 }
28
29 /* The LogSingleton class */
30
31 LogSingleton * LogSingleton::theInstance(0);
32
33 LogSingleton::LogSingleton(){}
34 LogSingleton::~LogSingleton(){}
35
36 LogSingleton &
37 LogSingleton::GetInstance()
38 {
39 if (!theInstance)
40 throw new invalid_argument ("No instance has been set!");
41 return *theInstance;
42 }
43
44 void
45 LogSingleton::SetInstance(LogSingleton &newInstance)
46 {
47 theInstance = &newInstance;
48 }
49
50 #if 0
51 // Logging class. Default logging level is PLAIN.
52 class LogSingleton : public ostream
53 {
54 public:
55 // Singleton support
56 /* Some platforms don't call destructors. So this call exists
57 * which guarantees to flush any log data...
58 * but doesn't call generic C++ destructors
59 */
60 virtual void exit (int const exit_code) __attribute__ ((noreturn));
61 // get a specific verbosity stream.
62 virtual ostream &operator() (enum log_level level);
63
64 friend ostream& endLog(ostream& outs);
65
66 protected:
67 LogSingleton (LogSingleton const &); // no copy constructor
68 LogSingleton &operator = (LogSingleton const&); // no assignment operator
69 void endEntry(); // the current in-progress entry is complete.
70 private:
71 static LogSingleton *theInstance;
72 };
73 #endif
This page took 0.040467 seconds and 6 git commands to generate.