INIFile
boost::spiritを利用したINIの読み込み・書き出し
初出:2009年03/14 更新:2009年03/14
INIFile
boost::spiritによるINIファイルの読み込みと書き出しを行うクラスINIFileと、INIFile中のセクションに対応するINISectionを公開しています。
- "によってクオートすることで値に改行を含められる
- \"を使うことでクオートされた値に"を含められる
- コメント(;で始まる行)は直下のキーと対応づけられ、保存時に再現可能
- "True", "False"をbool値として用いることが可能
- 値の読み取り/書き出しはlexical_castを利用
依存ライブラリ等
- Visual C++ 2008 Express Editionで動作を確認 (特にVC特有の機能は用いていません)
- boost 1.36.0で動作を確認(tuple, lexical_cast, spirit, foreach, mem_fn, bind, function)
ダウンロード
inifile-1.2.2.zip使用方法
inifile.hのコメントを参照してください。そのうちDoxygenか何かでドキュメント作るかも
使用例
#include <inifile.h>
class AutoShadeProfile : INIFile {
public:
...
void load() {
readFile("autoshade.ini");
// [Window]
Left = getSection("Window").getVal<int>("Left");
Top = getSection("Window").getVal<int>("Top");
Width = getSection("Window").getVal<int>("Width");
Height = getSection("Window").getVal<int>("Height");
ShowTrayIcon = getSection("Window").getVal<bool>("ShowTrayIcon");
StartMinimize = getSection("Window").getVal<bool>("StartMinimize");
// [Path]
FilterPath = getSection("Path").getVal<string>("FilterPath");
}
void save() {
// [Window]
getSection("Window").setVal<int>("Left", Left);
getSection("Window").setVal<int>("Top", Top);
getSection("Window").setVal<int>("Width", Width);
getSection("Window").setVal<int>("Height", Height);
writeFile("autoshade.ini");
}
};
