--- nono/lib/config.h 2026/04/29 17:05:39 1.1.1.10 +++ nono/lib/config.h 2026/04/29 17:05:52 1.1.1.12 @@ -28,6 +28,7 @@ #pragma once #include "mainapp.h" +#include #include // 設定の1項目 @@ -42,6 +43,7 @@ class ConfigItem FromConfig, // VM 設定ファイルで更新 FromOption, // コマンドライン引数で更新 FromPerf, // --perf オプション(を展開したもの)で更新 + FromRunning, // 実行中に更新 }; public: @@ -98,17 +100,22 @@ class ConfigItem // where を取得する const std::string& GetWhere() const { return where; } + // この項目で "Invalid argument" のエラーメッセージ文字列を返す。 + std::string ErrMsg() const; + // この項目で指定のメッセージのエラーメッセージ文字列を返す。 + std::string ErrMsg(const char *fmt, ...) const __printflike(2, 3); + std::string ErrMsg(const std::string& msg) const; + // この項目で "invalid argument" を warnx() で出力する void Err() const; - // この項目での指定のエラーメッセージを warnx() で出力する - void Err(const std::string& msg) const; void Err(const char *fmt, ...) const __printflike(2, 3); + void Err(const std::string& msg) const; private: - static void PrintErr(ConfigItem::from_t from, const std::string& where, - const std::string& key, const std::string& value, - const std::string& msg); + static std::string ErrFrom(ConfigItem::from_t from, + const std::string& where, + const std::string& key, const std::string& value); // key が変数名、value が値。 // value はここでは文字列でありそれ以上の構造は持たないが、 @@ -171,6 +178,9 @@ class Config // コマンドライン引数の内容で上書きする bool Update(const std::string& line, const std::string& optname); + // 実行中に動的に変更する + bool UpdateRunning(const std::string& line); + // 内容を表示する void Show(bool all) const; @@ -192,6 +202,9 @@ class Config // エイリアスを追加 bool AddAlias(const std::string& alias, const std::string& key); + // 廃止項目を追加 + void AddObsolete(const std::string& old, const std::string& alter); + // 項目を削除 void Delete(const std::string& key); @@ -214,12 +227,20 @@ class Config static bool SplitKeyVal(std::string *keyp, std::string *valp, const std::string& line); + // key が obsolete[] に含まれていれば true を返す。 + bool IsObsolete(const std::string& key) const { + return (obsolete.find(key) != obsolete.end()); + } + // 設定項目の集合 std::vector list {}; // エイリアス(別名)の集合 std::vector> aliases {}; + // 廃止項目名の集合 + std::map obsolete {}; + // 設定はある時点までは追加更新可能だが、途中からは読み込み専用としたい。 // プログラムミスを避けるため。 bool fixed {};