Resource.h
/*
* $Id: Resource.h 2839 2009-09-28 11:36:20Z karijes $
*
* Resource reader and writer
* Copyright (c) 2008-2009 edelib authors
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __EDELIB_RESOURCE_H__
#define __EDELIB_RESOURCE_H__
#include "String.h"
EDELIB_NS_BEGIN
enum ResourceType {
RES_SYS_FIRST,
RES_USER_FIRST,
RES_SYS_ONLY,
RES_USER_ONLY
};
class Config;
class EDELIB_API Resource {
private:
Config* sys_conf;
Config* user_conf;
E_DISABLE_CLASS_COPY(Resource)
public:
Resource();
~Resource();
bool load(const char* domain, const char* prefix = "ede");
bool save(const char* domain, const char* prefix = "ede");
void clear(void);
operator bool(void) const { return (sys_conf != NULL || user_conf != NULL); }
bool get(const char* section, const char* key, char* ret, unsigned int size,
ResourceType rt = RES_USER_FIRST);
bool get_localized(const char* section, const char* key, char* ret, unsigned int size,
ResourceType rt = RES_USER_FIRST);
bool get_allocated(const char* section, const char* key, char** ret, unsigned int& retsize,
ResourceType rt = RES_USER_FIRST);
bool get(const char* section, const char* key, int& ret, int dfl = 0, ResourceType rt = RES_USER_FIRST);
bool get(const char* section, const char* key, bool& ret, bool dfl = false, ResourceType rt = RES_USER_FIRST);
bool get(const char* section, const char* key, float& ret, float dfl = 0, ResourceType rt = RES_USER_FIRST);
bool get(const char* section, const char* key, long& ret, long dfl = 0, ResourceType rt = RES_USER_FIRST);
bool get(const char* section, const char* key, double& ret, double dfl = 0, ResourceType rt = RES_USER_FIRST);
bool get(const char* section, const char* key, char& ret, char dfl = 0, ResourceType rt = RES_USER_FIRST);
void set(const char* section, const char* key, char* val);
void set(const char* section, const char* key, const char* val);
void set_localized(const char* section, const char* key, char* val);
void set_localized(const char* section, const char* key, const char* val);
void set(const char* section, const char* key, bool val);
void set(const char* section, const char* key, int val);
void set(const char* section, const char* key, long val);
void set(const char* section, const char* key, float val);
void set(const char* section, const char* key, double val);
static String find_config(const char* name, ResourceType rt = RES_USER_FIRST, const char* prefix = "ede");
static String find_in_config_dir(const char* name, ResourceType rt = RES_USER_FIRST, const char* prefix = "ede");
static String find_data(const char* name, ResourceType rt = RES_USER_FIRST, const char* prefix = "ede");
};
EDELIB_NS_END
#endif
edelib::Config
A config file reader.
Definition: Config.h:112
edelib::RES_SYS_FIRST
Load system resource first.
Definition: Resource.h:33
edelib::ResourceType
ResourceType
Flags showing what resource to load first or to load it only.
Definition: Resource.h:32
edelib::Resource
Resource loader and saver.
Definition: Resource.h:143
edelib::RES_SYS_ONLY
Load system resource ignoring user one.
Definition: Resource.h:35
edelib::RES_USER_ONLY
Load user resource ignoring system one.
Definition: Resource.h:36
E_DISABLE_CLASS_COPY
#define E_DISABLE_CLASS_COPY(klass)
Definition: edelib-global.h:161
edelib::String
A (relatively simple) string implementation.
Definition: String.h:82
edelib::RES_USER_FIRST
Load user resource first.
Definition: Resource.h:34