diff options
Diffstat (limited to 'libs/pbd/pbd')
-rw-r--r-- | libs/pbd/pbd/abstract_ui.cc | 10 | ||||
-rw-r--r-- | libs/pbd/pbd/destructible.h | 20 | ||||
-rw-r--r-- | libs/pbd/pbd/id.h | 8 | ||||
-rw-r--r-- | libs/pbd/pbd/memento_command.h | 82 | ||||
-rw-r--r-- | libs/pbd/pbd/rcu.h | 14 | ||||
-rw-r--r-- | libs/pbd/pbd/stateful.h | 3 | ||||
-rw-r--r-- | libs/pbd/pbd/unknown_type.h | 11 |
7 files changed, 82 insertions, 66 deletions
diff --git a/libs/pbd/pbd/abstract_ui.cc b/libs/pbd/pbd/abstract_ui.cc index 0e34787a2d..eca53916af 100644 --- a/libs/pbd/pbd/abstract_ui.cc +++ b/libs/pbd/pbd/abstract_ui.cc @@ -4,6 +4,10 @@ #include <pbd/pthread_utils.h> #include <pbd/failed_constructor.h> +#include "i18n.h" + +using namespace std; + template <typename RequestObject> AbstractUI<RequestObject>::AbstractUI (string name, bool with_signal_pipes) : BaseUI (name, with_signal_pipes) @@ -44,7 +48,7 @@ AbstractUI<RequestObject>::get_request (RequestType rt) if (rbuf == 0) { /* Cannot happen, but if it does we can't use the error reporting mechanism */ cerr << _("programming error: ") - << string_compose (X_("no %1-UI request buffer found for thread %2"), name(), pthread_name()) + << string_compose ("no %1-UI request buffer found for thread %2", name(), pthread_name()) << endl; abort (); } @@ -55,7 +59,7 @@ AbstractUI<RequestObject>::get_request (RequestType rt) if (vec.len[0] == 0) { if (vec.len[1] == 0) { - cerr << string_compose (X_("no space in %1-UI request buffer for thread %2"), name(), pthread_name()) + cerr << string_compose ("no space in %1-UI request buffer for thread %2", name(), pthread_name()) << endl; return 0; } else { @@ -131,7 +135,7 @@ AbstractUI<RequestObject>::send_request (RequestObject *req) thread isn't registered! */ cerr << _("programming error: ") - << string_compose (X_("AbstractUI::send_request() called from %1, but no request buffer exists for that thread"), pthread_name()) + << string_compose ("AbstractUI::send_request() called from %1 (%2), but no request buffer exists for that thread", name(), pthread_name()) << endl; abort (); } diff --git a/libs/pbd/pbd/destructible.h b/libs/pbd/pbd/destructible.h new file mode 100644 index 0000000000..126bd04bba --- /dev/null +++ b/libs/pbd/pbd/destructible.h @@ -0,0 +1,20 @@ +#ifndef __pbd_destructible_h__ +#define __pbd_destructible_h__ + +#include <sigc++/signal.h> + +namespace PBD { + +class Destructible { + public: + Destructible() {} + virtual ~Destructible () {} + + sigc::signal<void> GoingAway; + + void drop_references () const { GoingAway(); } +}; + +} + +#endif /* __pbd_destructible_h__ */ diff --git a/libs/pbd/pbd/id.h b/libs/pbd/pbd/id.h index 1ce448d58b..c110362734 100644 --- a/libs/pbd/pbd/id.h +++ b/libs/pbd/pbd/id.h @@ -14,17 +14,17 @@ class ID { ID (std::string); bool operator== (const ID& other) const { - return id == other.id; + return _id == other._id; } bool operator!= (const ID& other) const { - return id != other.id; + return _id != other._id; } ID& operator= (std::string); bool operator< (const ID& other) const { - return id < other.id; + return _id < other._id; } void print (char* buf) const; @@ -35,7 +35,7 @@ class ID { static void init (); private: - uint64_t id; + uint64_t _id; int string_assign (std::string); static Glib::Mutex* counter_lock; diff --git a/libs/pbd/pbd/memento_command.h b/libs/pbd/pbd/memento_command.h index 122dcb4c86..3a72fc9841 100644 --- a/libs/pbd/pbd/memento_command.h +++ b/libs/pbd/pbd/memento_command.h @@ -36,70 +36,44 @@ class MementoCommand : public Command public: MementoCommand(XMLNode &state); MementoCommand(obj_T &obj, - XMLNode &before, - XMLNode &after + XMLNode *before, + XMLNode *after ) : obj(obj), before(before), after(after) {} - void operator() () { obj.set_state(after); } - void undo() { obj.set_state(before); } + void operator() () + { + if (after) + obj.set_state(*after); + } + void undo() + { + if (before) + obj.set_state(*before); + } virtual XMLNode &get_state() { - XMLNode *node = new XMLNode("MementoCommand"); + string name; + if (before && after) + name = "MementoCommand"; + else if (before) + name = "MementoUndoCommand"; + else + name = "MementoRedoCommand"; + + XMLNode *node = new XMLNode(name); node->add_property("obj_id", obj.id().to_s()); node->add_property("type_name", typeid(obj).name()); - node->add_child_copy(before); - node->add_child_copy(after); + + if (before) + node->add_child_copy(*before); + if (after) + node->add_child_copy(*after); + return *node; } protected: obj_T &obj; - XMLNode &before, &after; -}; - -template <class obj_T> -class MementoUndoCommand : public Command -{ -public: - MementoUndoCommand(XMLNode &state); - MementoUndoCommand(obj_T &obj, - XMLNode &before) - : obj(obj), before(before) {} - void operator() () { /* noop */ } - void undo() { obj.set_state(before); } - virtual XMLNode &get_state() - { - XMLNode *node = new XMLNode("MementoUndoCommand"); - node->add_property("obj_id", obj.id().to_s()); - node->add_property("type_name", typeid(obj).name()); - node->add_child_copy(before); - return *node; - } -protected: - obj_T &obj; - XMLNode &before; -}; - -template <class obj_T> -class MementoRedoCommand : public Command -{ -public: - MementoRedoCommand(XMLNode &state); - MementoRedoCommand(obj_T &obj, - XMLNode &after) - : obj(obj), after(after) {} - void operator() () { obj.set_state(after); } - void undo() { /* noop */ } - virtual XMLNode &get_state() - { - XMLNode *node = new XMLNode("MementoRedoCommand"); - node->add_property("obj_id", obj.id().to_s()); - node->add_property("type_name", typeid(obj).name()); - node->add_child_copy(after); - return *node; - } -protected: - obj_T &obj; - XMLNode &after; + XMLNode *before, *after; }; #endif // __lib_pbd_memento_h__ diff --git a/libs/pbd/pbd/rcu.h b/libs/pbd/pbd/rcu.h index 58a92a206a..e81db8ba87 100644 --- a/libs/pbd/pbd/rcu.h +++ b/libs/pbd/pbd/rcu.h @@ -5,8 +5,7 @@ #include "glibmm/thread.h" #include <list> - - + template<class T> class RCUManager { @@ -43,7 +42,7 @@ public: } - virtual boost::shared_ptr<T> write_copy () + boost::shared_ptr<T> write_copy () { m_lock.lock(); @@ -64,11 +63,11 @@ public: current_write_old = RCUManager<T>::m_rcu_value; boost::shared_ptr<T> new_copy (new T(**current_write_old)); - + return new_copy; } - virtual bool update (boost::shared_ptr<T> new_value) + bool update (boost::shared_ptr<T> new_value) { // we hold the lock at this point effectively blocking // other writers. @@ -98,6 +97,11 @@ public: return ret; } + + void flush () { + Glib::Mutex::Lock lm (m_lock); + m_dead_wood.clear (); + } private: Glib::Mutex m_lock; diff --git a/libs/pbd/pbd/stateful.h b/libs/pbd/pbd/stateful.h index 3038f16b4f..5adddfc1c0 100644 --- a/libs/pbd/pbd/stateful.h +++ b/libs/pbd/pbd/stateful.h @@ -22,6 +22,7 @@ #define __pbd_stateful_h__ #include <string> +#include <pbd/id.h> class XMLNode; @@ -41,10 +42,12 @@ class Stateful { virtual void add_instant_xml (XMLNode&, const std::string& dir); XMLNode *instant_xml (const std::string& str, const std::string& dir); + PBD::ID id() { return _id; } protected: XMLNode *_extra_xml; XMLNode *_instant_xml; + PBD::ID _id; }; #endif /* __pbd_stateful_h__ */ diff --git a/libs/pbd/pbd/unknown_type.h b/libs/pbd/pbd/unknown_type.h new file mode 100644 index 0000000000..fddc1aeddb --- /dev/null +++ b/libs/pbd/pbd/unknown_type.h @@ -0,0 +1,11 @@ +#ifndef __pbd_unknown_type_h__ +#define __pbd_unknown_type_h__ + +#include <exception> + +class unknown_type : public std::exception { + public: + virtual const char *what() const throw() { return "unknown type"; } +}; + +#endif /* __pbd_unknown_type_h__ */ |