Annotation of nono/lib/monitor.h, revision 1.1.1.4

1.1       root        1: //
                      2: // nono
                      3: // Copyright (C) 2021 nono project
                      4: // Licensed under nono-license.txt
                      5: //
                      6: 
1.1.1.2   root        7: //
                      8: // モニタ管理
                      9: //
                     10: 
1.1       root       11: #pragma once
                     12: 
                     13: #include "geometric.h"
1.1.1.3   root       14: #include "mainapp.h"
1.1       root       15: #include "object.h"
                     16: #include "textscreen.h"
                     17: 
                     18: // モニタ識別子
                     19: //
                     20: // テキストモニタの識別子だがメニューID (とウィンドウの識別ID) としても使う
                     21: // ので wxmainframe あたりも参照。
                     22: enum {
                     23: #include "monitor_id.h"
                     24: };
                     25: 
                     26: // 識別子 (n番目で指定)
                     27: static constexpr int ID_MONITOR_ATC(int n) {
                     28:        return ID_MONITOR_ATC0 + n;
                     29: }
                     30: static constexpr int ID_MONITOR_CMMU(int n) {
                     31:        return ID_MONITOR_CMMU0 + n;
                     32: }
                     33: static constexpr int ID_SUBWIN_CACHE(int n) {
                     34:        return ID_SUBWIN_CACHE0 + n;
                     35: }
                     36: static constexpr int ID_MONITOR_MEMDUMP(int n) {
                     37:        return ID_MONITOR_MEMDUMP0 + n;
                     38: }
1.1.1.4 ! root       39: static constexpr int ID_MONITOR_XPMEMDUMP(int n) {
        !            40:        return ID_MONITOR_XPMEMDUMP0 + n;
        !            41: }
1.1       root       42: // 判定
                     43: static constexpr bool IS_MONITOR_MEMDUMP(int id) {
                     44:        return (ID_MONITOR_MEMDUMP0 <= id &&
1.1.1.4 ! root       45:                id < ID_MONITOR_MEMDUMP(MAX_MEMDUMP_MONITOR));
        !            46: }
        !            47: static constexpr bool IS_MONITOR_XPMEMDUMP(int id) {
        !            48:        return (ID_MONITOR_XPMEMDUMP0 <= id &&
        !            49:                id < ID_MONITOR_XPMEMDUMP(MAX_XPMEMDUMP_MONITOR));
1.1       root       50: }
                     51: 
                     52: class Monitor;
                     53: using MonitorCallback_t = void (Object::*)(Monitor *, TextScreen&);
1.1.1.2   root       54: #define ToMonitorCallback(f) static_cast<MonitorCallback_t>(f)
                     55: 
