Annotation of nono/lib/configfile.h, revision 1.1.1.1

1.1       root        1: //
                      2: // nono
                      3: // Copyright (C) 2018 [email protected]
                      4: //
                      5: 
                      6: #pragma once
                      7: 
                      8: #include "header.h"
                      9: #include <unordered_map>
                     10: 
                     11: class Config
                     12: {
                     13:  public:
                     14:        Config(const std::string& dir);
                     15:        virtual ~Config();
                     16: 
                     17:        // 設定ファイルのロード、セーブ
                     18:        bool Load();
                     19:        bool Save();
                     20: 
                     21:        // 設定ファイル自身のパス名を取得
                     22:        std::string GetFilename() const { return filename; }
                     23: 
                     24:        // 設定ファイルのあるディレクトリパスを取得。
                     25:        // ディレクトリパスは必ず "/" で終わっている。
                     26:        // 絶対パスか相対パスかは不明?
                     27:        std::string GetConfigDir() const { return dirname; }
                     28: 
                     29:        // 関連するファイルのパスを取得。
                     30:        // ROM イメージなどはファイル名が固定で、以下の順でディレクトリを探索する。
                     31:        // 1. 設定ファイルディレクトリ
                     32:        // 2. 共通ディレクトリ(?)
                     33:        // 優先度の高いディレクトリに存在したファイルだけをターゲットにする。
                     34:        // ファイルがあるかどうかを調べるだけで、存在したけどそれに何らか
                     35:        // 不都合があったら次を試すとかはしない。
                     36:        std::string SearchFile(const char *filename) const;
                     37: 
                     38:        // 値の読み出し (整数)
                     39:        int ReadInt(const std::string& key) {
                     40:                return ReadInt(key.c_str(), 0);
                     41:        }
                     42:        int ReadInt(const char *key) {
                     43:                return ReadInt(key, 0);
                     44:        }
                     45:        int ReadInt(const std::string& key, int defaultvalue) {
                     46:                return ReadInt(key.c_str(), defaultvalue);
                     47:        }
                     48:        int ReadInt(const char *key, int defaultvalue);
                     49: 
                     50:        // 値の読み出し (文字列)
                     51:        std::string ReadStr(const std::string& key) {
                     52:                return ReadStr(key.c_str(), "");
                     53:        }
                     54:        std::string ReadStr(const char *key) {
                     55:                return ReadStr(key, "");
                     56:        }
                     57:        std::string ReadStr(const std::string& key, const std::string& defaultvalue)
                     58:        {
                     59:                return ReadStr(key.c_str(), defaultvalue);
                     60:        }
                     61:        std::string ReadStr(const char *key, const std::string& defaultvalue);
                     62: 
                     63:        // 値の書き込み (整数)
                     64:        void Write(std::string& key, int value) {
                     65:                Write(key.c_str(), value);
                     66:        }
                     67:        void Write(const char *key, int value);
                     68: 
                     69:        // 値の書き込み (文字列)
                     70:        void Write(std::string& key, std::string& value) {
                     71:                Write(key.c_str(), value.c_str());
                     72:        }
                     73:        void Write(std::string& key, const char *value) {
                     74:                Write(key.c_str(), value);
                     75:        }
                     76:        void Write(const char *key, std::string& value) {
                     77:                Write(key, value.c_str());
                     78:        }
                     79:        void Write(const char *key, const char *value);
                     80: 
                     81:        // エラー表示
                     82:        void Err(const std::string& key, const char *fmt, ...) __printflike(3, 4);
                     83:        void Err(const char *key, const char *fmt, ...) __printflike(3, 4);
                     84:        void Errv(const char *key, const char *fmt, va_list ap) __printflike(3, 0);
                     85: 
                     86:  private:
                     87:        // ファイル名
                     88:        std::string filename;
                     89: 
                     90:        // ファイルのあるディレクトリパス
                     91:        std::string dirname;
                     92: 
                     93:        // key = value が順不同で格納されている
                     94:        std::unordered_map<std::string, std::string> map;
                     95: };
                     96: 
                     97: extern Config *gConfig;

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.