--- nono/lib/config.h 2026/04/29 17:05:15 1.1.1.6 +++ nono/lib/config.h 2026/04/29 17:05:22 1.1.1.8 @@ -38,7 +38,8 @@ class ConfigItem public: enum from_t { FromInitial = 0, // 初期値 - FromConfig, // 設定ファイルで更新 + FromHome, // 共通設定ファイル(~/.nono.cfg)で更新 + FromConfig, // VM 設定ファイルで更新 FromOption, // コマンドライン引数で更新 }; @@ -118,7 +119,7 @@ class ConfigItem // from (と where) はこの変数の由来を示す。 // o FromOption なら値はコマンドラインオプションで指定されたことを示す。 // この場合 where に "-V" とかが入っている。 - // o FromConfig なら値は設定ファイルで指定されたことを示す。 + // o FromConfig, FromHome なら値は設定ファイルで指定されたことを示す。 // この場合 where に "ファイルパス:行番号" が入っている。 // o FromInitial なら値は初期値のままであることを示す。引数や // 設定ファイルで値を指定した場合は例え初期値と同じ値を指定したと @@ -131,7 +132,7 @@ class ConfigItem class ConfigFile { public: - ConfigFile(const std::string& filepath_); + ConfigFile(const std::string& filepath_, ConfigItem::from_t from_); ~ConfigFile(); // ファイルの読み込み。 @@ -141,6 +142,9 @@ class ConfigFile // パス std::string filepath {}; + // 設定元 + ConfigItem::from_t from {}; + // 読み込んだ行一覧 // 行(改行と前後の空白を除く) と行番号(1から始まる)の pair。 // コメント行や空行は取り除いてあるが、文法チェックはしていないので @@ -179,6 +183,9 @@ class Config bool Add(const std::string& key, const std::string& value, VMCap vmcap = VMCap::ALL); + // エイリアスを追加 + bool AddAlias(const std::string& alias, const std::string& key); + // 項目を削除 void Delete(const std::string& key); @@ -194,6 +201,9 @@ class Config bool UpdateLine(const std::string& line, ConfigItem::from_t, const std::string& from); + // キーの正規名を返す + const std::string& GetCanonKey(const std::string& key) const; + // "key=val" 形式の行から key, val を取り出す。 static bool SplitKeyVal(std::string *keyp, std::string *valp, const std::string& line); @@ -201,6 +211,9 @@ class Config // 設定項目の集合 std::vector list {}; + // エイリアス(別名)の集合 + std::vector> aliases {}; + // 設定はある時点までは追加更新可能だが、途中からは読み込み専用としたい。 // プログラムミスを避けるため。 bool fixed {};