在yate中涉及到配置文件的读取,参数获取的一个类Configuration ,头文件里面关于这个类的定义:
/**
* A class for parsing and quickly accessing INI style configuration files
* @short Configuration file handling
*一个类用于解析和快速访问INI配置文件风格
*@小的配置文件处理
*/
class YATE_API Configuration : public String
{
YNOCOPY(Configuration); // no automatic copies please
public:
/**
* Create an empty configuration
* 构造函数,创建一个空的对象
*/
Configuration();
/**
* Create a configuration from a file
* 构造函数,创建一个从文件读取的对象
* @param filename Name of file to initialize from
* @参数filename,初始化的文件名
* @param warn True to warn if the configuration could not be loaded
* @参数warn,如果对象不能被加载,warn为true
*/
explicit Configuration(const char* filename, bool warn = true);
/**
* Assignment from string operator
* 赋值运算符重载,字符串运算符
*/
inline Configuration& operator=(const String& value)
{ String::operator=(value); return *this; }
/**
* Get the number of sections
* 获得setctions的数量
* @return Count of sections
* @返回sections的数量
*/
inline unsigned int sections() const
{ return m_sections.length(); }
/**
* Get the number of non null sections
* 获得不为空的sections的数量
* @return Count of sections
* @返回sections的计数
*/
inline unsigned int count() const
{ return m_sections.count(); }
/**
* Retrieve an entire section
* 检索一个完整的section
* @param index Index of the section
* @参数index, sections 的索引
* @return The section's content or NULL if no such section
* @返回section的内容,如果没有的检索到返回为NULL
*/
NamedList* getSection(unsigned int index) const;
/**
* Retrieve an entire section
* 检索一个完整的section
* @param sect Name of the section
* @参数sect, section的名字
* @return The section's content or NULL if no such section
* @返回section的内容,如果没有的检索到返回为NULL
*/
NamedList* getSection(const String& sect) const;
/**
* Locate a key/value pair in the section.
* 从section中定位一个键/值对
* @param sect Name of the section
* @参数sect, section的名字
* @param key Name of the key in section
* @参数key, section中键的名字
* @return A pointer to the key/value pair or NULL.
* @返回一个指向键值对的指针或者为NULL
*/
NamedString* getKey(const String& sect, const String& key) const;
/**
* Retrieve the value of a key in a section.
* 从section中检索一个键对应的值
* @param sect Name of the section
* @参数sect, section的名字
* @param key Name of the key in section
* @参数key, section中键的名字
* @param defvalue Default value to return if not found
* @参数devalue,如果没有检索到,默认的返回值
* @return The string contained in the key or the default
* @返回键中被包含的字符串或者是默认default
*/
const char* getValue(const String& sect, const String& key, const char* defvalue = 0) const;
/**
* Retrieve the numeric value of a key in a section.
* 从sections中检索一个键对应的数值型的值
* @param sect Name of the section
* @参数sect, section的名字
* @param key Name of the key in section
* @参数key, section中键的名字
* @param defvalue Default value to return if not found
* @参数devalue,如果没有检索到,默认的返回值
* @param minvalue Minimum value allowed for the parameter
* @参数minvalue, 参数允许的最小值
* @param maxvalue Maximum value allowed for the parameter
* @参数maxvalue, 参数允许的最大值
* @param clamp Control the out of bound values: true to adjust to the nearest
* bound, false to return the default value
* @参数clamp, 控制的绑定值:真调整到最近的绑定,假返回默认值
* @return The number contained in the key or the default
* @返回键中被包含的数字或者是默认default
*/
int getIntValue(const String& sect, const String& key, int defvalue = 0,
int minvalue = INT_MIN, int maxvalue = INT_MAX, bool clamp = true) const;
/**
* Retrieve the numeric value of a key in a section trying first a table lookup.
* 从section中检索一个键对应的数值型的值,尝试从第一个表中查找
* @param sect Name of the section
* @参数sect, section的名字
* @param key Name of the key in section
* @参数key, section中键的名字
* @param tokens A pointer to an array of tokens to try to lookup
* @参数tokens, 指向查找令牌的数组的指针
* @param defvalue Default value to return if not found
* @参数defvalue, 如果没有找到默认的返回值
* @return The number contained in the key or the default
* @返回键中被包含的数字或者是默认default
*/
int getIntValue(const String& sect, const String& key, const TokenDict* tokens, int defvalue = 0) const;
/**
* Retrieve the floating point value of a key in a section.
* 从sections中检索一个键对应的浮点型的值
* @param sect Name of the section
* @参数sect, section的名字
* @param key Name of the key in section
* @参数key, section中键的名字
* @param defvalue Default value to return if not found
* @参数defvalue, 如果没有找到默认的返回值
* @return The numeric value contained in the key or the default
* @返回键中被包含的数字或者是默认default
*/
double getDoubleValue(const String& sect, const String& key, double defvalue = 0.0) const;
/**
* Retrieve the boolean value of a key in a section.
* 从sections中检索一个键对应的布尔型的值
* @param sect Name of the section
* @参数sect, section的名字
* @param key Name of the key in section
* @参数key, section中键的名字
* @param defvalue Default value to return if not found
* @参数defvalue, 如果没有找到默认的返回值
* @return The boolean value contained in the key or the default
* @返回键中被包含的布尔值或者是默认default
*/
bool getBoolValue(const String& sect, const String& key, bool defvalue = false) const;
/**
* Deletes an entire section
* 删除一个完整的section
* @param sect Name of section to delete, NULL to delete all
* @参数sect, 要被删除的section的名字,NULL 所有的都删除
*/
void clearSection(const char* sect = 0);
/**
* Makes sure a section with a given name exists, creates if required
* 确保节与给定名称存在,如果需要创建
* @param sect Name of section to check or create
* @参数sect, 检查或创建的section的名字
* @return The section's content or NULL if no such section
* @返回section的内容,如果没有的检索到返回为NULL
*/
NamedList* createSection(const String& sect);
/**
* Deletes a key/value pair
* 删除一个键/值对
* @param sect Name of section
* @参数sect, section的名字
* @param key Name of the key to delete
* @参数key,要删除的键的名字
*/
void clearKey(const String& sect, const String& key);
/**
* Add the value of a key in a section.
* 添加一个键的值到section
* @param sect Name of the section, will be created if missing
* @参数sect, sections的名字,如果丢失将会被创建
* @param key Name of the key to add in the section
* @参数key, 要添加到section的键的名字
* @param value Value to set in the key
* @参数value, 设置到键的值
*/
void addValue(const String& sect, const char* key, const char* value = 0);
/**
* Set the value of a key in a section.
* 设置section中键的值
* @param sect Name of the section, will be created if missing
* @参数sect, sections的名字,如果丢失将会被创建
* @param key Name of the key in section, will be created if missing
* @参数key, section中的键的名字,如果丢失了将会被创建
* @param value Value to set in the key
* @参数value, 设置到键的值
*/
void setValue(const String& sect, const char* key, const char* value = 0);
/**
* Set the numeric value of a key in a section.
* 设置section中键为数字型的值
* @param sect Name of the section, will be created if missing
* @参数sect, sections的名字,如果丢失将会被创建
* @param key Name of the key in section, will be created if missing
* @参数key, section中的键的名字,如果丢失了将会被创建
* @param value Value to set in the key
* @参数value, 设置到键的值
*/
void setValue(const String& sect, const char* key, int value);
/**
* Set the boolean value of a key in a section.
* 设置section中键为布尔型的值
* @param sect Name of the section, will be created if missing
* @参数sect, sections的名字,如果丢失将会被创建
* @param key Name of the key in section, will be created if missing
* @参数key, section中的键的名字,如果丢失了将会被创建
* @param value Value to set in the key
* @参数value, 设置到键的值
*/
void setValue(const String& sect, const char* key, bool value);
/**
* Load the configuration from file
* 从文件中加载配置
* @param warn True to also warn if the configuration could not be loaded
* @参数warn, 如果配置不能被加载, 参数为true,则警告
* @return True if successfull, false for failure
* @返回True 如果成功,false 如果失败
*/
bool load(bool warn = true);
/**
* Save the configuration to file
* 保存配置到文件
* @return True if successfull, false for failure
* @返回True 如果成功,false 如果失败
*/
bool save() const;
private:
ObjList *getSectHolder(const String& sect) const;
ObjList *makeSectHolder(const String& sect);
ObjList m_sections;
};