| Last change
 on this file since 549b62 was             e2e035e, checked in by Frederik Heber <heber@…>, 14 years ago | 
        
          | 
Refactored all Observer stuff into own subfolder and split up into distinct modules.
 Observer/all.hpp is all that's needed.
 | 
        
          | 
              
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 | * 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 "MemDebug.hpp" | 
|---|
|  | 21 |  | 
|---|
|  | 22 | #include "ObserverLog.hpp" | 
|---|
|  | 23 |  | 
|---|
|  | 24 |  | 
|---|
|  | 25 | ObserverLog::ObserverLog() : | 
|---|
|  | 26 | count (0) | 
|---|
|  | 27 | {} | 
|---|
|  | 28 |  | 
|---|
|  | 29 | ObserverLog::~ObserverLog(){} | 
|---|
|  | 30 |  | 
|---|
|  | 31 | std::string ObserverLog::getLog(){return log.str();} | 
|---|
|  | 32 |  | 
|---|
|  | 33 | std::string ObserverLog::getName(void* obj){ | 
|---|
|  | 34 | return names[obj]; | 
|---|
|  | 35 | } | 
|---|
|  | 36 |  | 
|---|
|  | 37 | bool ObserverLog::isObservable(void* obj){ | 
|---|
|  | 38 | return observables.count(obj); | 
|---|
|  | 39 | } | 
|---|
|  | 40 |  | 
|---|
|  | 41 | void ObserverLog::addName(void* obj , std::string name){ | 
|---|
|  | 42 | std::stringstream sstr; | 
|---|
|  | 43 | sstr << name << "_" << count++; | 
|---|
|  | 44 | names[obj] = sstr.str(); | 
|---|
|  | 45 | } | 
|---|
|  | 46 |  | 
|---|
|  | 47 | void ObserverLog::addObservable(void* obj){ | 
|---|
|  | 48 | observables.insert(obj); | 
|---|
|  | 49 | } | 
|---|
|  | 50 |  | 
|---|
|  | 51 | void ObserverLog::deleteName(void* obj){ | 
|---|
|  | 52 | names.erase(obj); | 
|---|
|  | 53 | } | 
|---|
|  | 54 |  | 
|---|
|  | 55 | void ObserverLog::deleteObservable(void* obj){ | 
|---|
|  | 56 | observables.erase(obj); | 
|---|
|  | 57 | } | 
|---|
|  | 58 |  | 
|---|
|  | 59 | std::stringstream &ObserverLog::addMessage(int depth){ | 
|---|
|  | 60 | for(int i=depth;i--;) | 
|---|
|  | 61 | log << "  "; | 
|---|
|  | 62 | return log; | 
|---|
|  | 63 | } | 
|---|
|  | 64 |  | 
|---|
|  | 65 | // The log needs to exist fairly early, so we make it construct on first use, | 
|---|
|  | 66 | // and never destroy it | 
|---|
|  | 67 | ObserverLog &observerLog(){ | 
|---|
|  | 68 | // yes, this memory is never freed... we need it around for the whole programm, | 
|---|
|  | 69 | // so no freeing is possible | 
|---|
|  | 70 | static ObserverLog *theLog = Memory::ignore(new ObserverLog()); | 
|---|
|  | 71 | return *theLog; | 
|---|
|  | 72 | } | 
|---|
|  | 73 |  | 
|---|
       
      
  Note:
 See   
TracBrowser
 for help on using the repository browser.