mirror of
https://github.com/Ardour/ardour.git
synced 2025-12-07 07:14:56 +01:00
Use PBD string conversion functions in PBD::ConfigurationVariable
No longer need a specialization for bool as PBD::to_string/string_to already has specializations for bool Remove template specialization for float as string_to/to_string handles string representations of infinity
This commit is contained in:
parent
cb3c564822
commit
2b58bbd50a
6 changed files with 8 additions and 63 deletions
|
|
@ -49,6 +49,7 @@
|
||||||
#include "ardour/search_paths.h"
|
#include "ardour/search_paths.h"
|
||||||
#include "ardour/revision.h"
|
#include "ardour/revision.h"
|
||||||
#include "ardour/utils.h"
|
#include "ardour/utils.h"
|
||||||
|
#include "ardour/types_convert.h"
|
||||||
|
|
||||||
#include "gtkmm2ext/rgb_macros.h"
|
#include "gtkmm2ext/rgb_macros.h"
|
||||||
#include "gtkmm2ext/gtk_ui.h"
|
#include "gtkmm2ext/gtk_ui.h"
|
||||||
|
|
|
||||||
|
|
@ -35,6 +35,7 @@
|
||||||
#include "ardour/port.h"
|
#include "ardour/port.h"
|
||||||
#include "ardour/rc_configuration.h"
|
#include "ardour/rc_configuration.h"
|
||||||
#include "ardour/session_metadata.h"
|
#include "ardour/session_metadata.h"
|
||||||
|
#include "ardour/types_convert.h"
|
||||||
|
|
||||||
#include "pbd/i18n.h"
|
#include "pbd/i18n.h"
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -104,6 +104,7 @@
|
||||||
#include "ardour/tempo.h"
|
#include "ardour/tempo.h"
|
||||||
#include "ardour/ticker.h"
|
#include "ardour/ticker.h"
|
||||||
#include "ardour/track.h"
|
#include "ardour/track.h"
|
||||||
|
#include "ardour/types_convert.h"
|
||||||
#include "ardour/user_bundle.h"
|
#include "ardour/user_bundle.h"
|
||||||
#include "ardour/utils.h"
|
#include "ardour/utils.h"
|
||||||
#include "ardour/vca_manager.h"
|
#include "ardour/vca_manager.h"
|
||||||
|
|
|
||||||
|
|
@ -27,6 +27,7 @@
|
||||||
#include "pbd/pathexpand.h"
|
#include "pbd/pathexpand.h"
|
||||||
|
|
||||||
#include "ardour/types.h"
|
#include "ardour/types.h"
|
||||||
|
#include "ardour/types_convert.h"
|
||||||
#include "ardour/filesystem_paths.h"
|
#include "ardour/filesystem_paths.h"
|
||||||
#include "ardour/session_configuration.h"
|
#include "ardour/session_configuration.h"
|
||||||
#include "ardour/utils.h"
|
#include "ardour/utils.h"
|
||||||
|
|
|
||||||
|
|
@ -111,11 +111,3 @@ ConfigVariableBase::miss ()
|
||||||
// placeholder for any debugging desired when a config variable
|
// placeholder for any debugging desired when a config variable
|
||||||
// is set but to the same value as it already has
|
// is set but to the same value as it already has
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Specialisation of ConfigVariable to deal with float (-inf etc)
|
|
||||||
* http://stackoverflow.com/questions/23374095/should-a-stringstream-parse-infinity-as-an-infinite-value
|
|
||||||
*/
|
|
||||||
template<> void
|
|
||||||
ConfigVariable<float>::set_from_string (std::string const & s) {
|
|
||||||
value = std::strtof (s.c_str(), NULL);
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -20,12 +20,10 @@
|
||||||
#ifndef __libpbd_configuration_variable_h__
|
#ifndef __libpbd_configuration_variable_h__
|
||||||
#define __libpbd_configuration_variable_h__
|
#define __libpbd_configuration_variable_h__
|
||||||
|
|
||||||
#include <iostream>
|
|
||||||
#include <sstream>
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include "pbd/xml++.h"
|
#include "pbd/xml++.h"
|
||||||
#include "pbd/convert.h"
|
#include "pbd/string_convert.h"
|
||||||
#include "pbd/libpbd_visibility.h"
|
#include "pbd/libpbd_visibility.h"
|
||||||
|
|
||||||
namespace PBD {
|
namespace PBD {
|
||||||
|
|
@ -63,9 +61,7 @@ class /*LIBPBD_API*/ ConfigVariable : public ConfigVariableBase
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string get_as_string () const {
|
std::string get_as_string () const {
|
||||||
std::ostringstream ss;
|
return to_string<T>(value);
|
||||||
ss << value;
|
|
||||||
return ss.str ();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual bool set (T val) {
|
virtual bool set (T val) {
|
||||||
|
|
@ -79,9 +75,7 @@ class /*LIBPBD_API*/ ConfigVariable : public ConfigVariableBase
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void set_from_string (std::string const & s) {
|
virtual void set_from_string (std::string const & s) {
|
||||||
std::stringstream ss;
|
value = string_to<T>(s);
|
||||||
ss << s;
|
|
||||||
ss >> value;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
@ -89,10 +83,6 @@ class /*LIBPBD_API*/ ConfigVariable : public ConfigVariableBase
|
||||||
T value;
|
T value;
|
||||||
};
|
};
|
||||||
|
|
||||||
/** Specialisation of ConfigVariable to deal with float (-inf etc) */
|
|
||||||
template<> LIBPBD_API void
|
|
||||||
ConfigVariable<float>::set_from_string (std::string const & s);
|
|
||||||
|
|
||||||
/** Specialisation of ConfigVariable for std::string to cope with whitespace properly */
|
/** Specialisation of ConfigVariable for std::string to cope with whitespace properly */
|
||||||
template<>
|
template<>
|
||||||
class /*LIBPBD_API*/ ConfigVariable<std::string> : public ConfigVariableBase
|
class /*LIBPBD_API*/ ConfigVariable<std::string> : public ConfigVariableBase
|
||||||
|
|
@ -129,43 +119,6 @@ class /*LIBPBD_API*/ ConfigVariable<std::string> : public ConfigVariableBase
|
||||||
std::string value;
|
std::string value;
|
||||||
};
|
};
|
||||||
|
|
||||||
template<>
|
|
||||||
class /*LIBPBD_API*/ ConfigVariable<bool> : public ConfigVariableBase
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
|
|
||||||
ConfigVariable (std::string str) : ConfigVariableBase (str), value (false) {}
|
|
||||||
ConfigVariable (std::string str, bool val) : ConfigVariableBase (str), value (val) {}
|
|
||||||
|
|
||||||
bool get() const {
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string get_as_string () const {
|
|
||||||
std::ostringstream ss;
|
|
||||||
ss << value;
|
|
||||||
return ss.str ();
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual bool set (bool val) {
|
|
||||||
if (val == value) {
|
|
||||||
miss ();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
value = val;
|
|
||||||
notify ();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void set_from_string (std::string const & s) {
|
|
||||||
value = PBD::string_is_affirmative (s);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected:
|
|
||||||
virtual bool get_for_save() { return value; }
|
|
||||||
bool value;
|
|
||||||
};
|
|
||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
class /*LIBPBD_API*/ ConfigVariableWithMutation : public ConfigVariable<T>
|
class /*LIBPBD_API*/ ConfigVariableWithMutation : public ConfigVariable<T>
|
||||||
{
|
{
|
||||||
|
|
@ -182,11 +135,7 @@ class /*LIBPBD_API*/ ConfigVariableWithMutation : public ConfigVariable<T>
|
||||||
}
|
}
|
||||||
|
|
||||||
void set_from_string (std::string const & s) {
|
void set_from_string (std::string const & s) {
|
||||||
T v;
|
set (string_to<T>(s));
|
||||||
std::stringstream ss;
|
|
||||||
ss << s;
|
|
||||||
ss >> v;
|
|
||||||
set (v);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue