edelib  2.0.0
edelib/Resource.h
00001 /*
00002  * $Id: Resource.h 2839 2009-09-28 11:36:20Z karijes $
00003  *
00004  * Resource reader and writer
00005  * Copyright (c) 2008-2009 edelib authors
00006  *
00007  * This library is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU Lesser General Public
00009  * License as published by the Free Software Foundation; either
00010  * version 2 of the License, or (at your option) any later version.
00011  *
00012  * This library is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
00015  * Lesser General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU Lesser General Public License
00018  * along with this library. If not, see <http://www.gnu.org/licenses/>.
00019  */
00020 
00021 #ifndef __EDELIB_RESOURCE_H__
00022 #define __EDELIB_RESOURCE_H__
00023 
00024 #include "String.h"
00025 
00026 EDELIB_NS_BEGIN
00027 
00032 enum ResourceType {
00033         RES_SYS_FIRST,   
00034         RES_USER_FIRST,  
00035         RES_SYS_ONLY,    
00036         RES_USER_ONLY    
00037 };
00038 
00039 class Config;
00040 
00143 class EDELIB_API Resource {
00144 private:
00145         Config* sys_conf;
00146         Config* user_conf;
00147 
00148         E_DISABLE_CLASS_COPY(Resource)
00149 public:
00153         Resource();
00154 
00158         ~Resource();
00159 
00182         bool load(const char* domain, const char* prefix = "ede");
00183 
00192         bool save(const char* domain, const char* prefix = "ede");
00193 
00198         void clear(void);
00199 
00209         operator bool(void) const   { return (sys_conf != NULL || user_conf != NULL); }
00210 
00221         bool get(const char* section, const char* key, char* ret, unsigned int size, 
00222                         ResourceType rt = RES_USER_FIRST);
00223 
00234         bool get_localized(const char* section, const char* key, char* ret, unsigned int size, 
00235                         ResourceType rt = RES_USER_FIRST);
00236 
00249         bool get_allocated(const char* section, const char* key, char** ret, unsigned int& retsize, 
00250                         ResourceType rt = RES_USER_FIRST);
00251 
00262         bool get(const char* section, const char* key, int& ret, int dfl = 0, ResourceType rt = RES_USER_FIRST);
00263 
00274         bool get(const char* section, const char* key, bool& ret, bool dfl = false, ResourceType rt = RES_USER_FIRST);
00275 
00286         bool get(const char* section, const char* key, float& ret, float dfl = 0, ResourceType rt = RES_USER_FIRST);
00287 
00298         bool get(const char* section, const char* key, long& ret, long dfl = 0, ResourceType rt = RES_USER_FIRST);
00299 
00310         bool get(const char* section, const char* key, double& ret, double dfl = 0, ResourceType rt = RES_USER_FIRST);
00311 
00322         bool get(const char* section, const char* key, char& ret, char dfl = 0, ResourceType rt = RES_USER_FIRST);
00323 
00332         void set(const char* section, const char* key, char* val);
00333 
00342         void set(const char* section, const char* key, const char* val);
00343 
00352         void set_localized(const char* section, const char* key, char* val);
00353 
00362         void set_localized(const char* section, const char* key, const char* val);
00363 
00372         void set(const char* section, const char* key, bool val);
00373 
00382         void set(const char* section, const char* key, int val);
00383 
00392         void set(const char* section, const char* key, long val);
00393 
00402         void set(const char* section, const char* key, float val);
00403 
00412         void set(const char* section, const char* key, double val);
00413 
00430         static String find_config(const char* name, ResourceType rt = RES_USER_FIRST, const char* prefix = "ede");
00431 
00442         static String find_in_config_dir(const char* name, ResourceType rt = RES_USER_FIRST, const char* prefix = "ede");
00443         
00453         static String find_data(const char* name, ResourceType rt = RES_USER_FIRST, const char* prefix = "ede");
00454 };
00455 
00456 EDELIB_NS_END
00457 #endif