summaryrefslogtreecommitdiff
path: root/libs/pbd
diff options
context:
space:
mode:
authorRobin Gareus <robin@gareus.org>2020-02-25 17:48:53 +0100
committerRobin Gareus <robin@gareus.org>2020-02-25 17:55:51 +0100
commit7532571fb27bda80563d0deb988863fb941ac2a0 (patch)
treece7a58b8519f0594675c872f6344eb3ca506a605 /libs/pbd
parenta886f2bfcbb05c855d2c5b1cab9a71d60cc3e957 (diff)
NO-OP: whitespace
Diffstat (limited to 'libs/pbd')
-rw-r--r--libs/pbd/pbd/undo.h89
-rw-r--r--libs/pbd/undo.cc171
2 files changed, 137 insertions, 123 deletions
diff --git a/libs/pbd/pbd/undo.h b/libs/pbd/pbd/undo.h
index c6d35c09a5..851818f36d 100644
--- a/libs/pbd/pbd/undo.h
+++ b/libs/pbd/pbd/undo.h
@@ -23,91 +23,109 @@
#ifndef __lib_pbd_undo_h__
#define __lib_pbd_undo_h__
-#include <string>
#include <list>
#include <map>
-#include <sigc++/slot.h>
+#include <string>
+
#include <sigc++/bind.h>
-#ifndef COMPILER_MSVC
+#include <sigc++/slot.h>
+
+#ifndef COMPILER_MSVC
#include <sys/time.h>
#else
#include <ardourext/misc.h>
#endif
-#include "pbd/libpbd_visibility.h"
#include "pbd/command.h"
+#include "pbd/libpbd_visibility.h"
typedef sigc::slot<void> UndoAction;
class LIBPBD_API UndoTransaction : public Command
{
- public:
+public:
UndoTransaction ();
UndoTransaction (const UndoTransaction&);
UndoTransaction& operator= (const UndoTransaction&);
~UndoTransaction ();
void clear ();
- bool empty() const;
- bool clearing () const { return _clearing; }
+ bool empty () const;
+ bool clearing () const {
+ return _clearing;
+ }
void add_command (Command* const);
void remove_command (Command* const);
void operator() ();
- void undo();
- void redo();
+ void undo ();
+ void redo ();
- XMLNode &get_state();
+ XMLNode& get_state ();
- void set_timestamp (struct timeval &t) {
+ void set_timestamp (struct timeval& t)
+ {
_timestamp = t;
}
- const struct timeval& timestamp() const {
+ const struct timeval& timestamp () const
+ {
return _timestamp;
}
- private:
- std::list<Command*> actions;
- struct timeval _timestamp;
- bool _clearing;
+private:
+ std::list<Command*> actions;
+ struct timeval _timestamp;
+ bool _clearing;
- friend void command_death (UndoTransaction*, Command *);
+ friend void command_death (UndoTransaction*, Command*);
void about_to_explicitly_delete ();
};
class LIBPBD_API UndoHistory : public PBD::ScopedConnectionList
{
- public:
- UndoHistory();
- ~UndoHistory() {}
+public:
+ UndoHistory ();
+ ~UndoHistory () {}
void add (UndoTransaction* ut);
void undo (unsigned int n);
void redo (unsigned int n);
- unsigned long undo_depth() const { return UndoList.size(); }
- unsigned long redo_depth() const { return RedoList.size(); }
+ unsigned long undo_depth () const
+ {
+ return UndoList.size ();
+ }
+ unsigned long redo_depth () const
+ {
+ return RedoList.size ();
+ }
- std::string next_undo() const { return (UndoList.empty() ? std::string() : UndoList.back()->name()); }
- std::string next_redo() const { return (RedoList.empty() ? std::string() : RedoList.back()->name()); }
+ std::string next_undo () const
+ {
+ return (UndoList.empty () ? std::string () : UndoList.back ()->name ());
+ }
+ std::string next_redo () const
+ {
+ return (RedoList.empty () ? std::string () : RedoList.back ()->name ());
+ }
void clear ();
void clear_undo ();
void clear_redo ();
/* returns all or part of the history.
- If depth==0 it returns just the top
- node. If depth<0, it returns everything.
- If depth>0, it returns state for that
- many elements of the history, or
- the full history, whichever is smaller.
- */
+ * If depth==0 it returns just the top
+ * node. If depth<0, it returns everything.
+ * If depth>0, it returns state for that
+ * many elements of the history, or
+ * the full history, whichever is smaller.
+ */
- XMLNode &get_state(int32_t depth = 0);
- void save_state();
+ XMLNode& get_state (int32_t depth = 0);
+ void save_state ();
void set_depth (uint32_t);
@@ -115,14 +133,13 @@ class LIBPBD_API UndoHistory : public PBD::ScopedConnectionList
PBD::Signal0<void> BeginUndoRedo;
PBD::Signal0<void> EndUndoRedo;
- private:
- bool _clearing;
- uint32_t _depth;
+private:
+ bool _clearing;
+ uint32_t _depth;
std::list<UndoTransaction*> UndoList;
std::list<UndoTransaction*> RedoList;
void remove (UndoTransaction*);
};
-
#endif /* __lib_pbd_undo_h__ */
diff --git a/libs/pbd/undo.cc b/libs/pbd/undo.cc
index ab8607faff..4a4ca81a3a 100644
--- a/libs/pbd/undo.cc
+++ b/libs/pbd/undo.cc
@@ -21,31 +21,29 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
-#include <string>
#include <sstream>
+#include <string>
#include <time.h>
#include "pbd/undo.h"
#include "pbd/xml++.h"
-#include <sigc++/bind.h>
-
using namespace std;
using namespace sigc;
UndoTransaction::UndoTransaction ()
- : _clearing(false)
+ : _clearing (false)
{
gettimeofday (&_timestamp, 0);
}
UndoTransaction::UndoTransaction (const UndoTransaction& rhs)
- : Command(rhs._name)
- , _clearing(false)
+ : Command (rhs._name)
+ , _clearing (false)
{
- _timestamp = rhs._timestamp;
+ _timestamp = rhs._timestamp;
clear ();
- actions.insert(actions.end(),rhs.actions.begin(),rhs.actions.end());
+ actions.insert (actions.end (), rhs.actions.begin (), rhs.actions.end ());
}
UndoTransaction::~UndoTransaction ()
@@ -57,13 +55,13 @@ UndoTransaction::~UndoTransaction ()
void
command_death (UndoTransaction* ut, Command* c)
{
- if (ut->clearing()) {
+ if (ut->clearing ()) {
return;
}
ut->remove_command (c);
- if (ut->empty()) {
+ if (ut->empty ()) {
delete ut;
}
}
@@ -71,19 +69,21 @@ command_death (UndoTransaction* ut, Command* c)
UndoTransaction&
UndoTransaction::operator= (const UndoTransaction& rhs)
{
- if (this == &rhs) return *this;
+ if (this == &rhs) {
+ return *this;
+ }
_name = rhs._name;
clear ();
- actions.insert(actions.end(),rhs.actions.begin(),rhs.actions.end());
+ actions.insert (actions.end (), rhs.actions.begin (), rhs.actions.end ());
return *this;
}
void
-UndoTransaction::add_command (Command *const cmd)
+UndoTransaction::add_command (Command* const cmd)
{
/* catch death of command (e.g. caused by death of object to
- which it refers. command_death() is a normal static function
- so there is no need to manage this connection.
+ * which it refers. command_death() is a normal static function
+ * so there is no need to manage this connection.
*/
cmd->DropReferences.connect_same_thread (*this, boost::bind (&command_death, this, cmd));
@@ -99,14 +99,14 @@ UndoTransaction::remove_command (Command* const action)
bool
UndoTransaction::empty () const
{
- return actions.empty();
+ return actions.empty ();
}
void
UndoTransaction::clear ()
{
_clearing = true;
- for (list<Command*>::iterator i = actions.begin(); i != actions.end(); ++i) {
+ for (list<Command*>::iterator i = actions.begin (); i != actions.end (); ++i) {
delete *i;
}
actions.clear ();
@@ -116,64 +116,69 @@ UndoTransaction::clear ()
void
UndoTransaction::operator() ()
{
- for (list<Command*>::iterator i = actions.begin(); i != actions.end(); ++i) {
- (*(*i))();
+ for (list<Command*>::iterator i = actions.begin (); i != actions.end (); ++i) {
+ (*(*i)) ();
}
}
void
UndoTransaction::undo ()
{
- for (list<Command*>::reverse_iterator i = actions.rbegin(); i != actions.rend(); ++i) {
- (*i)->undo();
+ for (list<Command*>::reverse_iterator i = actions.rbegin (); i != actions.rend (); ++i) {
+ (*i)->undo ();
}
}
void
UndoTransaction::redo ()
{
- (*this)();
+ (*this) ();
}
-XMLNode &UndoTransaction::get_state()
+XMLNode&
+UndoTransaction::get_state ()
{
- XMLNode *node = new XMLNode ("UndoTransaction");
- node->set_property("tv-sec", (int64_t)_timestamp.tv_sec);
- node->set_property("tv-usec", (int64_t)_timestamp.tv_usec);
- node->set_property("name", _name);
-
- list<Command*>::iterator it;
- for (it=actions.begin(); it!=actions.end(); it++)
- node->add_child_nocopy((*it)->get_state());
+ XMLNode* node = new XMLNode ("UndoTransaction");
+ node->set_property ("tv-sec", (int64_t)_timestamp.tv_sec);
+ node->set_property ("tv-usec", (int64_t)_timestamp.tv_usec);
+ node->set_property ("name", _name);
+
+ list<Command*>::iterator it;
+ for (it = actions.begin (); it != actions.end (); it++) {
+ node->add_child_nocopy ((*it)->get_state ());
+ }
- return *node;
+ return *node;
}
-class UndoRedoSignaller {
+class UndoRedoSignaller
+{
public:
- UndoRedoSignaller (UndoHistory& uh)
- : _history (uh) {
- _history.BeginUndoRedo();
- }
- ~UndoRedoSignaller() {
- _history.EndUndoRedo();
- }
+ UndoRedoSignaller (UndoHistory& uh)
+ : _history (uh)
+ {
+ _history.BeginUndoRedo ();
+ }
+
+ ~UndoRedoSignaller ()
+ {
+ _history.EndUndoRedo ();
+ }
private:
- UndoHistory& _history;
+ UndoHistory& _history;
};
UndoHistory::UndoHistory ()
{
_clearing = false;
- _depth = 0;
+ _depth = 0;
}
void
UndoHistory::set_depth (uint32_t d)
{
- UndoTransaction* ut;
- uint32_t current_depth = UndoList.size();
+ uint32_t current_depth = UndoList.size ();
_depth = d;
@@ -183,11 +188,10 @@ UndoHistory::set_depth (uint32_t d)
}
if (_depth > 0) {
-
uint32_t cnt = current_depth - d;
while (cnt--) {
- ut = UndoList.front();
+ UndoTransaction* ut = UndoList.front ();
UndoList.pop_front ();
delete ut;
}
@@ -197,17 +201,16 @@ UndoHistory::set_depth (uint32_t d)
void
UndoHistory::add (UndoTransaction* const ut)
{
- uint32_t current_depth = UndoList.size();
+ uint32_t current_depth = UndoList.size ();
ut->DropReferences.connect_same_thread (*this, boost::bind (&UndoHistory::remove, this, ut));
/* if the current undo history is larger than or equal to the currently
- requested depth, then pop off at least 1 element to make space
- at the back for new one.
- */
+ requested depth, then pop off at least 1 element to make space
+ at the back for new one.
+ */
if ((_depth > 0) && current_depth && (current_depth >= _depth)) {
-
uint32_t cnt = 1 + (current_depth - _depth);
while (cnt--) {
@@ -221,9 +224,9 @@ UndoHistory::add (UndoTransaction* const ut)
UndoList.push_back (ut);
/* Adding a transacrion makes the redo list meaningless. */
_clearing = true;
- for (std::list<UndoTransaction*>::iterator i = RedoList.begin(); i != RedoList.end(); ++i) {
- delete *i;
- }
+ for (std::list<UndoTransaction*>::iterator i = RedoList.begin (); i != RedoList.end (); ++i) {
+ delete *i;
+ }
RedoList.clear ();
_clearing = false;
@@ -259,7 +262,7 @@ UndoHistory::undo (unsigned int n)
UndoRedoSignaller exception_safe_signaller (*this);
while (n--) {
- if (UndoList.size() == 0) {
+ if (UndoList.size () == 0) {
return;
}
UndoTransaction* ut = UndoList.back ();
@@ -283,7 +286,7 @@ UndoHistory::redo (unsigned int n)
UndoRedoSignaller exception_safe_signaller (*this);
while (n--) {
- if (RedoList.size() == 0) {
+ if (RedoList.size () == 0) {
return;
}
UndoTransaction* ut = RedoList.back ();
@@ -300,23 +303,22 @@ void
UndoHistory::clear_redo ()
{
_clearing = true;
- for (std::list<UndoTransaction*>::iterator i = RedoList.begin(); i != RedoList.end(); ++i) {
- delete *i;
- }
+ for (std::list<UndoTransaction*>::iterator i = RedoList.begin (); i != RedoList.end (); ++i) {
+ delete *i;
+ }
RedoList.clear ();
_clearing = false;
Changed (); /* EMIT SIGNAL */
-
}
void
UndoHistory::clear_undo ()
{
_clearing = true;
- for (std::list<UndoTransaction*>::iterator i = UndoList.begin(); i != UndoList.end(); ++i) {
- delete *i;
- }
+ for (std::list<UndoTransaction*>::iterator i = UndoList.begin (); i != UndoList.end (); ++i) {
+ delete *i;
+ }
UndoList.clear ();
_clearing = false;
@@ -335,36 +337,31 @@ UndoHistory::clear ()
XMLNode&
UndoHistory::get_state (int32_t depth)
{
- XMLNode *node = new XMLNode ("UndoHistory");
-
- if (depth == 0) {
-
- return (*node);
+ XMLNode* node = new XMLNode ("UndoHistory");
- } else if (depth < 0) {
+ if (depth == 0) {
+ return (*node);
- /* everything */
+ } else if (depth < 0) {
+ /* everything */
- for (list<UndoTransaction*>::iterator it = UndoList.begin(); it != UndoList.end(); ++it) {
- node->add_child_nocopy((*it)->get_state());
- }
-
- } else {
+ for (list<UndoTransaction*>::iterator it = UndoList.begin (); it != UndoList.end (); ++it) {
+ node->add_child_nocopy ((*it)->get_state ());
+ }
- /* just the last "depth" transactions */
+ } else {
+ /* just the last "depth" transactions */
- list<UndoTransaction*> in_order;
+ list<UndoTransaction*> in_order;
- for (list<UndoTransaction*>::reverse_iterator it = UndoList.rbegin(); it != UndoList.rend() && depth; ++it, depth--) {
- in_order.push_front (*it);
- }
+ for (list<UndoTransaction*>::reverse_iterator it = UndoList.rbegin (); it != UndoList.rend () && depth; ++it, depth--) {
+ in_order.push_front (*it);
+ }
- for (list<UndoTransaction*>::iterator it = in_order.begin(); it != in_order.end(); it++) {
- node->add_child_nocopy((*it)->get_state());
- }
- }
+ for (list<UndoTransaction*>::iterator it = in_order.begin (); it != in_order.end (); it++) {
+ node->add_child_nocopy ((*it)->get_state ());
+ }
+ }
- return *node;
+ return *node;
}
-
-