Debian Codegraph @

android/app/jni/extern/SAASound/src/minIni/minIni.h

raw
1 /* minIni - Multi-Platform INI file parser, suitable for embedded systems
2 *
3 * Copyright (c) CompuPhase, 2008-2017
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
6 * use this file except in compliance with the License. You may obtain a copy
7 * of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14 * License for the specific language governing permissions and limitations
15 * under the License.
16 *
17 * Version: $Id: minIni.h 53 2015-01-18 13:35:11Z [email protected] $
18 */
19 #ifndef MININI_H
20 #define MININI_H
21
22 #include "minGlue.h"
23
24
25 #if (defined _UNICODE || defined __UNICODE__ || defined UNICODE) && !defined INI_ANSIONLY
26 #if !defined UNICODE /* for Windows */
27 #define UNICODE
28 #endif
29 #if !defined _UNICODE /* for C library */
30 #define _UNICODE
31 #endif
32 #endif
33
34 #if defined UNICODE
35 #include <tchar.h>
36 #define t_string std::wstring
37 #else
38 #define TCHAR char
39 #define t_string std::string
40 #define _tfopen fopen
41 #define _tremove remove
42 #define _trename rename
43 #endif
44
45 #if !defined __T
46 #define __T(s) s
47 #endif
48
49 #if !defined _T
50 #define _T(s) __T(s)
51 #endif
52
53 #if defined INI_ANSIONLY
54 #include <ctype.h>
55 #include <string.h>
56 #include <stdlib.h>
57 #define mTCHAR char
58 #define _mT(s) s
59 #define mString std::string
60 #define _mtcscat strcat
61 #define _mtcschr strchr
62 #define _mtcscmp strcmp
63 #define _mtcscpy strcpy
64 #define _mtcsicmp stricmp
65 #define _mtcslen strlen
66 #define _mtcsncmp strncmp
67 #define _mtcsnicmp strnicmp
68 #define _mtcsrchr strrchr
69 #define _mtcstol strtol
70 #define _mtcstod strtod
71 #define _mtotupper toupper
72 #define _mstprintf sprintf
73 #define _mtfgets fgets
74 #define _mtfputs fputs
75 #define _mtfopen fopen
76 #define _mtremove remove
77 #define _mtrename rename
78 #else
79 #define mTCHAR TCHAR
80 #define _mT(s) __T(s)
81 #define mString t_string
82 #define _mtcscat _tcscat
83 #define _mtcschr _tcschr
84 #define _mtcscmp _tcscmp
85 #define _mtcscpy _tcscpy
86 #define _mtcsicmp _tcsicmp
87 #define _mtcslen _tcslen
88 #define _mtcsncmp _tcsncmp
89 #define _mtcsnicmp _tcsnicmp
90 #define _mtcsrchr _tcsrchr
91 #define _mtcstol _tcstol
92 #define _mtcstod _tcstod
93 #define _mtotupper _totupper
94 #define _mstprintf _stprintf
95 #define _mtfgets _tfgets
96 #define _mtfputs _tfputs
97 #define _mtfopen _tfopen
98 #define _mtremove _tremove
99 #define _mtrename _trename
100 #endif
101
102
103 #if !defined INI_BUFFERSIZE
104 #define INI_BUFFERSIZE 512
105 #endif
106
107 #if defined __cplusplus
108 extern "C" {
109 #endif
110
111 int ini_getbool(const mTCHAR *Section, const mTCHAR *Key, int DefValue, const TCHAR *Filename);
112 long ini_getl(const mTCHAR *Section, const mTCHAR *Key, long DefValue, const TCHAR *Filename);
113 int ini_gets(const mTCHAR *Section, const mTCHAR *Key, const mTCHAR *DefValue, mTCHAR *Buffer, int BufferSize, const TCHAR *Filename);
114 int ini_getsection(int idx, mTCHAR *Buffer, int BufferSize, const TCHAR *Filename);
115 int ini_getkey(const mTCHAR *Section, int idx, mTCHAR *Buffer, int BufferSize, const TCHAR *Filename);
116
117 #if defined INI_REAL
118 INI_REAL ini_getf(const mTCHAR *Section, const mTCHAR *Key, INI_REAL DefValue, const TCHAR *Filename);
119 #endif
120
121 #if !defined INI_READONLY
122 int ini_putl(const mTCHAR *Section, const mTCHAR *Key, long Value, const TCHAR *Filename);
123 int ini_puts(const mTCHAR *Section, const mTCHAR *Key, const mTCHAR *Value, const TCHAR *Filename);
124 #if defined INI_REAL
125 int ini_putf(const mTCHAR *Section, const mTCHAR *Key, INI_REAL Value, const TCHAR *Filename);
126 #endif
127 #endif /* INI_READONLY */
128
129 #if !defined INI_NOBROWSE
130 typedef int (*INI_CALLBACK)(const mTCHAR *Section, const mTCHAR *Key, const mTCHAR *Value, void *UserData);
131 int ini_browse(INI_CALLBACK Callback, void *UserData, const TCHAR *Filename);
132 #endif /* INI_NOBROWSE */
133
134 #if defined __cplusplus
135 }
136 #endif
137
138
139 #if defined __cplusplus
140
141 #if defined __WXWINDOWS__
142 #include "wxMinIni.h"
143 #else
144 #include <string>
145
146 /* The C++ class in minIni.h was contributed by Steven Van Ingelgem. */
147 class minIni
148 {
149 public:
150 minIni(const t_string& filename) : iniFilename(filename)
151 { }
152
153 bool getbool(const mString& Section, const mString& Key, bool DefValue=false) const
154 { return ini_getbool(Section.c_str(), Key.c_str(), int(DefValue), iniFilename.c_str()) != 0; }
155
156 long getl(const mString& Section, const mString& Key, long DefValue=0) const
157 { return ini_getl(Section.c_str(), Key.c_str(), DefValue, iniFilename.c_str()); }
158
159 int geti(const mString& Section, const mString& Key, int DefValue=0) const
160 { return static_cast<int>(this->getl(Section, Key, long(DefValue))); }
161
162 mString gets(const mString& Section, const mString& Key, const mString& DefValue=_mT("")) const
163 {
164 mTCHAR buffer[INI_BUFFERSIZE];
165 ini_gets(Section.c_str(), Key.c_str(), DefValue.c_str(), buffer, INI_BUFFERSIZE, iniFilename.c_str());
166 return buffer;
167 }
168
169 mString getsection(int idx) const
170 {
171 mTCHAR buffer[INI_BUFFERSIZE];
172 ini_getsection(idx, buffer, INI_BUFFERSIZE, iniFilename.c_str());
173 return buffer;
174 }
175
176 mString getkey(const mString& Section, int idx) const
177 {
178 mTCHAR buffer[INI_BUFFERSIZE];
179 ini_getkey(Section.c_str(), idx, buffer, INI_BUFFERSIZE, iniFilename.c_str());
180 return buffer;
181 }
182
183 #if defined INI_REAL
184 INI_REAL getf(const mString& Section, const mString& Key, INI_REAL DefValue=0) const
185 { return ini_getf(Section.c_str(), Key.c_str(), DefValue, iniFilename.c_str()); }
186 #endif
187
188 #if ! defined INI_READONLY
189 bool put(const mString& Section, const mString& Key, long Value)
190 { return ini_putl(Section.c_str(), Key.c_str(), Value, iniFilename.c_str()) != 0; }
191
192 bool put(const mString& Section, const mString& Key, int Value)
193 { return ini_putl(Section.c_str(), Key.c_str(), (long)Value, iniFilename.c_str()) != 0; }
194
195 bool put(const mString& Section, const mString& Key, bool Value)
196 { return ini_putl(Section.c_str(), Key.c_str(), (long)Value, iniFilename.c_str()) != 0; }
197
198 bool put(const mString& Section, const mString& Key, const mString& Value)
199 { return ini_puts(Section.c_str(), Key.c_str(), Value.c_str(), iniFilename.c_str()) != 0; }
200
201 bool put(const mString& Section, const mString& Key, const mTCHAR* Value)
202 { return ini_puts(Section.c_str(), Key.c_str(), Value, iniFilename.c_str()) != 0; }
203
204 #if defined INI_REAL
205 bool put(const mString& Section, const mString& Key, INI_REAL Value)
206 { return ini_putf(Section.c_str(), Key.c_str(), Value, iniFilename.c_str()) != 0; }
207 #endif
208
209 bool del(const mString& Section, const mString& Key)
210 { return ini_puts(Section.c_str(), Key.c_str(), 0, iniFilename.c_str()) != 0; }
211
212 bool del(const mString& Section)
213 { return ini_puts(Section.c_str(), 0, 0, iniFilename.c_str()) != 0; }
214 #endif
215
216 #if !defined INI_NOBROWSE
217 bool browse(INI_CALLBACK Callback, void *UserData) const
218 { return ini_browse(Callback, UserData, iniFilename.c_str()) != 0; }
219 #endif
220
221 private:
222 t_string iniFilename;
223 };
224
225 #endif /* __WXWINDOWS__ */
226 #endif /* __cplusplus */
227
228 #endif /* MININI_H */