source: src/CodePatterns/Observer/ObserverLog.hpp@ 084729c

Action_Thermostats Add_AtomRandomPerturbation Add_RotateAroundBondAction Add_SelectAtomByNameAction Adding_Graph_to_ChangeBondActions Adding_MD_integration_tests Adding_StructOpt_integration_tests Automaking_mpqc_open AutomationFragmentation_failures Candidate_v1.6.0 Candidate_v1.6.1 ChangeBugEmailaddress ChangingTestPorts ChemicalSpaceEvaluator Combining_Subpackages Debian_Package_split Debian_package_split_molecuildergui_only Disabling_MemDebug Docu_Python_wait EmpiricalPotential_contain_HomologyGraph_documentation Enable_parallel_make_install Enhance_userguide Enhanced_StructuralOptimization Enhanced_StructuralOptimization_continued Example_ManyWaysToTranslateAtom Exclude_Hydrogens_annealWithBondGraph FitPartialCharges_GlobalError Fix_ChronosMutex Fix_StatusMsg Fix_StepWorldTime_single_argument Fix_Verbose_Codepatterns ForceAnnealing_goodresults ForceAnnealing_oldresults ForceAnnealing_tocheck ForceAnnealing_with_BondGraph ForceAnnealing_with_BondGraph_continued ForceAnnealing_with_BondGraph_continued_betteresults ForceAnnealing_with_BondGraph_contraction-expansion GeometryObjects Gui_displays_atomic_force_velocity IndependentFragmentGrids_IntegrationTest JobMarket_RobustOnKillsSegFaults JobMarket_StableWorkerPool JobMarket_unresolvable_hostname_fix ODR_violation_mpqc_open PartialCharges_OrthogonalSummation PythonUI_with_named_parameters QtGui_reactivate_TimeChanged_changes Recreated_GuiChecks RotateToPrincipalAxisSystem_UndoRedo StoppableMakroAction Subpackage_CodePatterns Subpackage_JobMarket Subpackage_levmar Subpackage_mpqc_open Subpackage_vmg ThirdParty_MPQC_rebuilt_buildsystem TremoloParser_IncreasedPrecision TremoloParser_MultipleTimesteps Ubuntu_1604_changes stable
Last change on this file since 084729c was 084729c, checked in by Frederik Heber <heber@…>, 8 years ago

Squashed 'ThirdParty/CodePatterns/' content from commit c1e1041

git-subtree-dir: ThirdParty/CodePatterns
git-subtree-split: c1e10418c454f98be2f43d93167642b0008428fc

  • Property mode set to 100644
File size: 2.5 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 <boost/thread/recursive_mutex.hpp>
18#include <map>
19#include <set>
20#include <iosfwd>
21#include <string>
22#include <sstream>
23
24#include "CodePatterns/Observer/Observable.hpp"
25#include "CodePatterns/Observer/Observer.hpp"
26#include "CodePatterns/Singleton.hpp"
27
28/**
29 * This class is used to log the working of the observer mechanism
30 *
31 * TODO: make this conditional dependent on compiler Flag.
32 */
33class ObserverLog : public Singleton<ObserverLog> {
34 friend class Observable;
35 friend class Observer;
36 friend class Relay;
37 template <typename> friend class Cacheable;
38 friend class Singleton<ObserverLog>;
39public:
40 std::string getLog(); // get everything that has been logged
41 std::string getName(void*); // get the name of an actor
42 bool isObservable(void*);
43 void disableLogging();
44 void enableLogging();
45
46 /** tiny helper class to allow for both capturing and printing of messages.
47 *
48 */
49 class Log {
50 public:
51 Log(ObserverLog *_callback_ref);
52 ~Log();
53
54 std::stringstream log; // the internal stream that later gets appended
55 ObserverLog *callback_ref; // internal stringstream to capture messages
56 };
57
58 boost::shared_ptr<ObserverLog::Log> addMessage(int depth=0); // Add a Message to the logging
59
60private:
61 ObserverLog();
62 ~ObserverLog();
63 int count; // number to reference each actor in this framework
64 std::map<void*,std::string> names; // List of names assigned to actors
65 std::set<void*> observables; // List of pointers to Observables. Needed to distinguish Observers and Observables
66 void addName(void*, std::string); // Assign a name to an Actor
67 void addObservable(void*);
68 void deleteName(void*); // delete the name of an Actor
69 void deleteObservable(void*);
70 std::stringstream log;
71 static std::ostream *nullstream; // stream that is not displayed
72 static std::ostream *outstream; // stream that is currently used
73
74 //!> mutex to ensure access is only per-thread
75 mutable boost::recursive_mutex mutex;
76};
77
78ObserverLog &observerLog();
79
80template <class T>
81boost::shared_ptr<ObserverLog::Log> operator<<(boost::shared_ptr<ObserverLog::Log> L, const T msg)
82{
83 L->log << msg;
84 return L;
85}
86
87#endif /* OBSERVERLOG_HPP_ */
Note: See TracBrowser for help on using the repository browser.