|
|
1.1 root 1: //
2: // nono
1.1.1.3 root 3: // Copyright (C) 2020 nono project
4: // Licensed under nono-license.txt
1.1 root 5: //
6:
7: #pragma once
8:
1.1.1.6 ! root 9: #include "mystring.h"
1.1 root 10: #include "textscreen.h"
1.1.1.6 ! root 11: #include <functional>
1.1 root 12: #include <vector>
13:
1.1.1.6 ! root 14: // ログ表示に指定するラムダ式の便利マクロ。
! 15: // fmt 内では __func__ が使えないので代わりに lam_func を使うこと。
! 16: // lstr("%s value=%d", lam_func, value) のようになる。
! 17: // 他のキャプチャ指定子が必要になったらまた考える。
! 18: #define lstr(fmt...) \
! 19: [&, lam_func = __func__] { (void)lam_func; return string_format(fmt); }
! 20:
1.1 root 21: //
22: // 基本オブジェクト
23: //
24: // ログ出力機能を持つ。
25: //
1.1.1.4 root 26: class Object : public IMonitor
1.1 root 27: {
28: public:
29: Object();
1.1.1.4 root 30: virtual ~Object() override;
1.1 root 31:
32: //
33: // ログ
34: //
35:
36: // ログ識別名
1.1.1.5 root 37: std::string logname {};
1.1 root 38: // ログレベル
39: // 0: 未実装動作などのデバッグログではない情報
40: // 1: 大雑把なデバッグログ
41: // 2: 詳細なデバッグログ
42: // 3: うるさいデバッグログ
1.1.1.5 root 43: int loglevel {};
1.1 root 44:
45: // メッセージ出力
1.1.1.6 ! root 46: // メッセージは仮想時刻も現在の PC も表示しない。Init() など VM 実行前や
1.1 root 47: // 仮想マシン(特に仮想時刻、PC) に関係ないあたりはこちらを使用。
48:
1.1.1.6 ! root 49: // レベル指定なし、フォーマット版。(レベルを評価した後で使う)
! 50: void putmsgn(const char *fmt, ...) const __printflike(2, 3);
! 51:
! 52: // レベル指定あり、フォーマット版。
! 53: #define putmsg(lv, fmt...) do { \
! 54: if (__predict_false(loglevel >= (lv))) { \
! 55: putmsgn(fmt); \
! 56: } \
! 57: } while (0)
! 58:
! 59: // レベル指定あり、ラムダ式版。
! 60: void putmsgf(int lv, std::function<std::string()> msgf) const {
! 61: if (__predict_false(loglevel >= lv)) {
! 62: putmsgn("%s", msgf().c_str());
1.1 root 63: }
64: }
65:
66: // ログ出力
1.1.1.6 ! root 67: // ログは仮想時刻と現在の PC も表示する。VM 実行中は基本的にこれで表示。
! 68:
! 69: // レベル指定なし、フォーマット版。(レベルを評価した後で使う)
! 70: void putlogn(const char *fmt, ...) const __printflike(2, 3);
1.1 root 71:
1.1.1.6 ! root 72: // レベル指定あり、フォーマット版。
! 73: #define putlog(lv, fmt...) do { \
! 74: if (__predict_false(loglevel >= (lv))) { \
! 75: putlogn(fmt); \
! 76: } \
! 77: } while (0)
! 78:
! 79: // レベル指定あり、ラムダ式版。
! 80: void putlogf(int lv, std::function<std::string()> msgf) const {
! 81: if (__predict_false(loglevel >= lv)) {
! 82: putlogn("%s", msgf().c_str());
1.1 root 83: }
84: }
85:
86: // デバイス名(デバッグ表示用)
87: // XXX オブジェクトなのにデバイス名とは一体...
1.1.1.5 root 88: std::string devname {};
1.1 root 89:
90: //
91: // モニター
92: //
93:
94: // モニター更新 (派生クラス側で用意)
1.1.1.4 root 95: void MonitorUpdate(TextScreen&) override { }
96: nnSize GetMonitorSize() override { return monitor_size; }
97: nnSize monitor_size {};
1.1 root 98: };
99:
100: // 全オブジェクトのリスト
101: extern std::vector<Object*> gObjects;
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.