--- nono/lib/config.h 2026/04/29 17:04:40 1.1.1.3 +++ nono/lib/config.h 2026/04/29 17:05:08 1.1.1.4 @@ -4,6 +4,10 @@ // Licensed under nono-license.txt // +// +// 設定 +// + // 設定ファイルは、テキスト形式、行志向で順序を持たない key=value ペアの羅列、 // アプリケーションが書き戻しを行わないためユーザが任意にコメント行を入れる // ことが出来る、タイプのもの。 @@ -56,6 +60,11 @@ class ConfigItem // なるので、それでもよければ使ってよい。 int AsInt() const { return atoi(value.c_str()); } + // 値を整数値として取得する。 + // 変換できたら true を返す。 + // 数値として評価出来ないときは false を返す。 + bool TryInt(int *val) const; + // デフォルト値を差し替える。 // この変数が FromInitial なら値(初期値)を val に差し替える。この時 // from は FromInitial のまま。 @@ -77,6 +86,10 @@ class ConfigItem void Err(const char *fmt, ...) const __printflike(2, 3); private: + static void PrintErr(ConfigItem::from_t from, const std::string& where, + const std::string& key, const std::string& value, + const std::string& msg); + // key が変数名、value が値。 // value はここでは文字列でありそれ以上の構造は持たないが、 // 整数値として解釈する或いはカンマ区切りにするなどは使う側の裁量。 @@ -174,4 +187,4 @@ class Config bool fixed {}; }; -extern std::unique_ptr gConfig; +extern Config *gConfig;