IniFile Read Write

#include <boost/shared_ptr.hpp>
#include <QSettings>
class IniFile
{
public:
	explicit IniFile(const char * path):m_path(path){}
	~IniFile(){};
	QString GetPath() const {return m_path;}
	void SetPath(const char * path) {if(m_path != path) m_path = path;}
	QString GetValue(const char * key)
	{
		if(key == NULL)
		{
			return QString();
		}
		if(m_pSetting == NULL)
		{
			// create setting failed
			if(CreateSetting() != 0)
			{
				return QString();
			}
		}
		return m_pSetting->value(key).toString();
	}
	int SetValue(const char *  key, const char *  value)
	{
		if(key == NULL)
		{
			return  -1;
		}
		
		if(m_pSetting == NULL)
		{
			if(CreateSetting() != 0)
			{
				return -1;
			}
		}
		m_pSetting->setValue(key, value);
		return 0;
	}
	int Remove(const char * key)
	{
		if(key == NULL) 
		{
			return -1;
		}
		if(m_pSetting == NULL)
		{
			// create setting failed
			if(CreateSetting() != 0)
			{
				return -1;
			}
		}
		this->m_pSetting->remove(key);
		return 0;
	}
protected:
	int CreateSetting()
	{
		if(m_path == NULL)
		{
			return -1;
		}
		m_pSetting.reset(new QSettings(m_path, QSettings::IniFormat));
		return 0;
	}
private:
	const char * m_path;
	boost::shared_ptr<QSettings> m_pSetting;
};

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值