diff options
author | Paul Davis <paul@linuxaudiosystems.com> | 2007-10-11 22:07:47 +0000 |
---|---|---|
committer | Paul Davis <paul@linuxaudiosystems.com> | 2007-10-11 22:07:47 +0000 |
commit | f7f9d6fdc40248b190ec9c6e1a886261d55777ae (patch) | |
tree | 080723e9dc35a66013b37acbafc67a6afa929302 /libs/pbd/pbd | |
parent | aa1f736a651376534acaa2268b65d42a3786fff7 (diff) |
merge from 2.0-ongoing by hand, minus key binding editor
git-svn-id: svn://localhost/ardour2/trunk@2539 d708f5d6-7413-0410-9779-e7cbd77b26cf
Diffstat (limited to 'libs/pbd/pbd')
-rw-r--r-- | libs/pbd/pbd/convert.h | 12 | ||||
-rw-r--r-- | libs/pbd/pbd/functor_command.h | 121 | ||||
-rw-r--r-- | libs/pbd/pbd/misc.h | 15 | ||||
-rw-r--r-- | libs/pbd/pbd/undo.h | 14 |
4 files changed, 157 insertions, 5 deletions
diff --git a/libs/pbd/pbd/convert.h b/libs/pbd/pbd/convert.h index 00176659cf..83cd285098 100644 --- a/libs/pbd/pbd/convert.h +++ b/libs/pbd/pbd/convert.h @@ -22,6 +22,9 @@ #include <string> #include <vector> +#include <sstream> +#include <iostream> +#include <glibmm/ustring.h> namespace PBD { @@ -30,6 +33,7 @@ std::string short_version (std::string, std::string::size_type target_length); int atoi (const std::string&); double atof (const std::string&); void url_decode (std::string&); +void url_decode (Glib::ustring&); // std::string length2string (const int32_t frames, const float sample_rate); std::string length2string (const int64_t frames, const double sample_rate); @@ -37,6 +41,14 @@ std::string length2string (const int64_t frames, const double sample_rate); std::vector<std::string> internationalize (const char *, const char **); bool strings_equal_ignore_case (const std::string& a, const std::string& b); +template <class T> std::string +to_string (T t, std::ios_base & (*f)(std::ios_base&)) +{ + std::ostringstream oss; + oss << f << t; + return oss.str(); +} + } //namespace PBD #endif /* __pbd_convert_h__ */ diff --git a/libs/pbd/pbd/functor_command.h b/libs/pbd/pbd/functor_command.h new file mode 100644 index 0000000000..e335f4418e --- /dev/null +++ b/libs/pbd/pbd/functor_command.h @@ -0,0 +1,121 @@ +/* + Copyright (C) 2007 Paul Davis + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +*/ + +#ifndef __lib_pbd_functor_command_h__ +#define __lib_pbd_functor_command_h__ + +#include <iostream> +#include <sstream> +#include <string> +#include <map> + +#include <pbd/xml++.h> +#include <pbd/shiva.h> +#include <pbd/command.h> +#include <pbd/failed_constructor.h> + +/** This command class is initialized + */ + +namespace PBD { + +template <class obj_type, class arg_type> +class FunctorCommand : public Command +{ + private: + typedef void (obj_type::*functor_type)(arg_type); + typedef std::map< std::string, functor_type > FunctorMap; + typedef typename FunctorMap::iterator FunctorMapIterator; + + public: + FunctorCommand( + std::string functor, + obj_type object, + arg_type b, + arg_type a + ) : functor_name(functor), + object(object), + before(b), + after(a) + { + method = find_functor(functor); + + /* catch destruction of the object */ + new PBD::Shiva< obj_type, FunctorCommand<obj_type, arg_type> > (object, *this); + } + + ~FunctorCommand() { + GoingAway(); + } + + void operator() () { + (object.*method) (after); + } + + void undo() { + (object.*method) (before); + } + + virtual XMLNode &get_state() { + std::stringstream ss; + + XMLNode *node = new XMLNode("FunctorCommand"); + node->add_property("functor", functor_name); + ss << before; + node->add_property("before", ss.str()); + ss.clear (); + ss << after; + node->add_property("after", ss.str()); + + return *node; + } + + static void register_functor(std::string name, functor_type f) { + functor_map[name] = f; + } + + private: + static functor_type find_functor(std::string name) { + FunctorMapIterator iter; + + if((iter = functor_map.find(name)) == functor_map.end()) { + throw failed_constructor(); + } + + return iter->second; + } + + protected: + std::string functor_name; + obj_type &object; + arg_type before; + arg_type after; + functor_type method; + static FunctorMap functor_map; +}; + +// static initialization of functor_map... +template <class obj_type, class arg_type> +typename FunctorCommand<obj_type, arg_type>::FunctorMap +FunctorCommand<obj_type, arg_type>::functor_map; + +}; + +#endif // __lib_pbd_functor_command_h__ + diff --git a/libs/pbd/pbd/misc.h b/libs/pbd/pbd/misc.h new file mode 100644 index 0000000000..306c00683e --- /dev/null +++ b/libs/pbd/pbd/misc.h @@ -0,0 +1,15 @@ +#ifndef __pbd_misc_h__ +#define __pbd_misc_h__ + +#ifdef __cplusplus +extern "C" { +#endif + + void disable_screen_updates (); + void enable_screen_updates (); + +#ifdef __cplusplus +} +#endif + +#endif /* __pbd_misc_h__ */ diff --git a/libs/pbd/pbd/undo.h b/libs/pbd/pbd/undo.h index 5bfccf5a06..8f1716d09f 100644 --- a/libs/pbd/pbd/undo.h +++ b/libs/pbd/pbd/undo.h @@ -80,20 +80,24 @@ class UndoHistory : public sigc::trackable 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 (); - XMLNode &get_state(uint32_t depth = 0); - void save_state(); + XMLNode &get_state(int32_t depth = 0); + void save_state(); - sigc::signal<void> Changed; + void set_depth (int32_t); + int32_t get_depth() const { return _depth; } + sigc::signal<void> Changed; + private: bool _clearing; + int32_t _depth; std::list<UndoTransaction*> UndoList; std::list<UndoTransaction*> RedoList; |