Main Page | Namespace List | Class Hierarchy | Alphabetical List | Compound List | File List | Namespace Members | Compound Members | File Members

DebugOutput.cpp

Go to the documentation of this file.
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 
00025 #include "LampBasic.h"
00026 #include "Core/System/StringMethod.h"
00027 #include "Core/Debug/DebugOutput.h"
00028 #include "Core/Debug/ErrorOutput.h"
00029 #include "Core/Debug/Logger.h"
00030 #include "Core/Debug/DebugStringTemporary.h"
00031 
00032 // デバッグ時
00033 #ifdef _DEBUG
00034 
00035 namespace Lamp{
00036 
00037 // ロガー
00038 Logger* DebugOutput::logger_ = NULL;
00039 
00040 //------------------------------------------------------------------------------
00041 // 初期化
00042 void DebugOutput::initialize(const char* fileName){
00043     if(fileName == NULL){ return; }
00044     logger_ = new Logger(fileName);
00045 }
00046 //------------------------------------------------------------------------------
00047 // 後始末
00048 void DebugOutput::finalize(){
00049     SafeDelete(logger_);
00050 }
00051 //------------------------------------------------------------------------------
00052 // デバッグ出力
00053 int DebugOutput::print(const char* format, ...){
00054     va_list args;
00055     va_start(args, format);
00056     int size = StdVsnprintf(DebugStringTemporary::buffer_,
00057         DebugStringTemporary::bufferSize_ - 1, format, args);
00058     if(size < 0){
00059         ErrorOut(String("デバッグ出力のフォーマットに失敗しました。"));
00060         return size;
00061     }
00062     DebugStringTemporary::buffer_[size] = '\0';
00063     va_end(args);
00064     StdOutputDebugString(DebugStringTemporary::buffer_);
00065     StdPrintf(DebugStringTemporary::buffer_);
00066     // 最高優先度でロガーへ出力
00067     if(logger_ != NULL){
00068         logger_->output(
00069             Logger::fewLevel, String(DebugStringTemporary::buffer_));
00070     }
00071     return size;
00072 }
00073 //------------------------------------------------------------------------------
00074 // デバッグ出力
00075 int DebugOutput::print(const String& string){
00076     StdOutputDebugString(string.getBytes());
00077     StdPrintf(string.getBytes());
00078     // 最高優先度でロガーへ出力
00079     if(logger_ != NULL){
00080         logger_->output(Logger::fewLevel, string);
00081     }
00082     return string.getSize();
00083 }
00084 //------------------------------------------------------------------------------
00085 } // End of namespace Lamp
00086 #endif// End of _DEBUG
00087 //------------------------------------------------------------------------------

Generated on Wed Mar 16 10:29:29 2005 for Lamp by doxygen 1.3.2