📄 prettydebug.cc~
字号:
// -*- mode:C++ ; tab-width:4 ; c-basic-offset:4 ; indent-tabs-mode:nil -*-// ----------------------------------------------------------------------------// CERTI - HLA RunTime Infrastructure// Copyright (C) 2002, 2003 ONERA//// This file is part of CERTI-libCERTI//// CERTI-libCERTI is free software ; you can redistribute it and/or// modify it under the terms of the GNU Lesser General Public License// as published by the Free Software Foundation ; either version 2 of// the License, or (at your option) any later version.//// CERTI-libCERTI is distributed in the hope that it will be useful, but// WITHOUT ANY WARRANTY ; without even the implied warranty of// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU// Lesser General Public License for more details.//// You should have received a copy of the GNU Lesser General Public// License along with this program ; if not, write to the Free Software// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307// USA//// $Id: PrettyDebug.cc,v 3.3 2003/03/21 18:22:12 breholee Exp $// ----------------------------------------------------------------------------#include "PrettyDebug.hh"DebugOStream DebugOStream::nullOutputStream(cout);DebugOStream PrettyDebug::defaultOutputStream(cerr);//Fix this pointer to the default initialisation of pointers for your compilerDebugOStream* PrettyDebug::nullOutputStreamPtr = 0 ; DebugOStream& PrettyDebug::nullOutputStream = DebugOStream::nullOutputStream;// ----------------------------------------------------------------------------/** Print the message to the default output ostream. * This function does NOT add any trailing \n. */voidPrettyDebug::Print(DebugOStream& theOutputStream, const char* theHeaderMessage, const char * Message){ if (Message != NULL) theOutputStream << theHeaderMessage << Message; else theOutputStream << theHeaderMessage << pdSEmptyMessage;}// ----------------------------------------------------------------------------/** Parse the environment variable value to find debug keys and enable * debug levels. The internal LEnvVar and LMessage variables must * already have been set. */voidPrettyDebug::ParseEnvString(const char *Name){ unsigned int i; const char *pdInitMessage = " variable read, content = "; const char *pdTooLongInitMessage = "Env Var read(string too long)."; char *Value = getenv(Name); // The value of the variable Name char Key; // A character from the value compared to keys. char *Pos; // The position of Key in pdDebugKeys char *DebugKeys = (char *) pdDebugKeysString ; // needs a non const string for (i = pdUnused; i < pdLast + 1; i++) // Clear current level map Level_Map[i] = PrettyDebug::nullOutputStreamPtr; if (Value != 0) { // Print Debug Init Message int length = strlen(LEnvVar) + strlen(pdInitMessage) + strlen(Value); if (length < pdMaxMessageSize) cout << endl << LEnvVar << pdInitMessage << Value << endl; else cout << endl << LEnvVar << pdTooLongInitMessage << endl; // Compare each char of Value to content of the pgDebugKeys // string, to enable matching debug levels. for (i = 0; i < strlen(Value); i++) { Key = Value[i]; Pos = strchr(DebugKeys, Key); if (Pos != 0) Level_Map [Pos - DebugKeys] = &(PrettyDebug::defaultOutputStream); } } return;}// ---------------------------------------------------------------------------- /** Constructor. Initialize the debug process according to the value * of the 'Name' environment variable. The 'Header' message is put * in front of all printed debug messages. It can be a module name or * whatever you need. */PrettyDebug::PrettyDebug(const char * Name, const char * Header){ if (Name == 0) { PrettyDebug::Print(PrettyDebug::defaultOutputStream, "", "Error in pgCDebug constructor, no Name specified.\n"); exit(EXIT_FAILURE); } LEnvVar = strdup(Name); if (Header != 0) HeaderMessage = strdup(Header); else HeaderMessage = strdup(""); //Initialisation de LMessage
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -