1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127
|
// -------------------------------------------------------------------
// MAdLib - Copyright (C) 2008-2009 Universite catholique de Louvain
//
// See the Copyright.txt and License.txt files for license information.
// You should have received a copy of these files along with MAdLib.
// If not, see <http://www.madlib.be/license/>
//
// Please report all bugs and problems to <contrib@madlib.be>
//
// Authors: Gaetan Compere, Jean-Francois Remacle
// -------------------------------------------------------------------
#include "MAdMessage.h"
#include <cstdarg>
#include <iostream>
#include <sstream>
#include <stdlib.h>
#include <stdio.h>
using std::stringstream;
using std::string;
using std::ostream;
namespace MAd {
// -------------------------------------------------------------------
MAdMsg::MAdMsg()
{
outStream = &std::cout;
errStream = &std::cerr;
}
// -------------------------------------------------------------------
void MAdMsg::initialize()
{
}
// -------------------------------------------------------------------
void MAdMsg::finalize()
{
}
// -------------------------------------------------------------------
void MAdMsg::registerAbortFct(AbortFunction fct, void * data)
{
abortFcts.push_back(std::make_pair(fct,data));
}
// -------------------------------------------------------------------
void MAdMsg::info(int line,
const char* file,
const char* fmt,...) const
{
char buff[1024];
va_list args;
va_start (args, fmt);
vsprintf(buff, fmt, args);
va_end (args);
if ( line >= 0 ) {
*outStream << "Info: " << buff << writePosition(line,file) << "" << std::endl;
}
else {
*outStream << "Info: " << buff << std::endl;
}
}
// -------------------------------------------------------------------
void MAdMsg::warning(int line,
const char* file,
const char* fmt,...) const
{
char buff[1024];
va_list args;
va_start (args, fmt);
vsprintf(buff, fmt, args);
va_end (args);
if ( line >= 0 ) {
*outStream << "WARNING: " << buff << writePosition(line,file) << "" << std::endl;
}
else {
*outStream << "WARNING: " << buff << std::endl;
}
}
// -------------------------------------------------------------------
void MAdMsg::error(int line,
const char* file,
const char* fmt,...) const
{
char buff[1024];
va_list args;
va_start (args, fmt);
vsprintf(buff, fmt, args);
va_end (args);
if ( line >= 0 ) {
*outStream << "ERROR: " << buff << writePosition(line,file) << "" << std::endl;
}
else {
*outStream << "ERROR: " << buff << std::endl;
}
// call abort functions
std::list<std::pair<AbortFunction,void*> >::const_iterator iter = abortFcts.begin();
for (; iter != abortFcts.end(); iter++) {
AbortFunction fct = (*iter).first;
void * data = (*iter).second;
fct(data);
}
abort();
}
// -------------------------------------------------------------------
string MAdMsg::writePosition(int line, const char* file) const
{
stringstream ss;
string iStr; ss << line; ss >> iStr;
return " (line " + iStr + " in file \'" + file + "\')";
}
// -------------------------------------------------------------------
}
|