source: src/CodePatterns/Observer/ObserverLog.hpp@ 9cc4ac

Last change on this file since 9cc4ac 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.4 KB
Line 
1/*
2 * ObserverLog.hpp
3 *
4 * Created on: Dec 1, 2011
5 * Author: heber
6 */
7
8#ifndef OBSERVERLOG_HPP_
9#define OBSERVERLOG_HPP_
10
11// include config.h
12#ifdef HAVE_CONFIG_H
13#include <config.h>
14#endif
15
16#include <boost/shared_ptr.hpp>
17#include <map>
18#include <set>
19#include <iosfwd>
20#include <string>
21#include <sstream>
22
23#include "CodePatterns/Observer/Observable.hpp"
24#include "CodePatterns/Observer/Observer.hpp"
25#include "CodePatterns/Singleton.hpp"
26
27/**
28 * This class is used to log the working of the observer mechanism
29 *
30 * TODO: make this conditional dependent on compiler Flag.
31 */
32class ObserverLog : public Singleton<ObserverLog> {
33 friend class Observable;
34 friend class Observer;
35 friend class Relay;
36 template <typename> friend class Cacheable;
37 friend class Singleton<ObserverLog>;
38public:
39 std::string getLog(); // get everything that has been logged
40 std::string getName(void*); // get the name of an actor
41 bool isObservable(void*);
42 void disableLogging();
43 void enableLogging();
44
45 /** tiny helper class to allow for both capturing and printing of messages.
46 *
47 */
48 class Log {
49 public:
50 Log(ObserverLog *_callback_ref);
51 ~Log();
52
53 std::stringstream log; // the internal stream that later gets appended
54 ObserverLog *callback_ref; // internal stringstream to capture messages
55 };
56
57private:
58 ObserverLog();
59 ~ObserverLog();
60 int count; // number to reference each actor in this framework
61 std::map<void*,std::string> names; // List of names assigned to actors
62 std::set<void*> observables; // List of pointers to Observables. Needed to distinguish Observers and Observables
63 void addName(void*, std::string); // Assign a name to an Actor
64 void addObservable(void*);
65 void deleteName(void*); // delete the name of an Actor
66 void deleteObservable(void*);
67 boost::shared_ptr<ObserverLog::Log> addMessage(int depth=0); // Add a Message to the logging
68 std::stringstream log;
69 static std::ostream *nullstream; // stream that is not displayed
70 static std::ostream *outstream; // stream that is currently used
71};
72
73ObserverLog &observerLog();
74
75template <class T>
76boost::shared_ptr<ObserverLog::Log> operator<<(boost::shared_ptr<ObserverLog::Log> L, const T msg)
77{
78 L->log << msg;
79 return L;
80}
81
82#endif /* OBSERVERLOG_HPP_ */
Note: See TracBrowser for help on using the repository browser.