From 9d2d0ddf00fa91978f2bb14b4dbc195542d46259 Mon Sep 17 00:00:00 2001 From: Tim Mayberry Date: Tue, 30 Aug 2016 21:07:24 +1000 Subject: [PATCH] Add AxisView::get_gui_property method, use PBD::string_to for string conversion --- gtk2_ardour/axis_view.cc | 21 +++++++++++++++++++++ gtk2_ardour/axis_view.h | 31 ++++++++++++++++++++----------- 2 files changed, 41 insertions(+), 11 deletions(-) diff --git a/gtk2_ardour/axis_view.cc b/gtk2_ardour/axis_view.cc index d5f7b46a37..1502c8e1ea 100644 --- a/gtk2_ardour/axis_view.cc +++ b/gtk2_ardour/axis_view.cc @@ -74,6 +74,27 @@ AxisView::gui_property (const string& property_name) const } } +bool +AxisView::get_gui_property (const std::string& property_name, std::string& value) const +{ + std::string str = gui_property(property_name); + + if (!str.empty()) { + value = str; + return true; + } + + return false; +} + +void +AxisView::set_gui_property (const std::string& property_name, const std::string& value) +{ + property_hashtable.erase (property_name); + property_hashtable.emplace (property_name, value); + gui_object_state ().set_property (state_id (), property_name, value); +} + bool AxisView::marked_for_display () const { diff --git a/gtk2_ardour/axis_view.h b/gtk2_ardour/axis_view.h index 8de39583ef..81fe489252 100644 --- a/gtk2_ardour/axis_view.h +++ b/gtk2_ardour/axis_view.h @@ -63,20 +63,29 @@ class AxisView : public virtual PBD::ScopedConnectionList, public virtual ARDOUR */ std::string gui_property (const std::string& property_name) const; + bool get_gui_property (const std::string& property_name, std::string& value) const; + + template + bool get_gui_property (const std::string& property_name, T& value) const + { + std::string str = gui_property (property_name); + + if (!str.empty ()) { + return PBD::string_to(str, value); + } + return false; + } + + void set_gui_property (const std::string& property_name, const std::string& value); + void set_gui_property (const std::string& property_name, const char* value) { - property_hashtable.erase(property_name); - property_hashtable.emplace(property_name, value); - gui_object_state().set_property (state_id(), property_name, value); + set_gui_property (property_name, std::string(value)); } - void set_gui_property (const std::string& property_name, const std::string& value) { - set_gui_property (property_name, value.c_str()); - } - - template void set_gui_property (const std::string& property_name, const T& value) { - property_hashtable.erase(property_name); - property_hashtable.emplace(property_name, PBD::to_string(value)); - gui_object_state().set_property (state_id(), property_name, value); + template + void set_gui_property (const std::string& property_name, const T& value) + { + set_gui_property (property_name, PBD::to_string(value)); } void cleanup_gui_properties () {