13
0

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:
Tim Mayberry 2016-08-24 22:32:51 +10:00
parent cb3c564822
commit 2b58bbd50a
6 changed files with 8 additions and 63 deletions

View File

@ -49,6 +49,7 @@
#include "ardour/search_paths.h"
#include "ardour/revision.h"
#include "ardour/utils.h"
#include "ardour/types_convert.h"
#include "gtkmm2ext/rgb_macros.h"
#include "gtkmm2ext/gtk_ui.h"

View File

@ -35,6 +35,7 @@
#include "ardour/port.h"
#include "ardour/rc_configuration.h"
#include "ardour/session_metadata.h"
#include "ardour/types_convert.h"
#include "pbd/i18n.h"

View File

@ -104,6 +104,7 @@
#include "ardour/tempo.h"
#include "ardour/ticker.h"
#include "ardour/track.h"
#include "ardour/types_convert.h"
#include "ardour/user_bundle.h"
#include "ardour/utils.h"
#include "ardour/vca_manager.h"

View File

@ -27,6 +27,7 @@
#include "pbd/pathexpand.h"
#include "ardour/types.h"
#include "ardour/types_convert.h"
#include "ardour/filesystem_paths.h"
#include "ardour/session_configuration.h"
#include "ardour/utils.h"

View File

@ -111,11 +111,3 @@ ConfigVariableBase::miss ()
// placeholder for any debugging desired when a config variable
// 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);
}

View File

@ -20,12 +20,10 @@
#ifndef __libpbd_configuration_variable_h__
#define __libpbd_configuration_variable_h__
#include <iostream>
#include <sstream>
#include <string>
#include "pbd/xml++.h"
#include "pbd/convert.h"
#include "pbd/string_convert.h"
#include "pbd/libpbd_visibility.h"
namespace PBD {
@ -63,9 +61,7 @@ class /*LIBPBD_API*/ ConfigVariable : public ConfigVariableBase
}
std::string get_as_string () const {
std::ostringstream ss;
ss << value;
return ss.str ();
return to_string<T>(value);
}
virtual bool set (T val) {
@ -79,9 +75,7 @@ class /*LIBPBD_API*/ ConfigVariable : public ConfigVariableBase
}
virtual void set_from_string (std::string const & s) {
std::stringstream ss;
ss << s;
ss >> value;
value = string_to<T>(s);
}
protected:
@ -89,10 +83,6 @@ class /*LIBPBD_API*/ ConfigVariable : public ConfigVariableBase
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 */
template<>
class /*LIBPBD_API*/ ConfigVariable<std::string> : public ConfigVariableBase
@ -129,43 +119,6 @@ class /*LIBPBD_API*/ ConfigVariable<std::string> : public ConfigVariableBase
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>
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) {
T v;
std::stringstream ss;
ss << s;
ss >> v;
set (v);
set (string_to<T>(s));
}
protected: