summaryrefslogtreecommitdiff
path: root/libs/pbd/enumwriter.cc
diff options
context:
space:
mode:
authorPaul Davis <paul@linuxaudiosystems.com>2007-01-02 17:36:38 +0000
committerPaul Davis <paul@linuxaudiosystems.com>2007-01-02 17:36:38 +0000
commit8fabcf4f760e68e10573efc0ef1da9d6d8453885 (patch)
treee7362b6dbb266b639c5e4855bd9eadf522d58911 /libs/pbd/enumwriter.cc
parentb529cbc5dc0b92f01ff01d5f40786ff025fbb63b (diff)
finish use of EnumWriter for saving flags etc. throughout the session file
git-svn-id: svn://localhost/ardour2/trunk@1259 d708f5d6-7413-0410-9779-e7cbd77b26cf
Diffstat (limited to 'libs/pbd/enumwriter.cc')
-rw-r--r--libs/pbd/enumwriter.cc71
1 files changed, 68 insertions, 3 deletions
diff --git a/libs/pbd/enumwriter.cc b/libs/pbd/enumwriter.cc
index d6c882e00a..7674410ec9 100644
--- a/libs/pbd/enumwriter.cc
+++ b/libs/pbd/enumwriter.cc
@@ -18,6 +18,9 @@
$Id$
*/
+#include <ctype.h>
+
+#include <string.h>
#include <stdlib.h>
#include <pbd/enumwriter.h>
@@ -30,6 +33,35 @@ using namespace PBD;
#include "i18n.h"
EnumWriter* EnumWriter::_instance = 0;
+map<string,string> EnumWriter::hack_table;
+
+static int
+nocase_cmp(const string & s1, const string& s2)
+{
+ string::const_iterator it1 = s1.begin();
+ string::const_iterator it2 = s2.begin();
+
+ while ((it1 != s1.end()) && (it2 != s2.end())) {
+ if(::toupper(*it1) != ::toupper(*it2)) {//letters differ?
+ // return -1 to indicate 'smaller than', 1 otherwise
+ return (::toupper(*it1) < ::toupper(*it2)) ? -1 : 1;
+ }
+
+ ++it1;
+ ++it2;
+ }
+
+ string::size_type size1 = s1.size();
+ string::size_type size2 = s2.size();
+
+ //return -1,0 or 1 according to strings' lengths
+
+ if (size1 == size2) {
+ return 0;
+ }
+
+ return (size1 < size2) ? -1 : 1;
+}
EnumWriter::EnumWriter ()
{
@@ -157,13 +189,19 @@ EnumWriter::read_bits (EnumRegistration& er, string str)
return strtol (str.c_str(), (char **) 0, 16);
}
+ /* catch old style dec numerics */
+
+ if (strspn (str.c_str(), "0123456789") == str.length()) {
+ return strtol (str.c_str(), (char **) 0, 10);
+ }
+
do {
comma = str.find_first_of (',');
string segment = str.substr (0, comma);
for (i = er.values.begin(), s = er.names.begin(); i != er.values.end(); ++i, ++s) {
- if (segment == (*s)) {
+ if (segment == *s || nocase_cmp (segment, *s) == 0) {
result |= (*i);
found = true;
}
@@ -196,13 +234,40 @@ EnumWriter::read_distinct (EnumRegistration& er, string str)
return strtol (str.c_str(), (char **) 0, 16);
}
+ /* catch old style dec numerics */
+
+ if (strspn (str.c_str(), "0123456789") == str.length()) {
+ return strtol (str.c_str(), (char **) 0, 10);
+ }
+
for (i = er.values.begin(), s = er.names.begin(); i != er.values.end(); ++i, ++s) {
- if (str == (*s)) {
+ if (str == (*s) || nocase_cmp (str, *s) == 0) {
return (*i);
}
}
+ /* failed to find it as-is. check to see if there a hack for the name we're looking up */
+
+ map<string,string>::iterator x;
+
+ if ((x = hack_table.find (str)) != hack_table.end()) {
+
+ cerr << "found hack for " << str << " = " << x->second << endl;
+
+ str = x->second;
+
+ for (i = er.values.begin(), s = er.names.begin(); i != er.values.end(); ++i, ++s) {
+ if (str == (*s) || nocase_cmp (str, *s) == 0) {
+ return (*i);
+ }
+ }
+ }
+
throw unknown_enumeration();
}
-
+void
+EnumWriter::add_to_hack_table (string str, string hacked)
+{
+ hack_table[str] = hacked;
+}