- Timestamp:
- Jun 9, 2010, 2:30:10 PM (15 years ago)
- Branches:
- Action_Thermostats, Add_AtomRandomPerturbation, Add_FitFragmentPartialChargesAction, Add_RotateAroundBondAction, Add_SelectAtomByNameAction, Added_ParseSaveFragmentResults, AddingActions_SaveParseParticleParameters, Adding_Graph_to_ChangeBondActions, Adding_MD_integration_tests, Adding_ParticleName_to_Atom, Adding_StructOpt_integration_tests, AtomFragments, Automaking_mpqc_open, AutomationFragmentation_failures, Candidate_v1.5.4, Candidate_v1.6.0, Candidate_v1.6.1, ChangeBugEmailaddress, ChangingTestPorts, ChemicalSpaceEvaluator, CombiningParticlePotentialParsing, Combining_Subpackages, Debian_Package_split, Debian_package_split_molecuildergui_only, Disabling_MemDebug, Docu_Python_wait, EmpiricalPotential_contain_HomologyGraph, EmpiricalPotential_contain_HomologyGraph_documentation, Enable_parallel_make_install, Enhance_userguide, Enhanced_StructuralOptimization, Enhanced_StructuralOptimization_continued, Example_ManyWaysToTranslateAtom, Exclude_Hydrogens_annealWithBondGraph, FitPartialCharges_GlobalError, Fix_BoundInBox_CenterInBox_MoleculeActions, Fix_ChargeSampling_PBC, Fix_ChronosMutex, Fix_FitPartialCharges, Fix_FitPotential_needs_atomicnumbers, Fix_ForceAnnealing, Fix_IndependentFragmentGrids, Fix_ParseParticles, Fix_ParseParticles_split_forward_backward_Actions, Fix_PopActions, Fix_QtFragmentList_sorted_selection, Fix_Restrictedkeyset_FragmentMolecule, Fix_StatusMsg, Fix_StepWorldTime_single_argument, Fix_Verbose_Codepatterns, Fix_fitting_potentials, Fixes, ForceAnnealing_goodresults, ForceAnnealing_oldresults, ForceAnnealing_tocheck, ForceAnnealing_with_BondGraph, ForceAnnealing_with_BondGraph_continued, ForceAnnealing_with_BondGraph_continued_betteresults, ForceAnnealing_with_BondGraph_contraction-expansion, FragmentAction_writes_AtomFragments, FragmentMolecule_checks_bonddegrees, GeometryObjects, Gui_Fixes, Gui_displays_atomic_force_velocity, ImplicitCharges, IndependentFragmentGrids, IndependentFragmentGrids_IndividualZeroInstances, IndependentFragmentGrids_IntegrationTest, IndependentFragmentGrids_Sole_NN_Calculation, JobMarket_RobustOnKillsSegFaults, JobMarket_StableWorkerPool, JobMarket_unresolvable_hostname_fix, MoreRobust_FragmentAutomation, ODR_violation_mpqc_open, PartialCharges_OrthogonalSummation, PdbParser_setsAtomName, PythonUI_with_named_parameters, QtGui_reactivate_TimeChanged_changes, Recreated_GuiChecks, Rewrite_FitPartialCharges, RotateToPrincipalAxisSystem_UndoRedo, SaturateAtoms_findBestMatching, SaturateAtoms_singleDegree, StoppableMakroAction, Subpackage_CodePatterns, Subpackage_JobMarket, Subpackage_LinearAlgebra, Subpackage_levmar, Subpackage_mpqc_open, Subpackage_vmg, Switchable_LogView, ThirdParty_MPQC_rebuilt_buildsystem, TrajectoryDependenant_MaxOrder, TremoloParser_IncreasedPrecision, TremoloParser_MultipleTimesteps, TremoloParser_setsAtomName, Ubuntu_1604_changes, stable
- Children:
- 112b09
- Parents:
- 2c8934
- Location:
- src
- Files:
-
- 15 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Actions/Process.cpp
r2c8934 rcd5047 11 11 12 12 Process::Process(int _maxSteps, std::string _name, bool _doRegister) : 13 Observable("Process"), 13 14 Action(_name,_doRegister), 14 15 maxSteps(_maxSteps), -
src/Parser/ChangeTracker.cpp
r2c8934 rcd5047 13 13 * Constructor. Signs on as an observer for the World. 14 14 */ 15 ChangeTracker::ChangeTracker() { 15 ChangeTracker::ChangeTracker() : 16 Observable("ChangeTracker") 17 { 16 18 isConsistent = true; 17 19 World::getInstance().signOn(this); -
src/Parser/FormatParser.cpp
r2c8934 rcd5047 14 14 * Constructor. 15 15 */ 16 FormatParser::FormatParser() { 16 FormatParser::FormatParser() : 17 Observer("FormatParser") 18 { 17 19 ChangeTracker::get()->signOn(this); 18 20 saveStream = NULL; -
src/Patterns/Cacheable.hpp
r2c8934 rcd5047 35 35 return busy; 36 36 } 37 virtual std::string getName()=0; 37 38 protected: 38 39 bool busy; … … 64 65 // nothing to do when entering this 65 66 } 67 68 virtual std::string getName(){ 69 return "invalid"; 70 } 66 71 }; 67 72 … … 90 95 State::busy = false; 91 96 } 97 98 virtual std::string getName(){ 99 return "valid"; 100 } 92 101 private: 93 102 T content; … … 118 127 // nothing to do when entering this state 119 128 } 129 130 virtual std::string getName(){ 131 return "destroyed"; 132 } 120 133 }; 121 134 … … 124 137 125 138 public: 126 Cacheable(Observable *_owner, boost::function<T()> _recalcMethod );139 Cacheable(Observable *_owner, boost::function<T()> _recalcMethod, std::string name); 127 140 virtual ~Cacheable(); 128 141 … … 151 164 152 165 template<typename T> 153 Cacheable<T>::Cacheable(Observable *_owner, boost::function<T()> _recalcMethod) : 166 Cacheable<T>::Cacheable(Observable *_owner, boost::function<T()> _recalcMethod, std::string name) : 167 Observer(name + "(Cached)"), 154 168 owner(_owner), 155 169 recalcMethod(_recalcMethod) … … 206 220 void Cacheable<T>::switchState(state_ptr newState){ 207 221 ASSERT(!state->isBusy(),"LOOP DETECTED: Cacheable state switched while recalculating.\nDid the recalculation trigger the Observable?"); 222 #ifdef LOG_OBSERVER 223 observerLog().addMessage() << "## Cacheable " << observerLog().getName(this) << " changed state (" << state->getName() 224 << "->" << newState->getName() << ")" << std::endl; 225 #endif 208 226 state = newState; 209 227 state->enter(); -
src/Patterns/Observer.cpp
r2c8934 rcd5047 12 12 13 13 #include "Helpers/Assert.hpp" 14 #include "Helpers/MemDebug.hpp" 14 15 15 16 using namespace std; … … 43 44 // if no entry for this observable is found, an new one is created 44 45 // by the STL and initialized to 0 (see STL documentation) 46 #ifdef LOG_OBSERVER 47 observerLog().addMessage(depth[publisher]) << ">> Locking " << observerLog().getName(publisher) << endl; 48 #endif 45 49 depth[publisher]++; 46 50 } … … 60 64 // if zero is reached all observed blocks are done and we can 61 65 // start to notify our observers 62 if(--(depth[publisher])){} 66 --depth[publisher]; 67 #ifdef LOG_OBSERVER 68 observerLog().addMessage(depth[publisher]) << "<< Unlocking " << observerLog().getName(publisher) << endl; 69 #endif 70 if(depth[publisher]){} 63 71 else{ 64 72 publisher->notifyAll(); … … 123 131 callees_t::iterator iter; 124 132 for(iter=callees.begin();iter!=callees.end();++iter){ 133 #ifdef LOG_OBSERVER 134 observerLog().addMessage() << "-> Sending update from " << observerLog().getName(this) 135 << " to " << observerLog().getName((*iter).second) 136 << " (priority=" << (*iter).first << ")"<< endl; 137 #endif 125 138 (*iter).second->update(this); 126 139 } … … 165 178 // we do not need to publish all the changes at each time we are called 166 179 if(depth.find(this)==depth.end()) { 180 #ifdef LOG_OBSERVER 181 observerLog().addMessage() << "-* Update from " << observerLog().getName(publisher) 182 << " propagated by " << observerLog().getName(this) << endl; 183 #endif 167 184 notifyAll(); 185 } 186 else{ 187 #ifdef LOG_OBSERVER 188 observerLog().addMessage() << "-| Update from " << observerLog().getName(publisher) 189 << " not propagated by " << observerLog().getName(this) << endl; 190 #endif 168 191 } 169 192 } … … 177 200 void Observable::signOn(Observer *target,int priority) { 178 201 ASSERT(priority>=-20 && priority<=+20, "Priority out of range [-20:+20] when signing on Observer"); 202 #ifdef LOG_OBSERVER 203 observerLog().addMessage() << "@@ Signing on " << observerLog().getName(target) << " to " << observerLog().getName(this) << endl; 204 #endif 179 205 bool res = false; 180 206 callees_t &callees = callTable[this]; … … 194 220 void Observable::signOff(Observer *target) { 195 221 ASSERT(callTable.count(this),"SignOff called for an Observable without Observers."); 222 #ifdef LOG_OBSERVER 223 observerLog().addMessage() << "** Signing off " << observerLog().getName(target) << " from " << observerLog().getName(this) << endl; 224 #endif 196 225 callees_t &callees = callTable[this]; 197 226 … … 238 267 /** Constructor for class Observable. 239 268 */ 240 Observable::Observable() 241 {} 269 Observable::Observable(string name) : 270 Observer(Observer::BaseConstructor()) 271 { 272 #ifdef LOG_OBSERVER 273 observerLog().addName(this,name); 274 observerLog().addMessage() << "++ Creating Observable " << observerLog().getName(this) << endl; 275 #endif 276 } 242 277 243 278 /** Destructor for class Observable. … … 246 281 Observable::~Observable() 247 282 { 283 #ifdef LOG_OBSERVER 284 observerLog().addMessage() << "-- Destroying Observable " << observerLog().getName(this) << endl; 285 #endif 248 286 if(callTable.count(this)) { 249 287 // delete all entries for this observable … … 259 297 /** Constructor for class Observer. 260 298 */ 261 Observer::Observer() 262 {} 299 Observer::Observer(string name) 300 { 301 #ifdef LOG_OBSERVER 302 observerLog().addName(this,name); 303 observerLog().addMessage() << "++ Creating Observer " << observerLog().getName(this) << endl; 304 #endif 305 } 306 307 /** 308 * Base Constructor for class Observer 309 * 310 * only called from Observable Constructor 311 */ 312 Observer::Observer(Observer::BaseConstructor){ 313 #ifdef LOG_OBSERVER 314 observerLog().addObservable(this); 315 #endif 316 } 263 317 264 318 /** Destructor for class Observer. 265 319 */ 266 320 Observer::~Observer() 267 {} 321 { 322 #ifdef LOG_OBSERVER 323 if(!observerLog().isObservable(this)){ 324 observerLog().addMessage() << "-- Destroying Observer " << observerLog().getName(this) << endl; 325 } 326 #endif 327 } 268 328 269 329 /** … … 296 356 } 297 357 } 358 359 #ifdef LOG_OBSERVER 360 361 /************************* Methods to do logging of the Observer Mechanism *********/ 362 363 // The log needs to exist fairly early, so we make it construct on first use, 364 // and never destroy it 365 ObserverLog &observerLog(){ 366 // yes, this memory is never freed... we need it around for the whole programm, 367 // so no freeing is possible 368 static ObserverLog *theLog = Memory::ignore(new ObserverLog()); 369 return *theLog; 370 } 371 372 373 ObserverLog::ObserverLog() : 374 count (0) 375 {} 376 377 ObserverLog::~ObserverLog(){} 378 379 string ObserverLog::getLog(){return log.str();} 380 381 std::string ObserverLog::getName(void* obj){ 382 return names[obj]; 383 } 384 385 bool ObserverLog::isObservable(void* obj){ 386 return observables.count(obj); 387 } 388 389 void ObserverLog::addName(void* obj , string name){ 390 stringstream sstr; 391 sstr << name << "_" << count++; 392 names[obj] = sstr.str(); 393 } 394 395 void ObserverLog::addObservable(void* obj){ 396 observables.insert(obj); 397 } 398 399 void ObserverLog::deleteName(void* obj){ 400 names.erase(obj); 401 } 402 403 void ObserverLog::deleteObservable(void* obj){ 404 observables.erase(obj); 405 } 406 407 stringstream &ObserverLog::addMessage(int depth){ 408 for(int i=depth;i--;) 409 log << " "; 410 return log; 411 } 412 413 #endif -
src/Patterns/Observer.hpp
r2c8934 rcd5047 11 11 #include <map> 12 12 #include <set> 13 #include <string> 14 #include <sstream> 13 15 14 16 /** … … 28 30 */ 29 31 32 // Deactivate any logging when we are not in debug mode 33 #ifdef NDEBUG 34 #undef LOG_OBSERVER 35 #endif 36 30 37 class Observable; 31 38 class Notification; … … 58 65 template<class> friend class ObservedIterator; 59 66 60 public: 61 Observer(); 67 // indicates the constructor called from Observables 68 struct BaseConstructor{}; 69 70 public: 71 Observer(BaseConstructor); 72 Observer(std::string); 62 73 virtual ~Observer(); 63 74 … … 91 102 class Observable : public Observer { 92 103 public: 93 Observable( );104 Observable(std::string _name); 94 105 virtual ~Observable(); 95 106 … … 192 203 }; 193 204 205 #ifdef LOG_OBSERVER 206 207 /** 208 * This class is used to log the working of the observer mechanism 209 * 210 * TODO: make this conditional dependent on compiler Flag. 211 */ 212 class ObserverLog{ 213 friend class Observable; 214 friend class Observer; 215 template <typename> friend class Cacheable; 216 public: 217 ObserverLog(); 218 ~ObserverLog(); 219 std::string getLog(); // get everything that has been logged 220 std::string getName(void*); // get the name of an actor 221 bool isObservable(void*); 222 private: 223 int count; // number to reference each actor in this framework 224 std::map<void*,std::string> names; // List of names assigned to actors 225 std::set<void*> observables; // List of pointers to Observables. Needed to distinguish Observers and Observables 226 void addName(void*, std::string); // Assign a name to an Actor 227 void addObservable(void*); 228 void deleteName(void*); // delete the name of an Actor 229 void deleteObservable(void*); 230 std::stringstream &addMessage(int depth=0); // Add a Message to the logging 231 std::stringstream log; // The internal log object 232 }; 233 234 ObserverLog &observerLog(); 235 236 #endif 237 194 238 // extra macro is necessary to work with __LINE__ 195 239 #define PASTE(a,b) PASTE_HELPER(a,b) -
src/UIElements/CommandLineUI/CommandLineStatusIndicator.cpp
r2c8934 rcd5047 15 15 using namespace std; 16 16 17 CommandLineStatusIndicator::CommandLineStatusIndicator() 17 CommandLineStatusIndicator::CommandLineStatusIndicator() : 18 Observer("CommandLineStatusIndicator") 18 19 { 19 20 Process::AddObserver(this); -
src/UIElements/TextUI/TextStatusIndicator.cpp
r2c8934 rcd5047 14 14 using namespace std; 15 15 16 TextStatusIndicator::TextStatusIndicator() 16 TextStatusIndicator::TextStatusIndicator() : 17 Observer("TextStatusIndicator") 17 18 { 18 19 Process::AddObserver(this); -
src/World.cpp
r2c8934 rcd5047 277 277 278 278 World::World() : 279 Observable("World"), 279 280 periode(new periodentafel), 280 281 configuration(new config), -
src/builder.cpp
r2c8934 rcd5047 2392 2392 ActionRegistry::purgeInstance(); 2393 2393 ActionHistory::purgeInstance(); 2394 #ifdef LOG_OBSERVER 2395 cout << observerLog().getLog(); 2396 #endif 2394 2397 Memory::getState(); 2395 2398 } -
src/molecule.cpp
r2c8934 rcd5047 35 35 * Initialises molecule list with correctly referenced start and end, and sets molecule::last_atom to zero. 36 36 */ 37 molecule::molecule(const periodentafel * const teil) : elemente(teil),38 MDSteps(0),39 BondCount(0), ElementCount(0), NoNonHydrogen(0), NoNonBonds(0), NoCyclicBonds(0), BondDistance(0.),40 ActiveFlag(false), IndexNr(-1),41 formula(this,boost::bind(&molecule::calcFormula,this) ),42 AtomCount(this,boost::bind(&molecule::doCountAtoms,this) ), last_atom(0), InternalPointer(begin())37 molecule::molecule(const periodentafel * const teil) : 38 Observable("molecule"), 39 elemente(teil), MDSteps(0), BondCount(0), ElementCount(0), NoNonHydrogen(0), NoNonBonds(0), 40 NoCyclicBonds(0), BondDistance(0.), ActiveFlag(false), IndexNr(-1), 41 formula(this,boost::bind(&molecule::calcFormula,this),"formula"), 42 AtomCount(this,boost::bind(&molecule::doCountAtoms,this),"AtomCount"), last_atom(0), InternalPointer(begin()) 43 43 { 44 44 -
src/moleculelist.cpp
r2c8934 rcd5047 29 29 */ 30 30 MoleculeListClass::MoleculeListClass(World *_world) : 31 Observable("MoleculeListClass"), 31 32 world(_world) 32 33 { -
src/unittests/CacheableTest.cpp
r2c8934 rcd5047 55 55 56 56 threeNumbers(int _x,int _y, int _z) : 57 Observable("threeNumbers"), 57 58 x(_x),y(_y),z(_z), 58 sum(this,boost::bind(&threeNumbers::calcSum,this) ),59 sum(this,boost::bind(&threeNumbers::calcSum,this),"sum"), 59 60 hasRecalced(false) 60 61 {} -
src/unittests/ObserverTest.cpp
r2c8934 rcd5047 33 33 public: 34 34 UpdateCountObserver() : 35 Observer("UpdateCountObserver"), 35 36 updates(0) 36 37 {}; … … 45 46 class SimpleObservable : public Observable { 46 47 public: 48 SimpleObservable() : 49 Observable("SimpleObservable") 50 {} 51 47 52 void changeMethod() { 48 53 OBSERVE; … … 54 59 class CallObservable : public Observable { 55 60 public: 61 CallObservable() : 62 Observable("CallObservable") 63 {} 64 56 65 void changeMethod1() { 57 66 OBSERVE; … … 70 79 class BlockObservable : public Observable { 71 80 public: 81 BlockObservable() : 82 Observable("BlockObservable") 83 {} 84 72 85 void changeMethod1(){ 73 86 OBSERVE; … … 104 117 class SuperObservable : public Observable { 105 118 public: 106 SuperObservable(){ 119 SuperObservable(): 120 Observable("SuperObservable") 121 { 107 122 subObservable = new SimpleObservable(); 108 123 subObservable->signOn(this); … … 123 138 public: 124 139 NotificationObservable() : 125 notification1(new Notification(this)), 126 notification2(new Notification(this)) 140 Observable("NotificationObservable"), 141 notification1(new Notification(this)), 142 notification2(new Notification(this)) 127 143 {} 128 144 … … 149 165 public: 150 166 NotificationObserver(Notification_ptr notification) : 167 Observer("NotificationObserver"), 151 168 requestedNotification(notification), 152 169 wasNotified(false) … … 172 189 173 190 ObservableCollection(int _num) : 174 num(_num) 191 Observable("ObservableCollection"), 192 num(_num) 175 193 { 176 194 for(int i=0; i<num; ++i){ -
src/unittests/manipulateAtomsTest.cpp
r2c8934 rcd5047 55 55 public: 56 56 countObserver() : 57 Observer("countObserver"), 57 58 count(0) 58 59 {}
Note:
See TracChangeset
for help on using the changeset viewer.