1.1       root       56: // モニタコールバックを宣言するマクロ。
                     57: // 強制力はないけどヘッダで宣言するところで使うこと。
                     58: // コールバック関数の型が変わった時にコンパイルエラーで検出させるため。
                     59: #define DECLARE_MONITOR_CALLBACK(name) void name (Monitor *, TextScreen&)
                     60: // モニタ更新を呼び出すマクロ
                     61: #define MONITOR_UPDATE(m, scr) ((((m).obj)->*((m).func))(&(m), (scr)))
                     62: 
                     63: // モニタ
                     64: class Monitor
                     65: {
                     66:  public:
                     67:        Monitor();
                     68:        Monitor(Object *obj_);
                     69:        virtual ~Monitor();
                     70: 
                     71:        Object *obj {};                         // オブジェクト
                     72:        MonitorCallback_t func {};      // コールバック関数
                     73: 
                     74:        int GetId() const { return id; }
                     75: 
1.1.1.3   root       76:        // モニターの表示サイズを設定・取得。
1.1       root       77:        void SetSize(nnSize size_) { size = size_; }
                     78:        void SetSize(int col_, int row_) { SetSize(nnSize(col_, row_)); }
                     79:        virtual nnSize GetSize() const { return size; }
                     80: 
1.1.1.3   root       81:        // モニターが縦に可変長の場合の最大表示行数。(固定長なら 0)
                     82:        void SetMaxHeight(int maxh_) { maxh = maxh_; }
                     83:        int GetMaxHeight() const { return maxh; }
                     84: 
1.1       root       85:        // 登録。
                     86:        // モニタの登録はコンストラクタおよび Create フェーズまでに行うこと。
                     87:        // Create() の後、Init() より前に -M オプションの処理があるため。
                     88:        // see wx/wxapp.cpp
                     89:        void Regist(int id);
                     90: 
                     91:        // 削除。
                     92:        void Unregist();
                     93: 
1.1.1.4 ! root       94:        // ID を表示用文字列にして返す。
        !            95:        static const char *GetIdText(int id);
        !            96: 
        !            97:        // このモニターの ID を表示用文字列にして返す。
        !            98:        const char *GetIdText() const { return GetIdText(id); }
        !            99: 
1.1       root      100:  private:
                    101:        // モニター識別子
                    102:        int id;
                    103: 
                    104:        // モニターサイズ
                    105:        nnSize size {};
1.1.1.3   root      106: 
                    107:        // 縦に可変長の場合の最大表示行数 (固定長なら 0)
                    108:        int maxh {};
1.1.1.4 ! root      109: 
        !           110:        // ID を表示用のテキストにしたものとの対応表。
        !           111:        static const std::vector<std::pair<int, const char *>> idtext;
1.1       root      112: };
                    113: 
                    114: //
                    115: // モニターマネージャ
                    116: //
                    117: class MonitorManager
                    118: {
                    119:        friend class Monitor;
                    120: 
                    121:        // モニター情報 (事前定義)
                    122:        struct MonitorInfo {
                    123:                int id;
1.1.1.3   root      124:                VMCap vmcap;
1.1       root      125:                std::vector<std::string> aliases;
                    126:        };
                    127: 
                    128:  public:
1.1.1.2   root      129:        MonitorManager();
                    130:        ~MonitorManager();
                    131: 
1.1       root      132:        // 現在登録されているモニターのリストを返す。
                    133:        const std::vector<Monitor *>& GetList() const { return list; }
                    134: 
                    135:        // 指定された id を持つモニターを返す。
                    136:        // こっちは、なければ assert する。
                    137:        Monitor& Get(int id) const {
                    138:                for (auto mon : list) {
                    139:                        if (mon->GetId() == id) {
                    140:                                return *mon;
                    141:                        }
                    142:                }
1.1.1.2   root      143:                PANIC("id=%d not found", id);
1.1       root      144:        }
                    145: 
                    146:        // 指定された id を持つモニターを返す。
                    147:        // こっちは、なければ NULL を返す。
                    148:        Monitor *Find(int id) const {
                    149:                for (auto mon : list) {
                    150:                        if (mon->GetId() == id) {
                    151:                                return mon;
                    152:                        }
                    153:                }
                    154:                return NULL;
                    155:        }
                    156: 
1.1.1.3   root      157:        // 指定された id に対応する機種ケーパビリティを返す。
                    158:        VMCap GetVMCap(int id) const {
1.1       root      159:                assert(0 <= id && id < info.size());
1.1.1.3   root      160:                return info[id].vmcap;
1.1       root      161:        }
                    162: 
                    163:        // 指定された id に対応する名前のリストを返す。
                    164:        // id が範囲外だと assert する。
                    165:        const std::vector<std::string>& GetAliases(int id) const {
                    166:                assert(0 <= id && id < info.size());
                    167:                return info[id].aliases;
                    168:        }
                    169: 
                    170:        // id リストから一覧表示用の文字列を生成して返す
                    171:        static std::string MakeListString(std::vector<int> list);
                    172: 
                    173:        // 以降の追加を禁止する (プログラムミスを避けるため)
                    174:        void Fix();
                    175: 
                    176:  private:
                    177:        // 登録 (friend の Monitor からのみ呼べる)
                    178:        void Regist(Monitor *mon);
                    179: 
                    180:        // 削除 (friend の Monitor からのみ呼べる)
                    181:        void Unregist(Monitor *mon);
                    182: 
                    183:        // 現在登録されているモニターのリスト
                    184:        std::vector<Monitor *> list {};
                    185: 
                    186:        // モニタの登録は -M オプションの処理が始まるまでに終えないといけない。
                    187:        bool fixed {};
1.1.1.4 ! root      188: 
        !           189:        // 事前に設定されているモニター情報
        !           190:        static const std::vector<MonitorInfo> info;
1.1       root      191: };
                    192: 
1.1.1.2   root      193: extern MonitorManager *gMonitorManager;

unix.superglobalmegacorp.com

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