mirror of
https://github.com/Ardour/ardour.git
synced 2025-12-17 20:26:30 +01:00
Make commands noncopyable (they are definitely not copy safe).
memento_command.h style. git-svn-id: svn://localhost/ardour2/branches/3.0@4648 d708f5d6-7413-0410-9779-e7cbd77b26cf
This commit is contained in:
parent
df4e6f2341
commit
5b04ddf424
2 changed files with 27 additions and 28 deletions
|
|
@ -22,8 +22,9 @@
|
||||||
#define __lib_pbd_command_h__
|
#define __lib_pbd_command_h__
|
||||||
|
|
||||||
#include <pbd/statefuldestructible.h>
|
#include <pbd/statefuldestructible.h>
|
||||||
|
#include <boost/utility.hpp>
|
||||||
|
|
||||||
class Command : public PBD::StatefulDestructible
|
class Command : public PBD::StatefulDestructible, public boost::noncopyable
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
virtual ~Command() { /* NOTE: derived classes must call drop_references() */ }
|
virtual ~Command() { /* NOTE: derived classes must call drop_references() */ }
|
||||||
|
|
|
||||||
|
|
@ -39,63 +39,61 @@ template <class obj_T>
|
||||||
class MementoCommand : public Command
|
class MementoCommand : public Command
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
MementoCommand(obj_T &object, XMLNode *before, XMLNode *after)
|
MementoCommand(obj_T& a_object, XMLNode* a_before, XMLNode* a_after)
|
||||||
: obj(object), before(before), after(after)
|
: obj(a_object), before(a_before), after(a_after)
|
||||||
{
|
{
|
||||||
/* catch destruction of the object */
|
/* catch destruction of the object */
|
||||||
new PBD::PairedShiva<obj_T,MementoCommand<obj_T> > (object, *this);
|
new PBD::PairedShiva< obj_T,MementoCommand<obj_T> > (obj, *this);
|
||||||
}
|
}
|
||||||
|
|
||||||
~MementoCommand ()
|
~MementoCommand () {
|
||||||
{
|
|
||||||
GoingAway(); /* EMIT SIGNAL */
|
GoingAway(); /* EMIT SIGNAL */
|
||||||
|
|
||||||
if (before)
|
|
||||||
delete before;
|
delete before;
|
||||||
|
|
||||||
if (after)
|
|
||||||
delete after;
|
delete after;
|
||||||
}
|
}
|
||||||
|
|
||||||
void operator() ()
|
void operator() () {
|
||||||
{
|
if (after) {
|
||||||
if (after)
|
|
||||||
obj.set_state(*after);
|
obj.set_state(*after);
|
||||||
}
|
}
|
||||||
|
|
||||||
void undo()
|
|
||||||
{
|
|
||||||
if (before)
|
|
||||||
obj.set_state(*before);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual XMLNode &get_state()
|
void undo() {
|
||||||
{
|
if (before) {
|
||||||
|
obj.set_state(*before);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual XMLNode &get_state() {
|
||||||
string name;
|
string name;
|
||||||
if (before && after)
|
if (before && after) {
|
||||||
name = "MementoCommand";
|
name = "MementoCommand";
|
||||||
else if (before)
|
} else if (before) {
|
||||||
name = "MementoUndoCommand";
|
name = "MementoUndoCommand";
|
||||||
else
|
} else {
|
||||||
name = "MementoRedoCommand";
|
name = "MementoRedoCommand";
|
||||||
|
}
|
||||||
|
|
||||||
XMLNode* node = new XMLNode(name);
|
XMLNode* node = new XMLNode(name);
|
||||||
|
|
||||||
node->add_property("obj_id", obj.id().to_s());
|
node->add_property("obj_id", obj.id().to_s());
|
||||||
node->add_property("type_name", typeid(obj).name());
|
node->add_property("type_name", typeid(obj).name());
|
||||||
|
|
||||||
if (before)
|
if (before) {
|
||||||
node->add_child_copy(*before);
|
node->add_child_copy(*before);
|
||||||
|
}
|
||||||
|
|
||||||
if (after)
|
if (after) {
|
||||||
node->add_child_copy(*after);
|
node->add_child_copy(*after);
|
||||||
|
}
|
||||||
|
|
||||||
return *node;
|
return *node;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
obj_T& obj;
|
obj_T& obj;
|
||||||
XMLNode *before, *after;
|
XMLNode* before;
|
||||||
|
XMLNode* after;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // __lib_pbd_memento_h__
|
#endif // __lib_pbd_memento_h__
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue