⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 prettydebug.cc

📁 分布式仿真 开放源码
💻 CC
字号:
// ----------------------------------------------------------------------------// 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.7 2003/11/21 16:32:33 breholee Exp $// ----------------------------------------------------------------------------#include <config.h>#include "PrettyDebug.hh"#include <cstring>#include <iostream>#include <stdlib.h>#include <stdarg.h>#include <iostream>using std::cout ;using std::cerr ;using std::endl ;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 << LEnvVar << pdInitMessage << Value << endl;        else            cout << 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 + -