|
Last change
on this file since d85532 was 2c11c1, checked in by Frederik Heber <heber@…>, 14 years ago |
|
Modified ObserverLog: Singleton and both output to screen and internal Log.
- ObserverLog can now either be printed concurrently or later requested as
string (e.g. on exit as has been done before). This should ease debugging
Observer code.
- enable/disableLogging() (dis)activate printing to screen.
- ObserverLog is now a true singleton.
Details:
- Implemented helper class ObserverLog::Log which is returned as
boost::shared_ptr on addMessage() and can be streamed to.
- On dstor the logged message is appended with endl, placed into ObserverLog's
internal log and printed on screen if enableLogging().
- NOTE: streaming std::endl is not working, and not necessary.
|
-
Property mode
set to
100644
|
|
File size:
1.5 KB
|
| Rev | Line | |
|---|
| [e2e035e] | 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 | * Observer.cpp
|
|---|
| 10 | *
|
|---|
| 11 | * Created on: Jan 19, 2010
|
|---|
| 12 | * Author: crueger
|
|---|
| 13 | */
|
|---|
| 14 |
|
|---|
| 15 | // include config.h
|
|---|
| 16 | #ifdef HAVE_CONFIG_H
|
|---|
| 17 | #include <config.h>
|
|---|
| 18 | #endif
|
|---|
| 19 |
|
|---|
| 20 | #include "MemDebug.hpp"
|
|---|
| 21 |
|
|---|
| 22 | #include "Observer/Observer.hpp"
|
|---|
| 23 |
|
|---|
| 24 | #include <iostream>
|
|---|
| 25 |
|
|---|
| 26 | #include "Assert.hpp"
|
|---|
| 27 | #ifdef LOG_OBSERVER
|
|---|
| 28 | #include "Observer/ObserverLog.hpp"
|
|---|
| 29 | #endif
|
|---|
| 30 |
|
|---|
| 31 |
|
|---|
| 32 | /** Constructor for class Observer.
|
|---|
| 33 | */
|
|---|
| [2c11c1] | 34 | Observer::Observer(std::string name)
|
|---|
| [e2e035e] | 35 | {
|
|---|
| 36 | #ifdef LOG_OBSERVER
|
|---|
| 37 | observerLog().addName(this,name);
|
|---|
| [2c11c1] | 38 | observerLog().addMessage() << "++ Creating Observer " << observerLog().getName(this);
|
|---|
| [e2e035e] | 39 | #endif
|
|---|
| 40 | }
|
|---|
| 41 |
|
|---|
| 42 | /**
|
|---|
| 43 | * Base Constructor for class Observer
|
|---|
| 44 | *
|
|---|
| 45 | * only called from Observable Constructor
|
|---|
| 46 | */
|
|---|
| 47 | Observer::Observer(Observer::BaseConstructor){
|
|---|
| 48 | #ifdef LOG_OBSERVER
|
|---|
| 49 | observerLog().addObservable(this);
|
|---|
| 50 | #endif
|
|---|
| 51 | }
|
|---|
| 52 |
|
|---|
| 53 | /** Destructor for class Observer.
|
|---|
| 54 | */
|
|---|
| 55 | Observer::~Observer()
|
|---|
| 56 | {
|
|---|
| 57 | #ifdef LOG_OBSERVER
|
|---|
| 58 | if(!observerLog().isObservable(this)){
|
|---|
| [2c11c1] | 59 | observerLog().addMessage() << "-- Destroying Observer " << observerLog().getName(this);
|
|---|
| [e2e035e] | 60 | }
|
|---|
| 61 | #endif
|
|---|
| 62 | }
|
|---|
| 63 |
|
|---|
| 64 | /**
|
|---|
| 65 | * Method for specialized notifications.
|
|---|
| 66 | * Most Observers wont need or use this, so it is implemented
|
|---|
| 67 | * empty in the base case;
|
|---|
| 68 | */
|
|---|
| 69 | void Observer::recieveNotification(Observable *publisher, Notification_ptr notification){
|
|---|
| 70 | ASSERT(0,"Notification received by object that did not sign on for it.");
|
|---|
| 71 | }
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.