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

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"
                     14: #include "object.h"
                     15: #include "textscreen.h"
                     16: #include "vm.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: }
                     39: // 判定
                     40: static constexpr bool IS_MONITOR_MEMDUMP(int id) {
                     41:        return (ID_MONITOR_MEMDUMP0 <= id &&
                     42:                id < (ID_MONITOR_MEMDUMP0 + MAX_MEMDUMP_MONITOR));
                     43: }
                     44: 
                     45: class Monitor;
                     46: using MonitorCallback_t = void (Object::*)(Monitor *, TextScreen&);
1.1.1.2 ! root       47: #define ToMonitorCallback(f) static_cast<MonitorCallback_t>(f)
        !            48: 
1.1       root       49: // モニタコールバックを宣言するマクロ。
                     50: // 強制力はないけどヘッダで宣言するところで使うこと。
                     51: // コールバック関数の型が変わった時にコンパイルエラーで検出させるため。
                     52: #define DECLARE_MONITOR_CALLBACK(name) void name (Monitor *, TextScreen&)
                     53: // モニタ更新を呼び出すマクロ
                     54: #define MONITOR_UPDATE(m, scr) ((((m).obj)->*((m).func))(&(m), (scr)))
                     55: 
                     56: // モニタ
                     57: class Monitor
                     58: {
                     59:  public:
                     60:        Monitor();
                     61:        Monitor(Object *obj_);
                     62:        virtual ~Monitor();
                     63: 
                     64:        Object *obj {};                         // オブジェクト
                     65:        MonitorCallback_t func {};      // コールバック関数
                     66: 
                     67:        int GetId() const { return id; }
                     68: 
                     69:        void SetSize(nnSize size_) { size = size_; }
                     70:        void SetSize(int col_, int row_) { SetSize(nnSize(col_, row_)); }
                     71:        virtual nnSize GetSize() const { return size; }
                     72: 
                     73:        // 登録。
                     74:        // モニタの登録はコンストラクタおよび Create フェーズまでに行うこと。
                     75:        // Create() の後、Init() より前に -M オプションの処理があるため。
                     76:        // see wx/wxapp.cpp
                     77:        void Regist(int id);
                     78: 
                     79:        // 削除。
                     80:        void Unregist();
                     81: 
                     82:  private:
                     83:        // モニター識別子
                     84:        int id;
                     85: 
                     86:        // モニターサイズ
                     87:        nnSize size {};
                     88: };
                     89: 
                     90: //
                     91: // モニターマネージャ
                     92: //
                     93: class MonitorManager
                     94: {
                     95:        friend class Monitor;
                     96: 
                     97:        // モニター情報 (事前定義)
                     98:        struct MonitorInfo {
                     99:                int id;
                    100:                vmf_t feature;
                    101:                std::vector<std::string> aliases;
                    102:        };
                    103: 
                    104:  public:
1.1.1.2 ! root      105:        MonitorManager();
        !           106:        ~MonitorManager();
        !           107: 
1.1       root      108:        // 現在登録されているモニターのリストを返す。
                    109:        const std::vector<Monitor *>& GetList() const { return list; }
                    110: 
                    111:        // 指定された id を持つモニターを返す。
                    112:        // こっちは、なければ assert する。
                    113:        Monitor& Get(int id) const {
                    114:                for (auto mon : list) {
                    115:                        if (mon->GetId() == id) {
                    116:                                return *mon;
                    117:                        }
                    118:                }
1.1.1.2 ! root      119:                PANIC("id=%d not found", id);
1.1       root      120:        }
                    121: 
                    122:        // 指定された id を持つモニターを返す。
                    123:        // こっちは、なければ NULL を返す。
                    124:        Monitor *Find(int id) const {
                    125:                for (auto mon : list) {
                    126:                        if (mon->GetId() == id) {
                    127:                                return mon;
                    128:                        }
                    129:                }
                    130:                return NULL;
                    131:        }
                    132: 
                    133:        // 指定された id に対応する機種フラグを返す。
                    134:        vmf_t GetFeature(int id) const {
                    135:                assert(0 <= id && id < info.size());
                    136:                return info[id].feature;
                    137:        }
                    138: 
                    139:        // 指定された id に対応する名前のリストを返す。
                    140:        // id が範囲外だと assert する。
                    141:        const std::vector<std::string>& GetAliases(int id) const {
                    142:                assert(0 <= id && id < info.size());
                    143:                return info[id].aliases;
                    144:        }
                    145: 
                    146:        // id リストから一覧表示用の文字列を生成して返す
                    147:        static std::string MakeListString(std::vector<int> list);
                    148: 
                    149:        // 以降の追加を禁止する (プログラムミスを避けるため)
                    150:        void Fix();
                    151: 
                    152:  private:
                    153:        // 登録 (friend の Monitor からのみ呼べる)
                    154:        void Regist(Monitor *mon);
                    155: 
                    156:        // 削除 (friend の Monitor からのみ呼べる)
                    157:        void Unregist(Monitor *mon);
                    158: 
                    159:        // 現在登録されているモニターのリスト
                    160:        std::vector<Monitor *> list {};
                    161: 
                    162:        // 事前に設定されているモニター情報
                    163:        static const std::vector<MonitorInfo> info;
                    164: 
                    165:        // モニタの登録は -M オプションの処理が始まるまでに終えないといけない。
                    166:        bool fixed {};
                    167: };
                    168: 
1.1.1.2 ! root      169: 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.