|
|
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:
1.1.1.7 root 7: //
1.1.1.8 ! root 8: // 基本オブジェクト
1.1.1.7 root 9: //
10:
1.1.1.8 ! root 11: // オブジェクトはログ出力機能 (とそのための自身のオブジェクト名) を持つ。
! 12:
! 13: #include "object.h"
! 14: #include "logger.h"
! 15: #include "mainapp.h"
! 16:
1.1 root 17: // コンストラクタ
1.1.1.7 root 18: Object::Object(const std::string& objname_)
1.1 root 19: {
1.1.1.7 root 20: // オブジェクト名(ログ表示名)を設定。
21: objname = objname_;
22:
23: // コンストラクタで指定した場合はエイリアスにも登録しておく。
24: AddAlias(objname_);
1.1 root 25:
26: // 自分自身をリストに繋ぐ
1.1.1.8 ! root 27: gMainApp.AddObject(this);
1.1 root 28: }
29:
30: // デストラクタ
31: Object::~Object()
32: {
1.1.1.7 root 33: // 自分自身をリストから削除する
1.1.1.8 ! root 34: gMainApp.DeleteObject(this);
! 35: }
! 36:
! 37: // ログレベルを設定する。
! 38: void
! 39: Object::SetLogLevel(int loglevel_)
! 40: {
! 41: loglevel = loglevel_;
1.1 root 42: }
43:
44: // メッセージ表示
45: // 常に表示 (あらかじめ loglevel の評価をした後で呼び出す用)
46: void
1.1.1.6 root 47: Object::putmsgn(const char *fmt, ...) const
1.1 root 48: {
1.1.1.2 root 49: char buf[1024];
1.1.1.6 root 50: va_list ap;
1.1.1.8 ! root 51: int len;
1.1 root 52:
1.1.1.7 root 53: // 名前だけ生表示されても分かりづらいので括弧でもつけておく
54: len = snprintf(buf, sizeof(buf), "(%s) ", GetName().c_str());
1.1.1.8 ! root 55:
1.1.1.6 root 56: va_start(ap, fmt);
1.1.1.2 root 57: vsnprintf(buf + len, sizeof(buf) - len, fmt, ap);
1.1.1.6 root 58: va_end(ap);
59:
1.1.1.8 ! root 60: WriteLog(buf);
1.1 root 61: }
62:
1.1.1.8 ! root 63: // ログ表示 (継承側で用意すること)
1.1 root 64: void
1.1.1.6 root 65: Object::putlogn(const char *fmt, ...) const
1.1 root 66: {
1.1.1.8 ! root 67: PANIC("Object::putlogn called");
! 68: }
1.1 root 69:
1.1.1.8 ! root 70: // ロガーに出力する共通部分
! 71: void
! 72: Object::WriteLog(const char *buf) const
! 73: {
! 74: logger->Write(buf);
1.1 root 75: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.