2015-08-16 22:29:54 +00:00
|
|
|
#ifndef DIFFMANAGER_H
|
|
|
|
#define DIFFMANAGER_H
|
|
|
|
|
|
|
|
#include "definition_global.h"
|
|
|
|
|
|
|
|
#include <map>
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
namespace paysages {
|
|
|
|
namespace definition {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Manager of diffs produced by a definition tree.
|
|
|
|
*
|
|
|
|
* Watchers can register themselves to received these diffs.
|
|
|
|
*/
|
2015-11-09 21:30:46 +00:00
|
|
|
class DEFINITIONSHARED_EXPORT DiffManager {
|
|
|
|
public:
|
2015-08-16 22:29:54 +00:00
|
|
|
DiffManager(DefinitionNode *tree);
|
2015-08-17 20:55:30 +00:00
|
|
|
~DiffManager();
|
2015-08-16 22:29:54 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Add a watcher for a specific node.
|
|
|
|
*
|
|
|
|
* The watcher reference must remain valid through the manager lifetime.
|
|
|
|
*/
|
|
|
|
void addWatcher(const DefinitionNode *node, DefinitionWatcher *watcher);
|
|
|
|
|
2015-09-21 21:10:43 +00:00
|
|
|
/**
|
|
|
|
* Get the number of watchers registered for a given node.
|
|
|
|
*/
|
|
|
|
int getWatcherCount(const DefinitionNode *node);
|
|
|
|
|
2015-08-16 22:29:54 +00:00
|
|
|
/**
|
|
|
|
* Add a new diff of a node to the change flow.
|
|
|
|
*/
|
|
|
|
void addDiff(DefinitionNode *node, const DefinitionDiff *diff);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Undo a diff in the definition tree.
|
|
|
|
*/
|
|
|
|
void undo();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Redo a diff in the definition tree, undone by undo().
|
|
|
|
*/
|
|
|
|
void redo();
|
|
|
|
|
2015-11-09 21:30:46 +00:00
|
|
|
private:
|
2015-08-16 22:29:54 +00:00
|
|
|
DefinitionNode *tree;
|
|
|
|
int undone;
|
|
|
|
std::vector<const DefinitionDiff *> diffs;
|
|
|
|
std::map<const DefinitionNode *, std::vector<DefinitionWatcher *>> watchers;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // DIFFMANAGER_H
|