source: src/Observer/ObserverLog.cpp@ 9b8fa4

Last change on this file since 9b8fa4 was 9b8fa4, checked in by Frederik Heber <heber@…>, 14 years ago

Huge update of file structure to place installation header files into right folder.

  • The problem ist that we desire use as include "CodePatterns/...". For this to work, especially with the new Observer subfolder structure, it has been necessary to place all header files away from their source files into a distinct folder called CodePatterns. This emulates the later, after make install present structure.
  • essentially all source and header files had to be changed to adapt the include.
  • all Makefile.am's had to be changed.
  • nobase_ ... was removed such that header files are installed flat and not creating their subfolder along the process.
  • We placed Observer into its own convenience library and own folder Observer away from Patterns.

Some other changes:

  • FIX: MemDebug.hpp inclusion has been removed in all stubs.
  • Property mode set to 100644
File size: 2.5 KB
Line 
1/*
2 * Project: MoleCuilder
3 * Description: creates and alters molecular systems
4 * Copyright (C) 2010 University of Bonn. All rights reserved.
5 * Please see the LICENSE file or "Copyright notice" in builder.cpp for details.
6 */
7
8/*
9 * ObserverLog.cpp
10 *
11 * Created on: Dec 1, 2011
12 * Author: heber
13 */
14
15// include config.h
16#ifdef HAVE_CONFIG_H
17#include <config.h>
18#endif
19
20#include "CodePatterns/MemDebug.hpp"
21
22#include <fstream>
23#include <iostream>
24#include <sstream>
25
26#include "CodePatterns/Observer/ObserverLog.hpp"
27#include "CodePatterns/Singleton_impl.hpp"
28
29std::ostream* ObserverLog::nullstream = NULL;
30std::ostream* ObserverLog::outstream = NULL;
31
32ObserverLog::ObserverLog()
33{
34 nullstream = new std::ofstream("/dev/null");
35 outstream = nullstream;
36}
37
38ObserverLog::~ObserverLog()
39{
40 outstream = NULL;
41 delete nullstream;
42}
43
44/** Constructor of class Log.
45 *
46 * Log is just a tiny helper to bring the log message to screen and to the
47 * ObserverLog's log.
48 *
49 * @param _callback_ref
50 */
51ObserverLog::Log::Log(ObserverLog *_callback_ref) :
52 callback_ref(_callback_ref)
53{}
54
55/** Destructor of class Log.
56 *
57 * Prints to both ObserverLog::log and to ObserverLog::outstream.
58 *
59 */
60ObserverLog::Log::~Log()
61{
62 callback_ref->log << log.str() << std::endl;
63 *callback_ref->outstream << log.str() << std::endl;
64
65 callback_ref = NULL;
66}
67
68void ObserverLog::disableLogging()
69{
70 outstream = nullstream;
71}
72
73void ObserverLog::enableLogging()
74{
75 outstream = &std::cout;
76}
77
78std::string ObserverLog::getLog() { return log.str(); }
79
80std::string ObserverLog::getName(void* obj){
81 return names[obj];
82}
83
84bool ObserverLog::isObservable(void* obj){
85 return observables.count(obj);
86}
87
88void ObserverLog::addName(void* obj , std::string name){
89 std::stringstream sstr;
90 sstr << name << "_" << count++;
91 names[obj] = sstr.str();
92}
93
94void ObserverLog::addObservable(void* obj){
95 observables.insert(obj);
96}
97
98void ObserverLog::deleteName(void* obj){
99 names.erase(obj);
100}
101
102void ObserverLog::deleteObservable(void* obj){
103 observables.erase(obj);
104}
105
106/** Obtain Log reference to place another message (line) in log.
107 *
108 * \warning Don't append std::endl to the message, won't work and is done
109 * automatically.
110 *
111 * @param depth depth (indenting) of the message
112 * @return ref to Log class which can be ostreamed to
113 */
114boost::shared_ptr<ObserverLog::Log> ObserverLog::addMessage(int depth){
115 boost::shared_ptr<ObserverLog::Log> L(new Log(this));
116 for(int i=depth;i--;)
117 L->log << " ";
118 return L;
119}
120
121ObserverLog &observerLog()
122{
123 return ObserverLog::getInstance();
124}
125
126CONSTRUCT_SINGLETON(ObserverLog)
Note: See TracBrowser for help on using the repository browser.