1999-10-07 18:44:17 +00:00
|
|
|
|
// -*- C++ -*-
|
2003-08-23 00:17:00 +00:00
|
|
|
|
/**
|
|
|
|
|
* \file debug.h
|
2007-05-28 22:27:45 +00:00
|
|
|
|
*
|
2006-11-14 16:46:06 +00:00
|
|
|
|
* FIXME: It would be nice if, in lyx::use_gui mode, instead of
|
|
|
|
|
* outputting to the console, we would pipe all messages onto a file
|
|
|
|
|
* and visualise the contents dynamically in a Qt window if needed.
|
|
|
|
|
*
|
2003-08-23 00:17:00 +00:00
|
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
|
* Licence details can be found in the file COPYING.
|
2002-03-21 17:27:08 +00:00
|
|
|
|
*
|
2003-08-23 00:17:00 +00:00
|
|
|
|
* \author Lars Gullik Bj<EFBFBD>nnes
|
|
|
|
|
* \author Jean-Marc Lasgouttes
|
2002-03-21 17:27:08 +00:00
|
|
|
|
*
|
2003-08-23 00:17:00 +00:00
|
|
|
|
* Full author contact details are available in file CREDITS.
|
|
|
|
|
*/
|
1999-10-07 18:44:17 +00:00
|
|
|
|
|
|
|
|
|
#ifndef LYXDEBUG_H
|
|
|
|
|
#define LYXDEBUG_H
|
|
|
|
|
|
2007-11-14 21:57:43 +00:00
|
|
|
|
#include "support/strfwd.h"
|
1999-10-07 18:44:17 +00:00
|
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
|
|
2007-11-28 22:12:03 +00:00
|
|
|
|
namespace std {
|
|
|
|
|
|
|
|
|
|
class ios_base;
|
|
|
|
|
|
|
|
|
|
template<typename CharT, typename Traits> class basic_streambuf;
|
|
|
|
|
typedef basic_streambuf<char, char_traits<char> > streambuf;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
|
namespace lyx {
|
|
|
|
|
|
2007-11-28 22:12:03 +00:00
|
|
|
|
/// This is all the different debug levels that we have.
|
|
|
|
|
namespace Debug {
|
1999-10-07 18:44:17 +00:00
|
|
|
|
///
|
2007-11-28 22:12:03 +00:00
|
|
|
|
enum Type {
|
1999-10-07 18:44:17 +00:00
|
|
|
|
///
|
|
|
|
|
NONE = 0,
|
|
|
|
|
///
|
|
|
|
|
INFO = (1 << 0), // 1
|
|
|
|
|
///
|
|
|
|
|
INIT = (1 << 1), // 2
|
|
|
|
|
///
|
|
|
|
|
KEY = (1 << 2), // 4
|
|
|
|
|
///
|
2000-07-24 13:53:19 +00:00
|
|
|
|
GUI = (1 << 3), // 8
|
1999-10-07 18:44:17 +00:00
|
|
|
|
///
|
|
|
|
|
PARSER = (1 << 4), // 16
|
|
|
|
|
///
|
|
|
|
|
LYXRC = (1 << 5), // 32
|
|
|
|
|
///
|
|
|
|
|
KBMAP = (1 << 6), // 64
|
|
|
|
|
///
|
|
|
|
|
LATEX = (1 << 7), // 128
|
|
|
|
|
///
|
|
|
|
|
MATHED = (1 << 8), // 256 // Alejandro, please use this.
|
|
|
|
|
///
|
|
|
|
|
FONT = (1 << 9), // 512
|
|
|
|
|
///
|
|
|
|
|
TCLASS = (1 << 10), // 1024
|
|
|
|
|
///
|
|
|
|
|
LYXVC = (1 << 11), // 2048
|
|
|
|
|
///
|
|
|
|
|
LYXSERVER = (1 << 12), // 4096
|
|
|
|
|
///
|
1999-11-25 17:29:19 +00:00
|
|
|
|
ROFF = (1 << 13), // 8192
|
|
|
|
|
///
|
2000-01-06 02:44:26 +00:00
|
|
|
|
ACTION = (1 << 14), // 16384
|
|
|
|
|
///
|
2000-01-25 12:35:27 +00:00
|
|
|
|
LYXLEX = (1 << 15),
|
|
|
|
|
///
|
2000-04-19 14:42:19 +00:00
|
|
|
|
DEPEND = (1 << 16),
|
|
|
|
|
///
|
2000-11-14 02:01:57 +00:00
|
|
|
|
INSETS = (1 << 17),
|
|
|
|
|
///
|
2001-11-09 13:44:48 +00:00
|
|
|
|
FILES = (1 << 18),
|
|
|
|
|
///
|
2001-11-28 16:09:25 +00:00
|
|
|
|
WORKAREA = (1 << 19),
|
|
|
|
|
///
|
2002-02-16 12:33:19 +00:00
|
|
|
|
INSETTEXT = (1 << 20),
|
|
|
|
|
///
|
2003-02-08 19:18:01 +00:00
|
|
|
|
GRAPHICS = (1 << 21),
|
|
|
|
|
/// change tracking
|
2003-09-04 17:01:00 +00:00
|
|
|
|
CHANGES = (1 << 22),
|
|
|
|
|
///
|
2003-09-26 14:27:20 +00:00
|
|
|
|
EXTERNAL = (1 << 23),
|
|
|
|
|
///
|
2006-03-10 16:10:35 +00:00
|
|
|
|
PAINTING = (1 << 24),
|
|
|
|
|
///
|
2004-06-18 13:31:55 +00:00
|
|
|
|
DEBUG = (1 << 31),
|
|
|
|
|
///
|
|
|
|
|
ANY = 0xffffffff
|
1999-10-07 18:44:17 +00:00
|
|
|
|
};
|
2003-09-26 14:27:20 +00:00
|
|
|
|
|
1999-10-07 18:44:17 +00:00
|
|
|
|
/** A function to convert symbolic string names on debug levels
|
|
|
|
|
to their numerical value.
|
|
|
|
|
*/
|
2007-11-28 22:12:03 +00:00
|
|
|
|
Type value(std::string const & val);
|
1999-12-13 15:31:52 +00:00
|
|
|
|
|
2002-03-21 17:27:08 +00:00
|
|
|
|
/** Display the tags and descriptions of the current debug level
|
|
|
|
|
of ds
|
1999-12-13 15:31:52 +00:00
|
|
|
|
*/
|
2007-11-28 22:12:03 +00:00
|
|
|
|
void showLevel(std::ostream & os, Type level);
|
1999-12-13 15:31:52 +00:00
|
|
|
|
|
|
|
|
|
/** show all the possible tags that can be used for debugging */
|
2007-11-28 22:12:03 +00:00
|
|
|
|
void showTags(std::ostream & os);
|
1999-12-13 15:31:52 +00:00
|
|
|
|
|
2007-11-28 22:12:03 +00:00
|
|
|
|
} // namespace Debug
|
1999-12-13 21:59:26 +00:00
|
|
|
|
|
2000-07-15 23:51:46 +00:00
|
|
|
|
|
2007-11-28 22:12:03 +00:00
|
|
|
|
inline void operator|=(Debug::Type & d1, Debug::Type d2)
|
1999-11-04 01:40:20 +00:00
|
|
|
|
{
|
2007-11-28 22:12:03 +00:00
|
|
|
|
d1 = static_cast<Debug::Type>(d1 | d2);
|
1999-11-04 01:40:20 +00:00
|
|
|
|
}
|
1999-10-07 18:44:17 +00:00
|
|
|
|
|
|
|
|
|
|
2007-11-28 22:12:03 +00:00
|
|
|
|
class LyXErr
|
|
|
|
|
{
|
|
|
|
|
public:
|
2007-12-08 15:02:34 +00:00
|
|
|
|
LyXErr(): enabled_(true) {}
|
2007-11-28 22:12:03 +00:00
|
|
|
|
/// Disable the stream completely
|
|
|
|
|
void disable();
|
|
|
|
|
/// Enable the stream after a possible call of disable()
|
|
|
|
|
void enable();
|
2007-12-08 15:02:34 +00:00
|
|
|
|
///
|
|
|
|
|
bool enabled() const { return enabled_; }
|
2007-11-28 22:12:03 +00:00
|
|
|
|
/// Returns true if t is part of the current debug level.
|
|
|
|
|
bool debugging(Debug::Type t = Debug::ANY) const;
|
|
|
|
|
/// Ends output
|
|
|
|
|
void endl();
|
|
|
|
|
/// Sets stream
|
|
|
|
|
void setStream(std::ostream & os) { stream_ = &os; }
|
|
|
|
|
/// Sets stream
|
|
|
|
|
std::ostream & stream() { return *stream_; }
|
|
|
|
|
/// Sets the debug level to t.
|
|
|
|
|
void level(Debug::Type t) { dt = t; }
|
|
|
|
|
/// Returns the current debug level.
|
|
|
|
|
Debug::Type level() const { return dt; }
|
|
|
|
|
/// Returns stream
|
|
|
|
|
operator std::ostream &() { return *stream_; }
|
|
|
|
|
private:
|
|
|
|
|
/// The current debug level
|
|
|
|
|
Debug::Type dt;
|
|
|
|
|
/// Is the stream enabled?
|
|
|
|
|
bool enabled_;
|
|
|
|
|
/// The real stream
|
|
|
|
|
std::ostream * stream_;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
namespace support { class FileName; }
|
|
|
|
|
|
|
|
|
|
LyXErr & operator<<(LyXErr &, void const *);
|
|
|
|
|
LyXErr & operator<<(LyXErr &, char const *);
|
|
|
|
|
LyXErr & operator<<(LyXErr &, char);
|
|
|
|
|
LyXErr & operator<<(LyXErr &, int);
|
|
|
|
|
LyXErr & operator<<(LyXErr &, unsigned int);
|
|
|
|
|
LyXErr & operator<<(LyXErr &, long);
|
|
|
|
|
LyXErr & operator<<(LyXErr &, unsigned long);
|
|
|
|
|
LyXErr & operator<<(LyXErr &, double);
|
|
|
|
|
LyXErr & operator<<(LyXErr &, std::string const &);
|
|
|
|
|
LyXErr & operator<<(LyXErr &, docstring const &);
|
|
|
|
|
LyXErr & operator<<(LyXErr &, support::FileName const &);
|
|
|
|
|
LyXErr & operator<<(LyXErr &, std::ostream &(*)(std::ostream &));
|
|
|
|
|
LyXErr & operator<<(LyXErr &, std::ios_base &(*)(std::ios_base &));
|
1999-10-13 10:34:07 +00:00
|
|
|
|
|
2003-09-26 14:27:20 +00:00
|
|
|
|
extern LyXErr lyxerr;
|
1999-10-07 18:44:17 +00:00
|
|
|
|
|
2007-11-28 22:12:03 +00:00
|
|
|
|
} // namespace lyx
|
|
|
|
|
|
2007-11-30 18:48:35 +00:00
|
|
|
|
#if USE_BOOST_CURRENT_FUNCTION
|
|
|
|
|
# include <boost/current_function.hpp>
|
|
|
|
|
# define CURRENT_POSITION BOOST_CURRENT_FUNCTION ": "
|
2007-11-29 21:10:35 +00:00
|
|
|
|
#else
|
2007-11-30 18:48:35 +00:00
|
|
|
|
# define CURRENT_POSITION __FILE__ << "(" << __LINE__ << "): "
|
2007-11-29 21:10:35 +00:00
|
|
|
|
#endif
|
2007-11-28 22:12:03 +00:00
|
|
|
|
|
2007-11-15 20:04:51 +00:00
|
|
|
|
#define LYXERR(type, msg) \
|
|
|
|
|
do { \
|
2007-11-28 22:12:03 +00:00
|
|
|
|
if (!lyx::lyxerr.debugging(type)) {} \
|
2007-11-30 18:48:35 +00:00
|
|
|
|
else { lyx::lyxerr << CURRENT_POSITION << msg; lyx::lyxerr.endl(); } \
|
2007-11-15 20:04:51 +00:00
|
|
|
|
} while (0)
|
2007-04-01 10:09:49 +00:00
|
|
|
|
|
2007-12-11 20:28:00 +00:00
|
|
|
|
#define LYXERR0(msg) \
|
|
|
|
|
do { \
|
|
|
|
|
lyx::lyxerr << CURRENT_POSITION << msg; lyx::lyxerr.endl(); \
|
|
|
|
|
} while (0)
|
|
|
|
|
|
2007-11-27 20:37:08 +00:00
|
|
|
|
|
1999-10-07 18:44:17 +00:00
|
|
|
|
#endif
|