00001 //------------------------------------------------------------------------------ 00002 // Lamp : Open source game middleware 00003 // Copyright (C) 2004 Junpei Ohtani ( Email : junpee@users.sourceforge.jp ) 00004 // 00005 // This library is free software; you can redistribute it and/or 00006 // modify it under the terms of the GNU Lesser General Public 00007 // License as published by the Free Software Foundation; either 00008 // version 2.1 of the License, or (at your option) any later version. 00009 // 00010 // This library is distributed in the hope that it will be useful, 00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00013 // Lesser General Public License for more details. 00014 // 00015 // You should have received a copy of the GNU Lesser General Public 00016 // License along with this library; if not, write to the Free Software 00017 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00018 //------------------------------------------------------------------------------ 00019 00020 /** @file 00021 * エラー出力ヘッダ 00022 * @author Junpee 00023 */ 00024 #ifndef ERROR_OUTPUT_H_ 00025 #define ERROR_OUTPUT_H_ 00026 00027 //------------------------------------------------------------------------------ 00028 00029 /** 00030 * エラー出力の初期化 00031 */ 00032 #define ErrorOutInitialize ::Lamp::ErrorOutput::initialize 00033 00034 /** 00035 * エラー出力の後始末 00036 */ 00037 #define ErrorOutFinalize ::Lamp::ErrorOutput::finalize 00038 00039 /** 00040 * エラー出力 00041 * 00042 * printfと同じ構文で呼び出すと、エラーハンドラを呼び出します。 00043 * デフォルトのエラーハンドラはメッセージを出力した後、強制終了します。 00044 * <pre> 00045 * サンプルコード 00046 * 00047 * // 「Hoge 1 2.0」というメッセージでエラーを発生させる。 00048 * ErrorOut("Hoge %d %.1f", 1, 2.f); 00049 * </pre> 00050 */ 00051 #define ErrorOut ::Lamp::ErrorOutput::print 00052 00053 /** 00054 * 線の出力 00055 * 00056 * エラー時にエラー出力に線を出力し、改行します。 00057 */ 00058 #define ErrorOutLine() ::Lamp::ErrorOutput::print("------------------------------"\ 00059 "--------------------------------------------------\n") 00060 00061 /** 00062 * 太い線の出力 00063 * 00064 * エラー時にエラー出力に太い線を出力し、改行します。 00065 */ 00066 #define ErrorOutThickLine() ::Lamp::ErrorOutput::print("##############################"\ 00067 "##################################################\n") 00068 00069 namespace Lamp{ 00070 00071 class Logger; 00072 class String; 00073 00074 /** 00075 * エラー出力クラス 00076 * 00077 * エラー出力の実装クラスです。 00078 */ 00079 class ErrorOutput{ 00080 public: 00081 /** 00082 * 初期化 00083 * @param fileName エラーログファイル名。NULLだとログを残しません。 00084 */ 00085 static void initialize(const char* fileName = "LampErrorLog.txt"); 00086 00087 /** 00088 * 後始末 00089 */ 00090 static void finalize(); 00091 00092 /** 00093 * エラー出力 00094 * 00095 * 可変長引数に対応したエラー出力メソッド。 00096 * @param format フォーマット 00097 * @param ... 可変長引数 00098 * @return 出力文字数 00099 */ 00100 static int print(const char* format, ...); 00101 00102 /** 00103 * エラー出力 00104 * @param string 文字列 00105 * @return 出力文字数 00106 */ 00107 static int print(const String& string); 00108 00109 /** 00110 * エラーハンドラの型 00111 * 00112 * デフォルトのエラーハンドラはメッセージを出力して強制終了します。 00113 * @param message エラーメッセージ 00114 */ 00115 typedef void (*ErrorHandler)(const char* message); 00116 00117 /** 00118 * エラーハンドラの設定 00119 * @param handler 設定するエラーハンドラ 00120 */ 00121 static void setErrorHandler(ErrorHandler handler){ handler_ = handler; } 00122 00123 private: 00124 // デフォルトエラーハンドラ 00125 static void defaultErrorHandler(const char* message); 00126 00127 // コンストラクタ隠蔽 00128 ErrorOutput(); 00129 00130 // エラーハンドラ 00131 static ErrorHandler handler_; 00132 // ロガー 00133 static Logger* logger_; 00134 }; 00135 00136 } // End of namespace Lamp 00137 00138 //------------------------------------------------------------------------------ 00139 #endif // End of ERROR_OUTPUT_H_ 00140 //------------------------------------------------------------------------------