edelib 1.0

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List

Resource.h
1 /*
2 * $Id: Resource.h 2839 2009-09-28 11:36:20Z karijes $
3 *
4 * Resource reader and writer
5 * Copyright (c) 2008-2009 edelib authors
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public License
18 * along with this library. If not, see <http://www.gnu.org/licenses/>.
19 */
20
21 #ifndef __EDELIB_RESOURCE_H__
22 #define __EDELIB_RESOURCE_H__
23
24 #include "String.h"
25
26 EDELIB_NS_BEGIN
27
32 enum ResourceType {
33 RES_SYS_FIRST,
34 RES_USER_FIRST,
35 RES_SYS_ONLY,
36 RES_USER_ONLY
37 };
38
39 class Config;
40
143 class EDELIB_API Resource {
144 private:
145 Config* sys_conf;
146 Config* user_conf;
147
148 E_DISABLE_CLASS_COPY(Resource)
149 public:
153 Resource();
154
158 ~Resource();
159
182 bool load(const char* domain, const char* prefix = "ede");
183
192 bool save(const char* domain, const char* prefix = "ede");
193
198 void clear(void);
199
209 operator bool(void) const { return (sys_conf != NULL || user_conf != NULL); }
210
221 bool get(const char* section, const char* key, char* ret, unsigned int size,
222 ResourceType rt = RES_USER_FIRST);
223
234 bool get_localized(const char* section, const char* key, char* ret, unsigned int size,
235 ResourceType rt = RES_USER_FIRST);
236
249 bool get_allocated(const char* section, const char* key, char** ret, unsigned int& retsize,
250 ResourceType rt = RES_USER_FIRST);
251
262 bool get(const char* section, const char* key, int& ret, int dfl = 0, ResourceType rt = RES_USER_FIRST);
263
274 bool get(const char* section, const char* key, bool& ret, bool dfl = false, ResourceType rt = RES_USER_FIRST);
275
286 bool get(const char* section, const char* key, float& ret, float dfl = 0, ResourceType rt = RES_USER_FIRST);
287
298 bool get(const char* section, const char* key, long& ret, long dfl = 0, ResourceType rt = RES_USER_FIRST);
299
310 bool get(const char* section, const char* key, double& ret, double dfl = 0, ResourceType rt = RES_USER_FIRST);
311
322 bool get(const char* section, const char* key, char& ret, char dfl = 0, ResourceType rt = RES_USER_FIRST);
323
332 void set(const char* section, const char* key, char* val);
333
342 void set(const char* section, const char* key, const char* val);
343
352 void set_localized(const char* section, const char* key, char* val);
353
362 void set_localized(const char* section, const char* key, const char* val);
363
372 void set(const char* section, const char* key, bool val);
373
382 void set(const char* section, const char* key, int val);
383
392 void set(const char* section, const char* key, long val);
393
402 void set(const char* section, const char* key, float val);
403
412 void set(const char* section, const char* key, double val);
413
430 static String find_config(const char* name, ResourceType rt = RES_USER_FIRST, const char* prefix = "ede");
431
442 static String find_in_config_dir(const char* name, ResourceType rt = RES_USER_FIRST, const char* prefix = "ede");
443
453 static String find_data(const char* name, ResourceType rt = RES_USER_FIRST, const char* prefix = "ede");
454 };
455
456 EDELIB_NS_END
457 #endif