yaml←→iniファイル自動生成、クラス自動生成
yamlを利用したINIファイル用ソースの自動コード生成の例
久しぶりにC++を使う必要性がありそうなため、 rails等にかぶれて作成中のもの。
その1 yaml→iniファイル, ini→yamlファイル
code_gen yaml2ini < test.yml > test.ini code_gen ini2yaml < test.ini > test.yml
次のファイルを相互変換する。
test.ymlの例
次のような疑似ini構造のデータを定義する。
- section: name1 values: - key: attr1 value: value type: string - key: attr2 value: 55 type: int comment: comment value2 default: 5
test.ini
ymlをiniファイルに変換した例
[name1] attr1=value ;comment value2 attr2=55
その2 CPPクラスの生成
code_gen ini_yml2cpp_class Test < test.yml
Test.h (with MFC)
section単位でクラスを生成する.
文字列クラスに何を利用するかは、どこかで解決する必要がある。
namespace ini { class Name : ISection { private: CString _attr1; // comment value2 int _attr2; public: Name() {} virtual ~Name(); public: bool load(const CString& iniFilePath, const CString& section); bool save(const CString& iniFilePath, const CString& section); public: void setAttr1(const CString& attr1) { _attr1 = attr1; } const CString& getAttr1() const { return _attr1; } void setAttr2(int attr2) { _attr2 = attr2; } int getAttr2() const { return _attr2; } }; }