[go: up one dir, main page]

Menu

[r999]: / mia2 / mia / core / msgstream.cc  Maximize  Restore  History

Download this file

122 lines (100 with data), 3.0 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
/* -*- mona-c++ -*-
*
* Copyright (c) Leipzig, Madrid 2004 - 2009
* Max-Planck-Institute for Human Cognitive and Brain Science
* Max-Planck-Institute for Evolutionary Anthropology
* BIT, ETSI Telecomunicacion, UPM
*
* 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.
*
* This program 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 PUcRPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU 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: miaIOStream.cc 932 2006-07-03 19:17:23Z write1 $
/*! \brief A verbose output stream
\file miaIOStream.cc
*/
#include <miaconfig.h>
#include <iostream>
#include <fstream>
#include <mia/core/msgstream.hh>
NS_MIA_BEGIN
const TDictMap<vstream::Level>::Table verbose_dict[] = {
{"trace", vstream::ml_trace},
{"debug", vstream::ml_debug},
{"message", vstream::ml_message},
{"warning", vstream::ml_warning},
{"error", vstream::ml_error},
{"fail", vstream::ml_fail},
{"fatal", vstream::ml_fatal},
{NULL, vstream::ml_undefined},
};
EXPORT_CORE const TDictMap<vstream::Level> g_verbose_dict(verbose_dict);
vstream::vstream(std::ostream& output, Level l):
_M_output(&output),
_M_output_level(l),
_M_message_level(ml_fatal)
{
}
void vstream::set_verbosity(Level l)
{
_M_output_level = l;
}
vstream& vstream::instance()
{
static vstream verb(_M_output_target ? *_M_output_target :
std::cerr, vstream::ml_fail);
return verb;
}
std::ostream *vstream::_M_output_target = 0;
void vstream::set_output_target(std::ostream* os)
{
_M_output_target = os;
}
vstream& vstream::operator << (Level l)
{
_M_message_level = l;
if (_M_message_level >= _M_output_level) {
switch (_M_message_level) {
case ml_debug: *_M_output << "DEBUG:"; break;
case ml_message:break;
case ml_warning:*_M_output << "WARNING:"; break;
case ml_fail: *_M_output << "FAILED:"; break;
case ml_error: *_M_output << "ERROR:"; break;
case ml_fatal: *_M_output << "FATAL:"; break;
default: *_M_output << "TRACE:";
}
}
return *this;
}
std::ostream& vstream::set_stream(std::ostream& os)
{
std::ostream& old_os = *_M_output;
_M_output = &os;
return old_os;
}
vstream & vstream::operator<<(std::ostream& (*f)(std::ostream&))
{
if (_M_message_level >= _M_output_level) {
*_M_output << f;
}
return *this;
}
void set_verbose(bool verbose)
{
vstream::instance().set_verbosity(verbose ? vstream::ml_message : vstream::ml_error);
}
#ifndef NDEBUG
size_t CTrace::_M_depth = 0;
#endif
NS_MIA_END