source: molecuilder/src/Parser/ChangeTracker.cpp@ 2e06c4

Last change on this file since 2e06c4 was 0f7883, checked in by Saskia Metzler <metzler@…>, 15 years ago

Merge Till's structure refactoring

Merge commit 'till/StructureRefactoring' into StateAndFormatParser

Conflicts:

molecuilder/src/Makefile.am
molecuilder/src/unittests/Makefile.am

  • Property mode set to 100644
File size: 1.4 KB
Line 
1/*
2 * ChangeTracker.cpp
3 *
4 * Created on: Mar 1, 2010
5 * Author: metzler
6 */
7
8#include "ChangeTracker.hpp"
9
10ChangeTracker* ChangeTracker::instance = NULL;
11
12/**
13 * Constructor. Signs on as an observer for the World.
14 */
15ChangeTracker::ChangeTracker() {
16 isConsistent = true;
17 World::getInstance().signOn(this);
18}
19
20/**
21 * Destructor. Signs off from the World.
22 */
23ChangeTracker::~ChangeTracker() {
24 World::getInstance().signOff(this);
25}
26
27/**
28 * Returns the change tracker instance.
29 *
30 * \return this
31 */
32ChangeTracker* ChangeTracker::get() {
33 if (instance == NULL) {
34 instance = new ChangeTracker();
35 }
36
37 return instance;
38}
39
40/**
41 * Destroys the change tracker instance. Be careful, the change tracker is a
42 * singleton and destruction might lead to a loss of consistency.
43 */
44void ChangeTracker::destroy() {
45 delete instance;
46 instance = NULL;
47}
48
49/**
50 * With this, the World can update the change tracker's state.
51 */
52void ChangeTracker::update(Observable *publisher) {
53 isConsistent = false;
54}
55
56/**
57 * Gets whether there are non-saved changes.
58 *
59 * \param true if there are any changes, false otherwise
60 */
61bool ChangeTracker::hasChanged() {
62 return !isConsistent;
63}
64
65/**
66 * Tells all observers (which are the different parsers) that they are supposed
67 * to save the current state.
68 */
69void ChangeTracker::saveStatus() {
70 if (hasChanged()) {
71 notifyAll();
72 }
73}
Note: See TracBrowser for help on using the repository browser.