utility.cpp

Go to the documentation of this file.
00001 #ifdef _MSC_VER
00002 #pragma warning(disable : 4786)
00003 #endif
00004 
00005 
00006 #include <ctype.h>
00007 #include "utility.h"
00008 #include "internal.h"
00009 
00010 
00011 namespace audiere {
00012 
00013   ParameterList::ParameterList(const char* parameters) {
00014     std::string key;
00015     std::string value;
00016 
00017     std::string* current_string = &key;
00018 
00019     // walk the string and generate the parameter list
00020     const char* p = parameters;
00021     while (*p) {
00022 
00023       if (*p == '=') {
00024 
00025         current_string = &value;
00026 
00027       } else if (*p == ',') {
00028 
00029         if (key.length() && value.length()) {
00030           m_values[key] = value;
00031         }
00032         key   = "";
00033         value = "";
00034         current_string = &key;
00035 
00036       } else {
00037         *current_string += *p;
00038       }
00039 
00040       ++p;
00041     }
00042 
00043     // is there one more parameter without a trailing comma?
00044     if (key.length() && value.length()) {
00045       m_values[key] = value;
00046     }
00047   }
00048 
00049   std::string
00050   ParameterList::getValue(
00051     const std::string& key,
00052     const std::string& defaultValue) const
00053   {
00054     std::map<std::string, std::string>::const_iterator i = m_values.find(key);
00055     return (i == m_values.end() ? defaultValue : i->second);
00056   }
00057 
00058   bool
00059   ParameterList::getBoolean(const std::string& key, bool def) const {
00060     std::string value = getValue(key, (def ? "true" : "false"));
00061     return (value == "true" || atoi(value.c_str()) != 0);
00062   }
00063 
00064   int
00065   ParameterList::getInt(const std::string& key, int def) const {
00066     char str[20];
00067     sprintf(str, "%d", def);
00068     return atoi(getValue(key, str).c_str());
00069   }
00070 
00071 
00072   int strcmp_case(const char* a, const char* b) {
00073     while (*a && *b) {
00074 
00075       char c = tolower(*a++);
00076       char d = tolower(*b++);
00077 
00078       if (c != d) {
00079         return c - d;
00080       }
00081     }
00082   
00083     char c = tolower(*a);
00084     char d = tolower(*b);
00085     return (c - d);
00086   }
00087 
00088 
00089   ADR_EXPORT(int) AdrGetSampleSize(SampleFormat format) {
00090     switch (format) {
00091       case SF_U8:  return 1;
00092       case SF_S16: return 2;
00093       default:     return 0;
00094     }
00095   }
00096 
00097 }

Generated on Mon Feb 13 23:07:47 2006 for audiere by  doxygen 1.4.6