--- nono/lib/config.h 2026/04/29 17:04:40 1.1.1.3 +++ nono/lib/config.h 2026/04/29 17:05:12 1.1.1.5 @@ -4,6 +4,10 @@ // Licensed under nono-license.txt // +// +// 設定 +// + // 設定ファイルは、テキスト形式、行志向で順序を持たない key=value ペアの羅列、 // アプリケーションが書き戻しを行わないためユーザが任意にコメント行を入れる // ことが出来る、タイプのもの。 @@ -22,7 +26,7 @@ #pragma once -#include "header.h" +#include "mainapp.h" #include // 設定の1項目 @@ -39,10 +43,11 @@ class ConfigItem public: ConfigItem() { } - ConfigItem(const std::string& key_, const std::string& val_, + ConfigItem(const std::string& key_, const std::string& val_, VMCap vmcap_, from_t from_, const std::string& where_) { key = key_; value = val_; + vmcap = vmcap_; from = from_; where = where_; } @@ -56,6 +61,11 @@ class ConfigItem // なるので、それでもよければ使ってよい。 int AsInt() const { return atoi(value.c_str()); } + // 値を整数値として取得する。 + // 変換できたら true を返す。 + // 数値として評価出来ないときは false を返す。 + bool TryInt(int *val) const; + // デフォルト値を差し替える。 // この変数が FromInitial なら値(初期値)を val に差し替える。この時 // from は FromInitial のまま。 @@ -66,6 +76,9 @@ class ConfigItem // コンストラクタでこれを呼び出すこと。例えば mpu-clock など。 void SetDefault(const std::string& val); + // vmcap を取得する + VMCap GetVMCap() const { return vmcap; } + // from を取得する from_t GetFrom() const { return from; } @@ -77,6 +90,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 はここでは文字列でありそれ以上の構造は持たないが、 // 整数値として解釈する或いはカンマ区切りにするなどは使う側の裁量。 @@ -85,6 +102,10 @@ class ConfigItem std::string key {}; std::string value {}; + // ケーパビリティ。 + // 機種確定後に、この機種に不要な変数は削除する。 + VMCap vmcap {}; + // from (と where) はこの変数の由来を示す。 // o FromOption なら値は -V オプションで指定されたことを示す。 // o FromConfig なら値は設定ファイルで指定されたことを示す。 @@ -143,9 +164,10 @@ class Config void SetDefault(const std::string& key, const std::string& value); // 項目を追加 - bool Add(const std::string& key); - bool Add(const std::string& key, int value); - bool Add(const std::string& key, const std::string& value); + bool Add(const std::string& key, VMCap vmcap = VMCap::ALL); + bool Add(const std::string& key, int value, VMCap vmcap = VMCap::ALL); + bool Add(const std::string& key, const std::string& value, + VMCap vmcap = VMCap::ALL); // 項目を削除 void Delete(const std::string& key); @@ -174,4 +196,4 @@ class Config bool fixed {}; }; -extern std::unique_ptr gConfig; +extern Config *gConfig;