[go: up one dir, main page]

Menu

[r40]: / src / message.cpp  Maximize  Restore  History

Download this file

140 lines (125 with data), 4.3 kB

  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
128
129
130
131
132
133
134
135
136
137
138
139
/***************************************************************************
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()