blob: 4e706d2bc1227fa7520eda526457143ed7934e7e (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
|
#ifdef _MSC_VER
#pragma warning(disable : 4786)
#endif
#ifdef WIN32
#include <windows.h>
#endif
#include <ctype.h>
#include "utility.h"
#include "threads.h"
#include "internal.h"
namespace audiere {
ParameterList::ParameterList(const char* parameters) {
std::string key;
std::string value;
std::string* current_string = &key;
// walk the string and generate the parameter list
const char* p = parameters;
while (*p) {
if (*p == '=') {
current_string = &value;
} else if (*p == ',') {
if (key.length() && value.length()) {
m_values[key] = value;
}
key = "";
value = "";
current_string = &key;
} else {
*current_string += *p;
}
++p;
}
// is there one more parameter without a trailing comma?
if (key.length() && value.length()) {
m_values[key] = value;
}
}
std::string
ParameterList::getValue(
const std::string& key,
const std::string& defaultValue) const
{
std::map<std::string, std::string>::const_iterator i = m_values.find(key);
return (i == m_values.end() ? defaultValue : i->second);
}
bool
ParameterList::getBoolean(const std::string& key, bool def) const {
std::string value = getValue(key, (def ? "true" : "false"));
return (value == "true" || atoi(value.c_str()) != 0);
}
int
ParameterList::getInt(const std::string& key, int def) const {
char str[20];
sprintf(str, "%d", def);
return atoi(getValue(key, str).c_str());
}
int strcmp_case(const char* a, const char* b) {
while (*a && *b) {
char c = tolower(*a++);
char d = tolower(*b++);
if (c != d) {
return c - d;
}
}
char c = tolower(*a);
char d = tolower(*b);
return (c - d);
}
#ifdef WIN32
ADR_EXPORT(long) AdrAtomicIncrement(volatile long& var) {
return InterlockedIncrement(&var);
}
ADR_EXPORT(long) AdrAtomicDecrement(volatile long& var) {
return InterlockedDecrement(&var);
}
#else
static Mutex atomicMutex;
ADR_EXPORT(long) AdrAtomicIncrement(volatile long& var) {
SYNCHRONIZED(atomicMutex);
return ++var;
}
ADR_EXPORT(long) AdrAtomicDecrement(volatile long& var) {
SYNCHRONIZED(atomicMutex);
return --var;
}
#endif
ADR_EXPORT(int) AdrGetSampleSize(SampleFormat format) {
switch (format) {
case SF_U8: return 1;
case SF_S16: return 2;
default: return 0;
}
}
}
|