/***************************************************************************
message.cpp - description
-------------------
begin : Wed Sep 15 2004
copyright : (C) 2004 by Jan Rheinlaender
email : jrheinlaender@users.sourceforge.net
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
//#include "../config/config.h" // *** added in 1.3.1
#include <sstream>
#include "message.h"
bool message_init::called = false;
message_init message_init::message_initializer;
message_init::message_init() {
if (called) {
//std::cerr << "Attempt to call message::init() more than one time!" << std::endl;
return;
} else
called = true;
message::init();
}
// *** Moved definition of message streams to main.cpp in 1.3.1
message::message(const message_type t, const int l) {
mode = m_stdc;
type = t;
level = l;
switch (type) {
case t_msg_error: { strm = &std::cerr; break; }
case t_msg_warn: { strm = &std::cout; break; }
case t_msg_info: { strm = &std::cout; break; }
//case t_msg_null: { strm = &devnull; break; } *** removed in 1.3.1
default: strm = NULL;
}
} // message::message()
message::message(std::ostream& of, const message_type t, const int l) {
mode = m_ostream;
type = t;
level = l;
strm = &of;
} // message::message()
//CONSTRUCTOR
message::~message() {
if ((mode = m_func) && (strm != NULL)) ;
//delete strm;
}
void message::setlevel(const int l) {
level = l;
} // message::setlevel()
// Helper method *** added in 1.3.1
inline const std::string printtype(const message_type t) {
switch (t) {
case t_msg_error: return std::string("Error");
case t_msg_warn: return std::string("Warning");
case t_msg_info: return std::string("Information");
default:
return std::string("");
}
}
message &message::operator<<(const char *cp) {
if (strm != NULL) (*strm) << cp;
return *this;
}
/// Print an unsigned int on the stream
message &message::operator<<(const unsigned int i) {
if (strm != NULL) (*strm) << i;
return *this;
}
/// Print a long unsigned int on the stream
message &message::operator<<(const long unsigned int i) {
if (strm != NULL) (*strm) << i;
return *this;
}
/// Print a signed int on the stream
message &message::operator<<(const int i) {
if (strm != NULL) (*strm) << i;
return *this;
}
/// Print a long int on the stream
message &message::operator<<(const long int i) {
if (strm != NULL) (*strm) << i;
return *this;
}
/// Print a double on the stream
message &message::operator<<(const double d) {
if (strm != NULL) (*strm) << d;
return *this;
}
/// Print a string on the stream
message &message::operator<<(const std::string &s) {
if (strm != NULL) (*strm) << s;
return *this;
}
message &message::operator<<(manip_type m) {
switch (m) {
case endline: {
if ((mode == m_stdc) || (mode == m_ostream)) {
if (strm != NULL) (*strm) << std::endl;
} /*else if (mode == m_func) {
(OUTPUTF)(printtype(type), ((std::ostringstream*)strm)->str());
((std::ostringstream*)strm)->str(std::string(""));
}*/
break;
}
case endstring: {
if ((mode == m_stdc) || (mode == m_ostream)) {
if (strm != NULL) (*strm) << std::ends;
} /*else if (mode == m_func) {
(OUTPUTF)(printtype(type), ((std::ostringstream*)strm)->str());
((std::ostringstream*)strm)->str(std::string(""));
} */
break;
}
}
return *this;
} // messsage::operator<<
void message::init() {
// devnull.open("/dev/null"); *** removed in 1.3.1
} // message::init()