📄 properties.h
字号:
/**
* 配置文件类
* @file Properties.h
* @date 2006年11月2日
* @author 周志武
* @version 1.0.0: 初始版本
**/
#ifndef _PROPERTIES_H_
#define _PROPERTIES_H_
#include <string>
#include "nlkit/AssocVector.h"
namespace nlkit
{
/**
* 配置文件类
*/
class Properties
{
public :
/**
* 构造函数
* @param 无
*/
Properties() {};
/**
* 构造函数
* @param fileName 配置文件名
*/
Properties(const std::string& fileName);
/**
* 构造函数
* @param fileName 配置文件名
*/
Properties(const char* fileName);
/**
* 析构函数
* @param 无
*/
~Properties();
/**
* 取字符属性的配置项
* @param profertyName 配置项名称
* @return 配置项值
*/
std::string getString(const std::string& profertyName) const;
/**
*
* @param profertyName
* @param defaultValue
* @return
*/
std::string getString(const std::string& profertyName, const std::string& defaultValue) const ;
/**
*
* @param profertyName
* @return
*/
int getInt(const std::string& profertyName) const;
/**
*
* @param profertyName
* @param defaultValue
* @return
*/
int getInt(const std::string& profertyName, int defaultValue) const;
/**
*
* @param profertyName
* @return
*/
bool getBool(const std::string& profertyName) const;
/**
*
* @param profertyName
* @param defaultValue
* @return
*/
bool getBool(const std::string& profertyName, bool defaultValue) const;
/**
*
* @param profertyName
* @param value
* @return
*/
void setString(const std::string& profertyName, const std::string& value);
/**
*
* @param profertyName
* @param value
* @return
*/
void setInt(const std::string& profertyName, int value);
/**
*
* @param profertyName
* @param value
* @return
*/
void setBool(const std::string& profertyName, bool value);
/**
*
* @param fileName
* @return
*/
void fromFile(const char* fileName);
/**
*
* @param fileName
* @return
*/
void fromFile(const std::string& fileName);
/**
*
* @param 无
* @return
*/
void reset();
typedef AssocVector<std::string, std::string> stor_t;
stor_t::iterator begin() { return m_ProferiesMap.begin(); }
stor_t::const_iterator begin() const { return m_ProferiesMap.begin(); }
stor_t::iterator end() { return m_ProferiesMap.end(); }
stor_t::const_iterator end() const { return m_ProferiesMap.end(); }
private :
enum {IS_NORMAL, IS_COMMENT, IS_INCLUDE, IS_GROUP, IS_BAD};
typedef AssocVector<std::string, std::string>::const_iterator storIter_t;
stor_t m_ProferiesMap;
std::string m_name, m_value;
std::string m_prefix;
bool getString(const std::string& profertyName, std::string& value) const;
int parserLine(char* lineStr);
void parserValue(std::string& m_value);
char *strim(char *str);
void regularization(const std::string& pathName, std::string& name);
std::string baseDir(const std::string& fileName);
};
}
#endif //_PROPERTIES_H_
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -