summaryrefslogtreecommitdiff
path: root/libs/pbd/enumwriter.cc
diff options
context:
space:
mode:
authorPaul Davis <paul@linuxaudiosystems.com>2010-09-22 15:21:06 +0000
committerPaul Davis <paul@linuxaudiosystems.com>2010-09-22 15:21:06 +0000
commitded4a143db069785aa33eeb6dc9da02770e3ae8e (patch)
treed1a2b94e11a4fe4a1d173e7972414cc16ecee7fd /libs/pbd/enumwriter.cc
parentd4aaa9c10cd21ef7e1b0f5509963b57c2465302b (diff)
much craziness with canvas cursors; fix 0 beat cursor text when shortening notes; fix crash when trimming locked regions; don't show trim cursors when region is locked; partial version of enumwriter validation fix from 2.X (less necessary with 3.0; probably more ...
git-svn-id: svn://localhost/ardour2/branches/3.0@7831 d708f5d6-7413-0410-9779-e7cbd77b26cf
Diffstat (limited to 'libs/pbd/enumwriter.cc')
-rw-r--r--libs/pbd/enumwriter.cc51
1 files changed, 45 insertions, 6 deletions
diff --git a/libs/pbd/enumwriter.cc b/libs/pbd/enumwriter.cc
index 2c6e5c73c8..5263a886fb 100644
--- a/libs/pbd/enumwriter.cc
+++ b/libs/pbd/enumwriter.cc
@@ -182,6 +182,41 @@ EnumWriter::write_distinct (EnumRegistration& er, int value)
}
int
+EnumWriter::validate (EnumRegistration& er, int val)
+{
+ if (er.values.empty()) {
+ return val;
+ }
+
+ if (val == 0) {
+ /* zero is always a legal value for our enumerations, just about
+ */
+ return val;
+ }
+
+ vector<int>::iterator i;
+ string enum_name = _("unknown enumeration");
+
+ for (Registry::iterator x = registry.begin(); x != registry.end(); ++x) {
+ if (&er == &(*x).second) {
+ enum_name = (*x).first;
+ }
+ }
+
+
+ for (i = er.values.begin(); i != er.values.end(); ++i) {
+ if (*i == val) {
+ return val;
+ }
+ }
+
+ warning << string_compose (_("Illegal value loaded for %1 (%2) - %3 used instead"),
+ enum_name, val, er.names.front())
+ << endmsg;
+ return er.values.front();
+}
+
+int
EnumWriter::read_bits (EnumRegistration& er, string str)
{
vector<int>::iterator i;
@@ -193,14 +228,16 @@ EnumWriter::read_bits (EnumRegistration& er, string str)
/* catch old-style hex numerics */
if (str.length() > 2 && str[0] == '0' && str[1] == 'x') {
- return strtol (str.c_str(), (char **) 0, 16);
+ int val = strtol (str.c_str(), (char **) 0, 16);
+ return validate (er, val);
}
/* catch old style dec numerics */
if (strspn (str.c_str(), "0123456789") == str.length()) {
- return strtol (str.c_str(), (char **) 0, 10);
- }
+ int val = strtol (str.c_str(), (char **) 0, 10);
+ return validate (er, val);
+ }
do {
@@ -238,14 +275,16 @@ EnumWriter::read_distinct (EnumRegistration& er, string str)
/* catch old-style hex numerics */
if (str.length() > 2 && str[0] == '0' && str[1] == 'x') {
- return strtol (str.c_str(), (char **) 0, 16);
+ int val = strtol (str.c_str(), (char **) 0, 16);
+ return validate (er, val);
}
/* catch old style dec numerics */
if (strspn (str.c_str(), "0123456789") == str.length()) {
- return strtol (str.c_str(), (char **) 0, 10);
- }
+ int val = strtol (str.c_str(), (char **) 0, 10);
+ return validate (er, val);
+ }
for (i = er.values.begin(), s = er.names.begin(); i != er.values.end(); ++i, ++s) {
if (str == (*s) || nocase_cmp (str, *s) == 0) {